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

createDifferentCabinRedirect() public method

Create a redirect
public createDifferentCabinRedirect ( string $oldURL, string $newURL, string $cabin ) : boolean
$oldURL string
$newURL string
$cabin string
return boolean
    public function createDifferentCabinRedirect(string $oldURL, string $newURL, string $cabin) : bool
    {
        $this->db->beginTransaction();
        try {
            $this->db->insert('airship_custom_redirect', ['oldpath' => $oldURL, 'newpath' => $newURL, 'cabin' => $cabin, 'same_cabin' => false]);
        } catch (QueryError $e) {
            $this->db->rollBack();
            return false;
        }
        return $this->db->commit();
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Create a new redirect
  *
  * @param string $cabin
  * @route redirects/{string}/new
  */
 public function newRedirect(string $cabin)
 {
     $cabins = $this->getCabinNamespaces();
     if (!\in_array($cabin, $cabins) && !$this->can('create')) {
         \Airship\redirect($this->airship_cabin_prefix . '/redirects');
     }
     $this->setTemplateExtraData($cabin);
     $post = $this->post(new RedirectFilter());
     if ($post) {
         if (\Airship\all_keys_exist(['old_url', 'new_url'], $post)) {
             if (\preg_match('#^https?://#', $post['new_url'])) {
                 // Less restrictions:
                 $result = $this->pg->createDifferentCabinRedirect(\trim($post['old_url'], '/'), \trim($post['new_url'], '/'), $cabin);
             } else {
                 $result = $this->pg->createSameCabinRedirect(\trim($post['old_url'], '/'), \trim($post['new_url'], '/'), $cabin);
             }
             if ($result) {
                 \Airship\redirect($this->airship_cabin_prefix . '/redirects/' . $cabin);
             }
         }
     }
     $this->lens('redirect/new', ['cabin' => $cabin]);
 }