diff --git a/migrate/hosting_migrate.module b/migrate/hosting_migrate.module index 17f99f2..579fed7 100755 --- a/migrate/hosting_migrate.module +++ b/migrate/hosting_migrate.module @@ -90,7 +90,7 @@ function hosting_task_migrate_form($node) { $packages = array(); $profile_platform_instances = hosting_package_instances_load( - array('r.type' => 'platform', 'n.nid' => $node->profile)); + array('r.type' => 'platform', 'n.nid' => $node->profile, 'h.status' => '1')); if (sizeof($profile_platform_instances) <= 1) { $form['no_targets'] = array( '#value' => t('
There are no platforms that can meet the dependencies for this site
')); diff --git a/package/hosting_package.instance.inc b/package/hosting_package.instance.inc index fcf3d35..7720b16 100644 --- a/package/hosting_package.instance.inc +++ b/package/hosting_package.instance.inc @@ -123,6 +123,7 @@ function _hosting_package_instances_load($param, $multiple = FALSE) { LEFT JOIN {hosting_package} p ON p.nid=i.package_id LEFT JOIN {node} n ON p.nid=n.nid LEFT JOIN {node} r ON r.nid=i.rid + LEFT JOIN {hosting_platform} h ON r.nid=h.nid WHERE " . $cond, $arguments); while ($instance = db_fetch_object($result)) { diff --git a/platform/hosting_platform.drush.inc b/platform/hosting_platform.drush.inc index bb11e8a..38506d8 100644 --- a/platform/hosting_platform.drush.inc +++ b/platform/hosting_platform.drush.inc @@ -31,6 +31,7 @@ function hosting_platform_post_hosting_verify_task($task, $data) { $packages = $context['packages']; $node->verified = mktime(); // set verified flag on platform, to let it know it has been checked. + $node->platform_status = HOSTING_PLATFORM_ENABLED; // Save the platform being verified node_save($node); @@ -65,3 +66,24 @@ function hosting_platform_post_hosting_verify_task($task, $data) { } } +/** + * implementation of hook_hosting_post_DELETE + */ +function hosting_platform_post_hosting_delete_task($task, $data) { + $task->ref->platform_status = HOSTING_PLATFORM_DELETED; + $task->ref->no_verify = TRUE; + node_save($task->ref); +} + +function hosting_platform_post_hosting_lock_task($task, $data) { + $task->ref->platform_status = HOSTING_PLATFORM_LOCKED; + $task->ref->no_verify = TRUE; + node_save($task->ref); +} + +function hosting_platform_post_hosting_unlock_task($task, $data) { + $task->ref->platform_status = HOSTING_PLATFORM_ENABLED; + $task->ref->no_verify = TRUE; + node_save($task->ref); +} + diff --git a/platform/hosting_platform.install b/platform/hosting_platform.install index 8edf049..407880b 100644 --- a/platform/hosting_platform.install +++ b/platform/hosting_platform.install @@ -40,6 +40,12 @@ function hosting_platform_schema() { 'not null' => TRUE, 'default' => 0, ), + 'status' => array( + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), ), 'primary key' => array('vid'), ); @@ -76,3 +82,18 @@ 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; +} + +// Add a status field to platforms so we can Delete tasks on them +function hosting_platform_update_6002() { + $ret = array(); + $ret[] = update_sql("ALTER TABLE {hosting_platform} ADD COLUMN status int(11) NOT NULL default '1'"); + return $ret; +} + diff --git a/platform/hosting_platform.module b/platform/hosting_platform.module index 51e3aa0..837745e 100644 --- a/platform/hosting_platform.module +++ b/platform/hosting_platform.module @@ -1,4 +1,10 @@ t('Verify'), 'description' => t('Verify that the platform is correctly installed and working.'), + 'weight' => 10, + ); + $tasks['platform']['delete'] = array( + 'title' => t('Delete'), + 'description' => t('Deleting this platform will completely remove it from the hosting system. + This process can not be undone. It can not be performed if you have sites currently + running on this platform. + Are you really sure you want to delete this platform?'), + 'weight' => 10, + ); + $tasks['platform']['lock'] = array( + 'title' => t('Lock'), + 'description' => t('Locking this platform will not delete or disable it or its sites, but will + prevent any new sites from being created on it. This may be useful when you have sites that + cannot be migrated onto a newer platform, but you wish to prevent other administrators or + clients from continuing to provision on this platform. The platform can be unlocked later. + Are you really sure you want to lock this platform?'), + 'weight' => 10, + ); + $tasks['platform']['unlock'] = array( + 'title' => t('Unlock'), + 'description' => t('Unlocking this platform will allow sites to be provisioned on it. + Are you really sure you want to unlock this platform?'), + 'weight' => 10, ); - return $tasks; } @@ -45,7 +73,7 @@ function hosting_platform_hosting_feature() { * Implementation of hook_perm() */ function hosting_platform_perm() { - return array('create platform', 'view platform', 'edit platform', 'delete platform'); + return array('create platform', 'view platform', 'edit platform', 'delete platform', 'lock platform', 'unlock platform', 'view locked platforms'); } /** @@ -66,15 +94,45 @@ function hosting_platform_access($op, $node, $account) { case 'delete': return user_access('delete platform', $account); break; - } + case 'lock': + return user_access('lock platform', $account); + break; + case 'unlock': + return user_access('unlock platform', $account); + break; + } } /** - * Small helper function to get platforms. + * Small helper function to get platforms that haven't been deleted. */ function _hosting_get_platforms() { $return = array(); - $result = db_query("SELECT nid, title FROM {node} WHERE type='platform' AND status=1"); + $result = db_query("SELECT n.nid, n.title FROM {node} n LEFT JOIN {hosting_platform} h ON n.nid = h.nid WHERE n.type='platform' AND n.status=1 AND h.status <> '%d'", HOSTING_PLATFORM_DELETED); + while($server = db_fetch_object($result)) { + $return[$server->nid] = $server->title; + } + return $return; +} + +/** + * Small helper function to get platforms that haven't been deleted or locked. +*/ +function _hosting_get_enabled_platforms() { + $return = array(); + $result = db_query("SELECT n.nid, n.title FROM {node} n LEFT JOIN {hosting_platform} h ON n.nid = h.nid WHERE n.type='platform' AND n.status=1 AND h.status > '%d'", HOSTING_PLATFORM_LOCKED); + while($server = db_fetch_object($result)) { + $return[$server->nid] = $server->title; + } + return $return; +} + +/** + * Small helper function to get platforms that have been locked. +*/ +function _hosting_get_locked_platforms() { + $return = array(); + $result = db_query("SELECT n.nid, n.title FROM {node} n LEFT JOIN {hosting_platform} h ON n.nid = h.nid WHERE n.type='platform' AND n.status=1 AND h.status = '%d'", HOSTING_PLATFORM_LOCKED); while($server = db_fetch_object($result)) { $return[$server->nid] = $server->title; } @@ -136,6 +194,19 @@ function hosting_platform_form(&$node) { } /** + * Hide the delete button on platform nodes + */ +function hosting_platform_form_alter(&$form, &$form_state, $form_id) { + // Remove delete button from platform edit form, unless the platform's already been deleted via the Delete task + if ($form_id == 'platform_node_form') { + $node = $form['#node']; + if ($node->platform_status !== '-2') { + $form['buttons']['delete']['#type'] = 'hidden'; + } + } +} + +/** * Implementation of hook_insert(). */ function hosting_platform_insert($node) { @@ -145,8 +216,8 @@ function hosting_platform_insert($node) { if (!isset($node->no_verify)) { hosting_add_task($node->nid, 'verify'); } - db_query("INSERT INTO {hosting_platform} (vid, nid, publish_path, verified, web_server) VALUES (%d, %d, '%s', %d, %d)", - $node->vid, $node->nid, hosting_path_normalize($node->publish_path), $node->verified, $node->web_server); + db_query("INSERT INTO {hosting_platform} (vid, nid, publish_path, verified, web_server, status) VALUES (%d, %d, '%s', %d, %d, %d)", + $node->vid, $node->nid, $node->publish_path, $node->verified, $node->web_server, $node->platform_status); } /** @@ -164,8 +235,8 @@ function hosting_platform_update($node) { if ($node->default_platform == 1) { variable_set('hosting_default_platform', $node->nid); } - db_query("UPDATE {hosting_platform} SET publish_path = '%s', web_server = %d, verified = %d WHERE nid=%d", - hosting_path_normalize($node->publish_path), $node->web_server, $node->verified, $node->nid); + db_query("UPDATE {hosting_platform} SET publish_path = '%s', web_server = %d, verified = %d, status= %d WHERE nid=%d", + $node->publish_path, $node->web_server, $node->verified, $node->platform_status, $node->nid); } } @@ -196,7 +267,7 @@ function hosting_platform_delete($node) { * Implementation of hook_validate() */ function hosting_platform_validate($node, &$form) { - if ($node->op != t('Delete') && $result = db_fetch_object(db_query("SELECT n.title AS name FROM {hosting_platform} AS h INNER JOIN {node} AS n ON n.nid = h.nid WHERE publish_path = '%s' AND web_server = %d AND n.nid <> %d", hosting_path_normalize($node->publish_path), $node->web_server, $node->nid))) { + if ($node->op != t('Delete') && $result = db_fetch_object(db_query("SELECT n.title AS name FROM {hosting_platform} AS h INNER JOIN {node} AS n ON n.nid = h.nid WHERE publish_path = '%s' AND web_server = %d AND n.nid <> %d AND h.status >= %d", hosting_path_normalize($node->publish_path), $node->web_server, $node->nid, HOSTING_PLATFORM_QUEUED))) { form_set_error('publish_path', t('Path already defined in platform %name', array('%name' => $result->name))); } } @@ -205,7 +276,7 @@ function hosting_platform_validate($node, &$form) { * Implementation of hook_load(). */ function hosting_platform_load($node) { - $additions = db_fetch_object(db_query('SELECT publish_path, verified, web_server FROM {hosting_platform} WHERE vid = %d', $node->vid)); + $additions = db_fetch_object(db_query('SELECT publish_path, verified, web_server, status AS platform_status FROM {hosting_platform} WHERE vid = %d', $node->vid)); $iid = db_result(db_query("SELECT iid FROM {hosting_package_instance} i left join {hosting_package} p on p.nid=i.package_id WHERE p.package_type='platform' AND i.rid=%d", $node->nid)); $additions->release = hosting_package_instance_load($iid); return $additions; @@ -243,6 +314,11 @@ function hosting_platform_view($node, $teaser = FALSE, $page = FALSE) { '#value' => _hosting_node_link($node->web_server), '#weight' => -7 ); + $node->content['info']['status'] = array( + '#type' => 'item', + '#title' => t('Status'), + '#value' => _hosting_platform_status($node), + ); if ($node->release) { $release = sprintf("%s %s", $node->release->title, $node->release->version); @@ -290,12 +366,27 @@ function hosting_platform_view($node, $teaser = FALSE, $page = FALSE) { return $node; } +function _hosting_platform_status($node) { + static $labels = array( + HOSTING_PLATFORM_QUEUED => "Queued", + HOSTING_PLATFORM_ENABLED => "Enabled", + HOSTING_PLATFORM_DELETED => "Deleted", + HOSTING_PLATFORM_LOCKED => "Locked", + ); + return $labels[$node->platform_status]; +} + /** * Implementation of hook_hosting_summary() */ function hosting_platform_hosting_summary() { $summary = array(); - $platforms = _hosting_get_platforms(); + if (user_access('view locked platforms', $account)) { + $platforms = _hosting_get_platforms(); + } + else { + $platforms = _hosting_get_enabled_platforms(); + } $summary['platforms'] = theme('item_list', array_map('_hosting_node_link', array_keys($platforms)), t('Platforms')); return $summary; } diff --git a/site/hosting_site.module b/site/hosting_site.module index 8eb68dd..ee14078 100644 --- a/site/hosting_site.module +++ b/site/hosting_site.module @@ -306,23 +306,28 @@ function hosting_site_form($node) { } if (!$node->nid) { - $platforms = _hosting_get_platforms(); - if (sizeof($platforms) > 1) { - $form['platform'] = array( - '#type' => 'radios', - '#title' => t('Platform'), - '#required' => TRUE, - '#description' => t('The platform you want the site to be hosted on.'), - '#options' => $platforms, - '#default_value' => HOSTING_DEFAULT_PLATFORM, - ); + $platforms = _hosting_get_enabled_platforms(); + if (sizeof($platforms)) { + if (sizeof($platforms) > 1) { + $form['platform'] = array( + '#type' => 'radios', + '#title' => t('Platform'), + '#required' => TRUE, + '#description' => t('The platform you want the site to be hosted on.'), + '#options' => $platforms, + '#default_value' => HOSTING_DEFAULT_PLATFORM, + ); + } + else { + $form['platform'] = array('#type' => 'hidden', '#value' => key($platforms)); + } + $form['port'] = _hosting_site_form_port(); + $form['profile'] = _hosting_site_form_profile(); + $form['site_language'] = _hosting_site_form_site_language(); } else { - $form['platform'] = array('#type' => 'hidden', '#value' => key($platforms)); + drupal_set_message(t('You have no enabled platforms! Please add or unlock a platform before attempting to create a site.'), 'error'); } - $form['port'] = _hosting_site_form_port(); - $form['profile'] = _hosting_site_form_profile(); - $form['site_language'] = _hosting_site_form_site_language(); } else { $form['info']['platform'] = array( @@ -379,7 +384,6 @@ function hosting_site_form($node) { foreach(array('verified', 'last_cron', 'site_status') as $extra_attribute) { $form["$extra_attribute"] = array('#type' => 'value', '#value' => $node->$extra_attribute); } - return $form; } @@ -780,7 +784,7 @@ function hosting_site_list($filter_by = null, $filter_value = null) { array('data' => t('Language'), 'field' => 'site_language'), array('data' => t('Created'), 'field' => 'created', 'sort' => 'desc'), ); - $platforms = _hosting_get_platforms(); + $platforms = _hosting_get_enabled_platforms(); if (sizeof($platforms) > 1) { $header[] = array('data' => t('Platform'), 'field' => 'platform'); } diff --git a/task/hosting_task.module b/task/hosting_task.module index 8e1aaf7..d935cde 100644 --- a/task/hosting_task.module +++ b/task/hosting_task.module @@ -88,6 +88,21 @@ function hosting_task_menu_access($node, $task) { $on_delete_task = ($task == 'enable' || $task == 'delete'); $site_enabled = (hosting_task_outstanding($node->nid, 'enable') || ($node->site_status == HOSTING_SITE_ENABLED)); return (!$site_enabled && $on_delete_task) || ($site_enabled && !$on_delete_task); + } + if ($node->type == 'platform') { + // If the platform is in a deleted state, nothing else can be done with it + if (hosting_task_outstanding($node->nid, 'delete') || ($node->platform_status == HOSTING_PLATFORM_DELETED)) { + return FALSE; + } + // If the platform's been locked, we can unlock it, delete, batch migrate existing sites or verify + if ($node->platform_status == HOSTING_PLATFORM_LOCKED) { + $platform_tasks = array('verify', 'unlock', 'delete', 'migrate'); + } + else { + // If the platform's unlocked, we can lock it, delete it or batch migrate sites + $platform_tasks = array('verify', 'lock', 'delete', 'migrate'); + } + return (in_array($task, $platform_tasks)); } else { return true; }