| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Public facade for uninstall diagnostics used by the modal and feedback email. |
| 10 |
* |
| 11 |
* Concrete readers own statistics, WordPress inventory, database metadata, |
| 12 |
* and collation snapshot presentation. This class preserves the historical |
| 13 |
* static API used by uninstall entry points. |
| 14 |
* |
| 15 |
* @since 4.3.0 |
| 16 |
*/ |
| 17 |
class ABJ_404_Solution_UninstallDiagnostics { |
| 18 |
|
| 19 |
/** |
| 20 |
* Get the count of redirects for display in the modal preview. |
| 21 |
* |
| 22 |
* @return int Number of active non-trashed redirects, or 0 if the table is missing. |
| 23 |
*/ |
| 24 |
public static function getRedirectCount(): int { |
| 25 |
return self::statisticsReader()->getRedirectCount(); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Get comprehensive plugin statistics for the diagnostic email. |
| 30 |
* |
| 31 |
* @return array{ |
| 32 |
* redirects: array{all:int,manual:int,auto:int,regex:int,trash:int}, |
| 33 |
* captured: array{all:int,captured:int,ignored:int,later:int,trash:int}, |
| 34 |
* log_count: int, |
| 35 |
* log_table_size_mb: int|float, |
| 36 |
* debug_file_size_mb: int|float, |
| 37 |
* _errors?: list<string> |
| 38 |
* } |
| 39 |
*/ |
| 40 |
public static function getPluginStatistics(): array { |
| 41 |
return self::statisticsReader()->getPluginStatistics(); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Get counts of categories, tags, pages, and posts for diagnostics. |
| 46 |
* |
| 47 |
* @return array{categories:int,tags:int,pages:int,posts:int} |
| 48 |
*/ |
| 49 |
public static function getContentCounts(): array { |
| 50 |
return self::wordPressInventory()->getContentCounts(); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Get a comma-separated list of active plugin names capped at 10. |
| 55 |
* |
| 56 |
* @return string |
| 57 |
*/ |
| 58 |
public static function getActivePluginsList(): string { |
| 59 |
return self::wordPressInventory()->getActivePluginsList(); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Get database version and charset info for diagnostics. |
| 64 |
* |
| 65 |
* @return array{version:string,charset:string,collation:string} |
| 66 |
*/ |
| 67 |
public static function getDatabaseInfo(): array { |
| 68 |
return self::databaseDefaultsReader()->getDatabaseInfo(); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Capture charset/collation details for key plugin tables. |
| 73 |
* |
| 74 |
* @return string Human-readable summary for email diagnostics. |
| 75 |
*/ |
| 76 |
public static function getDatabaseCollationSnapshot(): string { |
| 77 |
return self::collationSnapshotPresenter()->present(); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Get table info with fallback chain for locked-down hosts. |
| 82 |
* |
| 83 |
* @param string $tableName Table name to look up. |
| 84 |
* @return array{charset?:string|null,collation?:string|null,engine?:string,error?:string,source?:string} |
| 85 |
*/ |
| 86 |
public static function getTableInfo(string $tableName): array { |
| 87 |
$result = self::tryInformationSchema($tableName); |
| 88 |
if ($result !== null && !isset($result['error'])) { |
| 89 |
return $result; |
| 90 |
} |
| 91 |
|
| 92 |
$result = self::tryShowTableStatus($tableName); |
| 93 |
if ($result !== null && !isset($result['error'])) { |
| 94 |
return $result; |
| 95 |
} |
| 96 |
|
| 97 |
$result = self::tryShowCreateTable($tableName); |
| 98 |
if ($result !== null && !isset($result['error'])) { |
| 99 |
return $result; |
| 100 |
} |
| 101 |
|
| 102 |
return self::getWpdbDefaults(); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Compatibility wrapper for legacy reflection tests. |
| 107 |
* |
| 108 |
* @param string $tableName Table name to look up. |
| 109 |
* @return array{charset?:string|null,collation?:string|null,engine?:string,error?:string}|null |
| 110 |
*/ |
| 111 |
private static function tryInformationSchema(string $tableName) { |
| 112 |
return self::databaseMetadataReader()->tryInformationSchema($tableName); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Compatibility wrapper for legacy reflection tests. |
| 117 |
* |
| 118 |
* @param string $tableName Table name to look up. |
| 119 |
* @return array{charset?:string|null,collation?:string|null,engine?:string,error?:string}|null |
| 120 |
*/ |
| 121 |
private static function tryShowTableStatus(string $tableName) { |
| 122 |
return self::databaseMetadataReader()->tryShowTableStatus($tableName); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Compatibility wrapper for legacy reflection tests. |
| 127 |
* |
| 128 |
* @param string $tableName Table name to look up. |
| 129 |
* @return array{charset?:string|null,collation?:string|null,engine?:string,error?:string}|null |
| 130 |
*/ |
| 131 |
private static function tryShowCreateTable(string $tableName) { |
| 132 |
return self::databaseMetadataReader()->tryShowCreateTable($tableName); |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Compatibility wrapper for legacy reflection tests. |
| 137 |
* |
| 138 |
* @return array{charset:string,collation:string,engine:string,source:string} |
| 139 |
*/ |
| 140 |
private static function getWpdbDefaults(): array { |
| 141 |
return self::databaseMetadataReader()->getWpdbDefaults(); |
| 142 |
} |
| 143 |
|
| 144 |
private static function statisticsReader(): ABJ_404_Solution_UninstallStatisticsReader { |
| 145 |
return new ABJ_404_Solution_UninstallStatisticsReader(); |
| 146 |
} |
| 147 |
|
| 148 |
private static function wordPressInventory(): ABJ_404_Solution_UninstallWordPressInventory { |
| 149 |
return new ABJ_404_Solution_UninstallWordPressInventory(); |
| 150 |
} |
| 151 |
|
| 152 |
private static function databaseMetadataReader(): ABJ_404_Solution_UninstallDatabaseMetadataReader { |
| 153 |
return new ABJ_404_Solution_UninstallDatabaseMetadataReader(); |
| 154 |
} |
| 155 |
|
| 156 |
private static function databaseDefaultsReader(): ABJ_404_Solution_UninstallDatabaseDefaultsReader { |
| 157 |
return new ABJ_404_Solution_UninstallDatabaseDefaultsReader(); |
| 158 |
} |
| 159 |
|
| 160 |
private static function collationSnapshotPresenter(): ABJ_404_Solution_UninstallCollationSnapshotPresenter { |
| 161 |
return new ABJ_404_Solution_UninstallCollationSnapshotPresenter(self::databaseMetadataReader()); |
| 162 |
} |
| 163 |
} |
| 164 |
|