stringsService = $stringsService; $this->htmlStringsService = $htmlStringsService; $this->gettextStringsService = $gettextStringsService; $this->queueRepository = $queueRepository; $this->frontendQueueRepository = $frontendQueueRepository; $this->settingsRepository = $settingsRepository; } /** * @return array */ function get_routes() { return [ [ 'route' => 'strings/processstringsqueue', 'args' => [ 'methods' => 'POST', 'callback' => [ $this, 'post' ], ] ], ]; } /** * @return array */ public function post( \WP_REST_Request $request ) { if ( ! $this->gettextStringsService->isAutoregisterEnabled() ) { return [ 'wasProcessed' => false, ]; } $lock = make( Lock::class, [ ':name' => 'processstringsqueue' ] ); $hasLock = $lock->create( 60 ); if ( ! $hasLock ) { return [ 'wasProcessed' => false, ]; } $hasPendingGettextStrings = array_sum( array_map( 'count', $this->queueRepository->loadPendingStrings() ) ) > 0; $hasPendingHtmlStrings = array_sum( array_map( function( $gettextStringsByUrl ) { return count( $gettextStringsByUrl->getStrings() ); }, $this->frontendQueueRepository->get() ) ); if ( $hasPendingGettextStrings ) { $this->stringsService->maybeProcessQueue(); } if ( $hasPendingHtmlStrings ) { $this->htmlStringsService->maybeProcessFrontendGettextStringsQueue(); } $wasProcessed = $hasPendingGettextStrings || $hasPendingHtmlStrings; if ( $this->settingsRepository->wereNewTranslationsLoaded() ) { $wasProcessed = true; $this->settingsRepository->unsetNewTranslationsWereLoadedSetting(); } $lock->release(); return [ 'wasProcessed' => $wasProcessed, ]; } }