You are here

function hosting_platform_validate in Hostmaster (Aegir) 6

Implementation of hook_validate().

File

modules/hosting/platform/hosting_platform.module, line 320
Platform node type definition.

Code

function hosting_platform_validate($node, &$form) {

  // Make sure the platform name is unique, to avoid context clashes.
  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 n.title = '%s' AND n.nid <> %d AND h.status >= %d", $node->title, $node->nid, HOSTING_PLATFORM_QUEUED)))) {
    form_set_error('title', t('Platform name %name is already defined. Platform names must be unique across all servers.', array(
      '%name' => $result->name,
    )));
  }

  // Make sure the path is unique. Remote servers can't have the same path to a platform that is in use by another server.
  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 n.nid <> %d AND h.status >= %d", hosting_path_normalize($node->publish_path), $node->nid, HOSTING_PLATFORM_QUEUED)))) {
    form_set_error('publish_path', t('Path is already in use by platform %name. Platform paths must be unique across all servers.', array(
      '%name' => $result->name,
    )));
  }
}