You are here

function filefield_paths_update_7107 in File (Field) Paths 7

Removed filefield_paths table/schema.

File

./filefield_paths.install, line 153
Install, update and uninstall functions for the File (Field) Paths module.

Code

function filefield_paths_update_7107() {
  $results = db_select('filefield_paths', 'ffp')
    ->fields('ffp')
    ->execute();
  foreach ($results as $result) {
    $instance = field_info_instance('node', $result->field, $result->type);
    if (!is_null($instance) && isset($instance["ffp_{$result->field}}"])) {
      $filepath = unserialize($result->filepath);
      $filename = unserialize($result->filename);
      $instance["ffp_{$result->field}"] = array(
        'file_path' => $filepath['value'],
        'file_path_cleanup' => array(
          'file_path_pathauto' => $filepath['pathauto'],
          'file_path_transliterate' => $filepath['transliterate'],
        ),
        'file_name' => $filename['value'],
        'file_name_cleanup' => array(
          'file_name_pathauto' => $filename['pathauto'],
          'file_name_transliterate' => $filename['transliterate'],
        ),
        'active_updating' => $result->active_updating,
      );
      field_update_instance($instance);
    }
  }

  // Remove filefield_paths table/schema.
  db_drop_table('filefield_paths');

  // Update field instance settings.
  drupal_load('module', 'filefield_paths');
  $field_types = array_keys(_filefield_paths_get_field_types());
  foreach (field_info_fields() as $field) {
    if (in_array($field['type'], $field_types)) {
      foreach ($field['bundles'] as $entity_type => $bundles) {
        foreach ($bundles as $bundle_name) {
          $instance = field_info_instance($entity_type, $field['field_name'], $bundle_name);
          if (isset($instance["ffp_{$field['field_name']}"]) && !isset($instance['settings']['filefield_paths'])) {
            $instance['settings']['filefield_paths'] = array(
              'file_path' => array(
                'value' => $instance["ffp_{$field['field_name']}"]['file_path'],
                'options' => array(
                  'pathauto' => $instance["ffp_{$field['field_name']}"]['file_path_cleanup']['file_path_pathauto'],
                  'transliterate' => $instance["ffp_{$field['field_name']}"]['file_path_cleanup']['file_path_transliterate'],
                ),
              ),
              'file_name' => array(
                'value' => $instance["ffp_{$field['field_name']}"]['file_name'],
                'options' => array(
                  'pathauto' => $instance["ffp_{$field['field_name']}"]['file_name_cleanup']['file_name_pathauto'],
                  'transliterate' => $instance["ffp_{$field['field_name']}"]['file_name_cleanup']['file_name_transliterate'],
                ),
              ),
              'active_updating' => $instance["ffp_{$field['field_name']}"]['active_updating'],
            );
            unset($instance["ffp_{$field['field_name']}"]);
            field_update_instance($instance);
          }
        }
      }
    }
  }
}