You are here

hosting_site.install in Hosting 5

File

site/hosting_site.install
View source
<?php

function hosting_site_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {hosting_site} (\n        vid int(10) unsigned NOT NULL default '0',\n        nid int(10) unsigned NOT NULL default '0',\n        client int(11) NOT NULL default '0',\n        db_server int(11) NOT NULL default '0',\n        platform int(11) NOT NULL default '0',\n        profile int(11) NOT NULL default '0',\n        language VARCHAR(10) NOT NULL default 'en',\n        last_cron int(10) default NULL,\n        verified int(10) NOT NULL default '0',\n        status tinyint NOT NULL default '0',\n        PRIMARY KEY  (vid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {hosting_site_backups} (\n        bid int(10) unsigned NOT NULL,\n        site int(10) NOT NULL default '0',\n        web_server int(10) NOT NULL default '0',\n        description longtext,\n        filename longtext,\n        timestamp int(11) default NULL,\n        PRIMARY KEY  (bid)    \n        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
  }
}

/**
 * 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;
}

/**
 * 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;
}

/**
 * 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;
}

/**
 * Add verified timestamp to the site
 */
function hosting_site_update_4() {
  $ret = array();
  $now = mktime();
  $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;
}

Functions

Namesort descending Description
hosting_site_install
hosting_site_update_1 Add language field to hosting_sites table
hosting_site_update_2 Retry all failed site installs, to evaluate where they might be successfully imported instead
hosting_site_update_3 Move away from bitmasks for the status field.
hosting_site_update_4 Add verified timestamp to the site