You are here

admin.install in Admin 6.2

Same filename and directory in other branches
  1. 6 admin.install
  2. 7.2 admin.install

File

admin.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function admin_install() {
  if (db_table_exists('menu_custom') && !db_result(db_query("SELECT menu_name FROM {menu_custom} WHERE menu_name = 'admin'"))) {
    $t = get_t();
    db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", 'admin', $t('Admin'), $t('Administrative links.'));
  }
}

/**
 * Implementation of hook_uninstall().
 */
function admin_uninstall() {
  if (db_table_exists('menu_custom')) {
    db_query("DELETE FROM {menu_custom} WHERE menu_name = 'admin'");
  }
  variable_del('admin_toolbar');
}

/**
 * Implementation of hook_enable().
 */
function admin_enable() {
  $result = db_query("SELECT * FROM {menu_links} WHERE link_path LIKE 'admin%'");
  while ($item = db_fetch_array($result)) {
    _menu_delete_item($item, TRUE);
  }
  menu_rebuild();

  // Weight admin to come after other modules -- in particular, admin_theme().
  db_query("UPDATE {system} SET weight = 1 WHERE name = 'admin' AND type = 'module'");
}

/**
 * Update 6001: Create admin menu.
 */
function admin_update_6001() {
  $return = array();
  $return[] = update_sql("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('admin', 'Admin', 'Admin links.')");
  return $return;
}

/**
 * Update 6002: Update theme namespace to 'slate' & clears out any customizations to key admin menu items.
 */
function admin_update_6002() {
  db_query("DELETE FROM {system} WHERE name = 'admin' AND type = 'theme'");
  _admin_theme_rebuild(TRUE);
  if (variable_get('admin_theme', NULL) == 'admin') {
    variable_set('admin_theme', 'slate');
  }
  $result = db_query("SELECT * FROM {menu_links} WHERE link_path LIKE 'admin%'");
  while ($item = db_fetch_array($result)) {
    _menu_delete_item($item, TRUE);
  }
  menu_rebuild();
  return array();
}

/**
 * Update 6003: Weight admin module.
 */
function admin_update_6003() {

  // Weight admin to come after other modules -- in particular, admin_theme().
  $return = array();
  $return[] = update_sql("UPDATE {system} SET weight = 1 WHERE name = 'admin' AND type = 'module'");
  return $return;
}

/**
 * Update 6201: Migrate previous permissions for "admin menu" to "use admin toolbar".
 */
function admin_update_6201() {
  $return = array();
  $result = db_query("SELECT * FROM {permission}");
  while ($row = db_fetch_object($result)) {
    $perms = explode(', ', $row->perm);
    if (in_array('admin menu', $perms, TRUE)) {
      $key = array_search('admin menu', $perms);
      $perms[$key] = 'use admin toolbar';
      $perms = implode(', ', $perms);
      $return[] = update_sql("UPDATE {permission} SET perm = '{$perms}' WHERE pid = {$row->pid}");
    }
  }

  // Remove old theme instantiation stack & reset admin theme if
  // referring to deprecated admin themes.
  variable_del('admin_theme_invalidated');
  $theme = variable_get('admin_theme', '0');
  if ($theme === 'admin' || $theme === 'slate') {
    variable_del('admin_theme');
  }
  return $return;
}

/**
 * Update 6202: Update the format of the admin_toolbar variable.
 */
function admin_update_6202() {
  $ret = array();
  $settings = variable_get('admin_toolbar', array());
  if (isset($settings['blocks'])) {
    $needs_update = FALSE;

    // First pass, determine if we need to update these.
    foreach ($settings['blocks'] as $bid => $status) {
      if (!is_numeric($status)) {
        $needs_update = TRUE;
        break;
      }
    }
    if ($needs_update) {
      module_load_include('module', 'admin', 'admin');
      $defaults = admin_get_default_blocks(TRUE);

      // Second pass, do the update!
      foreach ($settings['blocks'] as $bid => $status) {
        if ($status) {
          $settings['blocks'][$bid] = isset($defaults[$bid]) ? $defaults[$bid] : BLOCK_NO_CACHE;
        }
        else {
          unset($settings['blocks'][$bid]);
        }
      }
      variable_set('admin_toolbar', $settings);
      $ret[] = array(
        'success' => TRUE,
        'query' => 'Updated admin settings.',
      );
    }
  }
  return $ret;
}

Functions

Namesort descending Description
admin_enable Implementation of hook_enable().
admin_install Implementation of hook_install().
admin_uninstall Implementation of hook_uninstall().
admin_update_6001 Update 6001: Create admin menu.
admin_update_6002 Update 6002: Update theme namespace to 'slate' & clears out any customizations to key admin menu items.
admin_update_6003 Update 6003: Weight admin module.
admin_update_6201 Update 6201: Migrate previous permissions for "admin menu" to "use admin toolbar".
admin_update_6202 Update 6202: Update the format of the admin_toolbar variable.