public function movePage(int $pageId, string $url = '', int $destinationDir = 0) : bool { $this->db->beginTransaction(); if ($destinationDir > 0) { $collision = $this->db->cell('SELECT COUNT(pageid) FROM airship_custom_page WHERE directory = ? AND url = ? AND pageid != ?', $destinationDir, $url, $pageId); } else { $collision = $this->db->cell('SELECT COUNT(pageid) FROM airship_custom_page WHERE directory IS NULL AND url = ? AND pageid != ?', $url, $pageId); } if ($collision > 0) { // Sorry, but no. throw new CustomPageCollisionException(\trk('errors.pages.collision')); } $this->db->update('airship_custom_page', ['url' => $url, 'directory' => $destinationDir > 0 ? $destinationDir : null], ['pageid' => $pageId]); return $this->db->commit(); }
/** * Move a page * * @param array $page * @param array $post * @param string $cabin * @param string $dir * @return bool */ protected function processMovePage(array $page, array $post, string $cabin, string $dir) : bool { if (\is_numeric($post['directory'])) { $post['cabin'] = $this->pg->getCabinForDirectory($post['directory']); } elseif (\is_string($post['directory'])) { // We're setting this to the root directory of a cabin $post['cabin'] = $post['directory']; $post['directory'] = 0; } else { // Invalid input. return false; } // Actually process the new page: if ($page['directory'] !== $post['directory'] || $page['cabin'] !== $post['cabin'] || $page['url'] !== $post['url']) { $this->pg->movePage((int) $page['pageid'], $post['url'], (int) $post['directory']); if (!empty($post['create_redirect'])) { $this->pg->createPageRedirect(\Airship\keySlice($page, ['cabin', 'directory', 'url']), \Airship\keySlice($post, ['cabin', 'directory', 'url'])); } \Airship\redirect($this->airship_cabin_prefix . '/pages/' . $cabin, ['dir' => $dir]); } return false; }