PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / classes / migration / handlers / cleanup-legacy-bulk-operations.php

cleanup-legacy-bulk-operations.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.7, at classes/migration/handlers/cleanup-legacy-bulk-operations.php

64 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Classes\Migration\Handlers;
4
5 use ImageOptimization\Classes\Async_Operation\{
6 Async_Operation,
7 Async_Operation_Hook,
8 Queries\Image_Optimization_Operation_Query
9 };
10 use ImageOptimization\Classes\Logger;
11 use ImageOptimization\Classes\Migration\Migration;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 class Cleanup_Legacy_Bulk_Operations extends Migration {
18 public static function get_name(): string {
19 return 'cleanup_legacy_bulk_operations';
20 }
21
22 public static function run(): bool {
23 self::cleanup_operations( Async_Operation_Hook::OPTIMIZE_BULK );
24 self::cleanup_operations( Async_Operation_Hook::REOPTIMIZE_BULK );
25
26 return true;
27 }
28
29 private static function cleanup_operations( string $hook ): void {
30 $query = ( new Image_Optimization_Operation_Query() )
31 ->set_hook( $hook )
32 ->set_status( [
33 Async_Operation::OPERATION_STATUS_PENDING,
34 Async_Operation::OPERATION_STATUS_RUNNING,
35 ] )
36 ->set_limit( -1 );
37
38 $operations = Async_Operation::get( $query );
39
40 if ( empty( $operations ) ) {
41 Logger::info( sprintf(
42 'No legacy operations found for hook %s',
43 $hook
44 ) );
45 return;
46 }
47
48 $operation_ids = array_map(
49 function( $operation ) {
50 return $operation->get_id();
51 },
52 $operations
53 );
54
55 Async_Operation::remove( $operation_ids );
56
57 Logger::info( sprintf(
58 'Removed %d legacy operations for hook %s',
59 count( $operation_ids ),
60 $hook
61 ) );
62 }
63 }
64