You are here

function media_type_batch_update in D7 Media 7

Adds a value for the type column in files_managed.

If $update_existing is TRUE, will update the type of files with an existing type value.

Parameters

boolean $update_existing:

integer $no_to_update:

integer $offset:

Return value

array A list of updated file ids

2 calls to media_type_batch_update()
media_admin_rebuild_types_batch_op in includes/media.admin.inc
Batch operation for fixing the file_managed table for media, adding type values where no value exists.
media_install in ./media.install
Implements hook_install().

File

includes/media.types.inc, line 263
Helper functions related to media types. CRUD for saving their settings mainly.

Code

function media_type_batch_update($update_existing = FALSE, $no_to_update = NULL, $offset = 0) {
  $results = array();
  $query = db_select('file_managed', 'fm')
    ->fields('fm', array(
    'fid',
  ));
  if (!$update_existing) {
    $query
      ->condition('type', FILE_TYPE_NONE);
  }
  if ($no_to_update) {
    $query
      ->range($offset, $no_to_update);
  }
  elseif ($offset) {
    $query
      ->range($offset);
  }
  $fids = $query
    ->execute()
    ->fetchCol();
  foreach ($fids as $fid) {
    $file = file_load($fid);
    if (!$file->fid) {
      throw new Exception('Unable to continue, file was not loaded.');
    }
    file_save($file);
    $results[] = $fid;
  }
  return $results;
}