Esempio n. 1
0
 /**
  * Creates job item and submits according to the configured settings.
  *
  * The job item will only be created if the given source plugin for the job is
  * configured to accept this source.
  *
  * The job item will be immediately submitted to the translator unless
  * this happens on cron runs.
  *
  * @param \Drupal\tmgmt\Entity\Job $job
  *   Continuous job.
  * @param string $plugin
  *   The plugin name.
  * @param string $item_type
  *   The source item type.
  * @param string $item_id
  *   The source item id.
  *
  * @return \Drupal\tmgmt\Entity\JobItem
  *   Continuous job item.
  */
 public function addItem(Job $job, $plugin, $item_type, $item_id)
 {
     // Check if a job item should be created.
     $most_recent_job_item = $job->getMostRecentItem($plugin, $item_type, $item_id);
     $should_create_item = $this->sourcePluginManager->createInstance($plugin)->shouldCreateContinuousItem($job, $plugin, $item_type, $item_id);
     if ($should_create_item) {
         if ($most_recent_job_item) {
             // If the most recent job item is active do nothing.
             if (!$most_recent_job_item->isAborted() && !$most_recent_job_item->isAccepted()) {
                 $most_recent_job_item->addMessage('Source was updated, changes were ignored as job item is still active.');
                 return NULL;
             }
         }
         // If there are no job items or it's finished/aborted create new one.
         $job_item = $job->addItem($plugin, $item_type, $item_id);
         $job_item->addMessage('Continuous job item created');
         // Only submit the item if cron submission is disabled.
         if (!$this->configFactory->get('tmgmt.settings')->get('submit_job_item_on_cron')) {
             $translator = $job->getTranslatorPlugin();
             $translator->requestJobItemsTranslation([$job_item]);
         }
         return $job_item;
     }
     return NULL;
 }