You are here

function uuid_file_features_rebuild in UUID Features Integration 6

Same name and namespace in other branches
  1. 7 includes/uuid_file.features.inc \uuid_file_features_rebuild()

Implementation of hook_features_rebuild(). Rebuilds files based on UUID from code defaults.

1 call to uuid_file_features_rebuild()
uuid_file_features_revert in includes/uuid_file.features.inc
Implementation of hook_features_revert().

File

includes/uuid_file.features.inc, line 67
Features hooks for the uuid_file features component.

Code

function uuid_file_features_rebuild($module) {
  $files = module_invoke($module, 'uuid_features_default_files');
  if (!empty($files)) {
    $source_dir = drupal_get_path('module', $module) . '/uuid_file';
    foreach ($files as $data) {
      $source = $source_dir . '/' . $data['uuid'] . '.' . $data['extension'];

      // Sometimes after deleting a file, the record for the uuid is still present.
      db_query('DELETE FROM {uuid_files} WHERE uuid = "%s"', $data['uuid']);

      // Copy the file and save to db.
      $file = field_file_save_file($source, array(), file_directory_path());

      // Make sure status is set to permanent.  file_set_status (and the rest of
      // core) expects $file to be an object, while filefields expect an array.
      $file = (object) $file;
      file_set_status($file, FILE_STATUS_PERMANENT);
      $file = (array) $file;

      // Update the uuid.
      uuid_set_uuid('files', 'fid', $file['fid'], $data['uuid']);
    }
  }
}