diff --git a/db_server/hosting_db_server.service.inc b/db_server/hosting_db_server.service.inc index b61a73d..27c5e16 100644 --- a/db_server/hosting_db_server.service.inc +++ b/db_server/hosting_db_server.service.inc @@ -16,6 +16,7 @@ class hostingService_db extends hostingService { */ class hostingService_db_mysql extends hostingService_db { public $type = 'mysql'; + public $name = 'MySQL'; public $has_port = TRUE; function default_port() { diff --git a/dns/hosting_dns.service.inc b/dns/hosting_dns.service.inc index b72541c..0901dea 100644 --- a/dns/hosting_dns.service.inc +++ b/dns/hosting_dns.service.inc @@ -111,6 +111,7 @@ class hostingService_dns_master extends hostingService_dns { */ class hostingService_dns_dnsmasq extends hostingService_dns_master { public $type = 'dnsmasq'; + public $name = 'DNSMasq'; public $has_restart_cmd = TRUE; @@ -124,6 +125,7 @@ class hostingService_dns_dnsmasq extends hostingService_dns_master { */ class hostingService_dns_bind extends hostingService_dns_master { public $type = 'bind'; + public $name = 'Bind'; public $has_restart_cmd = TRUE; @@ -137,6 +139,7 @@ class hostingService_dns_bind extends hostingService_dns_master { */ class hostingService_dns_bind_slave extends hostingService_dns { public $type = 'bind_slave'; + public $name = 'Bind Slave'; public $has_restart_cmd = TRUE; diff --git a/example/example_service/hosting_example.service.inc b/example/example_service/hosting_example.service.inc index fc002e8..8930362 100644 --- a/example/example_service/hosting_example.service.inc +++ b/example/example_service/hosting_example.service.inc @@ -29,6 +29,10 @@ class hostingService_example_basic extends hostingService_example { */ public $type = 'basic'; + /** + * The name displayed to users when creating or editing a server. + */ + public $name = 'Basic'; /** * this service needs to have a port specified for it. diff --git a/server/hosting_server.module b/server/hosting_server.module index 79a99fa..03de895 100644 --- a/server/hosting_server.module +++ b/server/hosting_server.module @@ -397,11 +397,21 @@ function hosting_server_form($node, &$form_state) { '#title' => check_plain($service['title']), '#weight' => isset($service['weight']) ? $service['weight'] : 0, ); + // Check to ensure at least one service provider for each type exists. if (array_key_exists('types', $service)) { + + $options = array( + 'null' => t('None'), + ); + foreach ($service['types'] as $type => $class_name) { + $service_objects[$name][$type] = hosting_services_new_object($name, $type, $node); + $options[$type] = $service_objects[$name][$type]->getName(); + } + $form['services'][$name]['type'] = array( '#type' => 'radios', '#weight' => -99, - '#options' => array_merge(array('null' => 'None'), drupal_map_assoc(array_keys($service['types']))), + '#options' => $options, '#default_value' => isset($node->services[$name]->available) && $node->services[$name]->available ? $node->services[$name]->type : 'null', ); @@ -419,7 +429,7 @@ function hosting_server_form($node, &$form_state) { $node->services[$name]->form($form['services'][$name][$type]); } else { - $service_object = hosting_services_new_object($name, $type, $node); + $service_object = $service_objects[$name][$type]; $service_object->form($form['services'][$name][$type]); } } diff --git a/server/hosting_server.service.inc b/server/hosting_server.service.inc index 89c10f4..f63daac 100644 --- a/server/hosting_server.service.inc +++ b/server/hosting_server.service.inc @@ -7,6 +7,17 @@ class hostingService { public $server; + + // The service this class represents. ie 'http', 'db' + public $service = ''; + + // The service type for this class. ie 'mysql', 'apache' + public $type = ''; + + // The human readable name for this service type. ie 'MySQL', 'Apache' + public $name = ''; + + // Whether or not the service is available. public $available = 0; protected $has_restart_cmd = FALSE; @@ -17,6 +28,18 @@ class hostingService { self::setValues($values); } + /** + * Returns human readable name for this service. + */ + public function getName() { + if (empty($this->name)) { + return $this->type; + } + else { + return $this->name; + } + } + public function has_port() { return $this->has_port; } diff --git a/server/includes/views/handlers/hosting_server_handler_field_services.inc b/server/includes/views/handlers/hosting_server_handler_field_services.inc index 600547c..9527e90 100644 --- a/server/includes/views/handlers/hosting_server_handler_field_services.inc +++ b/server/includes/views/handlers/hosting_server_handler_field_services.inc @@ -46,7 +46,7 @@ class hosting_server_handler_field_services extends views_handler_field { $node = node_load($values->hosting_server_nid); foreach ($node->services as $type => $class) { - $types[$type] = $class->type; + $types[$type] = $class->getName(); } return implode(',', $types); } diff --git a/web_cluster/hosting_web_cluster.service.inc b/web_cluster/hosting_web_cluster.service.inc index d6dfbfa..f6ed625 100644 --- a/web_cluster/hosting_web_cluster.service.inc +++ b/web_cluster/hosting_web_cluster.service.inc @@ -8,6 +8,7 @@ module_load_include('service.inc', 'hosting_web_server'); class hostingService_http_cluster extends hostingService_http { public $type = 'cluster'; + public $name = 'Web Cluster'; function view(&$render) { $render['web_servers'] = array( diff --git a/web_pack/hosting_web_pack.service.inc b/web_pack/hosting_web_pack.service.inc index 28ae37e..989d21b 100644 --- a/web_pack/hosting_web_pack.service.inc +++ b/web_pack/hosting_web_pack.service.inc @@ -8,6 +8,7 @@ module_load_include('service.inc', 'hosting_web_server'); class hostingService_http_pack extends hostingService_http { public $type = 'pack'; + public $name = 'Web Pack'; function view(&$render) { $render['master_servers'] = array( diff --git a/web_server/hosting_web_server.service.inc b/web_server/hosting_web_server.service.inc index b9c5d5d..fed9889 100644 --- a/web_server/hosting_web_server.service.inc +++ b/web_server/hosting_web_server.service.inc @@ -28,6 +28,7 @@ class hostingService_http_public extends hostingService_http { class hostingService_http_apache extends hostingService_http_public { public $type = 'apache'; + public $name = 'Apache'; protected $has_restart_cmd = TRUE; diff --git a/web_server/nginx/hosting_nginx.service.inc b/web_server/nginx/hosting_nginx.service.inc index 6807970..50777d1 100644 --- a/web_server/nginx/hosting_nginx.service.inc +++ b/web_server/nginx/hosting_nginx.service.inc @@ -8,6 +8,7 @@ module_load_include('service.inc', 'hosting_web_server'); class hostingService_http_nginx extends hostingService_http_public { public $type = 'nginx'; + public $name = 'NGINX'; public $has_restart_cmd = TRUE; function default_restart_cmd() { diff --git a/web_server/nginx/ssl/hosting_nginx_ssl.service.inc b/web_server/nginx/ssl/hosting_nginx_ssl.service.inc index 442516c..885f089 100644 --- a/web_server/nginx/ssl/hosting_nginx_ssl.service.inc +++ b/web_server/nginx/ssl/hosting_nginx_ssl.service.inc @@ -9,6 +9,7 @@ module_load_include('service.inc', 'hosting_ssl'); class hostingService_http_nginx_ssl extends hostingService_http_ssl { public $type = 'nginx_ssl'; + public $name = 'NGINX SSL'; protected $has_restart_cmd = TRUE; function default_restart_cmd() { diff --git a/web_server/ssl/hosting_ssl.service.inc b/web_server/ssl/hosting_ssl.service.inc index b2cdd32..b8cda1c 100644 --- a/web_server/ssl/hosting_ssl.service.inc +++ b/web_server/ssl/hosting_ssl.service.inc @@ -83,7 +83,7 @@ class hostingService_http_ssl extends hostingService_http_public { class hostingService_http_apache_ssl extends hostingService_http_ssl { public $type = 'apache_ssl'; - + public $name = 'Apache SSL'; protected $has_restart_cmd = TRUE;