Révision a192dc0b
Ajouté par Assos Assos il y a environ 8 ans
drupal7/sites/all/modules/feeds/includes/FeedsSource.inc | ||
---|---|---|
6 | 6 |
*/ |
7 | 7 |
|
8 | 8 |
/** |
9 |
* Distinguish exceptions occuring when handling locks. |
|
9 |
* Distinguish exceptions occurring when handling locks.
|
|
10 | 10 |
*/ |
11 | 11 |
class FeedsLockException extends Exception {} |
12 | 12 |
|
... | ... | |
134 | 134 |
$this->progress = FEEDS_BATCH_COMPLETE; |
135 | 135 |
} |
136 | 136 |
elseif ($total) { |
137 |
$this->progress = $progress / $total; |
|
137 |
$this->progress = (float) $progress / $total;
|
|
138 | 138 |
if ($this->progress == FEEDS_BATCH_COMPLETE && $total != $progress) { |
139 | 139 |
$this->progress = 0.99; |
140 | 140 |
} |
... | ... | |
197 | 197 |
*/ |
198 | 198 |
public static function instance($importer_id, $feed_nid) { |
199 | 199 |
$class = variable_get('feeds_source_class', 'FeedsSource'); |
200 |
static $instances = array(); |
|
200 |
|
|
201 |
$instances = &drupal_static(__METHOD__, array()); |
|
202 |
|
|
201 | 203 |
if (!isset($instances[$class][$importer_id][$feed_nid])) { |
202 | 204 |
$instances[$class][$importer_id][$feed_nid] = new $class($importer_id, $feed_nid); |
203 | 205 |
} |
... | ... | |
406 | 408 |
// occurred in hook_feeds_after_import(). |
407 | 409 |
$this->exception = $e; |
408 | 410 |
} |
409 |
$this->releaseLock(); |
|
410 | 411 |
|
411 | 412 |
// Clean up. |
412 | 413 |
$result = $this->progressImporting(); |
413 | 414 |
if ($result == FEEDS_BATCH_COMPLETE || isset($e)) { |
414 | 415 |
$this->imported = time(); |
415 |
$this->log('import', 'Imported in !s s', array('!s' => $this->imported - $this->state[FEEDS_START]), WATCHDOG_INFO);
|
|
416 |
$this->log('import', 'Imported in @s seconds.', array('@s' => $this->imported - $this->state[FEEDS_START]), WATCHDOG_INFO);
|
|
416 | 417 |
module_invoke_all('feeds_after_import', $this); |
417 | 418 |
unset($this->fetcher_result, $this->state); |
418 | 419 |
} |
419 | 420 |
$this->save(); |
421 |
|
|
422 |
$this->releaseLock(); |
|
423 |
|
|
420 | 424 |
if (isset($e)) { |
421 | 425 |
throw $e; |
422 | 426 |
} |
427 |
|
|
423 | 428 |
return $result; |
424 | 429 |
} |
425 | 430 |
|
431 |
/** |
|
432 |
* Imports a fetcher result all at once in memory. |
|
433 |
* |
|
434 |
* @param FeedsFetcherResult $fetcher_result |
|
435 |
* The fetcher result to process. |
|
436 |
* |
|
437 |
* @throws Exception |
|
438 |
* Thrown if an error occurs when importing. |
|
439 |
*/ |
|
440 |
public function pushImport(FeedsFetcherResult $fetcher_result) { |
|
441 |
// Since locks only work during a request, check if an import is active. |
|
442 |
if (!empty($this->fetcher_result) || !empty($this->state)) { |
|
443 |
throw new RuntimeException('The feed is currently importing.'); |
|
444 |
} |
|
445 |
|
|
446 |
$this->acquireLock(); |
|
447 |
$start = time(); |
|
448 |
|
|
449 |
try { |
|
450 |
module_invoke_all('feeds_before_import', $this); |
|
451 |
|
|
452 |
// Parse. |
|
453 |
do { |
|
454 |
$parser_result = $this->importer->parser->parse($this, $fetcher_result); |
|
455 |
module_invoke_all('feeds_after_parse', $this, $parser_result); |
|
456 |
|
|
457 |
// Process. |
|
458 |
$this->importer->processor->process($this, $parser_result); |
|
459 |
|
|
460 |
} while ($this->progressParsing() !== FEEDS_BATCH_COMPLETE); |
|
461 |
} |
|
462 |
catch (Exception $e) { |
|
463 |
// $e is stored and re-thrown once we've had a chance to log our progress. |
|
464 |
// Set the exception so that other modules can check if an exception |
|
465 |
// occurred in hook_feeds_after_import(). |
|
466 |
$this->exception = $e; |
|
467 |
} |
|
468 |
|
|
469 |
module_invoke_all('feeds_after_import', $this); |
|
470 |
|
|
471 |
$this->imported = time(); |
|
472 |
$this->log('import', 'Imported in @s seconds.', array('@s' => $this->imported - $start), WATCHDOG_INFO); |
|
473 |
|
|
474 |
unset($this->fetcher_result, $this->state); |
|
475 |
|
|
476 |
$this->save(); |
|
477 |
|
|
478 |
$this->releaseLock(); |
|
479 |
|
|
480 |
if (isset($e)) { |
|
481 |
throw $e; |
|
482 |
} |
|
483 |
} |
|
484 |
|
|
426 | 485 |
/** |
427 | 486 |
* Remove all items from a feed. |
428 | 487 |
* |
Formats disponibles : Unified diff
Weekly update of contrib modules