You are here

public function SmartlingApiWrapper::createJob in TMGMT Translator Smartling 8.4

Same name and namespace in other branches
  1. 8.3 src/Smartling/SmartlingApiWrapper.php \Drupal\tmgmt_smartling\Smartling\SmartlingApiWrapper::createJob()

Creates Smartling job.

Parameters

$name:

$description:

\DateTime|NULL $due_date:

Return value

array

File

src/Smartling/SmartlingApiWrapper.php, line 111
SmartlingApiWrapper.php.

Class

SmartlingApiWrapper
Class SmartlingApiWrapper @package Drupal\tmgmt_smartling\Smartling

Namespace

Drupal\tmgmt_smartling\Smartling

Code

public function createJob($name, $description, DateTime $due_date = NULL) {
  $job_id = NULL;
  try {
    $params = new CreateJobParameters();
    $params
      ->setName($name);
    $params
      ->setDescription($description);
    if (!empty($due_date)) {
      $params
        ->setDueDate($due_date);
    }
    $response = $this
      ->getApi('jobs')
      ->createJob($params);
    $job_id = $response['translationJobUid'];
    $this->logger
      ->info('Smartling created a job:<br/>
      Id: @id<br/>
      Name: @name<br/>
      Description: @description<br/>
      Due date (UTC): @due_date<br/>', [
      '@id' => $job_id,
      '@name' => $name,
      '@description' => $description,
      '@due_date' => empty($due_date) ? '' : $due_date
        ->format('Y-m-d H:i'),
    ]);
  } catch (Exception $e) {
    $this->logger
      ->error('Smartling failed to create a job:<br/>
      Name: @name<br/>
      Description: @description<br/>
      Due date (UTC): @due_date<br/>
      Error: @error', [
      '@name' => $name,
      '@description' => $description,
      '@due_date' => empty($due_date) ? '' : $due_date
        ->format('Y-m-d H:i'),
      '@error' => $e
        ->getMessage(),
    ]);
  }
  return $job_id;
}