l10n_server-2.x-dev/l10n_server/src/Plugin/QueueWorker/ParserQueue.php
l10n_server/src/Plugin/QueueWorker/ParserQueue.php
<?php namespace Drupal\l10n_server\Plugin\QueueWorker; use Drupal\Core\Queue\QueueWorkerBase; use Drupal\l10n_server\Entity\L10nServerReleaseInterface; /** * Defines 'l10n_server_parser' queue worker. * * @QueueWorker( * id = "l10n_server_parser", * title = @Translation("Parse releases"), * ) */ class ParserQueue extends QueueWorkerBase { /** * {@inheritdoc} */ public function processItem($data) { if ($data instanceof L10nServerReleaseInterface) { // Reload the current release object. /** @var \Drupal\l10n_server\Entity\L10nServerReleaseInterface $release */ $release = \Drupal::entityTypeManager() ->getStorage('l10n_server_release') ->load($data->id()); // Regardless of successful or not, indicate that it has been checked. $release->setQueuedTime(0); $release->save(); // Skip if already parsed. if ($release->getLastParsed()) { return; } // Get the associated project and connector. $project = $release->getProject(); $connector = $project->getConnector(); if ($connector->isEnabled() && $connector->isParsable()) { // Parse the release. /** @var \Drupal\l10n_server\ConnectorParseHandlerInterface $connector */ $connector->setRelease($release); if ($result = $connector->parseHandler()) { $release = $connector->getRelease(); $release ->setSourceStringCount($result->getStringCount()) ->setLineCount($result->getLineCount()) ->setFileCount($result->getFileCount()) ->setErrorCount($result->getErrorCount()) ->setLastParsed(time()) ->setQueuedTime(0) ->save(); } } } } }