You are here

hosting_db_server.install in Hosting 6.2

Install, update and uninstall for the database server module.

File

db_server/hosting_db_server.install
View source
<?php

/**
 * @file
 *   Install, update and uninstall for the database server module.
 */

/**
 * Implementation of hook_schema().
 */
function hosting_db_server_schema() {
  $schema['hosting_db_server'] = array(
    'fields' => array(
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'db_user' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
      ),
      'db_passwd' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'vid',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function hosting_db_server_install() {

  // Create tables.
  drupal_install_schema('hosting_db_server');
}

/**
 * Get rid of db_server node type and associate ourselves with server nodes instead.
 */
function hosting_db_server_update_6000() {
  drupal_install_modules(array(
    'hosting_server',
  ));
  $ret = array();
  $result = db_query("SELECT nid, vid, title FROM {node} WHERE type='db_server'");
  while ($record = db_fetch_object($result)) {
    if ($record->title == 'localhost') {
      $db_server = db_fetch_object(db_query("SELECT * FROM {hosting_db_server} WHERE nid=%d", $record->nid));

      // Remove old data to remove collision opportunities.
      db_query("DELETE FROM {hosting_db_server} WHERE nid=%d", $record->nid);

      // get all the web servers to add the localhost db service to.
      $web_result = db_query("SELECT n.nid, n.vid FROM {node} n WHERE (n.type='web_server')");
      while ($web_server = db_fetch_object($web_result)) {
        db_query("INSERT INTO {hosting_service} (nid, vid, service, type, available) VALUES (%d, %d, 'db', 'mysql', 1)", $web_server->nid, $web_server->vid);
        db_query("INSERT INTO {hosting_db_server} (nid, vid, db_user, db_passwd) VALUES (%d, %d, '%s', '%s')", $web_server->nid, $web_server->vid, $db_server->db_user, $db_server->db_passwd);
        db_query("UPDATE {hosting_site} SET db_server = %d WHERE db_server=%d", $web_server->nid, $record->nid);
      }
    }
    else {

      // couldn't find a relative web server, so we will need to lose this db server.
      db_query("DELETE FROM {hosting_db_server} WHERE nid=%d", $record->nid);
    }
    db_query("DELETE FROM {node_revisions} WHERE nid=%d", $record->nid);
  }
  db_query("DELETE FROM {node} WHERE type='db_server'");
  return $ret;
}

/**
 * Get rid of the db type value, it duplicates the service info
 */
function hosting_db_server_update_6001() {
  $ret = array();
  db_drop_field($ret, 'hosting_db_server', 'db_type');
  return $ret;
}

Functions

Namesort descending Description
hosting_db_server_install Implementation of hook_install().
hosting_db_server_schema Implementation of hook_schema().
hosting_db_server_update_6000 Get rid of db_server node type and associate ourselves with server nodes instead.
hosting_db_server_update_6001 Get rid of the db type value, it duplicates the service info