RefConfig.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <?php
  2. Lib::loadClass('Type_Field');
  3. Lib::loadClass('Type_RefConfig');
  4. Lib::loadClass('Api_WfsNs');
  5. Lib::loadClass('ACL');
  6. Lib::loadClass('SchemaVersionUpgrade');
  7. /*
  8. RefStorage - for ref data manipulation
  9. RefConfig - for ref config
  10. `CRM_REF_CONFIG`:
  11. - `ID`: primaryKey (used to generate **Storage** name for data)
  12. - `ROOT_OBJECT_NS`: root object namespace
  13. - `CHILD_NAME`: child typeName (or alias name - not supported yet)
  14. - `CHILD_NS`: child namespace (required when use `CHILD_NAME` as alias)
  15. - `A_STATUS`: status
  16. - 'WAITING': not Active, 'NORMAL': Active, 'DELETED': removed
  17. - `VERSION`: **Storage** version
  18. - `A_LAST_ACTION_DATE`: last action timestamp
  19. - `SOURCE`: place where data is stored
  20. - 'table': table with data
  21. - 'view': view by flat relation cache
  22. - 'backRef': view on ref table with replaced fields
  23. **Storage** - table or view - place where data is stored
  24. RefConfig::isActive($objectNamespace, $childTypeName) // Ref is active when: CRM_REF_CONFIG.A_STATUS = NORMAL
  25. RefConfig::getRefTable($objectNamespace, $childTypeName) // ref table - TODO not needed?
  26. */
  27. class RefConfig {
  28. static $REF_TABLE_VERSION = 2;
  29. static function isActive($objectNamespace, $childTypeName) {
  30. $refInfo = self::fetch($objectNamespace, $childTypeName);
  31. return ('NORMAL' === $refInfo->status);
  32. }
  33. /** static function fetch(Type_Namespace $rootObjectNamespace, Type_TypeName $childName, Type_Namespace $childNamespace = null): Type_RefConfig */
  34. static function fetch($rootObjectNamespace, $childName, $childNamespace = null) { // @returns Type_RefConfig
  35. SchemaVersionUpgrade::upgradeSchema();
  36. $rootObjectNamespace = ACL::getBaseNamespace($rootObjectNamespace);
  37. if (!$childNamespace && false !== strpos($childName, '__x3A__') && false !== strpos($childName, ':')) $childNamespace = Api_WfsNs::namespaceFromTypeName($childName);
  38. if (!$childNamespace) {
  39. $rootAcl = ACL::getAclByNamespace($rootObjectNamespace);
  40. $childXsdType = $rootAcl->getXsdFieldType($childName);
  41. list($typePrefix, $childTypeName) = explode(':', $childXsdType, 2);
  42. $childNamespace = Api_WfsNs::namespaceFromTypeName($childTypeName);
  43. DBG::log(['$childXsdType' => $childXsdType, '$typePrefix' => $typePrefix, '$childNamespace' => $childNamespace], 'array', "DBG get ref table ...");
  44. switch ($typePrefix) {
  45. case 'ref_uri': $childAcl = ACL::getAclByNamespace($childNamespace); break;
  46. case 'ref': $childAcl = ACL::getAclByTypeName($childNamespace); break;
  47. default: throw new Exception("Expected ref type for field '{$childName}' in object '{$rootObjectNamespace}'");
  48. }
  49. }
  50. $refInfo = DB::getPDO()->fetchFirst("
  51. select c.ID, c.A_STATUS, c.VERSION, c.SOURCE
  52. from `CRM_REF_CONFIG` c
  53. where c.ROOT_OBJECT_NS = :ROOT_OBJECT_NS
  54. and c.CHILD_NAME = :CHILD_NAME
  55. and c.CHILD_NS = :CHILD_NS
  56. ", [
  57. ':ROOT_OBJECT_NS' => $rootObjectNamespace,
  58. ':CHILD_NAME' => $childName,
  59. ':CHILD_NS' => $childNamespace,
  60. ]);
  61. if (empty($refInfo)) {
  62. $refInfo = [ 'ID' => 0, 'A_STATUS' => 'WAITING', 'VERSION' => self::$REF_TABLE_VERSION, 'SOURCE' => 'table',
  63. 'ROOT_OBJECT_NS' => $rootObjectNamespace,
  64. 'CHILD_NAME' => $childName,
  65. 'CHILD_NS' => $childNamespace,
  66. ];
  67. $refInfo['ID'] = DB::getPDO()->insert("CRM_REF_CONFIG", [
  68. 'ROOT_OBJECT_NS' => $rootObjectNamespace,
  69. 'CHILD_NAME' => $childName,
  70. 'CHILD_NS' => $childNamespace,
  71. 'VERSION' => self::$REF_TABLE_VERSION
  72. ]);
  73. }
  74. if (!$refInfo['ID']) throw new Exception("Ref table not found in ref config table for field '{$childName}' in object '{$rootObjectNamespace}'");
  75. return Type_RefConfig::build($refInfo);
  76. }
  77. static function getChildRefFullList($namespace) {
  78. $namespace = ACL::getBaseNamespace($namespace);
  79. if (!$namespace) throw new Exception("Missing namespace");
  80. return array_map('Type_RefConfig::build', DB::getPDO()->fetchAll("
  81. select c.ID
  82. , c.A_STATUS
  83. , c.SOURCE
  84. , c.CHILD_NAME
  85. from CRM_REF_CONFIG c
  86. where c.ROOT_OBJECT_NS = :namespace
  87. -- and c.A_STATUS = 'NORMAL'
  88. ", [
  89. ':namespace' => $namespace,
  90. ]));
  91. }
  92. static function isRefField($objectNamespace, $fieldName) {
  93. return (false !== strpos($fieldName, ':'));
  94. }
  95. /*
  96. @param $appInfo = [
  97. [type] => ref:default_db__x3A__BI_audit_CEIDG:BI_audit_CEIDG
  98. [minOccurs] => 0
  99. [maxOccurs] => unbounded
  100. [restrictions] => []
  101. [appInfo] => []
  102. ]
  103. */
  104. static function needUpdate($objectNamespace, $childTypeName, Type_Field $newField, Type_Field $oldField = null) {
  105. DBG::log(['objectNamespace' => $objectNamespace, 'childTypeName' => $childTypeName, 'newField' => $newField, 'oldField' => $oldField], 'array', "RefConfig::needUpdate...");
  106. if (!$oldField) throw new Exception("Missig oldField in RefConfig::needUpdate({$objectNamespace}, {$childTypeName}, ...) - TODO: fetch from #acl cache");
  107. if (!($newField instanceof Type_Field_Ref)) return false;
  108. if (!($oldField instanceof Type_Field_Ref)) return false;
  109. $oldRefActive = self::isActive($objectNamespace, $childTypeName);
  110. if (!$oldRefActive) return false; // if old not installed / adtivated then just fix struct and install
  111. $newRefSource = $newField->source;
  112. $oldRefConf = self::fetch($objectNamespace, $childTypeName);
  113. $oldRefSource = $oldRefConf->source;
  114. if ($newRefSource !== $oldRefSource) DBG::log("RefConfig::needUpdate Change ref source from '{$oldRefSource}' to '{$newRefSource}'");
  115. if ($newRefSource !== $oldRefSource) return true;
  116. return false;
  117. }
  118. static function update($objectNamespace, $childTypeName, Type_Field $newField) {
  119. if (!($newField instanceof Type_Field_Ref)) return;
  120. // $oldRefActive = self::isActive($objectNamespace, $childTypeName);
  121. // if (!$oldRefActive) return; // if old not installed / adtivated then just fix struct and install
  122. $newRefSource = $newField->source;
  123. $refConfig = self::fetch($objectNamespace, $childTypeName);
  124. $oldRefSource = $refConfig->source;
  125. if ($newRefSource !== $oldRefSource) DBG::log("RefConfig::update Change ref source from '{$oldRefSource}' to '{$newRefSource}'");
  126. { // always update ref config at reinstall - drop / create ref tables (table or view)
  127. switch ($newRefSource) {
  128. case 'table': return self::installRefTable($objectNamespace, $childTypeName, $newField, $refConfig);
  129. case 'view': return self::installRefView($objectNamespace, $childTypeName, $newField, $refConfig);
  130. case 'backRef': return self::installBackRef($objectNamespace, $childTypeName, $newField, $refConfig);
  131. }
  132. }
  133. if ($newRefSource !== $oldRefSource) {
  134. if ('table' === $oldRefSource) {
  135. // TODO: check if table has data
  136. // TODO: if no data in table then DROP ?
  137. }
  138. throw new Exception("TODO: RefConfig::update Change ref source from '{$oldRefSource}' to '{$newRefSource}' in '{$objectNamespace}'-&gt;'{$childTypeName}'");
  139. }
  140. }
  141. static function createRefTable($objectNamespace, $childTypeName, Type_RefConfig $refConfig = null) {
  142. if (!$refConfig) $refConfig = self::fetch($objectNamespace, $childTypeName);
  143. $refTableName = "CRM__#REF_TABLE__{$refConfig->id}";
  144. DB::getPDO()->execSql("
  145. CREATE TABLE IF NOT EXISTS `{$refTableName}` (
  146. `PRIMARY_KEY` int(11) NOT NULL
  147. , `REMOTE_PRIMARY_KEY` int(11) NOT NULL
  148. , `REMOTE_TYPENAME` varchar(255) NOT NULL DEFAULT ''
  149. , `A_STATUS` enum('WAITING', 'NORMAL', 'DELETED') NOT NULL DEFAULT 'WAITING'
  150. , `TRANSACTION_ID` int(11) NOT NULL
  151. , `A_LAST_ACTION_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
  152. , KEY `PRIMARY_KEY` (`PRIMARY_KEY`)
  153. , KEY `REMOTE_PRIMARY_KEY` (`REMOTE_PRIMARY_KEY`)
  154. , KEY `TRANSACTION_ID` (`TRANSACTION_ID`)
  155. ) ENGINE=MyISAM DEFAULT CHARSET=latin2 COMMENT='{$objectNamespace} #REF {$childTypeName}';
  156. ");
  157. $affected = DB::getPDO()->update("CRM_REF_CONFIG", 'ID', $refConfig->id, [
  158. 'A_STATUS' => "NORMAL",
  159. // 'VERSION' => self::$REF_TABLE_VERSION
  160. ]);
  161. self::upgradeRefTableFrom1to2($refConfig);
  162. }
  163. static function upgradeRefTableFrom1to2(Type_RefConfig $refConfig) { // TODO: rm ACL::upgradeRefConfigFrom1to2
  164. if (1 == $refConfig->version) {
  165. if ('table' === $refConfig->source && 'NORMAL' == $refConfig->status) {
  166. $refTableName = "CRM__#REF_TABLE__{$refConfig->id}";
  167. try {
  168. DB::getPDO()->execSql(" CREATE INDEX `TRANSACTION_ID` ON `{$refTableName}` (`TRANSACTION_ID`) ");
  169. } catch (Exception $e) {
  170. DBG::log($e);
  171. }
  172. }
  173. $affected = DB::getPDO()->update("CRM_REF_CONFIG", 'ID', $refConfig->id, [
  174. 'VERSION' => 2
  175. ]);
  176. }
  177. // TODO: return array_merge($refConfig, [ 'VERSION' => 2 ]);
  178. }
  179. static function installRefTable($objectNamespace, $childTypeName, Type_Field $newField, Type_RefConfig $refConfig = null) {
  180. if (!$refConfig) $refConfig = self::fetch($objectNamespace, $childTypeName);
  181. self::createRefTable($objectNamespace, $childTypeName, $refConfig);
  182. $affected = DB::getPDO()->update("CRM_REF_CONFIG", 'ID', $refConfig->id, [
  183. 'SOURCE' => "table",
  184. 'A_STATUS' => "NORMAL",
  185. 'VERSION' => self::$REF_TABLE_VERSION,
  186. ]);
  187. }
  188. static function installRefView($objectNamespace, $childTypeName, Type_Field $typeField, Type_RefConfig $refConfig = null) {
  189. if (!$refConfig) $refConfig = self::fetch($objectNamespace, $childTypeName);
  190. $viewSelectSql = RefConfig::generateRefSelectSqlByFlatRelationCache($objectNamespace, $childTypeName, $typeField);
  191. $refTableName = "CRM__#REF_TABLE__{$refConfig->id}_VIEW";
  192. DB::getPDO()->execSql(" CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `{$refTableName}` AS {$viewSelectSql} ");
  193. $affected = DB::getPDO()->update("CRM_REF_CONFIG", 'ID', $refConfig->id, [
  194. 'SOURCE' => 'view',
  195. 'A_STATUS' => "NORMAL",
  196. ]);
  197. }
  198. static function installBackRef($objectNamespace, $childTypeName, Type_Field $newField, Type_RefConfig $refConfig = null) {
  199. $viewSelectSql = self::generateRefSelectSqlByBackRef($objectNamespace, $childTypeName);
  200. if (!$refConfig) $refConfig = self::fetch($objectNamespace, $childTypeName);
  201. $refTableName = "CRM__#REF_TABLE__{$refConfig->id}_VIEW";
  202. DB::getPDO()->execSql(" CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `{$refTableName}` AS {$viewSelectSql} ");
  203. $affected = DB::getPDO()->update("CRM_REF_CONFIG", 'ID', $refConfig->id, [
  204. 'SOURCE' => 'backRef',
  205. 'A_STATUS' => "NORMAL",
  206. 'VERSION' => self::$REF_TABLE_VERSION,
  207. ]);
  208. }
  209. static function generateRefSelectSqlByBackRef($rootObjectNamespace, $childName) {
  210. // generate view which is select from {replaced(pk, remote pk) on ref table from backRef}
  211. // {
  212. // DBG::nicePrint($refInfo, "\$refInfo");
  213. // DBG::nicePrint($rootObjectNamespace, "\$rootObjectNamespace");
  214. // DBG::nicePrint($childName, "\$childName");
  215. // DBG::nicePrint($childNamespace, "\$childNamespace");
  216. // $replacedObjNs = Api_WfsNs::namespaceFromTypeName($childName);
  217. // $replacedChildName = Api_WfsNs::typeName($rootObjectNamespace);
  218. // DBG::nicePrint($replacedObjNs, "\$replacedObjNs");
  219. // DBG::nicePrint($replacedChildName, "\$replacedChildName");
  220. // return ACL::getRefTable($replacedObjNs, $replacedChildName, 1);
  221. // throw new Exception("Not Implemented ref SOURCE = '{$refInfo['SOURCE']}'");
  222. // }
  223. $childNs = Api_WfsNs::namespaceFromTypeName($childName);
  224. $rootTypeName = Api_WfsNs::typeName($rootObjectNamespace);
  225. $backRefTable = ACL::getRefTable($childNs, $rootTypeName);
  226. DBG::nicePrint($backRefTable, "ACL::getRefTable({$childNs}, {$rootTypeName})");
  227. // TODO: check if ref_config is not backRef to avoid loop // $refInfo = self::getRefConfig($fieldNs, $item['typeName'], $item['typeName']);
  228. $lastActionDateField = "NULL"; // , IF(l.A_RECORD_UPDATE_DATE > r.A_RECORD_UPDATE_DATE, l.A_RECORD_UPDATE_DATE, r.A_RECORD_UPDATE_DATE) as A_LAST_ACTION_DATE
  229. $sql = "
  230. select backRef.REMOTE_PRIMARY_KEY as PRIMARY_KEY
  231. , backRef.PRIMARY_KEY as REMOTE_PRIMARY_KEY
  232. , backRef.REMOTE_TYPENAME as REMOTE_TYPENAME
  233. , backRef.A_STATUS as A_STATUS
  234. , 0 as TRANSACTION_ID
  235. , {$lastActionDateField} as A_LAST_ACTION_DATE
  236. from `{$backRefTable}` backRef
  237. ";
  238. DBG::log($sql, 'sql', "generateRefSelectSqlByBackRef");
  239. return $sql;
  240. }
  241. static function generateRefSelectSqlByFlatRelationCache($rootObjectNamespace, $childName, Type_Field $typeField) { // CRM_REF_CONFIG
  242. $appInfo = $typeField->appInfo;
  243. if (empty($appInfo)) throw new Exception("Empty app:info for field '{$rootObjectNamespace}/{$childName}'");
  244. DBG::log(['$appInfo'=>$appInfo, '$rootObjectNamespace'=>$rootObjectNamespace, '$childName'=>$childName], 'array', "\$appInfo");
  245. $rootAcl = ACL::getAclByNamespace($rootObjectNamespace);
  246. $childXsdType = $rootAcl->getXsdFieldType($childName);
  247. list($typePrefix, $childNamespace) = explode(':', $childXsdType, 2);
  248. switch ($typePrefix) {
  249. case 'ref_uri': $childAcl = ACL::getAclByNamespace($childNamespace); break;
  250. case 'ref': $childAcl = ACL::getAclByTypeName($childNamespace); break;
  251. default: throw new Exception("Expected ref type for field '{$childName}' in object '{$rootObjectNamespace}'");
  252. }
  253. $lastActionDateField = "NULL"; // , IF(l.A_RECORD_UPDATE_DATE > r.A_RECORD_UPDATE_DATE, l.A_RECORD_UPDATE_DATE, r.A_RECORD_UPDATE_DATE) as A_LAST_ACTION_DATE
  254. $rootPrimaryKeyField = $rootAcl->getPrimaryKeyField();
  255. $childPrimaryKeyField = $childAcl->getPrimaryKeyField();
  256. $rootTableName = $rootAcl->getRootTableName();
  257. $childTableName = $childAcl->getRootTableName();
  258. // '$appInfo' => [
  259. // 'flat_relation_cache' => [
  260. // 'source' => [
  261. // '@name' => 'ID',
  262. // '@xpath' => 'default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK/ID_PROCES',
  263. // ),
  264. // ),
  265. // ),
  266. // '$rootObjectNamespace' => 'default_db/CRM_PROCES/PROCES',
  267. // '$childName' => 'default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK',
  268. // '$appInfo' => [
  269. // 'flat_relation_cache' => [
  270. // 'source' => [
  271. // '@name' => 'ID',
  272. // '@xpath' => 'default_db__x3A__CRM_PROCES:PROCES/PARENT_ID',
  273. // ),
  274. // ),
  275. // ),
  276. // '$rootObjectNamespace' => 'default_db/CRM_PROCES/PROCES',
  277. // '$childName' => 'default_db__x3A__CRM_PROCES:PROCES',
  278. $appInfoRootFieldName = null;
  279. $appInfoChildFieldName = null;
  280. {
  281. if (empty($appInfo['flat_relation_cache']['source']['@name'])) throw new Exception("Missing flat_relation_cache/source/@name");
  282. if (empty($appInfo['flat_relation_cache']['source']['@xpath'])) throw new Exception("Missing flat_relation_cache/source/@xpath");
  283. $appInfoName = $appInfo['flat_relation_cache']['source']['@name'];
  284. $appInfoXpath = $appInfo['flat_relation_cache']['source']['@xpath'];
  285. // $rootNs = $rootAcl->getNamespace()
  286. if ("{$childName}/" === substr($appInfoXpath, 0, strlen("{$childName}/"))) {
  287. $appInfoRootFieldName = substr($appInfoXpath, strlen("{$childName}/"));
  288. $appInfoChildFieldName = $appInfoName;
  289. } else {
  290. throw new Exception("TODO parse flat_relation_cache");
  291. }
  292. }
  293. if (!$appInfoRootFieldName || !$appInfoChildFieldName) throw new Exception("Error Processing flat_relation_cache");
  294. $sqlWhereFromRestrictions = [];
  295. DBG::log(['root'=>$rootAcl->getFields(), 'child'=>$childAcl->getFields()], 'array', "rootAcl and childAcl fields - xsdRestrictions");
  296. if ($rootAcl instanceof AntAclBase && $childAcl instanceof AntAclBase) {
  297. $rootLocalFieldsWithRestrictions = array_filter($rootAcl->getFields(), function ($field) {
  298. if (!$field['isLocal']) return false;
  299. if (empty($field['xsdRestrictions'])) return false;
  300. if ('[]' == $field['xsdRestrictions']) return false;
  301. return true;
  302. });
  303. $childLocalFieldsWithRestrictions = array_filter($childAcl->getFields(), function ($field) {
  304. if (!$field['isLocal']) return false;
  305. if (empty($field['xsdRestrictions'])) return false;
  306. if ('[]' == $field['xsdRestrictions']) return false;
  307. return true;
  308. });
  309. DBG::log(['root'=>$rootLocalFieldsWithRestrictions, 'child'=>$childLocalFieldsWithRestrictions], 'array', "root and child fields with xsdRestrictions");
  310. if (!empty($rootLocalFieldsWithRestrictions)) {
  311. $sqlTablePrefix = 'root';
  312. $sqlWhereFromRestrictions = array_reduce(
  313. array_map(function ($field) use ($sqlTablePrefix) {
  314. $sqlRestrictions = [];
  315. // 'xsdRestrictions' => '{"enumeration":{"PROCES":"PROCES"}}',
  316. $restrictions = @json_decode($field['xsdRestrictions'], $assoc = true);
  317. if (!empty($restrictions)) {
  318. if (!empty($restrictions['enumeration'])) {
  319. $sqlRestrictions[] = "{$sqlTablePrefix}.`{$field['fieldNamespace']}` in (" . implode(",", array_map([DB::getPDO(), 'quote'], array_keys($restrictions['enumeration']))) . ")";
  320. }
  321. }
  322. return $sqlRestrictions;
  323. }, $rootLocalFieldsWithRestrictions),
  324. function ($ret, $cur) {
  325. return array_merge($ret, array_filter($cur, ['V', 'filterNotEmpty']));
  326. },
  327. $sqlWhereFromRestrictions
  328. );
  329. }
  330. if (!empty($childLocalFieldsWithRestrictions)) {
  331. $sqlTablePrefix = 'child';
  332. $sqlWhereFromRestrictions = array_reduce(
  333. array_map(function ($field) use ($sqlTablePrefix) {
  334. $sqlRestrictions = [];
  335. // 'xsdRestrictions' => '{"enumeration":{"PROCES":"PROCES"}}',
  336. $restrictions = @json_decode($field['xsdRestrictions'], $assoc = true);
  337. if (!empty($restrictions)) {
  338. if (!empty($restrictions['enumeration'])) {
  339. $sqlRestrictions[] = "{$sqlTablePrefix}.`{$field['fieldNamespace']}` in (" . implode(",", array_map([DB::getPDO(), 'quote'], array_keys($restrictions['enumeration']))) . ")";
  340. }
  341. }
  342. return $sqlRestrictions;
  343. }, $childLocalFieldsWithRestrictions),
  344. function ($ret, $cur) {
  345. return array_merge($ret, array_filter($cur, ['V', 'filterNotEmpty']));
  346. },
  347. $sqlWhereFromRestrictions
  348. );
  349. }
  350. }
  351. $sqlWhereFromRestrictions = (!empty($sqlWhereFromRestrictions)) ? implode(" and ", $sqlWhereFromRestrictions) : "1=1";
  352. $sqlChildFieldName = $childAcl->getSqlFieldName($appInfoRootFieldName);
  353. $sql = "
  354. select root.{$rootPrimaryKeyField} as PRIMARY_KEY
  355. , child.{$childPrimaryKeyField} as REMOTE_PRIMARY_KEY
  356. , '' as REMOTE_TYPENAME
  357. , 'WAITING' as A_STATUS
  358. , 0 as TRANSACTION_ID
  359. , {$lastActionDateField} as A_LAST_ACTION_DATE
  360. from `{$rootTableName}` root
  361. join `{$childTableName}` child on(child.{$sqlChildFieldName} = root.{$appInfoChildFieldName})
  362. where {$sqlWhereFromRestrictions}
  363. ";
  364. DBG::log($sql, 'sql', "generateRefSelectSqlByFlatRelationCache");
  365. return $sql;
  366. }
  367. static function remove(Type_RefConfig $refConfig) {
  368. DB::getPDO()->update('CRM_REF_CONFIG', 'ID', $refConfig->id, [
  369. 'A_STATUS' => 'DELETED',
  370. 'A_LAST_ACTION_DATE' => 'NOW()',
  371. ]);
  372. }
  373. static function reactivate(Type_RefConfig $refConfig) {
  374. DB::getPDO()->update('CRM_REF_CONFIG', 'ID', $refConfig->id, [ // TODO: update ref table, update source -- fixed below by RefConfig::update
  375. 'A_STATUS' => 'WAITING',
  376. 'A_LAST_ACTION_DATE' => 'NOW()',
  377. ]);
  378. }
  379. }