legacyIndexes() as $tableName => $indexName ) { if ( ! $this->indexExists( $tableName, $indexName ) ) { continue; } // $tableName and $indexName are hardcoded in legacyIndexes(); no user input. aioseo()->core->db->execute( "ALTER TABLE `{$tableName}` DROP INDEX `{$indexName}`" ); } // Verify all drops landed before wiping the cache. If something failed, // verify() will return false and the runner will retry on the next request. if ( ! $this->verify() ) { return; } aioseo()->core->cache->clear(); } /** * {@inheritdoc} * * @since 4.9.7.2 */ public function verify() { foreach ( $this->legacyIndexes() as $tableName => $indexName ) { if ( $this->indexExists( $tableName, $indexName ) ) { return false; } } return true; } /** * The legacy unique indexes this migration drops, keyed by full table name. * * @since 4.9.7.2 * * @return array */ private function legacyIndexes() { $prefix = aioseo()->core->db->db->prefix; return [ $prefix . 'aioseo_cache' => 'ndx_aioseo_cache_key', $prefix . 'aioseo_crawl_cleanup_blocked_args' => 'ndx_aioseo_crawl_cleanup_blocked_args_key_value_hash' ]; } /** * Whether the given index currently exists on the given table. * * @since 4.9.7.2 * * @param string $tableName Full table name (with prefix). * @param string $indexName Index name. * @return bool */ private function indexExists( $tableName, $indexName ) { $db = aioseo()->core->db->db; $result = $db->get_var( $db->prepare( 'SELECT INDEX_NAME FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s AND INDEX_NAME = %s', $tableName, $indexName ) ); return ! empty( $result ); } }