class-rio-folder-processing.php
5 months ago
class-rio-media-processing-avif.php
3 months ago
class-rio-media-processing-webp.php
3 months ago
class-rio-media-processing.php
3 months ago
class-rio-nextgen-processing.php
5 months ago
class-rio-processing.php
5 months ago
class-rio-media-processing-avif.php
100 lines
| 1 | <?php |
| 2 | |
| 3 | use WBCR\Factory_Processing_759\WP_Background_Process; |
| 4 | |
| 5 | // Exit if accessed directly |
| 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | exit; |
| 8 | } |
| 9 | |
| 10 | /** |
| 11 | * Класс для работы AVIF конвертации в фоне |
| 12 | * Class for AVIF image format conversion background processing |
| 13 | * |
| 14 | * @version 1.6.0 |
| 15 | * @since 1.6.0 |
| 16 | */ |
| 17 | class WRIO_Media_Processing_Avif extends WRIO_Processing { |
| 18 | |
| 19 | /** |
| 20 | * @var string |
| 21 | */ |
| 22 | protected $action = 'convert_process'; |
| 23 | |
| 24 | /** |
| 25 | * @var string Format type |
| 26 | */ |
| 27 | protected $format = 'avif'; |
| 28 | |
| 29 | /** |
| 30 | * Constructor |
| 31 | * |
| 32 | * @param string $scope Processing scope |
| 33 | */ |
| 34 | public function __construct( $scope ) { |
| 35 | parent::__construct( $scope ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Push items to queue |
| 40 | * |
| 41 | * @return int Number of items in queue |
| 42 | */ |
| 43 | public function push_items() { |
| 44 | $attachment_ids = []; |
| 45 | |
| 46 | if ( $this->scope === 'media-library_avif' ) { |
| 47 | $media_library = WRIO_Media_Library::get_instance(); |
| 48 | $attachment_ids = $media_library->getUnconvertedImages( 'avif' ); |
| 49 | } |
| 50 | |
| 51 | foreach ( $attachment_ids as $attachment_id ) { |
| 52 | $this->push_to_queue( $attachment_id ); |
| 53 | } |
| 54 | |
| 55 | return $this->count_queue(); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Метод конвертирует изображения в AVIF при выполнении задачи |
| 60 | * Method converts images to AVIF when executing task |
| 61 | * |
| 62 | * @param int $image Attachment ID |
| 63 | * |
| 64 | * @return bool |
| 65 | */ |
| 66 | protected function task( $image ) { |
| 67 | if ( $image ) { |
| 68 | WRIO_Plugin::app()->logger->info( sprintf( 'Start convert attachment #%s to AVIF', $image ) ); |
| 69 | $media_library = WRIO_Media_Library::get_instance(); |
| 70 | |
| 71 | try { |
| 72 | if ( 'media-library_avif' === $this->scope ) { |
| 73 | $media_library->webpConvertAttachment( $image, 'avif' ); |
| 74 | } |
| 75 | } catch ( Throwable $throwable ) { |
| 76 | $wio_attachment = $media_library->getAttachment( $image ); |
| 77 | $wio_attachment->mark_conversion_failure( $throwable, 'avif', 'avif-conversion-background' ); |
| 78 | } |
| 79 | |
| 80 | WRIO_Plugin::app()->logger->info( sprintf( 'End convert attachment #%s to AVIF', $image ) ); |
| 81 | } |
| 82 | |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Fire after complete handle |
| 88 | * Вызывается после завершения обработки |
| 89 | * |
| 90 | * @return void |
| 91 | */ |
| 92 | protected function handle_after_complete() { |
| 93 | WRIO_Plugin::app()->updatePopulateOption( "{$this->scope}_process_running", false ); |
| 94 | |
| 95 | WRIO_Plugin::app()->logger->info( |
| 96 | sprintf( 'AVIF conversion background process completed for scope: %s', $this->scope ) |
| 97 | ); |
| 98 | } |
| 99 | } |
| 100 |