Airship\Cabin\Bridge\Blueprint\CustomPages::createRedirectsForMove PHP Méthode

createRedirectsForMove() public méthode

Create the redirects necessary for a directory being moved.
public createRedirectsForMove ( array $old, array $new ) : boolean
$old array
$new array
Résultat boolean
    public function createRedirectsForMove(array $old, array $new) : bool
    {
        $this->log('Creating directory redirects', LogLevel::DEBUG, ['old' => $old, 'new' => $new]);
        $oldDir = !empty($old['path']) ? $this->getParentDirFromStr($old['path'], $old['cabin']) : null;
        foreach ($this->listCustomPagesByDirectoryID($oldDir) as $page) {
            $oldPath = \explode('/', $old['path']);
            $oldPath[] = $page['url'];
            if ($old['cabin'] == $new['cabin']) {
                $this->createSameCabinRedirect(\implode('/', $oldPath), $new['path'] . '/' . $page['url'], $old['cabin']);
            }
        }
        $children = $this->listSubDirectoriesByDirectoryID($oldDir);
        foreach ($children as $dir) {
            $_old = $old;
            $_new = $new;
            $_old['path'] .= '/' . $dir['url'];
            $_new['path'] .= '/' . $dir['url'];
            $this->createRedirectsForMove($_old, $_new);
        }
        return true;
    }

Usage Example

Exemple #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);
 }