You are here

public static function FeedImport::deleteExpired in Feed Import 7.3

Delete all expired items.

Parameters

int $max: Max number of entity ids to delete from a hash manager

Return value

int Number of deleted entities

1 call to FeedImport::deleteExpired()
feed_import_base_cron in feed_import_base/feed_import_base.module
Implements hook_cron().

File

feed_import_base/inc/feed_import.inc, line 498
This file contains Feed Import helpers.

Class

FeedImport
This class provides helper functions for feed import.

Code

public static function deleteExpired($max = 0) {
  $deleted = 0;
  foreach (static::loadAllFeeds() as $feed) {
    if (empty($feed->settings['hashes']['class'])) {
      continue;
    }
    $class = $feed->settings['hashes']['class'];
    $items = $class::getExpired($feed->machine_name, $max);
    foreach ($items as $e => &$ids) {
      $entity = static::getEntityInfo($e);

      // Delete entities.
      if ($entity->deleteCallback) {
        $f = $entity->deleteCallback . '_multiple';
        if (function_exists($f)) {
          $f($ids);
        }
        else {
          array_map($entity->deleteCallback, $ids);
        }
      }
      else {
        $entity->controller
          ->delete($ids);
      }

      // Delete hashes.
      $class::delete(array_keys($ids));
      $deleted += count($ids);
      unset($items[$e], $entity);
    }
  }
  return $deleted;
}