public function createDirRedirect(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) {
$_old = ['cabin' => $old['cabin'], 'directory' => $page['directory'], 'url' => $page['url']];
$url = $page['url'];
$n = 1;
// Deduplication
do {
$_new = ['cabin' => $new['cabin'], 'directory' => $oldDir, 'url' => $url];
if ($n > self::MAX_DEDUP) {
// Don't let this go on forever.
$this->log('Create redirect -- too much recursion', LogLevel::DEBUG, ['new' => $_new]);
break;
}
++$n;
$url = $page['url'] . '-' . $n;
} while (!$this->createPageRedirect($_old, $_new, true));
}
foreach ($this->listSubDirectoriesByDirectoryID($oldDir) as $dir) {
$_old = $old;
$_new = $new;
$_old['path'] .= '/' . $dir['url'];
$_new['path'] .= '/' . $dir['url'];
$this->createDirRedirect($_old, $_new);
}
return true;
}