Fixed fatal error when moving a page using the old implementation [#2019]

This commit is contained in:
Matias Griese
2021-01-18 12:40:13 +02:00
parent de3a557b80
commit 5ed810a2ab
2 changed files with 21 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ use Grav\Common\Config\Config;
use Grav\Common\Debugger;
use Grav\Common\File\CompiledYamlFile;
use Grav\Common\Filesystem\Folder;
use Grav\Common\Flex\Types\Pages\PageIndex;
use Grav\Common\GPM\GPM as GravGPM;
use Grav\Common\GPM\Installer;
use Grav\Common\Grav;
@@ -1366,7 +1367,10 @@ class AdminController extends AdminBaseController
$pages = $this->admin::enablePages();
// Find new parent page in order to build the path.
$route = $data['route'] ?? dirname($this->admin->route);
$path = trim($data['route'] ?? dirname($this->admin->route), '/');
if ($path === '.') {
$path = '';
}
/** @var PageInterface $obj */
$obj = $this->admin->page(true);
@@ -1381,9 +1385,6 @@ class AdminController extends AdminBaseController
$this->data['folder'] = $obj->slug();
}
// Ensure route is prefixed with a forward slash.
$route = '/' . ltrim($route, '/');
// Check for valid frontmatter
if (isset($data['frontmatter']) && !$this->checkValidFrontmatter($data['frontmatter'])) {
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.INVALID_FRONTMATTER_COULD_NOT_SAVE'),
@@ -1403,7 +1404,21 @@ class AdminController extends AdminBaseController
}
}
$parent = $route && $route !== '/' && $route !== '.' && $route !== '/.' ? $pages->find($route, true) : $pages->root();
if ($path !== '') {
// First try to get page by its path.
$parent = $pages->get(GRAV_ROOT . '/' . $path);
if (!$parent) {
// Fall back using the route.
$route = '/' . preg_replace(PageIndex::PAGE_ROUTE_REGEX, '/', $path);
$parent = $pages->find($route, true);
if (!$parent) {
throw new \RuntimeException('New parent page cannot be resolved!');
}
}
} else {
$parent = $pages->root();
}
$original_order = (int)trim($obj->order(), '.');
try {