Piotr Labudda před 6 roky
rodič
revize
f232427025

+ 1 - 0
SE/schema/ant-object/default_db.IN7_MK_BAZA_DYSTRYBUCJI/ID_PROJECT/ID_PROJECT.xsd

@@ -235,6 +235,7 @@
       <xs:annotation>
          <!--preceding-sibling::complexType = test NO-->
          <xs:appinfo>
+            <system_cache__appinfo:table_structure system_cache__appinfo:charset="latin2"/>
             <system_cache__appinfo:heritage>
                <system_cache__appinfo:inherit system_cache__appinfo:heritage_acl="true" system_cache__appinfo:inherit_ref="default_db:IN7_MK_BAZA_DYSTRYBUCJI">
                   <system_cache__appinfo:acl_rule_inherit_to_all_same_name_elements_and_refs/>

+ 22 - 6
SE/se-lib/RefConfig.php

@@ -43,20 +43,27 @@ class RefConfig {
 			select count(*) as cnt
 			from `CRM_REF_CONFIG` c
 			where c.A_STATUS = 'NORMAL' and c.VERSION < :version
+				and c.SOURCE in ( 'table', 'view', 'backRef' )
 		", [
 			':version' => self::$REF_TABLE_VERSION,
 		]);
 	}
-	static function getToUpdateItems($type = 'table') {
-		$sqlWhereAndType = "";
+	static function getToUpdateItems($type = 'table', $limit = 0, $idLast = 0) {
+		$sqlAndWhere = "";
+		$sqlLimit = "";
+		if ($limit > 0) { // && $idLast > 0) {
+			$sqlAndWhere .= " and c.ID > {$idLast} ";
+			$sqlLimit .= " order by c.ID ASC limit {$limit} ";
+		}
 		switch ($type) {
-			case 'backRef': $sqlWhereAndType = " and c.SOURCE in ( 'backRef' ) "; break;
-			default: $sqlWhereAndType = " and c.SOURCE in ( 'table', 'view' ) "; break;
+			case 'backRef': $sqlAndWhere .= " and c.SOURCE in ( 'backRef' ) "; break;
+			default: $sqlAndWhere .= " and c.SOURCE in ( 'table', 'view' ) "; break;
 		}
 		return DB::getPDO()->fetchAll("
 			select c.ID, c.ROOT_OBJECT_NS, c.CHILD_NAME, c.CHILD_NS
 			from `CRM_REF_CONFIG` c
-			where c.A_STATUS = 'NORMAL' and c.VERSION < :version {$sqlWhereAndType}
+			where c.A_STATUS = 'NORMAL' and c.VERSION < :version {$sqlAndWhere}
+			{$sqlLimit}
 		", [
 			':version' => self::$REF_TABLE_VERSION,
 		]);
@@ -357,7 +364,16 @@ class RefConfig {
 		$viewSelectSql = self::generateRefSelectSqlByBackRef($objectNamespace, $childTypeName);
 		if (!$refConfig) $refConfig = self::fetch($objectNamespace, $childTypeName);
 		$backRefTableViewName = Type_RefConfig::generateTableName($refConfig->id, 'backRef');
-		DB::getPDO()->execSql(" CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `{$backRefTableViewName}` AS {$viewSelectSql} ");
+		try {
+			DB::getPDO()->execSql(" CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `{$backRefTableViewName}` AS {$viewSelectSql} ");
+		} catch (Exception $e) {
+			DBG::log($e);
+			if ('HY000' === $e->getCode()) { // SQLSTATE[HY000]: General error: 1271 Illegal mix of collations for operation ' IN '
+				// Missing @charset=latin2 in `CRM_#CACHE_ACL_OBJECT`.`appInfo`
+				// FIX: add xs:appInfo: <system_cache__appinfo:table_structure system_cache__appinfo:charset="latin2"/>
+			}
+			throw $e;
+		}
 
 		$affected = DB::getPDO()->update("CRM_REF_CONFIG", 'ID', $refConfig->id, [
 			'SOURCE' => 'backRef',

+ 51 - 21
SE/se-lib/Route/Status.php

@@ -156,25 +156,53 @@ class Route_Status extends RouteBase {
 	function updateRefTablesPostTask() {
 		Lib::loadClass('RefConfig');
 		DBG::log("DBG:updateRefTablesPostTask...");
-		$toUpdateStep = 10;
-		$baseRefOffset = V::get('baseref_offset', 0, $_POST, 'int');
-		$backRefOffset = V::get('backref_offset', 0, $_POST, 'int');
-		$todoBaseRefOffset = $baseRefOffset;
-		$todoBackRefOffset = $backRefOffset;
-		$baseRefToUpdate = RefConfig::getToUpdateItems();
-		DBG::log($baseRefToUpdate, 'array', "DBG:updateRefTablesPostTask \$baseRefToUpdate");
-		if ($baseRefOffset > count($baseRefToUpdate)) {
-			$backRefToUpdate = RefConfig::getToUpdateItems('backRef');
-			$listBackRefConf = array_slice($backRefToUpdate, $backRefOffset, $toUpdateStep);
-			DBG::log($listBackRefConf, 'array', "DBG:updateRefTablesPostTask \$listBackRefConf ({$backRefOffset}, {$toUpdateStep})");
-			self::_updateRefTables($listBackRefConf);
-			$todoBackRefOffset = $backRefOffset + $toUpdateStep;
-		} else {
-			$listBaseRefConf = array_slice($baseRefToUpdate, $baseRefOffset, $toUpdateStep);
-			DBG::log($listBaseRefConf, 'array', "DBG:updateRefTablesPostTask \$listBaseRefConf ({$baseRefOffset}, {$toUpdateStep})");
-			self::_updateRefTables($listBaseRefConf);
-			$todoBaseRefOffset = $baseRefOffset + $toUpdateStep;
+
+		if (0) { // TEST
+			// 5345 is backRef 2411
+			$todoRef = DB::getPDO()->fetchAll("
+				select c.ID, c.ROOT_OBJECT_NS, c.CHILD_NAME, c.CHILD_NS
+				from `CRM_REF_CONFIG` c
+				where c.A_STATUS = 'NORMAL' and c.ID = :id
+			", [
+				':id' => 2411,
+			]);
+			self::_updateRefTables($todoRef);
+
+			$todoRef = DB::getPDO()->fetchAll("
+				select c.ID, c.ROOT_OBJECT_NS, c.CHILD_NAME, c.CHILD_NS
+				from `CRM_REF_CONFIG` c
+				where c.A_STATUS = 'NORMAL' and c.ID = :id
+			", [
+				':id' => 5345,
+			]);
+			self::_updateRefTables($todoRef);
+
+			return;
+		}
+
+		$toUpdateStep = 100;
+		$todoType = V::get('type_type', 'base', $_POST); // base | back
+		$idLast = V::get('id_last', 0, $_POST, 'int');
+		// $baseRefToUpdate = RefConfig::getToUpdateItems('', $toUpdateStep, $idLast);
+		$todoRef = [];
+		if ('base' === $todoType) {
+			$todoRef = RefConfig::getToUpdateItems('', $toUpdateStep, $idLast);
+			if (empty($todoRef)) {
+				$todoType = 'back';
+				$idLast = 0;
+			}
+		}
+		if ('back' === $todoType) {
+			$todoRef = RefConfig::getToUpdateItems('backRef', $toUpdateStep, $idLast);
+		}
+
+		if (!empty($todoRef)) {
+			self::_updateRefTables($todoRef);
+			$lastRef = end($todoRef);
+			$idLast = $lastRef['ID'];
 		}
+		DBG::nicePrint($todoRef, '$todoRef');
+		DBG::nicePrint($idLast, '$idLast');
 
 		$totalToUpdateRef = RefConfig::getToUpdateTotal();
 		echo ($totalToUpdateRef)
@@ -184,8 +212,8 @@ class Route_Status extends RouteBase {
 					'class' => "btn btn-xs btn-default",
 					'data' => [
 						'_postTask' => 'updateRefTables',
-						'baseref_offset' => $todoBaseRefOffset,
-						'backref_offset' => $todoBackRefOffset,
+						'id_last' => $idLast,
+						'type_type' => $todoType,
 					]
 				])
 			])
@@ -202,7 +230,9 @@ class Route_Status extends RouteBase {
 			try {
 				UI::alert('info', "Aktualizuje ['{$refConf['ID']}'] od '{$refConf['ROOT_OBJECT_NS']}' do '{$refConf['CHILD_NAME']}' ...");
 				RefConfig::getRefConfig($refConf['ROOT_OBJECT_NS'], $refConf['CHILD_NAME'], $refConf['CHILD_NS']);
+				// expected fix ref config and set current version if no errors
 			} catch (\Exception $e) {
+				echo UI::h('p', [ 'class' => "p5-refconfig-exception", 'style' => "display:none" ], "#ERROR: " . $e->getMessage());
 				DBG::log($e);
 				if ('Ref allowed only for AntAcl objects' === $e->getMessage()) {
 					$totalTableSkippedNotAcl++;
@@ -211,7 +241,7 @@ class Route_Status extends RouteBase {
 				} else if ("Not Implemented acl type ''" === substr($e->getMessage(), 0, strlen("Not Implemented acl type ''"))) {
 					$totalTableSkippedMissingAclType++;
 				}
-				UI::alert('danger', "Problem z aktualizacją tabeli z relacjami ['{$refConf['ID']}'] od '{$refConf['ROOT_OBJECT_NS']}' do '{$refConf['CHILD_NAME']}'");
+				UI::alert('danger', "Problem z aktualizacją tabeli z relacjami ['{$refConf['ID']}'] od '{$refConf['ROOT_OBJECT_NS']}' do '{$refConf['CHILD_NAME']}'");
 			}
 		}
 		if ($totalTableSkippedNotAcl) UI::alert('warning', "Nie zaktualizowano {$totalTableSkippedNotAcl} tabeli z relajami - obiekty różnego typu od 'Acl'");