Файловый менеджер - Редактировать - /var/www/xthruster/html/wp-content/uploads/flags/backups.tar
Назад
classes/route-base.php 0000644 00000001357 14721626373 0011001 0 ustar 00 <?php namespace ImageOptimization\Modules\Backups\Classes; use ImageOptimization\Classes\Route; use WP_REST_Request; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Route_Base extends Route { protected $auth = true; protected string $path = ''; public function get_methods(): array { return []; } public function get_endpoint(): string { return 'backups/' . $this->get_path(); } public function get_path(): string { return $this->path; } public function get_name(): string { return ''; } public function get_permission_callback( WP_REST_Request $request ): bool { $valid = $this->permission_callback( $request ); return $valid && user_can( $this->current_user_id, 'manage_options' ); } } classes/remove-all-backups.php 0000644 00000001462 14721626373 0012421 0 ustar 00 <?php namespace ImageOptimization\Modules\Backups\Classes; use ImageOptimization\Classes\Async_Operation\{ Async_Operation, Async_Operation_Hook, Async_Operation_Queue, }; use ImageOptimization\Classes\Image\Image_Query_Builder; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Remove_All_Backups { private const CHUNK_SIZE = 100; public static function find_and_schedule_removing(): void { $query = ( new Image_Query_Builder() ) ->return_images_only_with_backups() ->execute(); $attachment_ids = $query->posts; $chunks = array_chunk( $attachment_ids, self::CHUNK_SIZE ); foreach ( $chunks as $chunk ) { Async_Operation::create( Async_Operation_Hook::REMOVE_MANY_BACKUPS, [ 'attachment_ids' => $chunk ], Async_Operation_Queue::BACKUP ); } } } classes/restore-images.php 0000644 00000005072 14721626373 0011657 0 ustar 00 <?php namespace ImageOptimization\Modules\Backups\Classes; use ImageOptimization\Classes\Async_Operation\{ Async_Operation, Async_Operation_Hook, Async_Operation_Queue, }; use ImageOptimization\Classes\Image\{ Image_Meta, Image_Query_Builder, Image_Status }; use Throwable; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Restore_Images { private const CHUNK_SIZE = 100; /** * Schedules a single restoring operation. * * @param int $image_id * @return void * @throws Throwable * @throws \ImageOptimization\Classes\Async_Operation\Exceptions\Async_Operation_Exception */ public static function schedule_single_restoring( int $image_id ): void { $meta = new Image_Meta( $image_id ); try { $meta ->set_status( Image_Status::RESTORING_IN_PROGRESS ) ->save(); Async_Operation::create( Async_Operation_Hook::RESTORE_SINGLE_IMAGE, [ 'attachment_id' => $image_id ], Async_Operation_Queue::RESTORE ); } catch ( Throwable $t ) { $meta ->set_status( Image_Status::RESTORING_FAILED ) ->save(); throw $t; } } /** * Schedules restoring operations for all valid images with backups created. * * @param array $image_ids * * @return void */ public static function find_and_schedule_restoring( array $image_ids = [] ): void { $query = ( new Image_Query_Builder() ) ->return_images_only_with_backups(); if ( ! empty( $image_ids ) ) { $query->set_image_ids( $image_ids ); } $query = $query->execute(); $attachment_ids = $query->posts; $chunks = array_chunk( $attachment_ids, self::CHUNK_SIZE ); foreach ( $chunks as $chunk ) { try { Async_Operation::create( Async_Operation_Hook::RESTORE_MANY_IMAGES, [ 'attachment_ids' => $chunk ], Async_Operation_Queue::RESTORE ); self::mark_chunk_as_in_progress( $chunk ); } catch ( Throwable $t ) { self::fail_restoring_for_chunk( $chunk ); } } } /** * Updates chunk images optimization status to in-progress. * * @param int[] $chunk * @return void */ private static function mark_chunk_as_in_progress( array $chunk ) { foreach ( $chunk as $image_id ) { ( new Image_Meta( $image_id ) ) ->set_status( Image_Status::RESTORING_IN_PROGRESS ) ->save(); } } /** * Updates chunk images optimization status to failed. * * @param int[] $chunk * @return void */ private static function fail_restoring_for_chunk( array $chunk ) { foreach ( $chunk as $image_id ) { ( new Image_Meta( $image_id ) ) ->set_status( Image_Status::RESTORING_FAILED ) ->save(); } } } rest/restore-all.php 0000644 00000001640 14721626373 0010477 0 ustar 00 <?php namespace ImageOptimization\Modules\Backups\Rest; use ImageOptimization\Modules\Backups\Classes\{ Restore_Images, Route_Base, }; use Throwable; use WP_REST_Request; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Restore_All extends Route_Base { const NONCE_NAME = 'image-optimization-restore-all'; protected string $path = 'restore'; public function get_name(): string { return 'restore-all'; } public function get_methods(): array { return [ 'POST' ]; } public function POST( WP_REST_Request $request ) { $this->verify_nonce_and_capability( $request->get_param( self::NONCE_NAME ), self::NONCE_NAME ); try { Restore_Images::find_and_schedule_restoring(); return $this->respond_success_json(); } catch ( Throwable $t ) { return $this->respond_error_json([ 'message' => $t->getMessage(), 'code' => 'internal_server_error', ]); } } } rest/remove-backups.php 0000644 00000001655 14721626373 0011177 0 ustar 00 <?php namespace ImageOptimization\Modules\Backups\Rest; use ImageOptimization\Modules\Backups\Classes\{ Route_Base, Remove_All_Backups, }; use Throwable; use WP_REST_Request; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Remove_Backups extends Route_Base { const NONCE_NAME = 'image-optimization-remove-backups'; protected string $path = ''; public function get_name(): string { return 'remove-backups'; } public function get_methods(): array { return [ 'DELETE' ]; } public function DELETE( WP_REST_Request $request ) { $this->verify_nonce_and_capability( $request->get_param( self::NONCE_NAME ), self::NONCE_NAME ); try { Remove_All_Backups::find_and_schedule_removing(); return $this->respond_success_json(); } catch ( Throwable $t ) { return $this->respond_error_json([ 'message' => $t->getMessage(), 'code' => 'internal_server_error', ]); } } } rest/restore-single.php 0000644 00000002454 14721626373 0011214 0 ustar 00 <?php namespace ImageOptimization\Modules\Backups\Rest; use ImageOptimization\Modules\Optimization\Classes\Validate_Image; use ImageOptimization\Modules\Backups\Classes\{ Restore_Images, Route_Base, }; use Throwable; use WP_REST_Request; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Restore_Single extends Route_Base { const NONCE_NAME = 'image-optimization-restore-single'; protected string $path = 'restore/(?P<image_id>\d+)'; public function get_name(): string { return 'restore-single'; } public function get_methods(): array { return [ 'POST' ]; } public function POST( WP_REST_Request $request ) { $this->verify_nonce_and_capability( $request->get_param( self::NONCE_NAME ), self::NONCE_NAME ); $image_id = (int) $request->get_param( 'image_id' ); if ( empty( $image_id ) ) { return $this->respond_error_json( [ 'message' => esc_html__( 'Invalid image id', 'image-optimization' ), 'code' => 'internal_server_error', ] ); } try { Validate_Image::is_valid( $image_id ); Restore_Images::schedule_single_restoring( $image_id ); return $this->respond_success_json(); } catch ( Throwable $t ) { return $this->respond_error_json([ 'message' => $t->getMessage(), 'code' => 'internal_server_error', ]); } } } module.php 0000644 00000001210 14721626373 0006547 0 ustar 00 <?php namespace ImageOptimization\Modules\Backups; use ImageOptimization\Classes\Module_Base; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Module extends Module_Base { public function get_name(): string { return 'backups'; } public static function routes_list() : array { return [ 'Remove_Backups', 'Restore_Single', 'Restore_All', ]; } public static function component_list() : array { return [ 'Handle_Backups_Removing', 'Restore_Images', ]; } /** * Module constructor. */ public function __construct() { $this->register_components(); $this->register_routes(); } } components/handle-backups-removing.php 0000644 00000001561 14721626373 0014165 0 ustar 00 <?php namespace ImageOptimization\Modules\Backups\Components; use ImageOptimization\Classes\Async_Operation\Async_Operation_Hook; use ImageOptimization\Classes\Image\Image_Backup; use WP_Post; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Handle_Backups_Removing { public function remove_backups_on_attachment_removing( int $attachment_id, WP_Post $attachment_post ) { if ( ! wp_attachment_is_image( $attachment_post ) ) { return; } Image_Backup::remove( $attachment_id ); } /** @async */ public function remove_many_backups( array $attachment_ids ) { Image_Backup::remove_many( $attachment_ids ); } public function __construct() { add_action( 'delete_attachment', [ $this, 'remove_backups_on_attachment_removing' ], 10, 2 ); add_action( Async_Operation_Hook::REMOVE_MANY_BACKUPS, [ $this, 'remove_many_backups' ] ); } } components/restore-images.php 0000644 00000002055 14721626373 0012405 0 ustar 00 <?php namespace ImageOptimization\Modules\Backups\Components; use ImageOptimization\Classes\Async_Operation\Async_Operation_Hook; use ImageOptimization\Classes\Image\{ Image_Meta, Image_Restore, Image_Status, }; use ImageOptimization\Classes\Logger; use Throwable; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Restore_Images { /** @async */ public function restore_image( int $image_id ) { try { Image_Restore::restore( $image_id ); } catch ( Throwable $t ) { Logger::log( Logger::LEVEL_ERROR, 'Image restoring error: ' . $t->getMessage() ); ( new Image_Meta( $image_id ) ) ->set_status( Image_Status::RESTORING_FAILED ) ->save(); throw $t; } } /** @async */ public function restore_many_images( array $attachment_ids ) { Image_Restore::restore_many( $attachment_ids ); } public function __construct() { add_action( Async_Operation_Hook::RESTORE_SINGLE_IMAGE, [ $this, 'restore_image' ] ); add_action( Async_Operation_Hook::RESTORE_MANY_IMAGES, [ $this, 'restore_many_images' ] ); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.3-4ubuntu2.24 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка