Exemplo n.º 1
0
 static function deleteGroup($group = null)
 {
     $dao = new CRM_Core_DAO_Cache();
     if (!empty($group)) {
         $dao->group_name = $group;
     }
     $dao->delete();
     // also reset ACL Cache
     require_once 'CRM/ACL/BAO/Cache.php';
     CRM_ACL_BAO_Cache::resetCache();
 }
Exemplo n.º 2
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     CRM_ACL_BAO_Cache::resetCache();
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_ACL_BAO_EntityRole::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Entity Role has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $params = $this->controller->exportValues($this->_name);
         if ($this->_id) {
             $params['id'] = $this->_id;
         }
         $params['entity_table'] = 'civicrm_group';
         CRM_ACL_BAO_EntityRole::create($params);
     }
 }
Exemplo n.º 3
0
 /**
  * Function to delete ACL records
  *
  * @param  int  $aclId     ID of the ACL record to be deleted.
  *
  * @access public
  * @static
  */
 static function del($aclId)
 {
     // delete all entries from the acl cache
     CRM_ACL_BAO_Cache::resetCache();
     $acl = new CRM_ACL_DAO_ACL();
     $acl->id = $aclId;
     $acl->delete();
 }
Exemplo n.º 4
0
 /**
  * Clear the contact cache so things are kosher. We started off being super aggressive with clearing
  * caches, but are backing off from this with every release. Compromise between ease of coding versus
  * performance versus being accurate at that very instant
  *
  * @param $contactID
  *   The contactID that was edited / deleted.
  */
 public static function clearContactCaches($contactID = NULL)
 {
     // clear acl cache if any.
     CRM_ACL_BAO_Cache::resetCache();
     if (empty($contactID)) {
         // also clear prev/next dedupe cache - if no contactID passed in
         CRM_Core_BAO_PrevNextCache::deleteItem();
     }
     // reset the group contact cache for this group
     CRM_Contact_BAO_GroupContactCache::remove();
 }
Exemplo n.º 5
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  */
 public function run()
 {
     // get the requested action
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     // assign vars to templates
     $this->assign('action', $action);
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
     // set breadcrumb to append to admin/access
     $breadCrumb = array(array('title' => ts('Access Control'), 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1')));
     CRM_Utils_System::appendBreadCrumb($breadCrumb);
     CRM_Utils_System::setTitle(ts('Assign Users to Roles'));
     // what action to take ?
     if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
         $this->edit($action, $id);
     }
     // reset cache if enabled/disabled
     if ($action & (CRM_Core_Action::DISABLE | CRM_Core_Action::ENABLE)) {
         CRM_ACL_BAO_Cache::resetCache();
     }
     // finally browse the acl's
     if ($action & CRM_Core_Action::BROWSE) {
     }
     // parent run
     return parent::run();
 }
Exemplo n.º 6
0
 /**
  * Given an array of contact ids, remove all the contacts from the group 
  *
  * @param array  $contactIds (reference ) the array of contact ids to be removed
  * @param int    $groupId    the id of the group
  *
  * @return array             (total, removed, notRemoved) count of contacts removed to group
  * @access public
  * @static
  */
 static function removeContactsFromGroup(&$contactIds, $groupId, $method = 'Admin', $status = 'Removed', $tracking = null)
 {
     if (!is_array($contactIds)) {
         return array(0, 0, 0);
     }
     require_once 'CRM/Utils/Hook.php';
     if ($status == 'Removed') {
         $op = 'delete';
     } else {
         $op = 'edit';
     }
     CRM_Utils_Hook::pre($op, 'GroupContact', $groupId, $contactIds);
     $date = date('YmdHis');
     $numContactsRemoved = 0;
     $numContactsNotRemoved = 0;
     require_once "CRM/Contact/DAO/Group.php";
     $group =& new CRM_Contact_DAO_Group();
     $group->id = $groupId;
     $group->find(true);
     foreach ($contactIds as $contactId) {
         $groupContact =& new CRM_Contact_DAO_GroupContact();
         $groupContact->group_id = $groupId;
         $groupContact->contact_id = $contactId;
         // check if the selected contact id already a member, or if this is
         // an opt-out of a smart group.
         // if not a member remove to groupContact else keep the count of contacts that are not removed
         if ($groupContact->find(true) || $group->saved_search_id) {
             // remove the contact from the group
             $numContactsRemoved++;
         } else {
             $numContactsNotRemoved++;
         }
         //now we grant the negative membership to contact if not member. CRM-3711
         $historyParams = array('group_id' => $groupId, 'contact_id' => $contactId, 'status' => $status, 'method' => $method, 'date' => $date, 'tracking' => $tracking);
         CRM_Contact_BAO_SubscriptionHistory::create($historyParams);
         $groupContact->status = $status;
         $groupContact->save();
     }
     // also reset the acl cache
     require_once 'CRM/ACL/BAO/Cache.php';
     CRM_ACL_BAO_Cache::resetCache();
     // reset the group contact cache for all group(s)
     // if this group is being used as a smart group
     require_once 'CRM/Contact/BAO/GroupContactCache.php';
     CRM_Contact_BAO_GroupContactCache::remove();
     CRM_Utils_Hook::post($op, 'GroupContact', $groupId, $contactIds);
     return array(count($contactIds), $numContactsRemoved, $numContactsNotRemoved);
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     CRM_ACL_BAO_Cache::resetCache();
     $params = $this->controller->exportValues($this->_name);
     if ($this->_id || $this->_id === '0') {
         $query = "\nDELETE\n  FROM civicrm_acl\n WHERE entity_id = %1\n   AND ( object_table NOT IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group' ) )\n";
         $deleteParams = array(1 => array($this->_id, 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($query, $deleteParams);
         if ($this->_action & CRM_Core_Action::DELETE) {
             CRM_Core_Session::setStatus(ts('Selected ACL has been deleted.'));
             return;
         }
     }
     $params['operation'] = 'All';
     $params['deny'] = 0;
     $params['is_active'] = 1;
     $params['entity_table'] = 'civicrm_acl_role';
     $params['name'] = 'Core ACL';
     foreach ($params['object_table'] as $object_table => $value) {
         if ($value) {
             $newParams = $params;
             unset($newParams['object_table']);
             $newParams['object_table'] = $object_table;
             CRM_ACL_BAO_ACL::create($newParams);
         }
     }
 }
Exemplo n.º 8
0
 static function clearContactCaches()
 {
     // clear acl cache if any.
     CRM_ACL_BAO_Cache::resetCache();
     // also clear prev/next dedupe cache
     CRM_Core_BAO_PrevNextCache::deleteItem();
     // reset the group contact cache for this group
     CRM_Contact_BAO_GroupContactCache::remove();
 }
Exemplo n.º 9
0
 /**
  * Clear the contact cache so things are kosher. We started off being super aggressive with clearing
  * caches, but are backing off from this with every release. Compromise between ease of coding versus
  * performance versus being accurate at that very instant
  *
  * @param $contactID
  *   The contactID that was edited / deleted.
  */
 public static function clearContactCaches($contactID = NULL)
 {
     // clear acl cache if any.
     CRM_ACL_BAO_Cache::resetCache();
     if (empty($contactID)) {
         // also clear prev/next dedupe cache - if no contactID passed in
         CRM_Core_BAO_PrevNextCache::deleteItem();
     }
     CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
 }
Exemplo n.º 10
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     require_once 'CRM/ACL/BAO/Cache.php';
     CRM_ACL_BAO_Cache::resetCache();
     require_once 'CRM/ACL/BAO/ACL.php';
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_ACL_BAO_ACL::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected ACL has been deleted.'));
     } else {
         $params = $this->controller->exportValues($this->_name);
         $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
         $params['deny'] = 0;
         $params['entity_table'] = 'civicrm_acl_role';
         // Figure out which type of object we're permissioning on and set object_table and object_id.
         switch ($params['object_type']) {
             case 1:
                 $params['object_table'] = 'civicrm_saved_search';
                 $params['object_id'] = $params['group_id'];
                 break;
             case 2:
                 $params['object_table'] = 'civicrm_uf_group';
                 $params['object_id'] = $params['uf_group_id'];
                 break;
             case 3:
                 $params['object_table'] = 'civicrm_custom_group';
                 $params['object_id'] = $params['custom_group_id'];
                 break;
             case 4:
                 $params['object_table'] = 'civicrm_event';
                 $params['object_id'] = $params['event_id'];
                 break;
         }
         if ($this->_id) {
             $params['id'] = $this->_id;
         }
         CRM_ACL_BAO_ACL::create($params);
     }
 }
Exemplo n.º 11
0
 /**
  * Delete all the cache elements that belong to a group OR delete the entire cache if group is not specified.
  *
  * @param string $group
  *   The group name of the entries to be deleted.
  * @param string $path
  *   Path of the item that needs to be deleted.
  * @param bool $clearAll clear all caches
  */
 public static function deleteGroup($group = NULL, $path = NULL, $clearAll = TRUE)
 {
     $dao = new CRM_Core_DAO_Cache();
     if (!empty($group)) {
         $dao->group_name = $group;
     }
     if (!empty($path)) {
         $dao->path = $path;
     }
     $dao->delete();
     if ($clearAll) {
         // also reset ACL Cache
         CRM_ACL_BAO_Cache::resetCache();
         // also reset memory cache if any
         CRM_Utils_System::flushCache();
     }
 }
Exemplo n.º 12
0
 /**
  * Delete all the cache elements that belong to a group OR delete the entire cache if group is not specified.
  *
  * @param string $group
  *   The group name of the entries to be deleted.
  * @param string $path
  *   Path of the item that needs to be deleted.
  * @param bool $clearAll clear all caches
  */
 public static function deleteGroup($group = NULL, $path = NULL, $clearAll = TRUE)
 {
     $table = self::getTableName();
     $where = self::whereCache($group, $path, NULL);
     CRM_Core_DAO::executeQuery("DELETE FROM {$table} WHERE {$where}");
     if ($clearAll) {
         // also reset ACL Cache
         CRM_ACL_BAO_Cache::resetCache();
         // also reset memory cache if any
         CRM_Utils_System::flushCache();
     }
 }
Exemplo n.º 13
0
 /**
  * Given an array of contact ids, remove all the contacts from the group
  *
  * @param array $contactIds
  *   (reference ) the array of contact ids to be removed.
  * @param int $groupId
  *   The id of the group.
  *
  * @param string $method
  * @param string $status
  * @param NULL $tracking
  *
  * @return array
  *   (total, removed, notRemoved) count of contacts removed to group
  */
 public static function removeContactsFromGroup(&$contactIds, $groupId, $method = 'Admin', $status = 'Removed', $tracking = NULL)
 {
     if (!is_array($contactIds)) {
         return array(0, 0, 0);
     }
     if ($status == 'Removed' || $status == 'Deleted') {
         $op = 'delete';
     } else {
         $op = 'edit';
     }
     CRM_Utils_Hook::pre($op, 'GroupContact', $groupId, $contactIds);
     $date = date('YmdHis');
     $numContactsRemoved = 0;
     $numContactsNotRemoved = 0;
     $group = new CRM_Contact_DAO_Group();
     $group->id = $groupId;
     $group->find(TRUE);
     foreach ($contactIds as $contactId) {
         if ($status == 'Deleted') {
             $query = "DELETE FROM civicrm_group_contact WHERE contact_id={$contactId} AND group_id={$groupId}";
             $dao = CRM_Core_DAO::executeQuery($query);
             $historyParams = array('group_id' => $groupId, 'contact_id' => $contactId, 'status' => $status, 'method' => $method, 'date' => $date, 'tracking' => $tracking);
             CRM_Contact_BAO_SubscriptionHistory::create($historyParams);
         } else {
             $groupContact = new CRM_Contact_DAO_GroupContact();
             $groupContact->group_id = $groupId;
             $groupContact->contact_id = $contactId;
             // check if the selected contact id already a member, or if this is
             // an opt-out of a smart group.
             // if not a member remove to groupContact else keep the count of contacts that are not removed
             if ($groupContact->find(TRUE) || $group->saved_search_id) {
                 // remove the contact from the group
                 $numContactsRemoved++;
             } else {
                 $numContactsNotRemoved++;
             }
             //now we grant the negative membership to contact if not member. CRM-3711
             $historyParams = array('group_id' => $groupId, 'contact_id' => $contactId, 'status' => $status, 'method' => $method, 'date' => $date, 'tracking' => $tracking);
             CRM_Contact_BAO_SubscriptionHistory::create($historyParams);
             $groupContact->status = $status;
             $groupContact->save();
         }
     }
     // also reset the acl cache
     $config = CRM_Core_Config::singleton();
     if (!$config->doNotResetCache) {
         CRM_ACL_BAO_Cache::resetCache();
     }
     // reset the group contact cache for all group(s)
     // if this group is being used as a smart group
     // @todo consider what to do here - it feels like we should either
     // 1) just invalidate the specific group's cache(& perhaps any parents) & let cron do it's thing or
     // possibly clear this specific groups cache, or just call opportunisticCacheFlush() - which would have the
     // same effect as the remove call. The reservation about that is that it is no more aggressive for the group that
     // we know is altered than for all the others, or perhaps, more the point with it's parents & groups that use it in
     // their criteria.
     CRM_Contact_BAO_GroupContactCache::remove();
     CRM_Utils_Hook::post($op, 'GroupContact', $groupId, $contactIds);
     return array(count($contactIds), $numContactsRemoved, $numContactsNotRemoved);
 }
Exemplo n.º 14
0
 /**
  * Function to create contact
  * takes an associative array and creates a contact object and all the associated
  * derived objects (i.e. individual, location, email, phone etc)
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array   $params      (reference ) an assoc array of name/value pairs
  * @param boolean $fixAddress  if we need to fix address
  * @param boolean $invokeHooks if we need to invoke hooks
  *
  * @return object CRM_Contact_BAO_Contact object 
  * @access public
  * @static
  */
 static function &create(&$params, $fixAddress = true, $invokeHooks = true)
 {
     $contact = null;
     if (!CRM_Utils_Array::value('contact_type', $params) && !CRM_Utils_Array::value('contact_id', $params)) {
         return $contact;
     }
     $isEdit = true;
     if ($invokeHooks) {
         require_once 'CRM/Utils/Hook.php';
         if (CRM_Utils_Array::value('contact_id', $params)) {
             CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params);
         } else {
             CRM_Utils_Hook::pre('create', $params['contact_type'], null, $params);
             $isEdit = false;
         }
     }
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $contact = self::add($params);
     if (!$contact) {
         // CRM_Core_Error::fatal( ts( 'THe contact was not created, not set up to handle error' ) );
     }
     $params['contact_id'] = $contact->id;
     if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) {
         // in order to make sure that every contact must be added to a group (CRM-4613) -
         require_once 'CRM/Core/BAO/Domain.php';
         $domainGroupID = CRM_Core_BAO_Domain::getGroupId();
         if (CRM_Utils_Array::value('group', $params) && is_array($params['group'])) {
             $grpFlp = array_flip($params['group']);
             if (!array_key_exists(1, $grpFlp)) {
                 $params['group'][$domainGroupID] = 1;
             }
         } else {
             $params['group'] = array($domainGroupID => 1);
         }
     }
     if (array_key_exists('group', $params)) {
         require_once 'CRM/Contact/BAO/GroupContact.php';
         $contactIds = array($params['contact_id']);
         foreach ($params['group'] as $groupId => $flag) {
             if ($flag == 1) {
                 CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
             } else {
                 if ($flag == -1) {
                     CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $groupId);
                 }
             }
         }
     }
     $config = CRM_Core_Config::singleton();
     if (!$config->doNotResetCache) {
         // Note: doNotResetCache flag is currently set by import contact process, since resetting and
         // rebuilding cache could be expensive (for many contacts). We might come out with better
         // approach in future.
         // clear acl cache if any.
         require_once 'CRM/ACL/BAO/Cache.php';
         CRM_ACL_BAO_Cache::resetCache();
     }
     //add location Block data
     $blocks = CRM_Core_BAO_Location::create($params, $fixAddress);
     foreach ($blocks as $name => $value) {
         $contact->{$name} = $value;
     }
     //get userID from session
     $session =& CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     // add notes
     if (CRM_Utils_Array::value('note', $params)) {
         if (is_array($params['note'])) {
             foreach ($params['note'] as $note) {
                 $contactId = $contact->id;
                 if (isset($note['contact_id'])) {
                     $contactId = $note['contact_id'];
                 }
                 //if logged in user, overwrite contactId
                 if ($userID) {
                     $contactId = $userID;
                 }
                 $noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $note['note'], 'subject' => $note['subject'], 'contact_id' => $contactId);
                 CRM_Core_BAO_Note::add($noteParams, CRM_Core_DAO::$_nullArray);
             }
         } else {
             $contactId = $contact->id;
             if (isset($note['contact_id'])) {
                 $contactId = $note['contact_id'];
             }
             //if logged in user, overwrite contactId
             if ($userID) {
                 $contactId = $userID;
             }
             $noteParams = array('entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $params['note'], 'subject' => CRM_Utils_Array::value('subject', $params), 'contact_id' => $contactId);
             CRM_Core_BAO_Note::add($noteParams, CRM_Core_DAO::$_nullArray);
         }
     }
     // update the UF user_unique_id if that has changed
     require_once 'CRM/Core/BAO/UFMatch.php';
     CRM_Core_BAO_UFMatch::updateUFName($contact->id);
     if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
         require_once 'CRM/Core/BAO/CustomValueTable.php';
         CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contact', $contact->id);
     }
     // make a civicrm_subscription_history entry only on contact create (CRM-777)
     if (!CRM_Utils_Array::value('contact_id', $params)) {
         $subscriptionParams = array('contact_id' => $contact->id, 'status' => 'Added', 'method' => 'Admin');
         CRM_Contact_BAO_SubscriptionHistory::create($subscriptionParams);
     }
     $transaction->commit();
     $contact->contact_type_display = $contact->contact_type;
     // reset the group contact cache for this group
     require_once 'CRM/Contact/BAO/GroupContactCache.php';
     CRM_Contact_BAO_GroupContactCache::remove();
     if ($invokeHooks) {
         if ($isEdit) {
             CRM_Utils_Hook::post('edit', $params['contact_type'], $contact->id, $contact);
         } else {
             CRM_Utils_Hook::post('create', $params['contact_type'], $contact->id, $contact);
         }
     }
     // process greetings CRM-4575, cache greetings
     self::processGreetings($contact);
     return $contact;
 }
Exemplo n.º 15
0
 /**
  * Reset the various system caches and some important static variables.
  */
 public static function flushCache()
 {
     // flush out all cache entries so we can reload new data
     // a bit aggressive, but livable for now
     $cache = CRM_Utils_Cache::singleton();
     $cache->flush();
     // also reset the various static memory caches
     // reset the memory or array cache
     CRM_Core_BAO_Cache::deleteGroup('contact fields', NULL, FALSE);
     // reset ACL cache
     CRM_ACL_BAO_Cache::resetCache();
     // reset various static arrays used here
     CRM_Contact_BAO_Contact::$_importableFields = CRM_Contact_BAO_Contact::$_exportableFields = CRM_Contribute_BAO_Contribution::$_importableFields = CRM_Contribute_BAO_Contribution::$_exportableFields = CRM_Pledge_BAO_Pledge::$_exportableFields = CRM_Contribute_BAO_Query::$_contributionFields = CRM_Core_BAO_CustomField::$_importFields = CRM_Core_BAO_Cache::$_cache = CRM_Core_DAO::$_dbColumnValueCache = NULL;
     CRM_Core_OptionGroup::flushAll();
     CRM_Utils_PseudoConstant::flushAll();
 }
Exemplo n.º 16
0
 /**
  * Set up an acl allowing contact to see 2 specified groups
  *  - $this->_permissionedGroup & $this->_permissionedDisabledGroup
  *
  *  You need to have pre-created these groups & created the user e.g
  *  $this->createLoggedInUser();
  *   $this->_permissionedDisabledGroup = $this->groupCreate(array('title' => 'pick-me-disabled', 'is_active' => 0, 'name' => 'pick-me-disabled'));
  *   $this->_permissionedGroup = $this->groupCreate(array('title' => 'pick-me-active', 'is_active' => 1, 'name' => 'pick-me-active'));
  *
  * @param bool $isProfile
  */
 public function setupACL($isProfile = FALSE)
 {
     global $_REQUEST;
     $_REQUEST = $this->_params;
     CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
     $optionGroupID = $this->callAPISuccessGetValue('option_group', array('return' => 'id', 'name' => 'acl_role'));
     $optionValue = $this->callAPISuccess('option_value', 'create', array('option_group_id' => $optionGroupID, 'label' => 'pick me', 'value' => 55));
     CRM_Core_DAO::executeQuery("\n      TRUNCATE civicrm_acl_cache\n    ");
     CRM_Core_DAO::executeQuery("\n      TRUNCATE civicrm_acl_contact_cache\n    ");
     CRM_Core_DAO::executeQuery("\n    INSERT INTO civicrm_acl_entity_role (\n    `acl_role_id`, `entity_table`, `entity_id`, `is_active`\n    ) VALUES (55, 'civicrm_group', {$this->_permissionedGroup}, 1);\n    ");
     if ($isProfile) {
         CRM_Core_DAO::executeQuery("\n      INSERT INTO civicrm_acl (\n      `name`, `entity_table`, `entity_id`, `operation`, `object_table`, `object_id`, `is_active`\n      )\n      VALUES (\n      'view picked', 'civicrm_acl_role', 55, 'Edit', 'civicrm_uf_group', 0, 1\n      );\n      ");
     } else {
         CRM_Core_DAO::executeQuery("\n      INSERT INTO civicrm_acl (\n      `name`, `entity_table`, `entity_id`, `operation`, `object_table`, `object_id`, `is_active`\n      )\n      VALUES (\n      'view picked', 'civicrm_group', {$this->_permissionedGroup} , 'Edit', 'civicrm_saved_search', {$this->_permissionedGroup}, 1\n      );\n      ");
         CRM_Core_DAO::executeQuery("\n      INSERT INTO civicrm_acl (\n      `name`, `entity_table`, `entity_id`, `operation`, `object_table`, `object_id`, `is_active`\n      )\n      VALUES (\n      'view picked', 'civicrm_group',  {$this->_permissionedGroup}, 'Edit', 'civicrm_saved_search', {$this->_permissionedDisabledGroup}, 1\n      );\n      ");
     }
     $this->_loggedInUser = CRM_Core_Session::singleton()->get('userID');
     $this->callAPISuccess('group_contact', 'create', array('group_id' => $this->_permissionedGroup, 'contact_id' => $this->_loggedInUser));
     if (!$isProfile) {
         //flush cache
         CRM_ACL_BAO_Cache::resetCache();
         CRM_Contact_BAO_Group::getPermissionClause(TRUE);
         CRM_ACL_API::groupPermission('whatever', 9999, NULL, 'civicrm_saved_search', NULL, NULL, TRUE);
     }
 }
Exemplo n.º 17
0
 /**
  * Given an array of contact ids, remove all the contacts from the group
  *
  * @param array $contactIds
  *   (reference ) the array of contact ids to be removed.
  * @param int $groupId
  *   The id of the group.
  *
  * @param string $method
  * @param string $status
  * @param NULL $tracking
  *
  * @return array
  *   (total, removed, notRemoved) count of contacts removed to group
  */
 public static function removeContactsFromGroup(&$contactIds, $groupId, $method = 'Admin', $status = 'Removed', $tracking = NULL)
 {
     if (!is_array($contactIds)) {
         return array(0, 0, 0);
     }
     if ($status == 'Removed' || $status == 'Deleted') {
         $op = 'delete';
     } else {
         $op = 'edit';
     }
     CRM_Utils_Hook::pre($op, 'GroupContact', $groupId, $contactIds);
     $date = date('YmdHis');
     $numContactsRemoved = 0;
     $numContactsNotRemoved = 0;
     $group = new CRM_Contact_DAO_Group();
     $group->id = $groupId;
     $group->find(TRUE);
     foreach ($contactIds as $contactId) {
         if ($status == 'Deleted') {
             $query = "DELETE FROM civicrm_group_contact WHERE contact_id={$contactId} AND group_id={$groupId}";
             $dao = CRM_Core_DAO::executeQuery($query);
             $historyParams = array('group_id' => $groupId, 'contact_id' => $contactId, 'status' => $status, 'method' => $method, 'date' => $date, 'tracking' => $tracking);
             CRM_Contact_BAO_SubscriptionHistory::create($historyParams);
         } else {
             $groupContact = new CRM_Contact_DAO_GroupContact();
             $groupContact->group_id = $groupId;
             $groupContact->contact_id = $contactId;
             // check if the selected contact id already a member, or if this is
             // an opt-out of a smart group.
             // if not a member remove to groupContact else keep the count of contacts that are not removed
             if ($groupContact->find(TRUE) || $group->saved_search_id) {
                 // remove the contact from the group
                 $numContactsRemoved++;
             } else {
                 $numContactsNotRemoved++;
             }
             //now we grant the negative membership to contact if not member. CRM-3711
             $historyParams = array('group_id' => $groupId, 'contact_id' => $contactId, 'status' => $status, 'method' => $method, 'date' => $date, 'tracking' => $tracking);
             CRM_Contact_BAO_SubscriptionHistory::create($historyParams);
             $groupContact->status = $status;
             $groupContact->save();
         }
     }
     // also reset the acl cache
     $config = CRM_Core_Config::singleton();
     if (!$config->doNotResetCache) {
         CRM_ACL_BAO_Cache::resetCache();
     }
     // reset the group contact cache for all group(s)
     // if this group is being used as a smart group
     CRM_Contact_BAO_GroupContactCache::remove();
     CRM_Utils_Hook::post($op, 'GroupContact', $groupId, $contactIds);
     return array(count($contactIds), $numContactsRemoved, $numContactsNotRemoved);
 }
Exemplo n.º 18
0
 /**
  * Function to delete ACL records 
  * 
  * @param  int  $aclId     ID of the ACL record to be deleted.
  * 
  * @access public
  * @static
  */
 static function del($aclId)
 {
     // delete all entries from the acl cache
     require_once 'CRM/ACL/BAO/Cache.php';
     CRM_ACL_BAO_Cache::resetCache();
     $acl = new CRM_ACL_DAO_ACL();
     $acl->id = $aclId;
     $acl->delete();
 }