Explorar o código

FixCrmProcesInitIdx use msg from storage

Piotr Labudda %!s(int64=10) %!d(string=hai) anos
pai
achega
32134c2408
Modificáronse 1 ficheiros con 40 adicións e 3 borrados
  1. 40 3
      SE/se-lib/Route/FixCrmProcesInitIdx.php

+ 40 - 3
SE/se-lib/Route/FixCrmProcesInitIdx.php

@@ -27,7 +27,19 @@ class Route_FixCrmProcesInitIdx extends RouteBase {
 		if ($DBG_TIME) $dbgExecTime->activate();
 		$dbgExecTime->log('start');
 
-		$this->_callProcedure();
+		try {
+			$this->_callProcedure();
+		} catch (Exception $e) {
+			?>
+			<div class="container">
+				<div class="alert alert-warning">
+					<?php echo $e->getMessage(); ?>
+				</div>
+			</div>
+			<?php
+			SE_Layout::dol();
+			exit;
+		}
 
 		$dbgExecTime->log('procedure');
 		$procExecTime = $dbgExecTime->getLastExecTime();
@@ -61,7 +73,18 @@ class Route_FixCrmProcesInitIdx extends RouteBase {
 		}
 		$res = $db->query($sql);
 		if ($db->has_errors()) {
-			throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
+			$dbErrors = array();
+			if ($db->has_errors()) {
+				$dbErrorsSql = $db->get_errors();
+				foreach ($dbErrorsSql as $vErr) {
+					if ('SQL QUERY FAILED: ' == substr($vErr, 0, 18)) {
+						$vErr = substr($vErr, 18);
+					}
+					//$dbErrors[] = StorageException::parseMessage($vErr);
+					$dbErrors[] = $vErr;
+				}
+			}
+			throw new StorageException($dbErrors);
 		}
 	}
 
@@ -375,6 +398,8 @@ BEGIN
 
 		replace into `CRM_CONFIG` (`conf_key`, `conf_val`) values (@conf_last_exec_lock_key, NOW()), (@conf_last_exec_start_key, NOW());
 
+-- select sleep(2); -- // DBG
+
 -- select 'truncate->delete...';
 		truncate table `CRM_PROCES_idx`;
 		-- delete from `CRM_PROCES_idx`;
@@ -403,7 +428,6 @@ BEGIN
 		update `CRM_PROCES_idx` i
 				join `CRM_WSKAZNIK` as wsk on(wsk.`ID_PROCES`=i.`ID`
 						and wsk.`A_STATUS` in('NORMAL', 'WAITING')
-						-- TODO: and wsk.`` like 'X' - IF(przyp.`FORM_TREAT` & 8, 1, 0) as PERM_X
 					)
 				join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=wsk.`ID_ZASOB`
 						and z.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
@@ -503,4 +527,17 @@ SQL;
 		}
 	}
 
+	/*
+		#1146 - Table '{DATABASE_NAME}.P5-MSG:Route_FixCrmProcesInitIdx:ERROR: Already executed' doesn't exist
+	 */
+	public function parseMessageFromStorage($msg) {
+		switch ($msg) {
+			case 'ERROR: Already executed': {
+				$msg = "Aktualizacja uprawnień została już uruchomiona przez inną osobę";
+				break;
+			}
+		}
+		return $msg;
+	}
+
 }