| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\Backups\Classes; |
| 4 |
|
| 5 |
use ImageOptimization\Classes\Async_Operation\{ |
| 6 |
Async_Operation, |
| 7 |
Async_Operation_Hook, |
| 8 |
Async_Operation_Queue, |
| 9 |
}; |
| 10 |
use ImageOptimization\Classes\Image\Image_Query_Builder; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly. |
| 14 |
} |
| 15 |
|
| 16 |
class Remove_All_Backups { |
| 17 |
private const CHUNK_SIZE = 100; |
| 18 |
|
| 19 |
public static function find_and_schedule_removing(): void { |
| 20 |
$query = ( new Image_Query_Builder() ) |
| 21 |
->return_images_only_with_backups() |
| 22 |
->execute(); |
| 23 |
|
| 24 |
$attachment_ids = $query->posts; |
| 25 |
$chunks = array_chunk( $attachment_ids, self::CHUNK_SIZE ); |
| 26 |
|
| 27 |
foreach ( $chunks as $chunk ) { |
| 28 |
Async_Operation::create( |
| 29 |
Async_Operation_Hook::REMOVE_MANY_BACKUPS, |
| 30 |
[ 'attachment_ids' => $chunk ], |
| 31 |
Async_Operation_Queue::BACKUP |
| 32 |
); |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
|