You are here

public function JobScheduler::remove in Job Scheduler 8.3

Same name and namespace in other branches
  1. 8.2 src/JobScheduler.php \Drupal\job_scheduler\JobScheduler::remove()

Removes a job from the schedule, replace any existing job.

A job is uniquely identified by $job = array(type, id).

Parameters

array $job: A job to remove.

Throws

\Exception Exceptions thrown by code called by this method are passed on.

Overrides JobSchedulerInterface::remove

File

src/JobScheduler.php, line 74

Class

JobScheduler
Manage scheduled jobs.

Namespace

Drupal\job_scheduler

Code

public function remove(array $job) {
  $storage = $this->jobScheduleStorage;
  $query = $storage
    ->getQuery();
  $query
    ->condition('name', $job['name']);
  $query
    ->condition('type', $job['type']);
  $query
    ->condition('id', isset($job['id']) ? $job['id'] : 0);
  $entity_ids = $query
    ->execute();
  if (!empty($entity_ids)) {
    $entities = $storage
      ->loadMultiple($entity_ids);
    $storage
      ->delete($entities);
  }
}