You are here

function media_wysiwyg_update_7205 in D7 Media 7.2

Same name and namespace in other branches
  1. 7.4 modules/media_wysiwyg/media_wysiwyg.install \media_wysiwyg_update_7205()
  2. 7.3 modules/media_wysiwyg/media_wysiwyg.install \media_wysiwyg_update_7205()

Install {media_restrict_wysiwyg} and {media_view_mode_wysiwyg}.

Remove variables media_wysiwyg_view_mode_%.

Uninstall media_wysiwyg_view_mode module.

File

modules/media_wysiwyg/media_wysiwyg.install, line 173
Install, update and uninstall functions for the Media WYSIWYG module.

Code

function media_wysiwyg_update_7205() {
  $schema = media_wysiwyg_schema();

  // Create the new configuration tables.
  if (!db_table_exists('media_restrict_wysiwyg')) {
    db_create_table('media_restrict_wysiwyg', $schema['media_restrict_wysiwyg']);
    db_create_table('media_view_mode_wysiwyg', $schema['media_view_mode_wysiwyg']);
  }

  // Migrate the configuration from the old variables into the new DB tables.
  $types = file_type_load_all(TRUE);
  foreach ($types as $type) {
    $enabled = variable_get("media_wysiwyg_view_mode_" . $type->type . "_wysiwyg_restricted_view_modes_status", FALSE);
    if ($enabled) {
      $wysiwyg_restricted_view_modes = variable_get("media_wysiwyg_view_mode_" . $type->type . "_wysiwyg_restricted_view_modes", array());
      foreach ($wysiwyg_restricted_view_modes as $wysiwyg_restricted_view_mode) {
        db_insert('media_restrict_wysiwyg')
          ->fields(array(
          'type' => $type->type,
          'display' => $wysiwyg_restricted_view_mode,
        ))
          ->execute();
      }
    }
    $enabled = variable_get("media_wysiwyg_view_mode_" . $type->type . "_file_wysiwyg_view_mode_status", FALSE);
    if ($enabled) {
      $file_wysiwyg_view_mode = variable_get("media_wysiwyg_view_mode_" . $type->type . "_file_wysiwyg_view_mode", 'wysiwyg');
      db_insert('media_view_mode_wysiwyg')
        ->fields(array(
        'type' => $type->type,
        'view_mode' => $file_wysiwyg_view_mode,
      ))
        ->execute();
    }
  }

  // Remove old configuration variables.
  db_delete('variable')
    ->condition('name', "media_wysiwyg_view_mode_%", "LIKE")
    ->execute();

  // Disable and uninstall View Mode module.Since the view mode module is
  // deleted, this copies from  module_disable() and drupal_uninstall_modules().
  // Disable first.
  $module = 'media_wysiwyg_view_mode';
  db_update('system')
    ->fields(array(
    'status' => 0,
  ))
    ->condition('type', 'module')
    ->condition('name', $module)
    ->execute();
  system_list_reset();
  module_list(TRUE);
  module_implements('', FALSE, TRUE);
  entity_info_cache_clear();

  // Invoke hook_modules_disabled before disabling modules,
  // so we can still call module hooks to get information.
  module_invoke_all('modules_disabled', array(
    $module,
  ));

  // Update the registry to remove the newly-disabled module.
  registry_update();
  _system_update_bootstrap_status();

  // Update the theme registry to remove the newly-disabled module.
  drupal_theme_rebuild();

  // Now uninstall.
  drupal_uninstall_schema($module);
  drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
  module_invoke_all('modules_uninstalled', array(
    $module,
  ));
}