You are here

function farm_import_log_archive_assets in farmOS 7

Callback for 'farm_import_log_archive_assets' target.

2 string references to 'farm_import_log_archive_assets'
farm_import_feeds_processor_targets_alter in modules/farm/farm_import/farm_import.module
Implements hook_feeds_processor_targets_alter().
farm_import_log_field_mappings in modules/farm/farm_import/farm_import.feeds_importer_default.inc
Define field mapping that will be added to logs.

File

modules/farm/farm_import/farm_import.module, line 110
Farm import module.

Code

function farm_import_log_archive_assets($source, $entity, $target, $value, $mapping) {

  // Don't do anything if we weren't given any data.
  if (empty($value)) {
    return;
  }

  // In case the value arrives as an array.
  if (is_array($value)) {
    $value = reset($value);
  }

  // Do nothing if the archiving is set to any of the FALSE values.
  if (empty($value)) {
    return;
  }

  // Load log entity metadata wrapper.
  $log_wrapper = entity_metadata_wrapper('log', $entity);

  // Iterate through the assets and archive them (if they aren't already).
  foreach ($log_wrapper->field_farm_asset as $asset_wrapper) {
    $asset = $asset_wrapper
      ->value();
    if (empty($asset->archived)) {
      $asset->archived = REQUEST_TIME;
      farm_asset_save($asset);
    }
  }
}