You are here

function redirect_change_status_multiple in Redirect 7

Same name and namespace in other branches
  1. 7.2 redirect.module \redirect_change_status_multiple()

Change the status of multiple URL redirects.

Parameters

array $rids: An array of redirect IDs to disable.

int|string $status: The status to set the redirect to: either disabled (0) or enabled (1).

Related topics

1 call to redirect_change_status_multiple()
redirect_disable_by_path in ./redirect.module
Disable any redirects associated with a path.
1 string reference to 'redirect_change_status_multiple'
redirect_redirect_operations in ./redirect.module
Implements hook_redirect_operations().

File

./redirect.module, line 1001

Code

function redirect_change_status_multiple(array $rids, $status) {
  if ($status !== 0 && $status !== 1 && $status !== '0' && $status !== '1') {
    watchdog('Cannot change redirect status to %status', array(
      '%status' => $status,
    ));
    drupal_set_message(t('Cannot change redirect status to %status', array(
      '%status' => $status,
    )));
    return;
  }
  if (!empty($rids)) {
    $redirects = redirect_load_multiple($rids, array(), TRUE);
    foreach ($redirects as $rid => $redirect) {
      if (isset($redirect->status) && $redirect->status == $status) {

        // We no-op if the redirect is not actually changing status.
        // So if a disabled redirect is disabled, neither redirect_save() is
        // triggered, nor do we log any message.
        continue;
      }
      $redirect->status = $status;
      redirect_save($redirect);
      if ($status) {
        $redirect_link = l($redirect->redirect, $redirect->redirect) . '=> ' . l($redirect->source, $redirect->source);
        watchdog('redirect', 'Enabled redirect: !redirect_link', array(
          '!redirect_link' => $redirect_link,
        ));
      }
      else {
        $redirect_link = l($redirect->redirect, $redirect->redirect) . '=> ' . l($redirect->source, $redirect->source);
        watchdog('redirect', 'Disabled redirect: !redirect_link', array(
          '!redirect_link' => $redirect_link,
        ));
      }
    }
  }
}