Explorar el Código

StorageException: change msg format

Piotr Labudda hace 11 años
padre
commit
0dfc6a8885
Se han modificado 3 ficheros con 80 adiciones y 32 borrados
  1. 33 6
      SE/se-lib/Route/FixProjectPath.php
  2. 26 0
      SE/se-lib/RouteBase.php
  3. 21 26
      SE/se-lib/StorageException.php

+ 33 - 6
SE/se-lib/Route/FixProjectPath.php

@@ -153,7 +153,6 @@ jQuery(document).ready(function () {
 					set p.`path`=i.`idx_PATH`;
 				update `IN7_DZIENNIK_KORESP` k left join `_project_path_idx` i on(i.`ID`=k.`ID_PROJECT`)
 					set k.`path`=coalesce(i.`idx_PATH`, '?');
-				-- TODO: update `PROBLEMS` if exists
 				update `PROBLEMS` pr left join `_project_path_idx` i on(i.`ID`=pr.`ID_PROJECT`)
 					set pr.`ID_PROJECT_path`=coalesce(i.`idx_PATH`, '?');
 			END ;
@@ -192,13 +191,13 @@ jQuery(document).ready(function () {
 						-- send error if loop
 						-- OLD.path like concat('%-', NEW.P_ID, '-%')
 						IF OLD.ID = NEW.P_ID THEN
-							UPDATE `ERROR: Loop detected ID=P_ID` SET x=1;
+							UPDATE `P5-MSG:Route_FixProjectPath:ERROR: Loop detected ID=P_ID` SET x=1;
 							-- #1146 - Table 'biall.ERROR: Loop detected ID=P_ID' doesn't exist
 						END IF;
 						IF NEW.P_ID > 0 THEN
 							-- check if project exists
 							IF (select count(1) from `IN7_MK_BAZA_DYSTRYBUCJI` p where p.`ID`=NEW.P_ID) = 0 THEN
-								UPDATE `ERROR: Parent item not exists` SET x=1;
+								UPDATE `P5-MSG:Route_FixProjectPath:ERROR: Parent item not exists` SET x=1;
 								-- #1146 - Table 'biall.ERROR: Parent item not exists' doesn't exist
 							END IF;
 							-- check loop error
@@ -209,7 +208,7 @@ jQuery(document).ready(function () {
 									or p.`path` like concat(OLD.ID,'-%')
 									, 1
 									, 0) from `IN7_MK_BAZA_DYSTRYBUCJI` p where p.`ID`=NEW.P_ID) > 0 THEN
-								UPDATE `ERROR: Loop detected in path` SET x=1;
+								UPDATE `P5-MSG:Route_FixProjectPath:ERROR: Loop detected in path` SET x=1;
 								-- #1146 - Table 'biall.ERROR: Loop detected in path' doesn't exist
 							END IF;
 						END IF;
@@ -228,7 +227,7 @@ jQuery(document).ready(function () {
 						-- DONT: throw warning to update all pathes in `IN7_MK_BAZA_DYSTRYBUCJI` with path under current?
 						-- NOTE: throw error like that prevent update fields
 						-- IF (select count(1) from `IN7_MK_BAZA_DYSTRYBUCJI` p where p.`P_ID`=NEW.ID) > 0 THEN
-						-- 	UPDATE `WARNING: Update all paths` SET x=1;
+						-- 	UPDATE `P5-MSG:Route_FixProjectPath:WARNING: Update all paths` SET x=1;
 						-- END IF;
 
 						-- DONT: update `IN7_DZIENNIK_KORESP`.`path` - rows under NEW.ID has wrong path
@@ -253,7 +252,7 @@ jQuery(document).ready(function () {
 					IF NEW.`P_ID`!=OLD.`P_ID` THEN
 						-- throw warning to update all pathes in `IN7_MK_BAZA_DYSTRYBUCJI` with path under current?
 						IF (select count(1) from `IN7_MK_BAZA_DYSTRYBUCJI` p where p.`P_ID`=NEW.ID) > 0 THEN
-							UPDATE `WARNING: Update all paths` SET x=1;
+							UPDATE `P5-MSG:Route_FixProjectPath:WARNING: Update all paths` SET x=1;
 						END IF;
 					END IF;
 				END
@@ -336,6 +335,34 @@ jQuery(document).ready(function () {
 		}
 	}
 
+	/*
+		Table 'DB.P5-MSG:Route_FixProjectPath:WARNING: Update all paths' doesn't exist
+		Table 'DB.P5-MSG:Route_FixProjectPath:ERROR: Loop detected ID=P_ID' doesn't exist
+		Table 'DB.P5-MSG:Route_FixProjectPath:ERROR: Parent item not exists' doesn't exist
+		Table 'DB.P5-MSG:Route_FixProjectPath:ERROR: Loop detected in path' doesn't exist
+	 */
+	public function parseMessageFromStorage($msg) {
+		switch ($msg) {
+			case 'WARNING: Update all paths': {
+				$msg = "Zaktualizuj ścieżki projektów!";
+				break;
+			}
+			case 'ERROR: Loop detected ID=P_ID': {
+				$msg = "Nr rekordu nadrzędnego musi różnić się od nr rekordu";
+				break;
+			}
+			case 'ERROR: Parent item not exists': {
+				$msg = "Nie istnieje rekord o numerze podanym jako nr nadrzędny";
+				break;
+			}
+			case 'ERROR: Loop detected in path': {
+				$msg = "Nieprawidłowy nr nadrzędny";
+				break;
+			}
+		}
+		return $msg;
+	}
+
 }
 
 /**

+ 26 - 0
SE/se-lib/RouteBase.php

@@ -21,4 +21,30 @@ class RouteBase {
 		die("default task not implemented");
 	}
 
+	public function parseMessageFromStorageTestAction() {
+		$msgs = V::get('msgs', '', $_GET);
+		//echo $this->parseMessageFromStorage($msg);
+		Lib::loadClass('StorageException');
+		if (is_array($msgs)) {
+			foreach ($msgs as $vMsg) {
+				try {
+					throw new StorageException($vMsg);
+				} catch (Exception $e) {
+					$vParsedMsg = $e->getMessage();
+					echo "   MSG: {$vMsg}\n";
+					echo "PARSED: {$vParsedMsg}\n";
+					echo "isMsgParsed(" . ($vMsg != $vParsedMsg) . ")\n\n";
+				}
+			}
+		} else {
+			throw new StorageException($msgs);
+		}
+		echo "\n\n";
+		die("parseMessageFromStorage end");
+	}
+
+	public function parseMessageFromStorage($msg) {
+		return $msg;
+	}
+
 }

+ 21 - 26
SE/se-lib/StorageException.php

@@ -11,7 +11,7 @@ class StorageException extends Exception {
 				}
 				$message = implode("\n", $dsErrors);
 			} else {
-				$message = 'XXX' . json_encode($message);
+				$message = 'XXX' . json_encode($message);// DBG
 			}
 		} else {
 			$message = self::parseMessage($message);
@@ -21,39 +21,34 @@ class StorageException extends Exception {
 
 	public static function parseMessage($message) {
 		$parsedMsg = $message;
+		// UPDATE `P5-MSG:Route_FixZasobPath:ERROR: Loop detected in path` SET x=1;
 		//echo "\nMSG: ({$message})\n";
 		//echo "\nMSG substr(0, 7): (" . substr($message, 0, 7) . ") substr(-15): (" . substr($message, -15) . ")\n";
 		if ("Table '" == substr($message, 0, 7) && "' doesn't exist" == substr($message, -15)) {
-			//  #1146 - Table '{DATABASE_NAME}.WARNING: Update all paths' doesn't exist
-			//  #1146 - Table '{DATABASE_NAME}.ERROR: Loop detected ID=P_ID' doesn't exist
-			//  #1146 - Table '{DATABASE_NAME}.ERROR: Parent item not exists' doesn't exist
-			//  #1146 - Table '{DATABASE_NAME}.ERROR: Loop detected in path' doesn't exist
+			//  #1146 - Table '{DATABASE_NAME}.P5-MSG:{CLASS_NAME}:WARNING: Update all paths' doesn't exist
+			//  #1146 - Table '{DATABASE_NAME}.P5-MSG:{CLASS_NAME}:ERROR: Loop detected ID=P_ID' doesn't exist
+			//  #1146 - Table '{DATABASE_NAME}.P5-MSG:{CLASS_NAME}:ERROR: Parent item not exists' doesn't exist
+			//  #1146 - Table '{DATABASE_NAME}.P5-MSG:{CLASS_NAME}:ERROR: Loop detected in path' doesn't exist
+			$clsName = null;
 			$tmpMsg = $message;
 			$tmpMsg = substr($tmpMsg, 7);
 			$tmpMsg = substr($tmpMsg, 0, -15);
-			if (false !== ($pos = strpos($tmpMsg, 'WARNING:'))) {
-				$tmpMsg = substr($tmpMsg, $pos + 9);
+			if (false !== ($pos = strpos($tmpMsg, '.P5-MSG:'))) {
+				$tmpMsg = substr($tmpMsg, $pos + 8);
+				//echo "DBG has P5-MSG({$tmpMsg})\n";
 			}
-			if (false !== ($pos = strpos($tmpMsg, 'ERROR:'))) {
-				$tmpMsg = substr($tmpMsg, $pos + 7);
+			if (false !== ($pos = strpos($tmpMsg, ':'))) {
+				$clsName = substr($tmpMsg, 0, $pos);
+				$tmpMsg = substr($tmpMsg, $pos + 1);
+				//echo "DBG has class({$clsName}) msg({$tmpMsg})\n";
 			}
-			//echo "\ntmpMsg: ({$tmpMsg})\n";
-			switch ($tmpMsg) {
-				case 'Update all paths': {
-					$parsedMsg = "Zaktualizuj ścieżki projektów!";
-					break;
-				}
-				case 'Loop detected ID=P_ID': {
-					$parsedMsg = "Nr rekordu nadrzędnego musi różnić się od nr rekordu";
-					break;
-				}
-				case 'Parent item not exists': {
-					$parsedMsg = "Nie istnieje rekord o numerze podanym jako nr nadrzędny";
-					break;
-				}
-				case 'Loop detected in path': {
-					$parsedMsg = "Nieprawidłowy nr nadrzędny";
-					break;
+			if ($clsName) {
+				if (Lib::tryLoadClass($clsName)) {
+					$obj = new $clsName();
+					$methodName = 'parseMessageFromStorage';
+					if (method_exists($obj, $methodName)) {
+						$parsedMsg = $obj->{$methodName}($tmpMsg);
+					}
 				}
 			}
 		}