v1.2.0
This commit is contained in:
parent
6708bbb67f
commit
650e69349f
21 changed files with 2919 additions and 268 deletions
89
includes/External/ExternalScanner.php
vendored
89
includes/External/ExternalScanner.php
vendored
|
|
@ -184,6 +184,39 @@ class ExternalScanner {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-queues all attachments that previously failed with external_status = 'error'.
|
||||
*
|
||||
* Does not touch pending, queued, scanned, or matched attachments.
|
||||
* Schedules a background scan batch if any items were re-queued and
|
||||
* no batch is already pending.
|
||||
*
|
||||
* @return int Number of attachments re-queued.
|
||||
*/
|
||||
public static function requeue_errors(): int {
|
||||
global $wpdb;
|
||||
|
||||
// phpcs:disable WordPress.DB.DirectDatabaseQuery
|
||||
$count = (int) $wpdb->get_var(
|
||||
"SELECT COUNT(*) FROM {$wpdb->prefix}mra_media_index WHERE external_status = 'error'"
|
||||
);
|
||||
|
||||
if ( $count > 0 ) {
|
||||
$wpdb->query(
|
||||
"UPDATE {$wpdb->prefix}mra_media_index
|
||||
SET external_status = 'queued', external_scanned_at = NULL
|
||||
WHERE external_status = 'error'"
|
||||
);
|
||||
|
||||
if ( ! Scheduler::has_pending( self::AS_HOOK ) ) {
|
||||
Scheduler::schedule_single( self::AS_HOOK );
|
||||
}
|
||||
}
|
||||
// phpcs:enable WordPress.DB.DirectDatabaseQuery
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes external scan results and resets status to pending for given IDs.
|
||||
*
|
||||
|
|
@ -221,6 +254,62 @@ class ExternalScanner {
|
|||
// phpcs:enable WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all external scan results and resets every attachment's external_status to pending.
|
||||
*
|
||||
* @return int Number of result rows deleted.
|
||||
*/
|
||||
public static function purge_all(): int {
|
||||
global $wpdb;
|
||||
|
||||
// phpcs:disable WordPress.DB.DirectDatabaseQuery
|
||||
$count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}mra_external_results" );
|
||||
$wpdb->query( "DELETE FROM {$wpdb->prefix}mra_external_results" );
|
||||
$wpdb->query(
|
||||
"UPDATE {$wpdb->prefix}mra_media_index
|
||||
SET external_status = 'pending', external_scanned_at = NULL"
|
||||
);
|
||||
// phpcs:enable WordPress.DB.DirectDatabaseQuery
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a count of attachments grouped by external_status.
|
||||
*
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public static function get_status_counts(): array {
|
||||
global $wpdb;
|
||||
|
||||
$rows = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
||||
"SELECT external_status, COUNT(*) AS cnt
|
||||
FROM {$wpdb->prefix}mra_media_index
|
||||
GROUP BY external_status",
|
||||
ARRAY_A
|
||||
);
|
||||
|
||||
$counts = array(
|
||||
'pending' => 0,
|
||||
'queued' => 0,
|
||||
'scanned' => 0,
|
||||
'matches' => 0,
|
||||
'error' => 0,
|
||||
);
|
||||
|
||||
if ( is_array( $rows ) ) {
|
||||
foreach ( $rows as $row ) {
|
||||
$s = is_array( $row ) && is_string( $row['external_status'] ) ? $row['external_status'] : '';
|
||||
if ( isset( $counts[ $s ] ) ) {
|
||||
$cnt = isset( $row['cnt'] ) && is_numeric( $row['cnt'] ) ? (int) $row['cnt'] : 0;
|
||||
$counts[ $s ] = $cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $counts;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Private helpers
|
||||
// -------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue