You are here

public static function Paths::checkAliasesExist in Hook Update Deploy Tools 7

Same name and namespace in other branches
  1. 8 src/Paths.php \HookUpdateDeployTools\Paths::checkAliasesExist()

Checks to see if the aliases exist in an alterable combination.

Parameters

object $alias: An alias object containing $alias->original and $alias->new.

Return value

bool TRUE if alterable combination.

Throws

HudtException If not an alterable combination.

1 call to Paths::checkAliasesExist()
Paths::modifyAlias in src/Paths.php
Change the value of an alias.

File

src/Paths.php, line 133

Class

Paths
Public methods for altering aliases.

Namespace

HookUpdateDeployTools

Code

public static function checkAliasesExist($alias) {
  $variables = array(
    '!original_alias' => $alias->original->alias,
    '!new_alias' => $alias->new->alias,
  );
  if (empty($alias->original->source) && empty($alias->new->source)) {

    // The original alias does not exist.
    $message = "Alias '!original_alias' does not exist so could not be altered, and '!new_alias' does not already exist.  Adjust your update hook and try again.";
    Message::make($message, $variables, WATCHDOG_ERROR);
    throw new HudtException($message, $variables, WATCHDOG_ERROR, FALSE);
  }
  elseif (empty($alias->original->source) && !empty($alias->new->source)) {

    // The original alias does not exist and the new one does.  Make the
    // assumption that the change has already been made, so warn, but don't
    // fail the update.
    $message = "'!new_alias' already exists and '!original_alias' does not.  Assuming this change has already been made.";
    $return = Message::make($message, $variables, WATCHDOG_INFO);
    $return = FALSE;
  }
  elseif (!empty($alias->original->source) && !empty($alias->new->source)) {

    // The new alias is already in use, so can not be reassigned.
    // Fail the update.
    $message = "'!new_alias' already exists and '!original_alias' does too.  The pre-existance of the new alias blocks the change.";
    Message::make($message, $variables, WATCHDOG_ERROR);
    throw new HudtException($message, $variables, WATCHDOG_ERROR, FALSE);
  }
  else {

    // This is the case where original alias is not empty and the new alias
    // is empty.  Good to go.
    $return = TRUE;
  }
  return $return;
}