public function JobItem::abortTranslation

Attempts to abort the translation job item.

Already accepted job items can not be aborted. Always use this method if you want to abort a translation job item.

Throws

\Drupal\tmgmt\TMGMTException If fails to abort the job item.

Overrides JobItemInterface::abortTranslation

File

src/Entity/JobItem.php, line 902

Class

JobItem
Entity class for the tmgmt_job_item entity.

Namespace

Drupal\tmgmt\Entity

Code

public function abortTranslation() {
  if (!$this
    ->isAbortable() || !$this
    ->getTranslatorPlugin()) {
    throw new TMGMTException('Cannot abort job item.');
  }
  $this
    ->setState(JobItemInterface::STATE_ABORTED);

  // Check if this was the last unfinished job item in this job.
  $job = $this
    ->getJob();
  if ($job && !$job
    ->isContinuous() && tmgmt_job_check_finished($this
    ->getJobId())) {

    // Mark the job as finished in case it is a normal job.
    $job
      ->finished();
  }
}