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

movePagesToDir() public method

public movePagesToDir ( integer $parent, integer $destinationDir, boolean $createRedirect = false, string $oldCabin = '', string $newCabin = '', array $pieces = [] ) : boolean
$parent integer
$destinationDir integer
$createRedirect boolean
$oldCabin string
$newCabin string
$pieces array
return boolean
    public function movePagesToDir(int $parent, int $destinationDir = 0, bool $createRedirect = false, string $oldCabin = '', string $newCabin = '', array $pieces = []) : bool
    {
        $this->log('Moving pages to a new directroy', LogLevel::DEBUG, ['from' => $parent, 'to' => $destinationDir, 'redirect' => $createRedirect, 'oldCabin' => $oldCabin, 'newCabin' => $newCabin, 'pieces' => $pieces]);
        $old = ['cabin' => $oldCabin, 'path' => \implode('/', $this->getDirectoryPieces($parent))];
        $new = ['cabin' => $newCabin, 'path' => \implode('/', $pieces)];
        if ($createRedirect) {
            $this->createDirRedirect($old, $new);
        }
        foreach ($this->listCustomPagesByDirectoryID($parent) as $page) {
            $this->movePage((int) $page['pageid'], $page['url'], $destinationDir);
        }
        $this->db->beginTransaction();
        if ($destinationDir > 0) {
            $update = ['parent' => null, 'cabin' => $newCabin];
        } else {
            $update = ['parent' => $destinationDir];
        }
        $this->db->update('airship_custom_dir', $update, ['parent' => $parent]);
        return $this->db->commit();
    }

Usage Example

Example #1
0
 /**
  * @param int $targetID
  * @param array $post
  * @param string $oldCabin
  * @param array $cabins
  * @return bool
  */
 protected function processDeleteDir(int $targetID, array $post = [], string $oldCabin = '', array $cabins = []) : bool
 {
     if (empty($post['move_contents'])) {
         // Delete everything
         return $this->pg->recursiveDelete($targetID);
     }
     // We're moving the contents
     if (\is_numeric($post['move_destination'])) {
         // To a different directory...
         $destination = (int) $post['move_destination'];
         $newCabin = $this->pg->getCabinForDirectory($destination);
         $this->pg->movePagesToDir($targetID, $destination, !empty($post['create_redirect']), $oldCabin, $newCabin, $this->pg->getDirectoryPieces($destination));
     } else {
         if (!\in_array($post['move_destination'], $cabins)) {
             // Cabin doesn't exist!
             return false;
         }
         // To the root directory of a different cabin...
         // To a different directory...
         $this->pg->movePagesToDir($targetID, 0, !empty($post['create_redirect']), $oldCabin, $post['move_destination']);
     }
     return $this->pg->deleteDir($targetID);
 }