You are here

public function FeedsSource::scheduleImport in Feeds 7.2

Schedule periodic or background import tasks.

Parameters

bool $force: (optional) If true, forces the scheduling to happen. Defaults to true.

2 calls to FeedsSource::scheduleImport()
FeedsSource::ensureSchedule in includes/FeedsSource.inc
Schedule all periodic tasks for this source if not already scheduled.
FeedsSource::schedule in includes/FeedsSource.inc
Schedule all periodic tasks for this source, even when scheduled before.

File

includes/FeedsSource.inc, line 402
Definition of FeedsSourceInterface, FeedsState and FeedsSource class.

Class

FeedsSource
Holds the source of a feed to import.

Code

public function scheduleImport($force = TRUE) {

  // Check whether any fetcher is overriding the import period.
  $period = $this->importer->config['import_period'];
  $fetcher_period = $this->importer->fetcher
    ->importPeriod($this);
  if (is_numeric($fetcher_period)) {
    $period = $fetcher_period;
  }
  $job = array(
    'type' => $this->id,
    'id' => $this->feed_nid,
    'period' => $period,
    'periodic' => TRUE,
  );
  if ($period == FEEDS_SCHEDULE_NEVER && $this
    ->progressImporting() === FEEDS_BATCH_COMPLETE) {
    JobScheduler::get('feeds_source_import')
      ->remove($job);
  }
  elseif ($this
    ->progressImporting() === FEEDS_BATCH_COMPLETE) {

    // Check for an existing job first.
    $existing = JobScheduler::get('feeds_source_import')
      ->check($job);
    if (!$existing || $force) {

      // If there is no existing job, schedule a new job.
      JobScheduler::get('feeds_source_import')
        ->set($job);
    }
    elseif ($existing['scheduled']) {

      // If the previous job is still marked as 'running', reschedule it.
      JobScheduler::get('feeds_source_import')
        ->reschedule($existing);
    }
  }
  elseif (!$this
    ->isQueued()) {

    // Feed is not fully imported yet, so we put this job back in the queue
    // immediately for further processing.
    $queue = DrupalQueue::get('feeds_source_import');
    $queue
      ->createItem($job);
  }
}