You are here

hosting_site.install in Hosting 7.4

Define database schema and update functions for the hosting_site module.

File

site/hosting_site.install
View source
<?php

/**
 * @file
 * Define database schema and update functions for the hosting_site module.
 *
 */

/**
 * Implements hook_schema().
 */
function hosting_site_schema() {
  $schema['hosting_site'] = 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,
      ),
      'client' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'db_server' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'db_name' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => FALSE,
        'default' => '',
      ),
      'platform' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'profile' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'language' => array(
        'type' => 'varchar',
        'length' => 10,
        'not null' => TRUE,
        'default' => 'en',
      ),
      'last_cron' => array(
        'type' => 'int',
        'not null' => FALSE,
      ),
      'cron_key' => array(
        'type' => 'varchar',
        'not null' => FALSE,
        'length' => 80,
        'default' => '',
      ),
      'verified' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'file_public_path' => array(
        'description' => 'The path to the public site files."',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
        'default' => '',
      ),
      'file_private_path' => array(
        'description' => 'The path to the private site files."',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
        'default' => '',
      ),
      'file_temporary_path' => array(
        'description' => 'The path to the temporary site files."',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'vid',
    ),
  );
  $schema['hosting_site_backups'] = array(
    'fields' => array(
      'bid' => array(
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'site' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'web_server' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'description' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'filename' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'size' => array(
        'type' => 'int',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'timestamp' => array(
        'type' => 'int',
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'bid',
    ),
  );
  return $schema;
}

/**
 * Implements hook_update_N().
 *
 * Add language field to hosting_sites table
 */
function hosting_site_update_1() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {hosting_site} ADD COLUMN language VARCHAR(10) NOT NULL default 'en'");
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Retry all failed site installs, to evaluate where they might be successfully imported instead
 */
function hosting_site_update_2() {
  include_once drupal_get_path('module', 'hosting_task') . '/hosting_task.module';
  $ret = array();
  $result = db_query("select n.nid from {node} n left join {hosting_task} t on n.vid = t.vid where t.task_type = 'install' and t.task_status > 1 and n.type='task'");
  while ($obj = db_fetch_object($result)) {
    hosting_task_retry($obj->nid);
  }
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Move away from bitmasks for the status field.
 */
function hosting_site_update_3() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {hosting_site} CHANGE COLUMN status status int(11) NOT NULL default '0'");
  $ret[] = update_sql("CREATE TEMPORARY TABLE {hosting_site_statuses} SELECT nid,\n    (status&4) as deleted, NOT (status&2) AS disabled, status&1 AS installed FROM {hosting_site}");

  // Reset them all to queued
  $ret[] = update_sql("UPDATE {hosting_site} SET status = 0");

  // First, we get rid of the deleted sites.
  $ret[] = update_sql("UPDATE {hosting_site} SET status = -2 WHERE nid in (SELECT nid FROM {hosting_site_statuses} WHERE deleted > 0)");
  $ret[] = update_sql("DELETE FROM {hosting_site_statuses} WHERE deleted > 0");

  // Then the disabled sites.
  $ret[] = update_sql("UPDATE {hosting_site} SET status = -1 WHERE nid in (SELECT nid FROM {hosting_site_statuses} WHERE disabled > 0)");
  $ret[] = update_sql("DELETE FROM {hosting_site_statuses} WHERE disabled > 0");

  // Then the installed sites, which are the same as 'enabled' sites.
  $ret[] = update_sql("UPDATE {hosting_site} SET status = 1 WHERE nid in (SELECT nid FROM {hosting_site_statuses} WHERE installed > 0)");
  $ret[] = update_sql("DELETE FROM {hosting_site_statuses} WHERE installed > 0");
  $ret[] = update_sql("DROP TABLE {hosting_site_statuses}");

  // Now we rid ourself of 'enabled', we really care about installed.
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Add verified timestamp to the site
 */
function hosting_site_update_4() {
  $ret = array();
  $now = time();
  $ret[] = update_sql("ALTER TABLE {hosting_site} ADD COLUMN verified int(10) NOT NULL default '0'");
  db_query("UPDATE {hosting_site} SET verified=%d WHERE status=1", $now);
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Turn the bid column of hosting_site_backups into a serial field
 *
 * Required by Drupal 6 update.
 */
function hosting_site_update_5() {
  $ret = array();
  db_drop_primary_key($ret, 'hosting_site_backups');
  db_field_set_no_default($ret, 'hosting_site_backups', 'bid');
  db_change_field($ret, 'hosting_site_backups', 'bid', 'bid', array(
    'type' => 'serial',
    'not null' => TRUE,
  ), array(
    'primary key' => array(
      'bid',
    ),
  ));
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Add port field to hosting_site table.
 */
function hosting_site_update_6() {
  $ret = array();
  db_add_field($ret, 'hosting_site', 'port', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Add ssl field to hosting_site table.
 */
function hosting_site_update_6001() {
  $ret = array();
  db_add_field($ret, 'hosting_site', 'ssl', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Add ssl_redirect field to hosting_site table.
 */
function hosting_site_update_6002() {
  $ret = array();
  db_add_field($ret, 'hosting_site', 'ssl_redirect', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Update imported sites that have port 0 in the db. See #588072
 */
function hosting_site_update_6003() {
  $ret = array();

  // this is now irrelevant as the ports have been refactored completely.
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * no-op - this is to be Re-verify all sites, moved to
 * hosting_update_6002()
 */
function hosting_site_update_6004() {
  return array();
}

/**
 * Implements hook_update_N().
 *
 * Port is no longer configured per site.
 */
function hosting_site_update_6005() {
  $ret = array();
  db_drop_field($ret, "hosting_site", "port");
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Remove the ssl configuration which should be in a separate table.
 */
function hosting_site_update_6006() {
  $ret = array();
  db_drop_field($ret, "hosting_site", "`ssl`");
  db_drop_field($ret, "hosting_site", "ssl_redirect");
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Add backup size to hosting_site_backups table
 */
function hosting_site_update_6007() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {hosting_site_backups} ADD COLUMN size INT");
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Add the cron_key column to the hosting_site table.
 */
function hosting_site_update_6008() {
  $ret = array();
  db_add_field($ret, 'hosting_site', 'cron_key', array(
    'type' => 'varchar',
    'not null' => TRUE,
    'length' => 80,
    'default' => '',
  ));
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Rename tasks login_reset and backup_delete to use dashes
 *
 * We re-named 'login_reset' tasks to 'login-reset' and 'backup_delete' to
 * 'backup-delete'.
 */
function hosting_site_update_6200() {
  $ret = array();
  $replacements = array(
    'backup_delete' => 'backup-delete',
    'login_reset' => 'login-reset',
  );
  foreach ($replacements as $old => $new) {
    db_query("UPDATE {hosting_task} SET task_type = '%s' where task_type = '%s'", $new, $old);
  }
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Fix permissions for renamed tasks
 *
 * We re-named 'login_reset' tasks to 'login-reset' and 'backup_delete' to
 * 'backup-delete' and so we need to fix any roles using those permissions.
 */
function hosting_site_update_6201() {
  $ret = array();
  $replacements = array(
    'create backup_delete task' => 'create backup-delete task',
    'create login_reset task' => 'create login-reset task',
  );

  // Process all the roles.
  $roles = db_query('SELECT rid, perm FROM {permission}');
  while ($role = db_fetch_object($roles)) {
    $perms = explode(', ', $role->perm);
    $perms = str_replace(array_keys($replacements), array_values($replacements), $perms);
    db_query("UPDATE {permission} SET perm = '%s' where rid = %d", implode(', ', $perms), $role->rid);
  }
  return $ret;
}

/**
 * Add 'db_name' column to 'hosting_site' table.
 */
function hosting_site_update_6202() {
  $ret = array();
  db_add_field($ret, 'hosting_site', 'db_name', array(
    'type' => 'varchar',
    'length' => 64,
    'not null' => TRUE,
    'default' => '',
  ));
  return $ret;
}

/**
 * Add new Action permissions.
 */
function hosting_site_update_6203() {
  $ret = array();

  // Enable Actions permissions, and temporarily Install Profile API
  // module to load permission CRUD functions
  module_enable(array(
    'actions_permissions',
    'install_profile_api',
  ));
  module_load_include('inc', 'install_profile_api', 'core/user');
  install_add_permissions(install_get_rid('aegir administrator'), array(
    'execute Site: Backup (hosting_site_op_backup)',
    'execute Site: Delete (hosting_site_op_delete)',
    'execute Site: Disable (hosting_site_op_disable)',
    'execute Site: Enable (hosting_site_op_enable)',
    'execute Site: Reset password (hosting_site_op_login_reset)',
    'execute Site: Verify (hosting_site_op_verify)',
  ));
  install_add_permissions(install_get_rid('aegir platform manager'), array(
    'execute Site: Delete (hosting_site_op_delete)',
    'execute Site: Disable (hosting_site_op_disable)',
    'execute Site: Enable (hosting_site_op_enable)',
    'execute Site: Verify (hosting_site_op_verify)',
  ));
  install_add_permissions(install_get_rid('aegir client'), array(
    'execute Site: Backup (hosting_site_op_backup)',
    'execute Site: Delete (hosting_site_op_delete)',
    'execute Site: Disable (hosting_site_op_disable)',
    'execute Site: Enable (hosting_site_op_enable)',
    'execute Site: Reset password (hosting_site_op_login_reset)',
    'execute Site: Verify (hosting_site_op_verify)',
  ));
  module_disable(array(
    'install_profile_api',
  ));
  return $ret;
}

/**
 * Place new block.
 */
function hosting_site_update_6204() {
  $ret = array();

  // Temporarily enable Install Profile API module and load includes.
  module_enable(array(
    'install_profile_api',
  ));
  drupal_load('module', 'install_profile_api');
  install_include(array(
    'block',
  ));

  // Enable blocks.
  $theme = 'eldir';
  install_set_block('views', 'hosting_site_list-block_client2', $theme, 'content_bottom', 0, 2, "<?php\nglobal \$user;\n\$node = menu_get_object();\n\$menu_item = menu_get_item();\nif (!empty(\$node)) && \$menu_item['number_parts'] == 2) {\n  return \$node->type == 'client' && {$user->uid} != 1;\n}\n?>");
  install_set_block('views', 'hosting_site_list-block_client', $theme, 'content_bottom', 0, 2, "<?php\n\$node = menu_get_object();\n\$menu_item = menu_get_item();\nif (!empty(\$node) && \$menu_item['number_parts'] == 2) {\n  return \$node->type == 'client';\n}\n?>");
  install_set_block('views', 'hosting_site_list-block_1', $theme, 'content_bottom', 0, 1, 'hosting/c/platform_*');
  module_disable(array(
    'install_profile_api',
  ));
  return $ret;
}

/**
 * Place platform site-list block.
 */
function hosting_site_update_6205() {
  $ret = array();

  // Temporarily enable Install Profile API module and load includes.
  module_enable(array(
    'install_profile_api',
  ));
  drupal_load('module', 'install_profile_api');
  install_include(array(
    'block',
  ));

  // Enable block.
  $theme = 'eldir';
  install_set_block('views', 'hosting_site_list-block_1', $theme, 'content_bottom', 0, 1, 'hosting/c/platform_*');
  module_disable(array(
    'install_profile_api',
  ));
  return $ret;
}

/**
 * Place call custom functions for block visibility.
 */
function hosting_site_update_6206() {
  $ret = array();

  // Temporarily enable Install Profile API module and load includes.
  module_enable(array(
    'install_profile_api',
  ));
  drupal_load('module', 'install_profile_api');
  install_include(array(
    'block',
  ));

  // Set block visibility.
  $theme = 'eldir';
  install_set_block('views', 'hosting_site_list-block_client', $theme, 'content_bottom', 0, 2, "<?php\nreturn hosting_site_client_admin_block_visibility();\n?>");
  install_set_block('views', 'hosting_site_list-block_client2', $theme, 'content_bottom', 0, 2, "<?php\nreturn hosting_site_client_list_block_visibility();\n?>");
  install_set_block('views', 'hosting_site_list-block_profile', $theme, 'content_bottom', 0, 2, "\n<?php\nreturn hosting_site_profile_block_visibility();\n?>");
  module_disable(array(
    'install_profile_api',
  ));
  return $ret;
}

/**
 * Force a re-verification of all enabled sites,
 * to re-generate their Apache virtualhost configurations to use
 * correct handlers in the 'files' or 'private' subdirectories
 */
function hosting_site_update_6207() {
  $result = db_query("SELECT nid FROM {hosting_site} WHERE status=1");
  while ($site = db_fetch_object($result)) {
    hosting_add_task($site->nid, 'verify');
  }
  return $ret;
}

/**
 * Allow NULLs in 'db_name' column in 'hosting_site' table.
 */
function hosting_site_update_7300() {
  db_change_field('hosting_site', 'db_name', 'db_name', array(
    'type' => 'varchar',
    'length' => 64,
    'not null' => FALSE,
    'default' => '',
  ));
}

/**
 * Use int:big to store backup size.
 */
function hosting_site_update_7301() {
  db_change_field('hosting_site_backups', 'size', 'size', array(
    'type' => 'int',
    'size' => 'big',
  ));
}

/**
 * Add 'file_public_path', 'file_private_path', 'file_temporary_path' columns
 * to 'hosting_site' table.
 */
function hosting_site_update_7302() {
  $ret = array();
  db_add_field('hosting_site', 'file_public_path', array(
    'description' => 'The path to the public site files."',
    'type' => 'varchar',
    'length' => 64,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field('hosting_site', 'file_private_path', array(
    'description' => 'The path to the private site files."',
    'type' => 'varchar',
    'length' => 64,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field('hosting_site', 'file_temporary_path', array(
    'description' => 'The path to the temporary site files."',
    'type' => 'varchar',
    'length' => 64,
    'not null' => TRUE,
    'default' => '',
  ));
  return $ret;
}

Functions

Namesort descending Description
hosting_site_schema Implements hook_schema().
hosting_site_update_1 Implements hook_update_N().
hosting_site_update_2 Implements hook_update_N().
hosting_site_update_3 Implements hook_update_N().
hosting_site_update_4 Implements hook_update_N().
hosting_site_update_5 Implements hook_update_N().
hosting_site_update_6 Implements hook_update_N().
hosting_site_update_6001 Implements hook_update_N().
hosting_site_update_6002 Implements hook_update_N().
hosting_site_update_6003 Implements hook_update_N().
hosting_site_update_6004 Implements hook_update_N().
hosting_site_update_6005 Implements hook_update_N().
hosting_site_update_6006 Implements hook_update_N().
hosting_site_update_6007 Implements hook_update_N().
hosting_site_update_6008 Implements hook_update_N().
hosting_site_update_6200 Implements hook_update_N().
hosting_site_update_6201 Implements hook_update_N().
hosting_site_update_6202 Add 'db_name' column to 'hosting_site' table.
hosting_site_update_6203 Add new Action permissions.
hosting_site_update_6204 Place new block.
hosting_site_update_6205 Place platform site-list block.
hosting_site_update_6206 Place call custom functions for block visibility.
hosting_site_update_6207 Force a re-verification of all enabled sites, to re-generate their Apache virtualhost configurations to use correct handlers in the 'files' or 'private' subdirectories
hosting_site_update_7300 Allow NULLs in 'db_name' column in 'hosting_site' table.
hosting_site_update_7301 Use int:big to store backup size.
hosting_site_update_7302 Add 'file_public_path', 'file_private_path', 'file_temporary_path' columns to 'hosting_site' table.