1 image.install image_update_1004()

Update all image fields to use a static default image URI.

Related topics

File

core/modules/image/image.install, line 257
Install, update and uninstall functions for the image module.

Code

function image_update_1004() {
  $old_fids = array();

  // Update field configs.
  $config_names = config_get_names_with_prefix('field.field.');
  foreach ($config_names as $config_name) {
    $config = config($config_name);
    $data = $config->get();
    if (array_key_exists('default_image', $data['settings'])) {
      if ($old_fid = _image_update_1004($data)) {
        $old_fids[] = $old_fid;
        $config->setData($data);
        $config->save();
      }
    }
  }

  // Update field instances.
  $config_names = config_get_names_with_prefix('field.instance.');
  foreach ($config_names as $config_name) {
    $config = config($config_name);
    $data = $config->get();
    if (array_key_exists('default_image', $data['settings'])) {
      if ($old_fid = _image_update_1004($data)) {
        $old_fids[] = $old_fid;
        $config->setData($data);
        $config->save();
      }
    }
  }

  // Clean up the now unneeded file entities.
  if ($old_fids) {
    db_delete('file_managed')
      ->condition('fid', $old_fids, 'IN')
      ->execute();
    db_delete('file_usage')
      ->condition('fid', $old_fids, 'IN')
      ->execute();
  }
}