You are here

public function TMGMTJobUIController::applyOperation in Translation Management Tool 7

Applies an operation to the given entity.

Note: the export operation is directly carried out by the operationForm() method.

Parameters

string $op: The operation (revert, delete or import).

$entity: The entity to manipulate.

Return value

string The status message of what has been applied.

Overrides EntityDefaultUIController::applyOperation

File

ui/includes/tmgmt_ui.controller.job.inc, line 86
Contains the job UI controller.

Class

TMGMTJobUIController
Entity UI controller for the Job Entity.

Code

public function applyOperation($op, $entity) {
  switch ($op) {
    case 'delete':
      $entity
        ->delete();
      return t('Deleted the translation job %label.', array(
        '%label' => $entity
          ->label(),
      ));
    case 'abort':
      if (!$entity
        ->abortTranslation()) {

        // This is the case when a translator does not support the abort operation.
        // It would make more sense to not display the button for the action,
        // however we do not know if the translator is able to abort a job until
        // we trigger the action.
        foreach ($entity
          ->getMessagesSince() as $message) {
          if ($message->type == 'debug') {
            continue;
          }
          if ($text = $message
            ->getMessage()) {

            // We want to persist also the type therefore we will set the
            // messages directly and not return them.
            drupal_set_message(filter_xss($text), $message->type);
          }
        }
      }
      break;
    case 'resubmit':
      $this->jobToResubmit = $entity
        ->cloneAsUnprocessed();
      $this->jobToResubmit->uid = $GLOBALS['user']->uid;
      $this->jobToResubmit
        ->save();

      /** @var TMGMTJobItem $item */
      foreach ($entity
        ->getItems() as $item) {
        $item_to_resubmit = $item
          ->cloneAsActive();
        $this->jobToResubmit
          ->addExistingItem($item_to_resubmit);
      }
      $entity
        ->addMessage('Job has been duplicated as a new job <a href="@url">#@id</a>.', array(
        '@url' => url('admin/tmgmt/jobs/' . $this->jobToResubmit->tjid),
        '@id' => $this->jobToResubmit->tjid,
      ));
      $this->jobToResubmit
        ->addMessage('This job is a duplicate of the previously aborted job <a href="@url">#@id</a>', array(
        '@url' => url('admin/tmgmt/jobs/' . $entity->tjid),
        '@id' => $entity->tjid,
      ));
      return t('The aborted job has been duplicated. You can resubmit it now.');
  }
  return FALSE;
}