checkSourceListView(); // $this->checkAntAclPathListView(); $this->fixAntAclWithStructNotInstalledView(); } function checkSourceListView() { $sourceStorage = SchemaFactory::loadDefaultObject('SystemSource'); $listSourceToUpdate = $sourceStorage->getItems([ 'f_hasConfig' => 1 ]); UI::table([ 'caption' => "\$listSourceToUpdate:", 'rows' => $listSourceToUpdate ]); } function checkAntAclPathListView() { $basePath = APP_PATH_SCHEMA . "/ant-object"; foreach (glob("{$basePath}/*/*/build.xml", GLOB_NOSORT) as $buildXmlPath) { try { // $this->_updateAntObjectCache($buildXmlPath, $basePath); $relativePath = substr($buildXmlPath, strlen("{$basePath}/")); // expected: "{prefix}.{rootTableName}/{objectName}/build.xml" $ret = preg_match_all('/^([0-9a-zA-Z_]*)\.([0-9a-zA-Z_]*)\/([0-9a-zA-Z_-]*)\/build\.xml$/', $relativePath, $matches, PREG_SET_ORDER); DBG::nicePrint($matches, "ret({$ret}) \$matches for({$relativePath})"); $sourceName = $matches[0][1]; $rootTableName = $matches[0][2]; $name = $matches[0][3]; DBG::nicePrint([$sourceName, $rootTableName], "\$name='{$name}' - [\$lowerSource, \$rootTableName]"); } catch (Exception $e) { UI::alert('danger', $e->getMessage()); } } } function fixAntAclWithStructNotInstalledView() { Lib::loadClass('Schema_SystemObjectStorageAcl'); // Fix objects AntAcl which struct is not installed $listAntAclObjectsToFix = DB::getPDO()->fetchAll(" select t.* from `CRM_#CACHE_ACL_OBJECT` t where t._type = 'AntAcl' and t.idZasob is not NULL and t.hasStruct = 1 and t.isStructInstalled = 0 "); if (!empty($listAntAclObjectsToFix)) { UI::alert('info', "Fix AntAcl objects which is not installed (total: ".count($listAntAclObjectsToFix).")"); foreach ($listAntAclObjectsToFix as $antAclInfo) { $namespace = $antAclInfo['namespace']; DBG::nicePrint($antAclInfo, "\$antAclInfo ({$namespace})"); $zasobyStruct = DB::getPDO()->fetchAll(" select z.ID, z.`DESC` from `CRM_LISTA_ZASOBOW` z where z.PARENT_ID = :parent_id and z.`TYPE` = 'KOMORKA' and z.A_STATUS not in ('DELETED') ", [ ':parent_id' => $antAclInfo['idZasob'] ]); DBG::nicePrint($zasobyStruct, "\$zasobyStruct ({$namespace})"); ob_start(); { Lib::loadClass('Schema_SystemObjectFieldStorageAcl'); { // TODO $item = []; $exNs = explode('/', $namespace); $item['name'] = array_pop($exNs); $item['nsPrefix'] = implode('__x3A__', $exNs); $item['typeName'] = implode('__x3A__', $exNs) . ':' . $item['name']; $antAclPath = Schema_SystemObjectFieldStorageAcl::getAntAclXsdBasePath($item['typeName']); if (!file_exists("{$antAclPath}/build.xml")) { UI::alert('danger', "Ant build file not exists for namespace '{$antAclInfo['namespace']}' - Removing AntAcl"); Schema_SystemObjectStorageAcl::deleteObjectFromCache($antAclInfo['idZasob'], $antAclInfo['namespace']); throw new Exception("Ant build file not exists #TEST_OFF"); // continue; } } // TODO $objFieldAcl = new Schema_SystemObjectFieldStorageAcl(); try { $objFieldAcl->updateCache($namespace); } catch (Exception $e) { UI::alert('danger', $e->getMessage()); Schema_SystemObjectStorageAcl::deleteObjectFromCache($antAclInfo['idZasob'], $antAclInfo['namespace']); continue; } $reinstallLog = ob_get_clean(); } // DBG::nicePrint($reinstallLog, "\$reinstallLog ({$namespace})"); $fieldCacheStruct = DB::getPDO()->fetchAll(" select t.namespace, t.fieldNamespace from `CRM_#CACHE_ACL_OBJECT_FIELD` t where t.objectNamespace = :namespace and t.idZasob is NULL ", [ ':namespace' => $namespace ]); DBG::nicePrint($fieldCacheStruct, "\$fieldCacheStruct ({$namespace})"); $fieldsToFix = []; foreach ($fieldCacheStruct as $cacheField) { $fieldName = $cacheField['fieldNamespace']; foreach ($zasobyStruct as $fieldZasob) { if ($fieldZasob['DESC'] === $fieldName) { $fieldsToFix[] = [ 'idZasob' => $fieldZasob['ID'], 'namespace' => $cacheField['namespace'], ]; } } } DBG::nicePrint($fieldsToFix, "\$fieldsToFix ({$namespace})"); foreach ($fieldsToFix as $fixField) { $affected = SchemaFactory::loadDefaultObject('SystemObjectField')->updateItem([ 'namespace' => $fixField['namespace'], 'idZasob' => $fixField['idZasob'] ]); if (!$affected) UI::alert('warning', "field ({$fixField['namespace']}) update idZasob failed"); } $affected = SchemaFactory::loadDefaultObject('SystemObject')->updateItem([ 'namespace' => $namespace, 'isObjectActive' => 1 ]); ($affected) ? UI::alert('success', "object ({$namespace}) activated") : UI::alert('warning', "object ({$namespace}) activation failed"); } } } }