> */ private const RETIRED = array( 'abj404_logsv2' => array('country', 'location', 'reason'), 'abj404_permalink_cache' => array('structure', 'rowtype'), 'abj404_ngram_cache' => array('page_id'), 'abj404_spelling_cache' => array('redirect_id'), ); /** * Whether this plugin deliberately retired a column from a table. * * The table matches when its name ENDS with a listed suffix, so any WordPress * or multisite prefix works and a name that merely contains or extends a * suffix (wp_abj404_logsv2_tmp, wp_abj404_logsv2x) does not. The column * comparison is case-insensitive; neither argument is trimmed. * * @param string $tableName Full table name including the WordPress prefix. * @param string $columnName Column name. * @return bool True only when the column is listed as retired for this table. */ public static function isRetired(string $tableName, string $columnName): bool { if ($columnName === '') { return false; } return in_array(strtolower($columnName), self::retiredFor($tableName), true); } /** * The retired columns of a table. * * @param string $tableName Full table name including the WordPress prefix. * @return array Lowercase column names; empty when the table has none, * including when the name only contains or extends a known suffix. */ public static function retiredFor(string $tableName): array { $lowerName = strtolower($tableName); foreach (self::RETIRED as $suffix => $columns) { $suffixLength = strlen($suffix); if (strlen($lowerName) >= $suffixLength && substr($lowerName, -$suffixLength) === $suffix) { return $columns; } } return array(); } /** * Sort columns a build's DDL does not declare into the ones this plugin * deliberately retired (safe to drop) and the unknown ones (kept). * * @param string $tableName Full table name including the WordPress prefix. * @param array $columns Column names to sort; input order is kept. * @return array{retired: array, unknown: array} */ public static function partition(string $tableName, array $columns): array { $partitioned = array('retired' => array(), 'unknown' => array()); foreach ($columns as $column) { $kind = self::isRetired($tableName, $column) ? 'retired' : 'unknown'; $partitioned[$kind][] = $column; } return $partitioned; } }