Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
aegir_backup_storage/hosting/hosting_backup_storage.module
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
183 lines (159 sloc)
5.79 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * $Id$ | |
| */ | |
| /** | |
| * Expose a type of service to the Service API. | |
| * | |
| * Return a new type of service (such as http, dns, db etc.) to | |
| * the service API. | |
| * | |
| * This information will be used to display the server node form, | |
| * allowing you to create services of this type. | |
| * | |
| * Just defining a service type without any implementations of it, | |
| * will automatically provide the "None" implementation. | |
| * | |
| * You will then need to create a new file in the same directory | |
| * as your module named "$module.service.inc, containing at | |
| * least a single class named "provisionService_$service", which | |
| * extends the base provisionService class. | |
| * | |
| * @return | |
| * an associative array with the index declaring the service | |
| * type, and containing another associative array of properties. | |
| * At present only the 'title' property is required for display | |
| * of the server node form. | |
| */ | |
| function hosting_backup_storage_hosting_service_type() { | |
| return array('backup_storage' => array('title' => t('Backup storage service'))); | |
| } | |
| /** | |
| * Expose a service implementation to the service API. | |
| * | |
| * Return a service implementation, such as the "apache" implementation | |
| * of the "http" service. | |
| * | |
| * You will then need to either extend the existing $module.service.inc | |
| * file, or create a new file, containing the implementation of your service. | |
| */ | |
| function hosting_backup_storage_hosting_service() { | |
| return array('s3' => 'backup_storage'); | |
| } | |
| /** | |
| * Implementation of hook_form_alter() | |
| */ | |
| function hosting_backup_storage_form_alter(&$form, $form_state, $form_id) { | |
| if ($form_id == 'site_node_form') { | |
| $node = $form['#node']; | |
| $configurable_locations = FALSE; | |
| if ($node->nid && !empty($node->backup_storage_server)) { | |
| $storage_server = node_load($node->backup_storage_server); | |
| if ($storage_server->services['backup_storage']->configurable_locations) { | |
| $configurable_locations = TRUE; | |
| } | |
| } | |
| _hosting_site_field($form, $node, 'backup_storage_server', array( | |
| '#type' => 'radios', | |
| '#title' => t('Backup storage server'), | |
| '#required' => TRUE, | |
| '#description' => t('The backup storage server the site will use.'), | |
| '#options' => array('' => t('None')) + hosting_get_servers('backup_storage'), | |
| '#default_value' => $node->backup_storage_server ? $node->backup_storage_server : '', | |
| ), '_hosting_node_link', !$node->nid || empty($node->backup_storage_server)); | |
| _hosting_site_field($form, $node, 'backup_storage_location_id', array( | |
| '#type' => 'radios', | |
| '#title' => t('Backup storage location'), | |
| '#description' => t("Choose a location to store backups in."), | |
| '#options' => hosting_backup_storage_get_locations(), | |
| '#required' => FALSE, | |
| '#default_value' => ($node->backup_storage_location_id) ? $node->backup_storage_location_id : '', | |
| //'#access' => user_access('administer ssl'), | |
| /*'#weight' => -8*/ | |
| ), 'filter_xss', $configurable_locations, !$node->nid); | |
| return $form; | |
| } | |
| } | |
| /** | |
| * Implementation of hook_nodeapi() | |
| */ | |
| function hosting_backup_storage_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { | |
| if ($node->type == 'site') { | |
| switch ($op) { | |
| case 'insert': | |
| hosting_backup_storage_insert($node); | |
| break; | |
| case 'update': | |
| hosting_backup_storage_update($node); | |
| break; | |
| case 'delete' : | |
| hosting_backup_storage_delete($node); | |
| break; | |
| case 'delete revision': | |
| hosting_backup_storage_delete_revision($node); | |
| break; | |
| case 'validate' : | |
| //if (!empty($node->http_basic_auth_username) && empty($node->http_basic_auth_password)) { | |
| // form_set_error('http_basic_auth_password', t('You must specify a password for the HTTP basic authentication.')); | |
| //} | |
| break; | |
| case 'load': | |
| $additions = db_fetch_array(db_query("SELECT backup_storage_server, location_id AS backup_storage_location_id FROM {hosting_site_backup_storage} WHERE vid = %d", $node->vid)); | |
| return $additions; | |
| break; | |
| } | |
| } | |
| } | |
| /** | |
| * Implementation of hook_insert() | |
| */ | |
| function hosting_backup_storage_insert($node) { | |
| db_query("INSERT INTO {hosting_site_backup_storage} (vid, nid, backup_storage_server, location_id) VALUES (%d, %d, '%s', '%s')", $node->vid, $node->nid, $node->backup_storage_server, $node->backup_storage_location_id); | |
| } | |
| /** | |
| * Implementation of hook_update() | |
| */ | |
| function hosting_backup_storage_update($node) { | |
| hosting_backup_storage_delete_revision($node); | |
| hosting_backup_storage_insert($node); | |
| } | |
| /** | |
| * Implementation of hook_delete() | |
| */ | |
| function hosting_backup_storage_delete($node) { | |
| db_query("DELETE FROM {hosting_site_backup_storage} WHERE nid=%d", $node->nid); | |
| } | |
| /** | |
| * Implementation of hook_delete_revision() | |
| */ | |
| function hosting_backup_storage_delete_revision($node) { | |
| db_query("DELETE FROM {hosting_site_backup_storage} WHERE vid=%d", $node->vid); | |
| } | |
| function hosting_backup_storage_get_locations($server = NULL) { | |
| $locations = array(); | |
| $query = "SELECT location_id, location_name FROM {hosting_backup_storage_s3}"; | |
| $args = array(); | |
| if (!empty($server)) { | |
| $query .= " WHERE nid = %d"; | |
| $args[] = $server; | |
| } | |
| $result = db_query($query, $args); | |
| while ($row = db_fetch_object($result)) { | |
| $locations[$row->location_id] = $row->location_name; | |
| } | |
| return $locations; | |
| } | |
| function hosting_backup_storage_hosting_site_options_alter(&$return, $node) { | |
| $return['backup_storage_location_id'] = FALSE; | |
| if ($node->backup_storage_server != 0) { | |
| $keys = hosting_backup_storage_get_locations($node->backup_storage_server); | |
| // return the list of valid keys | |
| $return['backup_storage_location_id'] = array_keys($keys); | |
| } | |
| } | |
| /** | |
| * Return a list of servers which have SSL enabled web services. | |
| */ | |
| function hosting_backup_storage_get_servers() { | |
| return hosting_get_servers('backup_storage'); | |
| } |