Airship\Cabin\Bridge\Blueprint\CustomPages::updateRedirect PHP Method

updateRedirect() public method

Save changes to a custom redirect
public updateRedirect ( integer $redirectID, array $post ) : boolean
$redirectID integer
$post array
return boolean
    public function updateRedirect(int $redirectID, array $post) : bool
    {
        $this->db->beginTransaction();
        $sameCabin = !\preg_match('#^https?://#', $post['new_url']);
        try {
            $this->db->update('airship_custom_redirect', ['oldpath' => $post['old_url'], 'newpath' => $post['new_url'], 'same_cabin' => !$sameCabin], ['redirectid' => $redirectID]);
        } catch (QueryError $e) {
            $this->db->rollBack();
            return false;
        }
        return $this->db->commit();
    }

Usage Example

Esempio n. 1
0
 /**
  * Edit a redirect.
  *
  * @param string $cabin
  * @param string $redirectId
  * @route redirects/{string}/edit/{id}
  */
 public function editRedirect(string $cabin, string $redirectId)
 {
     $cabins = $this->getCabinNamespaces();
     if (!\in_array($cabin, $cabins) && !$this->can('update')) {
         \Airship\redirect($this->airship_cabin_prefix . '/redirects');
     }
     $this->setTemplateExtraData($cabin);
     $post = $this->post(new RedirectFilter());
     $redirect = $this->pg->getRedirect($cabin, (int) $redirectId);
     if (empty($redirect)) {
         \Airship\redirect($this->airship_cabin_prefix . '/redirects/' . $cabin);
     }
     if ($post) {
         if (\Airship\all_keys_exist(['old_url', 'new_url'], $post)) {
             if ($this->pg->updateRedirect((int) $redirectId, $post)) {
                 \Airship\redirect($this->airship_cabin_prefix . '/redirects/' . $cabin);
             } else {
                 $this->storeLensVar('form_error', 'Could not update redirect. Check that it does not already exist.');
             }
         }
     }
     $this->lens('redirect/edit', ['cabin' => $cabin, 'redirect' => $redirect]);
 }