Projet

Général

Profil

Révision 41cc1b08

Ajouté par Assos Assos il y a presque 9 ans

Update feeds 7.x-2.0-alpha9 -> 7.x-2.0-beta1

Install lib simplepie 1.3.1

Voir les différences:

drupal7/sites/all/modules/feeds/includes/FeedsSource.inc
18 18
define('FEEDS_PARSE', 'parse');
19 19
define('FEEDS_PROCESS', 'process');
20 20
define('FEEDS_PROCESS_CLEAR', 'process_clear');
21
define('FEEDS_PROCESS_EXPIRE', 'process_expire');
21 22

  
22 23
/**
23 24
 * Declares an interface for a class that defines default values and form
......
86 87
  public $created;
87 88
  public $updated;
88 89
  public $deleted;
90
  public $unpublished;
91
  public $blocked;
89 92
  public $skipped;
90 93
  public $failed;
91 94

  
95
  /**
96
   * IDs of entities to be removed.
97
   */
98
  public $removeList;
99

  
92 100
  /**
93 101
   * Constructor, initialize variables.
94 102
   */
......
98 106
    $this->created =
99 107
    $this->updated =
100 108
    $this->deleted =
109
    $this->unpublished =
110
    $this->blocked =
101 111
    $this->skipped =
102 112
    $this->failed = 0;
103 113
  }
......
178 188
  // Timestamp when this source was imported the last time.
179 189
  protected $imported;
180 190

  
191
  // Holds an exception object in case an exception occurs during importing.
192
  protected $exception;
193

  
181 194
  /**
182 195
   * Instantiate a unique object per class/id/feed_nid. Don't use
183 196
   * directly, use feeds_source() instead.
......
237 250
   *   method may throw the same exceptions as FeedsSource::import().
238 251
   */
239 252
  public function startImport() {
240
    module_invoke_all('feeds_before_import', $this);
241 253
    $config = $this->importer->getConfig();
242 254
    if ($config['process_in_background']) {
243 255
      $this->startBackgroundJob('import');
......
274 286
   */
275 287
  public function schedule() {
276 288
    $this->scheduleImport();
289
    $this->scheduleExpire();
277 290
  }
278 291

  
279 292
  /**
......
286 299
    if (is_numeric($fetcher_period)) {
287 300
      $period = $fetcher_period;
288 301
    }
289
    $period = $this->progressImporting() === FEEDS_BATCH_COMPLETE ? $period : 0;
290 302
    $job = array(
291 303
      'type' => $this->id,
292 304
      'id' => $this->feed_nid,
293
      // Schedule as soon as possible if a batch is active.
294 305
      'period' => $period,
295 306
      'periodic' => TRUE,
296 307
    );
297
    if ($period != FEEDS_SCHEDULE_NEVER) {
308
    if ($period == FEEDS_SCHEDULE_NEVER && $this->progressImporting() === FEEDS_BATCH_COMPLETE) {
309
      JobScheduler::get('feeds_source_import')->remove($job);
310
    }
311
    elseif ($this->progressImporting() === FEEDS_BATCH_COMPLETE) {
298 312
      JobScheduler::get('feeds_source_import')->set($job);
299 313
    }
300 314
    else {
301
      JobScheduler::get('feeds_source_import')->remove($job);
315
      // Feed is not fully imported yet, so we put this job back in the queue
316
      // immediately for further processing.
317
      $queue = DrupalQueue::get('feeds_source_import');
318
      $queue->createItem($job);
319
    }
320
  }
321

  
322
  /**
323
   * Schedule background expire tasks.
324
   */
325
  public function scheduleExpire() {
326
    // Schedule as soon as possible if a batch is active.
327
    $period = $this->progressExpiring() === FEEDS_BATCH_COMPLETE ? 3600 : 0;
328

  
329
    $job = array(
330
      'type' => $this->id,
331
      'id' => $this->feed_nid,
332
      'period' => $period,
333
      'periodic' => TRUE,
334
    );
335
    if ($this->importer->processor->expiryTime() == FEEDS_EXPIRE_NEVER) {
336
      JobScheduler::get('feeds_source_expire')->remove($job);
337
    }
338
    else {
339
      JobScheduler::get('feeds_source_expire')->set($job);
302 340
    }
303 341
  }
304 342

  
......
340 378
    try {
341 379
      // If fetcher result is empty, we are starting a new import, log.
342 380
      if (empty($this->fetcher_result)) {
381
        module_invoke_all('feeds_before_import', $this);
343 382
        $this->state[FEEDS_START] = time();
344 383
      }
345 384

  
......
356 395

  
357 396
      // Process.
358 397
      $this->importer->processor->process($this, $parser_result);
398

  
399
      // Import finished without exceptions, so unset any potentially previously
400
      // recorded exceptions.
401
      unset($this->exception);
359 402
    }
360 403
    catch (Exception $e) {
361
      // Do nothing.
404
      // $e is stored and re-thrown once we've had a chance to log our progress.
405
      // Set the exception so that other modules can check if an exception
406
      // occurred in hook_feeds_after_import().
407
      $this->exception = $e;
362 408
    }
363 409
    $this->releaseLock();
364 410

  
......
399 445
      $this->importer->processor->clear($this);
400 446
    }
401 447
    catch (Exception $e) {
402
      // Do nothing.
448
      // $e is stored and re-thrown once we've had a chance to log our progress.
403 449
    }
404 450
    $this->releaseLock();
405 451

  
......
416 462
    return $result;
417 463
  }
418 464

  
465
  /**
466
   * Removes all expired items from a feed.
467
   */
468
  public function expire() {
469
    $this->acquireLock();
470
    try {
471
      $result = $this->importer->processor->expire($this);
472
    }
473
    catch (Exception $e) {
474
      // Will throw after the lock is released.
475
    }
476
    $this->releaseLock();
477

  
478
    if (isset($e)) {
479
      throw $e;
480
    }
481

  
482
    return $result;
483
  }
484

  
419 485
  /**
420 486
   * Report progress as float between 0 and 1. 1 = FEEDS_BATCH_COMPLETE.
421 487
   */
......
450 516
    return $this->state(FEEDS_PROCESS_CLEAR)->progress;
451 517
  }
452 518

  
519
  /**
520
   * Report progress on expiry.
521
   */
522
  public function progressExpiring() {
523
    return $this->state(FEEDS_PROCESS_EXPIRE)->progress;
524
  }
525

  
453 526
  /**
454 527
   * Return a state object for a given stage. Lazy instantiates new states.
455 528
   *
......
556 629
      'id' => $this->feed_nid,
557 630
    );
558 631
    JobScheduler::get('feeds_source_import')->remove($job);
632
    JobScheduler::get('feeds_source_expire')->remove($job);
559 633
  }
560 634

  
561 635
  /**
......
726 800
  protected function releaseLock() {
727 801
    lock_release("feeds_source_{$this->id}_{$this->feed_nid}");
728 802
  }
803

  
804
  /**
805
   * Implements FeedsConfigurable::dependencies().
806
   */
807
  public function dependencies() {
808
    $dependencies = parent::dependencies();
809
    return array_merge($dependencies, $this->importer()->dependencies());
810
  }
811

  
729 812
}

Formats disponibles : Unified diff