| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- Lib::loadClass('RouteBase');
- class Route_Test_StorageUpdateCache extends RouteBase {
- function defaultAction() { UI::layout([ $this, 'defaultView' ]); }
- function defaultView() {
- // $this->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");
- }
- }
- }
- }
|