You are here

function hosting_platform_validate in Hosting 7.4

Same name and namespace in other branches
  1. 5 platform/hosting_platform.module \hosting_platform_validate()
  2. 6.2 platform/hosting_platform.module \hosting_platform_validate()
  3. 7.3 platform/hosting_platform.module \hosting_platform_validate()

Implements hook_validate().

File

platform/hosting_platform.module, line 664
Platform node type definition.

Code

function hosting_platform_validate($node, &$form) {
  if ($node->op != t('Delete')) {

    // Make sure the platform name is unique, to avoid context clashes.
    $sql = "SELECT n.title as name\n              FROM {hosting_platform} h\n        INNER JOIN {node} n ON n.nid = h.nid\n             WHERE n.title = :title\n               AND h.status >= :status";
    $args = array(
      ':title' => $node->title,
      ':status' => HOSTING_PLATFORM_QUEUED,
    );
    if (!is_null($node->nid)) {
      $sql .= " AND n.nid <> :nid";
      $args[':nid'] = $node->nid;
    }
    $result = db_query($sql, $args)
      ->fetch();
    if ($result) {
      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.
    $exists = hosting_platform_path_exists($node->publish_path);
    if ($exists) {
      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,
      )));
    }

    // Make sure the git_root is unique. Can't clone two repos to the same folder.
    $exists = hosting_platform_path_exists($node->git_root);
    if ($exists) {
      form_set_error('git_root', t('Path is already in use by the platform %name. Platform paths must be unique across all servers.', array(
        '%name' => l($result->name, "node/{$result->name}/nid"),
      )));
    }
    if (is_null($node->web_server)) {
      form_set_error('web_server', t('Platform needs to be associated with a webserver. Make sure you have a verified webserver on this Aegir install!'));
    }
  }
}