| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Read-only metadata queries against the database engine and WordPress content. |
| 9 |
* |
| 10 |
* Owns the three "ask the DB what it can do" reads previously inlined in |
| 11 |
* ViewReadService: per-table engine name, MyISAM support flag, and the |
| 12 |
* distinct post-type list from wp_posts. Extracted in the i805 ViewReadService |
| 13 |
* decomposition so the staged view-read service stays focused on its |
| 14 |
* pipeline. |
| 15 |
*/ |
| 16 |
class ABJ_404_Solution_DatabaseMetadataReader { |
| 17 |
|
| 18 |
/** @var ABJ_404_Solution_DatabaseCore */ |
| 19 |
private $dbCore; |
| 20 |
|
| 21 |
/** |
| 22 |
* @param ABJ_404_Solution_DatabaseCore $dbCore |
| 23 |
*/ |
| 24 |
public function __construct(ABJ_404_Solution_DatabaseCore $dbCore) { |
| 25 |
$this->dbCore = $dbCore; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Run the canned selectTableEngines.sql query and return the raw |
| 30 |
* queryAndGetResults envelope (rows + last_error + timed_out). |
| 31 |
* |
| 32 |
* @return array<string, mixed> |
| 33 |
*/ |
| 34 |
public function getTableEngines(): array { |
| 35 |
$query = ABJ_404_Solution_FileSystemService::readFileContents(__DIR__ . "/../sql/selectTableEngines.sql"); |
| 36 |
return $this->dbCore->queryAndGetResults($query); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* @return bool True if information_schema.ENGINES reports SUPPORT=YES for MyISAM. |
| 41 |
*/ |
| 42 |
public function isMyISAMSupported(): bool { |
| 43 |
$supportResults = $this->dbCore->queryAndGetResults( |
| 44 |
"SELECT ENGINE, SUPPORT FROM information_schema.ENGINES WHERE lower(ENGINE) = 'myisam'", |
| 45 |
array('log_errors' => false) |
| 46 |
); |
| 47 |
|
| 48 |
if (!empty($supportResults) && !empty($supportResults['rows']) && is_array($supportResults['rows'])) { |
| 49 |
$rows = $supportResults['rows']; |
| 50 |
$row = is_array($rows[0] ?? null) ? $rows[0] : array(); |
| 51 |
$supportValue = array_key_exists('support', $row) ? (string)($row['support'] ?? '') |
| 52 |
: (array_key_exists('SUPPORT', $row) ? (string)($row['SUPPORT'] ?? '') : 'nope'); |
| 53 |
return strtolower($supportValue) == 'yes'; |
| 54 |
} |
| 55 |
return false; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* @return array<int, string> Distinct post_type values from wp_posts in alphabetical order. |
| 60 |
*/ |
| 61 |
public function getAllPostTypes(): array { |
| 62 |
// LIMIT 200 bounds the DISTINCT scan on wp_posts (design-audit-2026-06-06 M502 / i309). |
| 63 |
// CPT-heavy ecommerce/learning installs can hold tens of millions of rows; without a |
| 64 |
// LIMIT the admin advanced-settings render forces a full-table read to compute the |
| 65 |
// distinct set. WordPress sites with over 200 distinct post types are pathological, so |
| 66 |
// 200 is well above any legitimate count and keeps the read cheap on large installs. |
| 67 |
$query = "SELECT DISTINCT post_type FROM {wp_posts} order by post_type LIMIT 200"; |
| 68 |
$results = $this->dbCore->queryAndGetResults($query); |
| 69 |
$rows = $results['rows']; |
| 70 |
|
| 71 |
$postType = array(); |
| 72 |
if (is_array($rows)) { |
| 73 |
foreach ($rows as $row) { |
| 74 |
array_push($postType, $row['post_type']); |
| 75 |
} |
| 76 |
} |
| 77 |
return $postType; |
| 78 |
} |
| 79 |
} |
| 80 |
|