hosting_platform.install in Hosting 7.4
Same filename and directory in other branches
Define database schema and update functions for the Platforms module.
File
platform/hosting_platform.installView source
<?php
/**
* @file
* Define database schema and update functions for the Platforms module.
*/
/**
* Implements 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,
),
'git_remote' => array(
'description' => 'The URL or path of the git repository to use when creating this platform.',
'type' => 'varchar',
'length' => 255,
'default' => NULL,
),
'git_reference' => array(
'description' => 'The desired git reference. Can be a branch, tag or SHA. Defaults to the git repository default branch.',
'type' => 'varchar',
'length' => 255,
'default' => NULL,
),
'git_reset' => array(
'description' => 'Reset any changes to this platform when verifying.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 1,
),
'git_root' => array(
'description' => 'The full path on the server to clone the git repository to.',
'type' => 'varchar',
'length' => 255,
'default' => NULL,
),
'git_docroot' => array(
'description' => 'The relative path within the git repository to publish to the web.',
'type' => 'varchar',
'length' => 255,
'default' => NULL,
),
'publish_path' => array(
'type' => 'text',
'size' => 'big',
),
'makefile' => array(
'type' => 'text',
'size' => 'big',
),
'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;
}
/**
* Implements hook_update_N().
*
* 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;
}
/**
* Implements hook_update_N().
*
* no-op - this was replaced by hosting_update_6002()
*/
function hosting_platform_update_6000() {
// this update was moved to hosting_update_6002()
return array();
}
/*
* Implements hook_update_N().
*
* 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;
}
/**
* Implements hook_update_N().
*
* 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);
menu_rebuild();
return $ret;
}
/**
* Implements hook_update_N().
*
* 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;
}
/*
* Implements hook_update_N().
*
* TODO: Document this update.
*/
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);
}
}
/**
* Implements hook_update_N().
*
* 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;
}
/**
* Create new columns for git properties.
*/
function hosting_platform_update_7400() {
$spec = array(
'git_remote' => array(
'description' => 'The URL or path of the git repository to use when creating this platform.',
'type' => 'varchar',
'length' => 255,
'default' => NULL,
),
'git_reference' => array(
'description' => 'The desired git reference. Can be a branch, tag or SHA. Defaults to the git repository default branch.',
'type' => 'varchar',
'length' => 255,
'default' => NULL,
),
'git_reset' => array(
'description' => 'Reset any changes to this platform when verifying.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 1,
),
'git_root' => array(
'description' => 'The full path on the server to clone the git repository to.',
'type' => 'varchar',
'length' => 255,
'default' => NULL,
),
'git_docroot' => array(
'description' => 'The relative path within the git repository to publish to the web.',
'type' => 'varchar',
'length' => 255,
'default' => NULL,
),
);
foreach ($spec as $field => $field_spec) {
db_add_field('hosting_platform', $field, $field_spec);
}
}
/**
* Migrate data from hosting_git for each platform.
*/
function hosting_platform_update_7401() {
$platforms = db_query('SELECT * FROM {hosting_git} g INNER JOIN {hosting_platform} p ON p.nid = g.nid');
foreach ($platforms as $platform) {
db_merge('hosting_platform')
->key(array(
'nid' => $platform->nid,
))
->fields(array(
'git_remote' => $platform->repo_url,
'git_reference' => $platform->git_ref,
'git_root' => $platform->repo_path,
'git_docroot' => $platform->repo_docroot,
))
->execute();
}
}
Functions
Name | Description |
---|---|
hosting_platform_schema | Implements hook_schema(). |
hosting_platform_update_1 | Implements hook_update_N(). |
hosting_platform_update_6000 | Implements hook_update_N(). |
hosting_platform_update_6001 | |
hosting_platform_update_6002 | Implements hook_update_N(). |
hosting_platform_update_6003 | Implements hook_update_N(). |
hosting_platform_update_6004 | |
hosting_platform_update_6205 | Implements hook_update_N(). |
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_7400 | Create new columns for git properties. |
hosting_platform_update_7401 | Migrate data from hosting_git for each platform. |