/** * Get a list of managed relationship-types by searching CiviCase XML files * * @return array * @see CRM_Utils_Hook::managed * @throws CRM_Core_Exception */ public static function createManagedRelationshipTypes(CRM_Case_XMLRepository $xmlRepo, CRM_Core_ManagedEntities $me) { $result = array(); $p = new CRM_Case_XMLProcessor(); $validRelTypes = $p->allRelationshipTypes(); $relTypes = $xmlRepo->getAllDeclaredRelationshipTypes(); foreach ($relTypes as $relType) { $managed = array('module' => 'civicrm', 'name' => "civicase:rel:{$relType}", 'entity' => 'RelationshipType', 'update' => 'never', 'cleanup' => 'unused', 'params' => array('version' => 3, 'name_a_b' => "{$relType} is", 'name_b_a' => $relType, 'label_a_b' => "{$relType} is", 'label_b_a' => $relType, 'description' => $relType, 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'contact_sub_type_a' => NULL, 'contact_sub_type_b' => NULL)); // We'll create managed-entity if this record doesn't exist yet // or if we previously decided to manage this record. if (!in_array($relType, $validRelTypes)) { $result[] = $managed; } elseif ($me->get($managed['module'], $managed['name'])) { $result[] = $managed; } } return $result; }
/** * Takes an associative array and creates a Case Type object. * * the function extract all the params it needs to initialize the create a * case type object. the params array could contain additional unused name/value * pairs * * @param array $params * (reference ) an assoc array of name/value pairs. * * @throws CRM_Core_Exception * * @return CRM_Case_BAO_CaseType */ public static function add(&$params) { $caseTypeDAO = new CRM_Case_DAO_CaseType(); // form the name only if missing: CRM-627 $nameParam = CRM_Utils_Array::value('name', $params, NULL); if (!$nameParam && empty($params['id'])) { $params['name'] = CRM_Utils_String::titleToVar($params['title']); } // Old case-types (pre-4.5) may keep their ucky names, but new case-types must satisfy isValidName() if (empty($params['id']) && !empty($params['name']) && !CRM_Case_BAO_CaseType::isValidName($params['name'])) { throw new CRM_Core_Exception("Cannot create new case-type with malformed name [{$params['name']}]"); } $caseTypeName = isset($params['name']) ? $params['name'] : CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $params['id'], 'name', 'id', TRUE); // function to format definition column if (isset($params['definition']) && is_array($params['definition'])) { $params['definition'] = self::convertDefinitionToXML($caseTypeName, $params['definition']); CRM_Core_ManagedEntities::scheduleReconciliation(); } $caseTypeDAO->copyValues($params); return $caseTypeDAO->save(); }
/** * Get a list of managed relationship-types by searching CiviCase XML files. * * @param \CRM_Case_XMLRepository $xmlRepo * @param \CRM_Core_ManagedEntities $me * * @return array * @see CRM_Utils_Hook::managed */ public static function createManagedRelationshipTypes(CRM_Case_XMLRepository $xmlRepo, CRM_Core_ManagedEntities $me) { $result = array(); if (!isset(Civi::$statics[__CLASS__]['reltypes'])) { $relationshipInfo = CRM_Core_PseudoConstant::relationshipType('label', TRUE, NULL); Civi::$statics[__CLASS__]['reltypes'] = CRM_Utils_Array::collect(CRM_Case_XMLProcessor::REL_TYPE_CNAME, $relationshipInfo); } $validRelTypes = Civi::$statics[__CLASS__]['reltypes']; $relTypes = $xmlRepo->getAllDeclaredRelationshipTypes(); foreach ($relTypes as $relType) { $managed = array('module' => 'civicrm', 'name' => "civicase:rel:{$relType}", 'entity' => 'RelationshipType', 'update' => 'never', 'cleanup' => 'unused', 'params' => array('version' => 3, 'name_a_b' => "{$relType} is", 'name_b_a' => $relType, 'label_a_b' => "{$relType} is", 'label_b_a' => $relType, 'description' => $relType, 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'contact_sub_type_a' => NULL, 'contact_sub_type_b' => NULL)); // We'll create managed-entity if this record doesn't exist yet // or if we previously decided to manage this record. if (!in_array($relType, $validRelTypes)) { $result[] = $managed; } elseif ($me->get($managed['module'], $managed['name'])) { $result[] = $managed; } } return $result; }
static function rebuildMenuAndCaches($triggerRebuild = FALSE, $sessionReset = FALSE) { $config = CRM_Core_Config::singleton(); $config->clearModuleList(); // also cleanup all caches $config->cleanupCaches($sessionReset || CRM_Utils_Request::retrieve('sessionReset', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')); CRM_Core_Menu::store(); // also reset navigation CRM_Core_BAO_Navigation::resetNavigation(); // also cleanup module permissions $config->cleanupPermissions(); // also rebuild word replacement cache CRM_Core_BAO_WordReplacement::rebuild(); CRM_Core_BAO_Setting::updateSettingsFromMetaData(); CRM_Core_Resources::singleton()->resetCacheCode(); // also rebuild triggers if requested explicitly if ($triggerRebuild || CRM_Utils_Request::retrieve('triggerRebuild', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')) { CRM_Core_DAO::triggerRebuild(); } CRM_Core_DAO_AllCoreTables::reinitializeCache(TRUE); CRM_Core_ManagedEntities::singleton(TRUE)->reconcile(); }
public function tearDown() { parent::tearDown(); CRM_Core_ManagedEntities::singleton(TRUE)->reconcile(); }
/** * Setup an active module with an entity -- then entirely uninstall the * module */ public function testUninstallModule() { // create first managed entity ('foo') $decls = array(); $decls[] = $this->fixtures['com.example.one-foo']; $me = new CRM_Core_ManagedEntities($this->modules, $decls); $me->reconcile(); $foo = $me->get('com.example.one', 'foo'); $this->assertEquals('CRM_Example_One_Foo', $foo['name']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "CRM_Example_One_Foo"'); // then destroy module; note that decls go away unset($this->modules['one']); $me = new CRM_Core_ManagedEntities($this->modules, array()); $me->reconcile(); $fooNew = $me->get('com.example.one', 'foo'); $this->assertTrue(NULL === $fooNew); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "CRM_Example_One_Foo"'); }
/** * @param bool $triggerRebuild * @param bool $sessionReset * * @throws Exception */ public static function rebuildMenuAndCaches($triggerRebuild = FALSE, $sessionReset = FALSE) { $config = CRM_Core_Config::singleton(); $config->clearModuleList(); // also cleanup all caches $config->cleanupCaches($sessionReset || CRM_Utils_Request::retrieve('sessionReset', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')); CRM_Core_Menu::store(); // also reset navigation CRM_Core_BAO_Navigation::resetNavigation(); // also cleanup module permissions $config->cleanupPermissions(); // rebuild word replacement cache - pass false to prevent operations redundant with this fn CRM_Core_BAO_WordReplacement::rebuild(FALSE); Civi::service('settings_manager')->flush(); // Clear js caches CRM_Core_Resources::singleton()->flushStrings()->resetCacheCode(); CRM_Case_XMLRepository::singleton(TRUE); // also rebuild triggers if requested explicitly if ($triggerRebuild || CRM_Utils_Request::retrieve('triggerRebuild', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')) { CRM_Core_DAO::triggerRebuild(); } CRM_Core_DAO_AllCoreTables::reinitializeCache(TRUE); CRM_Core_ManagedEntities::singleton(TRUE)->reconcile(); //CRM-16257 update Config.IDS.ini might be an old copy CRM_Core_IDS::createConfigFile(TRUE); }
/** * @inheritDoc * @return array * @throws CRM_Core_Exception */ public function getManagedEntities() { $entities = array_merge(CRM_Case_ManagedEntities::createManagedCaseTypes(), CRM_Case_ManagedEntities::createManagedActivityTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()), CRM_Case_ManagedEntities::createManagedRelationshipTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton())); return $entities; }
/** * Perform an asynchronous reconciliation when the transaction ends. */ public static function scheduleReconcilation() { CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, function () { CRM_Core_ManagedEntities::singleton(TRUE)->reconcile(); }, array(), 'ManagedEntities::reconcile'); }
/** * Setup an active module with an entity -- then entirely uninstall the * module */ function testUninstallModule() { // create first managed entity ('foo') $decls = array(); $decls[] = array('module' => 'com.example.one', 'name' => 'foo', 'entity' => 'CustomSearch', 'params' => array('version' => 3, 'class_name' => 'CRM_Example_One_Foo', 'is_reserved' => 1)); $me = new CRM_Core_ManagedEntities($this->modules, $decls); $me->reconcile(); $foo = $me->get('com.example.one', 'foo'); $this->assertEquals('CRM_Example_One_Foo', $foo['name']); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "CRM_Example_One_Foo"'); // then destory module; note that decls go away unset($this->modules['one']); $me = new CRM_Core_ManagedEntities($this->modules, array()); $me->reconcile(); $fooNew = $me->get('com.example.one', 'foo'); $this->assertTrue(NULL === $fooNew); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "CRM_Example_One_Foo"'); }
static function rebuildMenuAndCaches($triggerRebuild = FALSE, $sessionReset = FALSE) { $config = CRM_Core_Config::singleton(); $config->clearModuleList(); CRM_Core_Menu::store(); // also reset navigation CRM_Core_BAO_Navigation::resetNavigation(); // also cleanup all caches $config->cleanupCaches($sessionReset || CRM_Utils_Request::retrieve('sessionReset', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')); // also rebuild triggers if requested explicitly if ($triggerRebuild || CRM_Utils_Request::retrieve('triggerRebuild', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')) { CRM_Core_DAO::triggerRebuild(); } CRM_Core_ManagedEntities::singleton(TRUE)->reconcile(); }
public function upgrade_1_3_002() { CRM_Core_ManagedEntities::singleton(TRUE)->reconcile(); return TRUE; }