コード例 #1
0
ファイル: Cache.php プロジェクト: ksecor/civicrm
 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();
 }
コード例 #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);
     }
 }
コード例 #3
0
ファイル: Cache.php プロジェクト: bhirsch/voipdev
 static function resetCache()
 {
     // reset any static caching
     self::$_cache = null;
     // reset any db caching
     $config =& CRM_Core_Config::singleton();
     $smartGroupCacheTimeout = isset($config->smartGroupCacheTimeout) && is_numeric($config->smartGroupCacheTimeout) ? $config->smartGroupCacheTimeout : 0;
     $query = "\nDELETE FROM civicrm_acl_cache \nWHERE  modified_date IS NULL OR (TIMESTAMPDIFF(MINUTE, modified_date, NOW()) >= {$smartGroupCacheTimeout})\n";
     CRM_Core_DAO::singleValueQuery($query);
     CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache");
 }
コード例 #4
0
 /**
  * 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);
         }
     }
 }
コード例 #5
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);
     }
 }
コード例 #6
0
ファイル: ACL.php プロジェクト: hampelm/Ginsberg-CiviDemo
 /**
  * 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();
 }
コード例 #7
0
ファイル: System.php プロジェクト: rollox/civicrm-core
 /**
  * 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();
 }
コード例 #8
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();
 }
コード例 #9
0
ファイル: EntityRole.php プロジェクト: kidaa30/yes
 /**
  * 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();
 }
コード例 #10
0
ファイル: Cache.php プロジェクト: saurabhbatra96/civicrm-core
 /**
  * Deletes all the cache entries.
  */
 public static function resetCache()
 {
     // reset any static caching
     self::$_cache = NULL;
     // reset any db caching
     $config = CRM_Core_Config::singleton();
     $smartGroupCacheTimeout = CRM_Contact_BAO_GroupContactCache::smartGroupCacheTimeout();
     //make sure to give original timezone settings again.
     $now = CRM_Utils_Date::getUTCTime();
     $query = "\nDELETE\nFROM   civicrm_acl_cache\nWHERE  modified_date IS NULL\n   OR  (TIMESTAMPDIFF(MINUTE, modified_date, {$now}) >= {$smartGroupCacheTimeout})\n";
     CRM_Core_DAO::singleValueQuery($query);
     // CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache"); // No, force-commits transaction
     // CRM_Core_DAO::singleValueQuery("DELETE FROM civicrm_acl_contact_cache"); // Transaction-safe
     if (CRM_Core_Transaction::isActive()) {
         CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, function () {
             CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache");
         });
     } else {
         CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache");
     }
 }
コード例 #11
0
ファイル: Cache.php プロジェクト: nielosz/civicrm-core
 /**
  * Deletes all the cache entries.
  */
 public static function resetCache()
 {
     // reset any static caching
     self::$_cache = NULL;
     $query = "\nDELETE\nFROM   civicrm_acl_cache\nWHERE  modified_date IS NULL\n   OR  (modified_date <= %1)\n";
     $params = array(1 => array(CRM_Contact_BAO_GroupContactCache::getCacheInvalidDateTime(), 'String'));
     CRM_Core_DAO::singleValueQuery($query, $params);
     // CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache"); // No, force-commits transaction
     // CRM_Core_DAO::singleValueQuery("DELETE FROM civicrm_acl_contact_cache"); // Transaction-safe
     if (CRM_Core_Transaction::isActive()) {
         CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, function () {
             CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache");
         });
     } else {
         CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache");
     }
 }
コード例 #12
0
 static function resetCache()
 {
     // reset any static caching
     self::$_cache = NULL;
     // reset any db caching
     $config = CRM_Core_Config::singleton();
     $smartGroupCacheTimeout = isset($config->smartGroupCacheTimeout) && is_numeric($config->smartGroupCacheTimeout) ? $config->smartGroupCacheTimeout : 0;
     //make sure to give original timezone settings again.
     $originalTimezone = date_default_timezone_get();
     date_default_timezone_set('UTC');
     $now = date('YmdHis');
     date_default_timezone_set($originalTimezone);
     $query = "\nDELETE FROM civicrm_acl_cache \nWHERE  modified_date IS NULL OR (TIMESTAMPDIFF(MINUTE, modified_date, {$now}) >= {$smartGroupCacheTimeout})\n";
     CRM_Core_DAO::singleValueQuery($query);
     CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache");
 }
コード例 #13
0
ファイル: Cache.php プロジェクト: kcristiano/civicrm-core
 /**
  * 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();
     }
 }
コード例 #14
0
ファイル: GroupContact.php プロジェクト: nielosz/civicrm-core
 /**
  * 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);
 }
コード例 #15
0
ファイル: Contact.php プロジェクト: bhirsch/voipdev
 /**
  * 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;
 }
コード例 #16
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();
 }
コード例 #17
0
ファイル: GroupContact.php プロジェクト: ksecor/civicrm
 /**
  * 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);
 }
コード例 #18
0
ファイル: ACL.php プロジェクト: ksecor/civicrm
 /**
  * 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);
     }
 }
コード例 #19
0
ファイル: Utils.php プロジェクト: FundingWorks/civicrm-core
 /**
  * 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();
 }
コード例 #20
0
ファイル: Cache.php プロジェクト: hyebahi/civicrm-core
 /**
  * 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();
     }
 }
コード例 #21
0
 /**
  * Process the mapped fields and map it into the uploaded file
  * preview the file and extract some summary statistics
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $importJobParams = array('doGeocodeAddress' => $this->controller->exportValue('DataSource', 'doGeocodeAddress'), 'invalidRowCount' => $this->get('invalidRowCount'), 'conflictRowCount' => $this->get('conflictRowCount'), 'onDuplicate' => $this->get('onDuplicate'), 'dedupe' => $this->get('dedupe'), 'newGroupName' => $this->controller->exportValue($this->_name, 'newGroupName'), 'newGroupDesc' => $this->controller->exportValue($this->_name, 'newGroupDesc'), 'groups' => $this->controller->exportValue($this->_name, 'groups'), 'allGroups' => $this->get('groups'), 'newTagName' => $this->controller->exportValue($this->_name, 'newTagName'), 'newTagDesc' => $this->controller->exportValue($this->_name, 'newTagDesc'), 'tag' => $this->controller->exportValue($this->_name, 'tag'), 'allTags' => $this->get('tag'), 'mapper' => $this->controller->exportValue('MapField', 'mapper'), 'mapFields' => $this->get('fields'), 'contactType' => $this->get('contactType'), 'contactSubType' => $this->get('contactSubType'), 'primaryKeyName' => $this->get('primaryKeyName'), 'statusFieldName' => $this->get('statusFieldName'), 'statusID' => $this->get('statusID'), 'totalRowCount' => $this->get('totalRowCount'));
     $tableName = $this->get('importTableName');
     $importJob = new CRM_Contact_Import_ImportJob($tableName);
     $importJob->setJobParams($importJobParams);
     // If ACL applies to the current user, update cache before running the import.
     if (!CRM_Core_Permission::check('view all contacts')) {
         $session = CRM_Core_Session::singleton();
         $userID = $session->get('userID');
         CRM_ACL_BAO_Cache::updateEntry($userID);
     }
     // run the import
     $importJob->runImport($this);
     // update cache after we done with runImport
     if (!CRM_Core_Permission::check('view all contacts')) {
         CRM_ACL_BAO_Cache::updateEntry($userID);
     }
     // clear all caches
     CRM_Contact_BAO_Contact_Utils::clearContactCaches();
     // add all the necessary variables to the form
     $importJob->setFormVariables($this);
     // check if there is any error occured
     $errorStack = CRM_Core_Error::singleton();
     $errors = $errorStack->getErrors();
     $errorMessage = array();
     if (is_array($errors)) {
         foreach ($errors as $key => $value) {
             $errorMessage[] = $value['message'];
         }
         // there is no fileName since this is a sql import
         // so fudge it
         $config = CRM_Core_Config::singleton();
         $errorFile = $config->uploadDir . "sqlImport.error.log";
         if ($fd = fopen($errorFile, 'w')) {
             fwrite($fd, implode('\\n', $errorMessage));
         }
         fclose($fd);
         $this->set('errorFile', $errorFile);
         $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Contact_Import_Parser';
         $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
         $urlParams = 'type=' . CRM_Import_Parser::CONFLICT . '&parser=CRM_Contact_Import_Parser';
         $this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
         $urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Contact_Import_Parser';
         $this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
     }
     //hack to clean db
     //if job complete drop table.
     $importJob->isComplete(TRUE);
 }
コード例 #22
0
ファイル: Utils.php プロジェクト: kcristiano/civicrm-core
 /**
  * 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();
 }
コード例 #23
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);
 }
コード例 #24
0
ファイル: Cache.php プロジェクト: ksecor/civicrm
 static function resetCache()
 {
     self::$_cache = null;
     $query = "\nDELETE     c \nFROM       civicrm_acl_cache c\nINNER JOIN civicrm_acl       a ON c.acl_id = a.id\n";
     $dao =& CRM_Core_DAO::executeQuery($query);
 }