/** * @param $rev */ public function upgrade_3_2_alpha1($rev) { //CRM-5666 -if user already have 'access CiviCase' //give all new permissions and drop access CiviCase. $config = CRM_Core_Config::singleton(); if ($config->userSystem->is_drupal) { $config->userSystem->replacePermission('access CiviCase', array('access my cases and activities', 'access all cases and activities', 'administer CiviCase')); //insert core acls. $casePermissions = array('delete in CiviCase', 'administer CiviCase', 'access my cases and activities', 'access all cases and activities'); $aclParams = array('name' => 'Core ACL', 'deny' => 0, 'acl_id' => NULL, 'object_id' => NULL, 'acl_table' => NULL, 'entity_id' => 1, 'operation' => 'All', 'is_active' => 1, 'entity_table' => 'civicrm_acl_role'); foreach ($casePermissions as $per) { $aclParams['object_table'] = $per; $acl = new CRM_ACL_DAO_ACL(); $acl->object_table = $per; if (!$acl->find(TRUE)) { $acl->copyValues($aclParams); $acl->save(); } } //drop 'access CiviCase' acl CRM_Core_DAO::executeQuery("DELETE FROM civicrm_acl WHERE object_table = 'access CiviCase'"); } $upgrade = new CRM_Upgrade_Form(); $upgrade->processSQL($rev); }
function upgrade_3_2_alpha1($rev) { //CRM-5666 -if user already have 'access CiviCase' //give all new permissions and drop access CiviCase. $config = CRM_Core_Config::singleton(); if ($config->userFramework == 'Drupal') { db_query("UPDATE {permission} SET perm = REPLACE( perm, 'access CiviCase', 'access my cases and activities, access all cases and activities, administer CiviCase' )"); //insert core acls. $casePermissions = array('delete in CiviCase', 'administer CiviCase', 'access my cases and activities', 'access all cases and activities'); require_once 'CRM/ACL/DAO/ACL.php'; $aclParams = array('name' => 'Core ACL', 'deny' => 0, 'acl_id' => NULL, 'object_id' => NULL, 'acl_table' => NULL, 'entity_id' => 1, 'operation' => 'All', 'is_active' => 1, 'entity_table' => 'civicrm_acl_role'); foreach ($casePermissions as $per) { $aclParams['object_table'] = $per; $acl = new CRM_ACL_DAO_ACL(); $acl->object_table = $per; if (!$acl->find(true)) { $acl->copyValues($aclParams); $acl->save(); } } //drop 'access CiviCase' acl CRM_Core_DAO::executeQuery("DELETE FROM civicrm_acl WHERE object_table = 'access CiviCase'"); } $upgrade =& new CRM_Upgrade_Form(); $upgrade->processSQL($rev); }
/** * Updates contacts affected by the option value passed. * * @param int $optionValueId * The option value id. * @param int $action * The action describing whether prefix/suffix was UPDATED or DELETED. * * @return bool */ public static function updateRecords(&$optionValueId, $action) { //finding group name $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->id = $optionValueId; $optionValue->find(TRUE); $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->id = $optionValue->option_group_id; $optionGroup->find(TRUE); // group name $gName = $optionGroup->name; // value $value = $optionValue->value; // get the proper group name & affected field name // todo: this may no longer be needed for individuals - check inputs $individuals = array('gender' => 'gender_id', 'individual_prefix' => 'prefix_id', 'individual_suffix' => 'suffix_id', 'communication_style' => 'communication_style_id'); $contributions = array('payment_instrument' => 'payment_instrument_id'); $activities = array('activity_type' => 'activity_type_id'); $participant = array('participant_role' => 'role_id'); $eventType = array('event_type' => 'event_type_id'); $aclRole = array('acl_role' => 'acl_role_id'); $all = array_merge($individuals, $contributions, $activities, $participant, $eventType, $aclRole); $fieldName = ''; foreach ($all as $name => $id) { if ($gName == $name) { $fieldName = $id; } } if ($fieldName == '') { return TRUE; } if (array_key_exists($gName, $individuals)) { $contactDAO = new CRM_Contact_DAO_Contact(); $contactDAO->{$fieldName} = $value; $contactDAO->find(); while ($contactDAO->fetch()) { if ($action == CRM_Core_Action::DELETE) { $contact = new CRM_Contact_DAO_Contact(); $contact->id = $contactDAO->id; $contact->find(TRUE); // make sure dates doesn't get reset $contact->birth_date = CRM_Utils_Date::isoToMysql($contact->birth_date); $contact->deceased_date = CRM_Utils_Date::isoToMysql($contact->deceased_date); $contact->{$fieldName} = 'NULL'; $contact->save(); } } return TRUE; } if (array_key_exists($gName, $contributions)) { $contribution = new CRM_Contribute_DAO_Contribution(); $contribution->{$fieldName} = $value; $contribution->find(); while ($contribution->fetch()) { if ($action == CRM_Core_Action::DELETE) { $contribution->{$fieldName} = 'NULL'; $contribution->save(); } } return TRUE; } if (array_key_exists($gName, $activities)) { $activity = new CRM_Activity_DAO_Activity(); $activity->{$fieldName} = $value; $activity->find(); while ($activity->fetch()) { $activity->delete(); } return TRUE; } //delete participant role, type and event type option value if (array_key_exists($gName, $participant)) { $participantValue = new CRM_Event_DAO_Participant(); $participantValue->{$fieldName} = $value; if ($participantValue->find(TRUE)) { return FALSE; } return TRUE; } //delete event type option value if (array_key_exists($gName, $eventType)) { $event = new CRM_Event_DAO_Event(); $event->{$fieldName} = $value; if ($event->find(TRUE)) { return FALSE; } return TRUE; } //delete acl_role option value if (array_key_exists($gName, $aclRole)) { $entityRole = new CRM_ACL_DAO_EntityRole(); $entityRole->{$fieldName} = $value; $aclDAO = new CRM_ACL_DAO_ACL(); $aclDAO->entity_id = $value; if ($entityRole->find(TRUE) || $aclDAO->find(TRUE)) { return FALSE; } return TRUE; } }
/** * 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(); }
/** * adds $value['foo_display'] for each $value['foo'] enum from civicrm_acl * * @param array $values (reference) the array up for enhancing * @return void */ static function addDisplayEnums(&$values) { $enumFields =& CRM_ACL_DAO_ACL::getEnums(); foreach ($enumFields as $enum) { if (isset($values[$enum])) { $values[$enum . '_display'] = CRM_ACL_DAO_ACL::tsEnum($enum, $values[$enum]); } } }
static function updateCiviACL(&$params, $op) { $dao = new CRM_ACL_DAO_ACL(); $dao->object_table = 'civicrm_saved_search'; $dao->object_id = $params['civicrm_group_id']; if ($op == 'delete') { $dao->delete(); return; } $dao->find(TRUE); $dao->entity_table = 'civicrm_acl_role'; $dao->entity_id = $params['acl_role_id']; $dao->operation = 'Edit'; $dao->is_active = TRUE; $dao->save(); $params['acl_id'] = $dao->id; }
/** * Returns the list of fields that can be exported * * @param bool $prefix * * @return array */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['acl'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * 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(); }
/** * Construct an associative array of an ACL rule's properties * * @param * @return array - Assoc. array of the ACL rule's properties * @access public */ public function toArray() { $result = array(); if (!self::$_fieldKeys) { $fields =& CRM_ACL_DAO_ACL::fields(); self::$_fieldKeys = array_keys($fields); } foreach (self::$_fieldKeys as $field) { $result[$field] = $this->{$field}; } return $result; }