StorageException.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. class StorageException extends Exception {
  3. public function __construct($message = null, $code = 0, Exception $previous = null) {
  4. if (is_array($message)) {
  5. if (count($message) > 0) {
  6. $dsErrors = array();
  7. foreach ($message as $vMsg) {
  8. $dsErrors[] = self::parseMessage($vMsg);
  9. }
  10. $message = implode("\n", $dsErrors);
  11. } else {
  12. $message = 'XXX' . json_encode($message);// DBG
  13. }
  14. } else {
  15. $message = self::parseMessage($message);
  16. }
  17. return parent::__construct($message, $code, $previous);
  18. }
  19. public static function parseMessage($message) {
  20. $parsedMsg = $message;
  21. // UPDATE `P5-MSG:Route_FixZasobPath:ERROR: Loop detected in path` SET x=1;
  22. //echo "\nMSG: ({$message})\n";
  23. //echo "\nMSG substr(0, 7): (" . substr($message, 0, 7) . ") substr(-15): (" . substr($message, -15) . ")\n";
  24. if ("Table '" == substr($message, 0, 7) && "' doesn't exist" == substr($message, -15)) {
  25. // #1146 - Table '{DATABASE_NAME}.P5-MSG:{CLASS_NAME}:WARNING: Update all paths' doesn't exist
  26. // #1146 - Table '{DATABASE_NAME}.P5-MSG:{CLASS_NAME}:ERROR: Loop detected ID=P_ID' doesn't exist
  27. // #1146 - Table '{DATABASE_NAME}.P5-MSG:{CLASS_NAME}:ERROR: Parent item not exists' doesn't exist
  28. // #1146 - Table '{DATABASE_NAME}.P5-MSG:{CLASS_NAME}:ERROR: Loop detected in path' doesn't exist
  29. $clsName = null;
  30. $tmpMsg = $message;
  31. $tmpMsg = substr($tmpMsg, 7);
  32. $tmpMsg = substr($tmpMsg, 0, -15);
  33. if (false !== ($pos = strpos($tmpMsg, '.P5-MSG:'))) {
  34. $tmpMsg = substr($tmpMsg, $pos + 8);
  35. //echo "DBG has P5-MSG({$tmpMsg})\n";
  36. }
  37. if (false !== ($pos = strpos($tmpMsg, ':'))) {
  38. $clsName = substr($tmpMsg, 0, $pos);
  39. $tmpMsg = substr($tmpMsg, $pos + 1);
  40. //echo "DBG has class({$clsName}) msg({$tmpMsg})\n";
  41. }
  42. if ($clsName) {
  43. if (Lib::tryLoadClass($clsName)) {
  44. $obj = new $clsName();
  45. $methodName = 'parseMessageFromStorage';
  46. if (method_exists($obj, $methodName)) {
  47. $parsedMsg = $obj->{$methodName}($tmpMsg);
  48. }
  49. }
  50. }
  51. }
  52. return $parsedMsg;
  53. }
  54. }