<?php

/**
 * @file
 * Update scripts for Admin Views.
 */

/**
 * Implementations of hook_update_N().
 */

/**
 * Remove deprecated views_plugin_access_menu plugin.
 */
function admin_views_update_7100() {
  $result = db_query("SELECT vid, id, display_options FROM {views_display}");
  foreach ($result as $record) {
    $options = unserialize($record->display_options);
    if (isset($options['access']) && is_array($options['access']) && isset($options['access']['type']) && $options['access']['type'] === 'menu') {
      $options['access'] = array(
        'type' => 'perm',
        'perm' => 'access administration pages',
      );

      db_query("UPDATE {views_display} SET display_options = :options WHERE vid = :vid AND id = :id", array(
        'vid' => $record->vid,
        'id' => $record->id,
        'options' => serialize($options),
      ));
    }
  }
}

/**
 * Enable the new system display submodule.
 */
function admin_views_update_7101() {
  if (module_enable(array('admin_views_system_display'))) {
    return t('Enabled the new Admin Views System Display submodule.');
  }
  else {
    throw new DrupalUpdateException('Unable to enable the new Admin Views System Display submodule.');
  }
}

/**
 * Reset this module's weight.
 */
function admin_views_update_7102() {
  db_query("UPDATE {system} SET weight = 0 WHERE name = 'admin_views'");
}
