Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. $myFeed->startImport()
  2.  
  3. public function startImport() {
  4. module_invoke_all('feeds_before_import', $this);
  5. $config = $this->importer->getConfig();
  6. if ($config['process_in_background']) {
  7. $this->startBackgroundJob('import');
  8. }
  9. else {
  10. $this->startBatchAPIJob(t('Importing'), 'import');
  11. }
  12. }
  13.  
  14. /**
  15. * Background job helper. Starts a background job using Job Scheduler.
  16. *
  17. * Execute the first batch chunk of a background job on the current page load,
  18. * moves the rest of the job processing to a cron powered background job.
  19. *
  20. * Executing the first batch chunk is important, otherwise, when a user
  21. * submits a source for import or clearing, we will leave her without any
  22. * visual indicators of an ongoing job.
  23. *
  24. * @see FeedsSource::startImport().
  25. * @see FeedsSource::startClear().
  26. *
  27. * @param $method
  28. * Method to execute on importer; one of 'import' or 'clear'.
  29. *
  30. * @throws Exception $e
  31. */
  32. protected function startBackgroundJob($method) {
  33. if (FEEDS_BATCH_COMPLETE != $this->$method()) {
  34. $job = array(
  35. 'type' => $this->id,
  36. 'id' => $this->feed_nid,
  37. 'period' => 0,
  38. 'periodic' => FALSE,
  39. );
  40. JobScheduler::get("feeds_source_{$method}")->set($job);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement