You are here

private static function Paths::changeAlias in Hook Update Deploy Tools 8

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

Assuming all alias prechecks have passed, this method makes the save.

Parameters

object $alias: The alias object for passing around

Throws

HudtException Calls the update a failure, preventing it from registering the update_N.

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

File

src/Paths.php, line 63

Class

Paths
Public methods for altering aliases.

Namespace

HookUpdateDeployTools

Code

private static function changeAlias($alias) {
  $alias->original->path = _pathauto_existing_alias_data($alias->original->source, $alias->original->language);
  $variables = array(
    '!new_alias' => $alias->new->alias,
    '!old_alias' => $alias->original->alias,
  );
  if (!empty($alias->original->path)) {

    // Clone the current path array to make changes.
    $alias->new->path = $alias->original->path;

    // Clean the new alias and assign.
    $alias->new->path['alias'] = $alias->new->alias;
  }
  else {

    // Original alias could not be loaded.  Blame language.
    $message = "The original alias of could not be loaded.  This is most likely due to specifying the wrong language in the call to modifyAlias. Adjust your update hook and try again.";
    Message::make($message, $variables, WATCHDOG_ERROR);
    throw new HudtException($message, $variables, WATCHDOG_ERROR, FALSE);
  }

  // Make the changes.
  $saved_alias = _pathauto_set_alias($alias->new->path, $alias->original->path);

  // Was it successful?
  if (!empty($saved_alias)) {

    // It saved, set the success message.
    $message = "'!new_alias' has been set as the new alias for what used to be '!old_alias'.";
    $return = Message::make($message, $variables, WATCHDOG_INFO);
  }
  else {

    // For some reason the save failed.  Reason unknown.
    $message = "Alias save of '!new_alias' was not successful in replacing '!old_alias'. Sorry, unable to say why. Adjust your update hook and try again.";
    Message::make($message, $variables, WATCHDOG_ERROR);
    throw new HudtException($message, $variables, WATCHDOG_ERROR, FALSE);
  }
  return $return;
}