$columns ) { $exists[ $table ] = $read->exists( $table ); } if ( ! in_array( true, $exists, true ) ) { if ( in_array( $marker, $absent_markers, true ) ) { return false; } throw new \RuntimeException( 'retained_store_missing' ); } if ( in_array( false, $exists, true ) || $marker !== $version ) { throw new \RuntimeException( 'retained_store_incomplete' ); } foreach ( $definitions as $suffix => $expected ) { $columns = Db::rows( $wpdb->suppress_errors( true ), $wpdb->get_results( $wpdb->prepare( 'SHOW COLUMNS FROM %i', $read->table( $suffix ) ), ARRAY_A ), 'retained_capacity_storage_unavailable' ); $actual = array(); foreach ( $columns as $column ) { $actual[ $column['Field'] ] = preg_replace( '/\b(bigint|tinyint|int)\(\d+\)/', '$1', strtolower( $column['Type'] ) ); } foreach ( $expected as $name => $type ) { if ( ! isset( $actual[ $name ] ) || ( $type !== '' && $actual[ $name ] !== $type ) ) { throw new \RuntimeException( 'retained_store_shape' ); } } $indexes = Db::rows( $wpdb->suppress_errors( true ), $wpdb->get_results( $wpdb->prepare( 'SHOW INDEX FROM %i', $read->table( $suffix ) ), ARRAY_A ), 'retained_capacity_storage_unavailable' ); $keys = array(); foreach ( $indexes as $index ) { if ( (int) $index['Non_unique'] === 0 ) { $keys[ $index['Key_name'] ][ (int) $index['Seq_in_index'] ] = $index['Column_name']; } } $ordered = array(); foreach ( $keys as $key ) { ksort( $key ); $ordered[] = array_values( $key ); } foreach ( $unique[ $suffix ] ?? array() as $required ) { if ( ! in_array( $required, $ordered, true ) ) { throw new \RuntimeException( 'retained_store_index' ); } } } return true; } }