| 1 |
<?php |
| 2 |
/** |
| 3 |
* Pure database schema / data-shape error taxonomy. |
| 4 |
* |
| 5 |
* Owns string-based classification of integrity failures: corrupted or |
| 6 |
* crashed tables (MyISAM "marked as crashed", "Incorrect key file"), |
| 7 |
* missing plugin tables, transient view-build table churn, and data-shape |
| 8 |
* issues (invalid UTF-8, collation mismatch). These are the error classes |
| 9 |
* the auto-repair, table-recreate, and collation-degrade policies act on. |
| 10 |
* |
| 11 |
* No side effects: callers reuse the matchers without inheriting recovery |
| 12 |
* behavior. |
| 13 |
*/ |
| 14 |
|
| 15 |
if (!defined('ABSPATH')) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
// allow-no-test-found: covered through DatabaseInfrastructureErrorTaxonomy facade by tests/ErrorClassifierTest.php and tests/StagedBuildHostQuirksTest.php |
| 20 |
class ABJ_404_Solution_DatabaseSchemaErrorTaxonomy { |
| 21 |
|
| 22 |
/** @var ABJ_404_Solution_Functions */ |
| 23 |
private $f; |
| 24 |
|
| 25 |
/** |
| 26 |
* @param ABJ_404_Solution_Functions $functions |
| 27 |
*/ |
| 28 |
public function __construct($functions) { |
| 29 |
$this->f = $functions; |
| 30 |
} |
| 31 |
|
| 32 |
/** @param string $errorText @return bool */ |
| 33 |
public function isCrashedTableError(string $errorText): bool { |
| 34 |
if ($errorText === '') { |
| 35 |
return false; |
| 36 |
} |
| 37 |
return stripos($errorText, 'is marked as crashed') !== false; |
| 38 |
} |
| 39 |
|
| 40 |
/** @param string $errorText @return bool */ |
| 41 |
public function isIncorrectKeyFileError(string $errorText): bool { |
| 42 |
if ($errorText === '') { |
| 43 |
return false; |
| 44 |
} |
| 45 |
return stripos($errorText, 'Incorrect key file') !== false; |
| 46 |
} |
| 47 |
|
| 48 |
/** @param string $errorText @return bool */ |
| 49 |
public function isMissingPluginTableError(string $errorText): bool { |
| 50 |
if ($errorText === '') { |
| 51 |
return false; |
| 52 |
} |
| 53 |
$lower = strtolower($errorText); |
| 54 |
if ($this->f->strpos($lower, '_abj404_logs_hits') !== false) { |
| 55 |
return false; |
| 56 |
} |
| 57 |
return ($this->f->strpos($lower, "doesn't exist") !== false && |
| 58 |
$this->f->strpos($lower, '_abj404_') !== false); |
| 59 |
} |
| 60 |
|
| 61 |
/** @param string $errorText @return bool */ |
| 62 |
public function isTransientViewBuildTableError(string $errorText): bool { |
| 63 |
if ($errorText === '') { |
| 64 |
return false; |
| 65 |
} |
| 66 |
$lower = strtolower($errorText); |
| 67 |
return ($this->f->strpos($lower, '_abj404_view_build') !== false || |
| 68 |
$this->f->strpos($lower, '_abj404_view_done') !== false || |
| 69 |
$this->f->strpos($lower, '_abj404_view_deleteme') !== false); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Determine whether an error indicates invalid text/charset payload. |
| 74 |
* |
| 75 |
* @param mixed $errorText |
| 76 |
* @return bool |
| 77 |
*/ |
| 78 |
public function isInvalidDataError($errorText): bool { |
| 79 |
if (!is_string($errorText) || $errorText === '') { |
| 80 |
return false; |
| 81 |
} |
| 82 |
$lower = strtolower($errorText); |
| 83 |
return ( |
| 84 |
$this->f->strpos($lower, 'contains invalid data') !== false || |
| 85 |
$this->f->strpos($lower, 'incorrect string value') !== false || |
| 86 |
$this->f->strpos($lower, 'invalid utf8') !== false |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
/** @param string $errorText @return bool */ |
| 91 |
public function isCollationError(string $errorText): bool { |
| 92 |
if ($errorText === '') { |
| 93 |
return false; |
| 94 |
} |
| 95 |
$lower = strtolower($errorText); |
| 96 |
return ($this->f->strpos($lower, 'illegal mix of collations') !== false || |
| 97 |
$this->f->strpos($lower, 'unknown collation') !== false || |
| 98 |
$this->f->strpos($lower, 'collation') !== false && $this->f->strpos($lower, 'not valid') !== false); |
| 99 |
} |
| 100 |
} |
| 101 |
|