You are here

public static function Paths::modifyAlias in Hook Update Deploy Tools 8

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

Change the value of an alias.

Parameters

string $original_alias: The old alias.

string $new_alias: The new alias you are changing to.

string $language: The language of the entity being modified.

Return value

string Messsage indicating success. Failure messages come from Watchdog.

Throws

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

File

src/Paths.php, line 25

Class

Paths
Public methods for altering aliases.

Namespace

HookUpdateDeployTools

Code

public static function modifyAlias($original_alias, $new_alias, $language) {
  try {
    $return = self::checkSame($original_alias, $new_alias);
    if (empty($return)) {

      // They are not the same. Proceed.
      $alias = self::getAliasObject($original_alias, $new_alias, $language);
      if (self::checkAliasesExist($alias)) {

        // Made it this far without exception, clear for change.
        $return = self::changeAlias($alias);
      }
    }
    return $return;
  } catch (\Exception $e) {
    $vars = array(
      '!error' => method_exists($e, 'logMessage') ? $e
        ->logMessage() : $e
        ->getMessage(),
      '@file' => $e
        ->getFile(),
      '@line' => $e
        ->getLine(),
    );
    if (!method_exists($e, 'logMessage')) {

      // Not logged yet, so log it.
      $message = 'Paths::modifyAlias failed in "@file" on line @line.  Message: !error';
      Message::make($message, $vars, WATCHDOG_ERROR);
    }
    throw new HudtException('Caught Exception: Update aborted!  !error', $vars, WATCHDOG_ERROR);
  }
}