Yoast\WP\SEO\Repositories
Indexable_Cleanup_Repository::clean_indexables_for_object_type_and_source_table()
Deletes rows from the indexable table where the source is no longer there.
Метод класса: Indexable_Cleanup_Repository{}
Хуков нет.
Возвращает
int|true|false
. The number of rows that was deleted or false if the query failed.
Использование
$Indexable_Cleanup_Repository = new Indexable_Cleanup_Repository(); $Indexable_Cleanup_Repository->clean_indexables_for_object_type_and_source_table( $source_table, $source_identifier, $object_type, $limit );
- $source_table(строка) (обязательный)
- The source table which we need to check the indexables against.
- $source_identifier(строка) (обязательный)
- The identifier which the indexables are matched to.
- $object_type(строка) (обязательный)
- The indexable object type.
- $limit(int) (обязательный)
- The limit we'll apply to the delete query.
Код Indexable_Cleanup_Repository::clean_indexables_for_object_type_and_source_table() Indexable Cleanup Repository::clean indexables for object type and source table Yoast 23.5
public function clean_indexables_for_object_type_and_source_table( $source_table, $source_identifier, $object_type, $limit ) { global $wpdb; $indexable_table = Model::get_table_name( 'Indexable' ); $source_table = $wpdb->prefix . $source_table; // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input. $query = $wpdb->prepare( " SELECT indexable_table.object_id FROM {$indexable_table} indexable_table LEFT JOIN {$source_table} AS source_table ON indexable_table.object_id = source_table.{$source_identifier} WHERE source_table.{$source_identifier} IS NULL AND indexable_table.object_id IS NOT NULL AND indexable_table.object_type = '{$object_type}' LIMIT %d", $limit ); // phpcs:enable // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: Already prepared. $orphans = $wpdb->get_col( $query ); if ( empty( $orphans ) ) { return 0; } // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: Already prepared. return $wpdb->query( "DELETE FROM $indexable_table WHERE object_type = '{$object_type}' AND object_id IN( " . \implode( ',', $orphans ) . ' )' ); }