You are here

hosting_package.install in Hosting 5

File

package/hosting_package.install
View source
<?php

function hosting_package_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {hosting_package} (\n        vid int NOT NULL default '0',\n        nid int(10) unsigned NOT NULL default '0',\n        package_type varchar(16) NOT NULL default '',\n        short_name longtext NOT NULL default '',\n        description longtext NOT NULL default '',\n        PRIMARY KEY (vid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {hosting_package_instance} (\n        iid int NOT NULL DEFAULT '0',\n        rid int(11) NOT NULL default '0',\n        package_id int(11) NOT NULL default '0',\n        filename longtext NOT NULL DEFAULT '',\n        schema_version int(10) NOT NULL default '0',\n        version longtext NOT NULL default '',\n        status int(1) NOT NULL default '0',\n        PRIMARY KEY (iid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {hosting_package_languages} (\n        iid int NOT NULL,\n        language VARCHAR(12) NOT NULL DEFAULT ''\n      )  /*!40100 DEFAULT CHARACTER SET UTF8 */");
      break;
  }
}

/**
 * Add package description to hosting_package table
 */
function hosting_package_update_1() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {hosting_package} ADD COLUMN description longtext NOT NULL default ''");
  return $ret;
}

/**
 * Add localization support for installed sites
 */
function hosting_package_update_2() {
  $ret = array();
  $ret[] = update_sql("CREATE TABLE {hosting_package_languages} (\n    vid int NOT NULL,\n    nid int(10) UNSIGNED NOT NULL,\n    language VARCHAR(12) NOT NULL DEFAULT ''\n  )  /*!40100 DEFAULT CHARACTER SET UTF8 */");
  return $ret;
}

/**
 * No limit on short_name length 
 */
function hosting_package_update_3() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {hosting_package} MODIFY COLUMN short_name longtext NOT NULL default ''");
  return $ret;
}

/**
 * Package languages are associated to package instances, not packages
 */
function hosting_package_update_4() {
  include_once drupal_get_path('module', 'hosting_task') . '/hosting_task.module';
  $ret = array();
  $ret[] = update_sql("DROP TABLE {hosting_package_languages}");
  $ret[] = update_sql("CREATE TABLE {hosting_package_languages} (\n    iid int UNSIGNED NOT NULL,\n    language VARCHAR(12) NOT NULL DEFAULT ''\n  )  /*!40100 DEFAULT CHARACTER SET UTF8 */");

  // Re-verify all existing platforms
  $result = db_query("SELECT nid FROM {node} WHERE type='platform' AND status=1");
  while ($platform = db_fetch_object($result)) {
    hosting_add_task($platform->nid, 'verify');
  }
  return $ret;
}

/**
 * Denormalize package and package release node types
 */
function hosting_package_update_5() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {hosting_package_instance} ADD COLUMN package_id int(10) NOT NULL default '0'");
  $ret[] = update_sql("ALTER TABLE {hosting_package_instance} ADD COLUMN version longtext NOT NULL default ''");
  $ret[] = update_sql("ALTER TABLE {hosting_package_instance} ADD COLUMN filename longtext NOT NULL default ''");
  $ret[] = update_sql("ALTER TABLE {hosting_package_instance} ADD COLUMN schema_version int(10) NOT NULL default '0'");
  $ret[] = update_sql("ALTER TABLE {hosting_package_instance} ADD COLUMN status int(1) NOT NULL default '0'");

  // Now we replace the release ID of platform node types with instance types.
  // This needs to be done from the package module, even though it modifies the
  // hosting_platform table, so we can be _SURE_ that the order of execution is correct.
  $platforms = _hosting_get_platforms();
  foreach ($platforms as $nid => $name) {
    $platform = db_fetch_object(db_query("SELECT release_id FROM {hosting_platform} WHERE nid=%d", $nid));
    $release = db_fetch_object(db_query("SELECT * FROM {hosting_package_release} WHERE nid = %d", $platform->release_id));
    $instance = new stdClass();
    $instance->rid = $nid;
    $instance->package_id = $release->package;
    $instance->version = $release->version;

    // A future step will fill these in from the packages.
    $instance->filename = '';
    $instance->schema_version = 0;
    hosting_package_instance_save($instance);
    hosting_add_task($nid, 'verify');
  }
  $ret[] = update_sql("ALTER TABLE {hosting_platform} DROP COLUMN release_id");

  // Now we iterate through all the package
  $result = db_query("SELECT * FROM {hosting_package_release}");
  while ($release = db_fetch_object($result)) {
    db_query("UPDATE {hosting_package_instance} SET version='%s', schema_version=%d, package_id=%d WHERE release_id=%d", $release->version, $release->schema_version, $release->package, $release->nid);
  }
  $ret[] = update_sql("DELETE FROM {node_revisions} WHERE nid IN (SELECT nid FROM {node} WHERE type='package_release')");
  $ret[] = update_sql("DELETE FROM {node} WHERE type='package_release'");
  $ret[] = update_sql("ALTER TABLE {hosting_package_instance} DROP COLUMN release_id");
  $ret[] = update_sql("ALTER TABLE {hosting_package_instance} DROP COLUMN path");
  $ret[] = update_sql("DROP TABLE {hosting_package_release}");
  return $ret;
}

// Rebuild the package instance database and re-verify all sites.
function hosting_package_update_6() {
  $ret = array();
  $ret[] = update_sql("DELETE FROM {hosting_package_instance}");
  $ret[] = update_sql("UPDATE {sequences} SET id=1 WHERE name='{hosting_package_instance}_iid'");
  $result = db_query("SELECT nid FROM {node} WHERE type='platform' AND status=1");
  while ($platform = db_fetch_object($result)) {
    hosting_add_task($platform->nid, 'verify');
  }
  $result = db_query("SELECT nid FROM {node} WHERE type='site' AND status=1");
  while ($site = db_fetch_object($result)) {
    hosting_add_task($site->nid, 'verify');
  }
  return $ret;
}

Functions

Namesort descending Description
hosting_package_install
hosting_package_update_1 Add package description to hosting_package table
hosting_package_update_2 Add localization support for installed sites
hosting_package_update_3 No limit on short_name length
hosting_package_update_4 Package languages are associated to package instances, not packages
hosting_package_update_5 Denormalize package and package release node types
hosting_package_update_6