Файловый менеджер - Редактировать - /var/www/xthruster/html/wp-content/uploads/flags/background-task.tar
Назад
BackgroundTaskViewModel.php 0000644 00000003403 14721674547 0012014 0 ustar 00 <?php namespace WPML\BackgroundTask; use WPML\Core\BackgroundTask\Model\TaskEndpointInterface; use WPML\Core\BackgroundTask\Model\BackgroundTask; use function WPML\Container\make; class BackgroundTaskViewModel { /** * Prepares the endpoint data for the react component to consume it. * * @param BackgroundTask $backgroundTask * @param bool $getLock * * @return ?array{ * isPaused: bool, * progressTotal: int, * progressDone: int, * payload: object, * taskId: int, * taskStatus: string, * isCompleted: bool, * description: string, * taskType: string, * hasLock: bool * } **/ public static function get( $backgroundTask, $getLock = false ) { $className = $backgroundTask->getTaskType(); if ( ! class_exists( $className ) ) { return; } /** @var TaskEndpointInterface $endpointInstance */ $endpointInstance = make( $className ); $endpointLock = make( 'WPML\Utilities\Lock', [ ':name' => $backgroundTask->getTaskType() ] ); $hasLock = $getLock ? $endpointLock->create( $endpointInstance->getLockTime() ) : false; return [ 'isPaused' => $backgroundTask->isStatusPaused(), 'progressTotal' => $backgroundTask->getTotalCount(), 'progressDone' => $backgroundTask->getCompletedCount(), 'payload' => $backgroundTask->getPayload(), 'taskId' => $backgroundTask->getTaskId(), 'taskStatus' => $backgroundTask->getStatusName(), 'isCompleted' => $backgroundTask->isStatusCompleted(), 'description' => $endpointInstance->getDescription( wpml_collect( $backgroundTask->getPayload() ) ), 'taskType' => $backgroundTask->getTaskType(), 'isDisplayed' => $endpointInstance->isDisplayed(), 'hasLock' => $hasLock, ]; } } AbstractTaskEndpoint.php 0000644 00000004544 14721674547 0011374 0 ustar 00 <?php namespace WPML\BackgroundTask; use WPML\BackgroundTask\BackgroundTaskLoader; use WPML\BackgroundTask\BackgroundTaskViewModel; use WPML\Collect\Support\Collection; use WPML\Core\BackgroundTask\Exception\TaskIsNotRunnableException; use WPML\Core\BackgroundTask\Model\TaskEndpointInterface; use WPML\Core\BackgroundTask\Service\BackgroundTaskService; use WPML\Core\BackgroundTask\Command\UpdateBackgroundTask; use WPML\Core\BackgroundTask\Model\BackgroundTask; use WPML\FP\Either; use function WPML\Container\make; abstract class AbstractTaskEndpoint implements TaskEndpointInterface { const LOCK_TIME = 2*60; const MAX_RETRIES = 0; /** @var UpdateBackgroundTask $updateBackgroundTask */ protected $updateBackgroundTask; /** @var BackgroundTaskService $backgroundTaskService */ protected $backgroundTaskService; /** * @param UpdateBackgroundTask $updateBackgroundTask * @param BackgroundTaskService $backgroundTaskService */ public function __construct( UpdateBackgroundTask $updateBackgroundTask, BackgroundTaskService $backgroundTaskService ) { $this->updateBackgroundTask = $updateBackgroundTask; $this->backgroundTaskService = $backgroundTaskService; } public function isDisplayed() { return true; } public function getLockTime() { return static::LOCK_TIME; } public function getMaxRetries() { return static::MAX_RETRIES; } public function getType() { return static::class; } /** * @param BackgroundTask $task * * @return BackgroundTask */ abstract function runBackgroundTask( BackgroundTask $task ); public function run( Collection $data ) { try { $taskId = $data['taskId']; $task = $this->backgroundTaskService->startByTaskId( $taskId ); $task = $this->runBackgroundTask( $task ); $this->updateBackgroundTask->runUpdate( $task ); return $this->getResponse( $task ); } catch ( TaskIsNotRunnableException $e ) { return Either::of( [ 'error' => $e->getMessage() ] ); } } /** * @param BackgroundTask $backgroundTask * * @return callable|\WPML\FP\Right */ private function getResponse( BackgroundTask $backgroundTask ) { /** @var \WPML\Utilities\Lock $endpointLock */ $endpointLock = make( 'WPML\Utilities\Lock', [ ':name' => $backgroundTask->getTaskType() ] ); $endpointLock->release(); return Either::of( BackgroundTaskViewModel::get( $backgroundTask, true ) ); } } BackgroundTaskLoader.php 0000644 00000004527 14721674547 0011337 0 ustar 00 <?php namespace WPML\BackgroundTask; use WPML\Collect\Support\Collection; use WPML\Core\BackgroundTask\Command\UpdateBackgroundTask; use WPML\Core\BackgroundTask\Repository\BackgroundTaskRepository; use WPML\Core\WP\App\Resources; use WPML\FP\Either; use WPML\FP\Fns; use WPML\FP\Lst; use WPML\LIB\WP\Hooks; class BackgroundTaskLoader implements \IWPML_Backend_Action, \IWPML_DIC_Action { /** @var UpdateBackgroundTask $updateBackgroundTaskCommand */ private $updateBackgroundTaskCommand; /** @var BackgroundTaskRepository $backgroundTaskRepository */ private $backgroundTaskRepository; /** * @param UpdateBackgroundTask $updateBackgroundTaskCommand * @param BackgroundTaskRepository $backgroundTaskRepository */ public function __construct( UpdateBackgroundTask $updateBackgroundTaskCommand, BackgroundTaskRepository $backgroundTaskRepository ) { $this->updateBackgroundTaskCommand = $updateBackgroundTaskCommand; $this->backgroundTaskRepository = $backgroundTaskRepository; } public function add_hooks() { Hooks::onAction( 'wp_loaded' ) ->then( function() { $tasks = $this->getSerializedTasks(); Resources::enqueueGlobalVariable('wpml_background_tasks', [ /** @phpstan-ignore-next-line */ 'endpoints' => array_merge( Lst::pluck('taskType', $tasks), [ BackgroundTaskLoader::class ] ), 'tasks' => $tasks, ] ); } ); } /** * @param \WPML\Collect\Support\Collection $data */ public function run( Collection $data ) { $taskId = $data['taskId']; $cmd = $data['cmd']; $task = $this->backgroundTaskRepository->getByTaskId( $taskId ); if ( 'stop' === $cmd ) { $this->updateBackgroundTaskCommand->runStop( $task ); } elseif ( 'pause' === $cmd ) { $this->updateBackgroundTaskCommand->saveStatusPaused( $task ); } elseif ( 'resume' === $cmd ) { $this->updateBackgroundTaskCommand->saveStatusResumed( $task ); } elseif ( 'restart' === $cmd ) { $this->updateBackgroundTaskCommand->saveStatusRestart( $task ); } $taskData = BackgroundTaskViewModel::get( $task ); return Either::of( $taskData ); } /** * @return array */ public function getSerializedTasks() { return Fns::map( function( $task ) { return BackgroundTaskViewModel::get( $task, true ); }, $this->backgroundTaskRepository->getAllRunnableTasks() ); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.3-4ubuntu2.24 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка