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

moveDir() public method

Move/rename a directory
public moveDir ( integer $dirID, string $url = '', integer $parent, string $cabin = '' ) : boolean
$dirID integer
$url string
$parent integer
$cabin string
return boolean
    public function moveDir(int $dirID, string $url = '', int $parent = 0, string $cabin = '') : bool
    {
        $this->db->beginTransaction();
        if ($parent > 0) {
            $collision = $this->db->exists('SELECT COUNT(directoryid) FROM airship_custom_dir WHERE parent = ? AND url = ? AND directoryid != ?', $parent, $url, $dirID);
        } else {
            $collision = $this->db->exists('SELECT COUNT(directoryid) FROM airship_custom_dir WHERE parent IS NULL AND url = ? AND directoryid != ?', $url, $dirID);
        }
        if ($collision) {
            // Sorry, but no.
            $this->db->rollBack();
            throw new CustomPageCollisionException(\trk('errors.pages.collision'));
        }
        $this->db->update('airship_custom_dir', ['url' => $url, 'cabin' => $cabin, 'parent' => $parent > 0 ? $parent : null], ['directoryid' => $dirID]);
        return $this->db->commit();
    }

Usage Example

Esempio n. 1
0
 /**
  * Move/rename a directory.
  *
  * @param array $dirInfo
  * @param array $post
  * @param string $oldCabin
  * @param array $cabins
  * @return bool
  */
 protected function processMoveDir(array $dirInfo, array $post = [], string $oldCabin = '', array $cabins = []) : bool
 {
     $targetID = (int) $dirInfo['directoryid'];
     if (\is_numeric($post['move_destination'])) {
         $destination = (int) $post['move_destination'];
         $newCabin = $this->pg->getCabinForDirectory($destination);
         $newPieces = $this->pg->getDirectoryPieces($destination);
         \array_pop($newPieces);
         $newPieces[] = Util::charWhitelist($post['url'], Util::NON_DIRECTORY);
         $newPath = \implode('/', $newPieces);
     } elseif (!\in_array($post['move_destination'], $cabins)) {
         // Cabin doesn't exist!
         return false;
     } else {
         $newCabin = $post['move_destination'];
         $newPath = Util::charWhitelist($post['url'], Util::NON_DIRECTORY);
     }
     if (!empty($post['create_redirect'])) {
         $old = ['cabin' => $oldCabin, 'path' => \implode('/', $this->pg->getDirectoryPieces($targetID))];
         $new = ['cabin' => $newCabin, 'path' => $newPath];
         $this->pg->createRedirectsForMove($old, $new);
     }
     return $this->pg->moveDir($targetID, $post['url'], $destination ?? 0, $newCabin);
 }