You are here

hosting_platform.install in Hosting 6.2

Install, update and uninstall for the Platforms module.

File

platform/hosting_platform.install
View source
<?php

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

/**
 * Implementation of hook_schema().
 */
function hosting_platform_schema() {
  $schema['hosting_platform'] = 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,
      ),
      'publish_path' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'makefile' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'web_server' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'verified' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'make_working_copy' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'vid',
    ),
  );
  return $schema;
}

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

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

/**
 * Re-synch all platform to correctly set up the
 * master url, so redirects on disabled sites will
 * work correctly.
 */
function hosting_platform_update_1() {
  include_once drupal_get_path('module', 'hosting_task') . '/hosting_task.module';
  $ret = array();
  $result = db_query("SELECT nid FROM {node} WHERE type='platform' AND status=1");
  while ($platform = db_fetch_object($result)) {
    hosting_add_task($platform->nid, 'synch');
  }
  return $ret;
}

/**
 * no-op - this was replaced by hosting_update_6002()
 */
function hosting_platform_update_6000() {

  // this update was moved to hosting_update_6002()
  return array();
}

// Add a status field to platforms so we can Delete tasks on them
function hosting_platform_update_6001() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {hosting_platform} ADD COLUMN status int(11) NOT NULL default '1'");
  return $ret;
}

/**
 * Move the new menu item to the primary navigation
 */
function hosting_platform_update_6002() {
  $ret = array();
  install_include(array(
    'menu',
  ));
  $menu_name = variable_get('menu_primary_links_source', 'primary-links');
  $items = install_menu_get_items('hosting/platforms');
  $item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $items[0]['mlid']));
  $item['menu_name'] = $menu_name;
  $item['customized'] = 1;
  $item['options'] = unserialize($item['options']);
  install_menu_update_menu_item($item);
  hosting_menu_rebuild();
  return $ret;
}

/**
 * Add the 'makefile' column.
 */
function hosting_platform_update_6003() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {hosting_platform} ADD COLUMN makefile TEXT NOT NULL");
  return $ret;
}
function hosting_platform_update_6004() {
  if (!variable_get('hosting_platform_update_6004_run', false)) {
    $result = db_query("SELECT n.nid, n.title FROM {node} n LEFT JOIN {hosting_platform} p ON p.nid=n.nid WHERE p.status <> -2 AND n.type='platform'");
    while ($object = db_fetch_object($result)) {
      $records[$object->nid] = 'platform_' . preg_replace("/[!\\W]/", "", $object->title);
    }
    foreach ($records as $nid => $name) {
      hosting_context_register($nid, $name);
    }
    variable_set('hosting_platform_update_6004_run', true);
  }
}

/**
 * Add the 'make_working_copy' column.
 */
function hosting_platform_update_6205() {
  $ret = array();
  $spec = array(
    'make_working_copy' => array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ),
  );
  foreach ($spec as $field => $field_spec) {
    db_add_field($ret, 'hosting_platform', $field, $field_spec);
  }
  return $ret;
}

/**
 * Add new permission.
 */
function hosting_platform_update_6206() {
  $ret = array();

  // Temporarily enable Install Profile API module and load includes.
  module_enable(array(
    'install_profile_api',
  ));
  module_load_include('inc', 'install_profile_api', 'core/user');
  install_add_permissions(install_get_rid('aegir administrator'), array(
    'create sites on locked platforms',
  ));
  install_add_permissions(install_get_rid('aegir platform manager'), array(
    'create sites on locked platforms',
  ));
  module_disable(array(
    'install_profile_api',
  ));
  return $ret;
}

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

  // Enable Acstions 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 Platform: Delete (hosting_platform_op_delete)',
    'execute Platform: Lock (hosting_platform_op_lock)',
    'execute Platform: Unlock (hosting_platform_op_unlock)',
    'execute Platform: Verify (hosting_platform_op_verify)',
  ));
  install_add_permissions(install_get_rid('aegir platform manager'), array(
    'execute Platform: Delete (hosting_platform_op_delete)',
    'execute Platform: Lock (hosting_platform_op_lock)',
    'execute Platform: Unlock (hosting_platform_op_unlock)',
    'execute Platform: Verify (hosting_platform_op_verify)',
  ));
  module_disable(array(
    'install_profile_api',
  ));
  return $ret;
}

/**
 * Drop release_id from hosting_platform.
 */
function hosting_platform_update_6208() {
  $ret = array();
  if (db_column_exists('hosting_platform', 'release_id')) {
    db_drop_field($ret, 'hosting_platform', 'release_id');
  }
  return $ret;
}

/**
 * Add a list of platforms on the server node.
 *
 * https://drupal.org/node/2259511
 */
function hosting_platform_update_6209() {
  $ret = array();
  $theme = 'eldir';

  // 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',
  ));
  install_set_block('views', 'hosting_platform_list-block_server', $theme, 'content_bottom', 0, 1, 'hosting/c/server_*');
  module_disable(array(
    'install_profile_api',
  ));
  return $ret;
}

Functions

Namesort descending Description
hosting_platform_install Implementation of hook_install().
hosting_platform_schema Implementation of hook_schema().
hosting_platform_update_1 Re-synch all platform to correctly set up the master url, so redirects on disabled sites will work correctly.
hosting_platform_update_6000 no-op - this was replaced by hosting_update_6002()
hosting_platform_update_6001
hosting_platform_update_6002 Move the new menu item to the primary navigation
hosting_platform_update_6003 Add the 'makefile' column.
hosting_platform_update_6004
hosting_platform_update_6205 Add the 'make_working_copy' column.
hosting_platform_update_6206 Add new permission.
hosting_platform_update_6207 Add new Action permissions.
hosting_platform_update_6208 Drop release_id from hosting_platform.
hosting_platform_update_6209 Add a list of platforms on the server node.