This commit is contained in:
Diego Najar 2017-12-17 21:16:30 +01:00
parent c88bb01323
commit ff1abc1e36
5 changed files with 45 additions and 19 deletions

View File

@ -48,6 +48,7 @@ function table($status, $icon='arrow-circle-o-down') {
foreach($list as $pageKey=>$fields) {
$page = buildPage($pageKey);
if ($page) {
echo '<tr>';
echo '<td>
<a href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'">'
@ -62,6 +63,7 @@ function table($status, $icon='arrow-circle-o-down') {
echo '</tr>';
}
}
}
if ($Url->pageNumber()==1) {
table('draft', 'spinner');

View File

@ -19,9 +19,7 @@ class dbPages extends dbJSON
'category'=> array('inFile'=>false, 'value'=>''),
'md5file'=> array('inFile'=>false, 'value'=>''),
'uuid'=> array('inFile'=>false, 'value'=>''),
'allowComments'=> array('inFile'=>false, 'value'=>true),
'parent'=> array('inFile'=>false, 'value'=>''),
'slug'=> array('inFile'=>false, 'value'=>'')
'allowComments'=> array('inFile'=>false, 'value'=>true)
);
function __construct()
@ -61,6 +59,11 @@ class dbPages extends dbJSON
$args['slug'] = Text::truncate($tmpslug, 60, '');
}
// Parent
if (!isset($args['parent'])) {
$args['parent'] = '';
}
// Generate key
$key = $this->generateKey($args['slug'], $args['parent']);
@ -156,6 +159,11 @@ class dbPages extends dbJSON
$args[$field] = $value;
}
// Parent
if (!isset($args['parent'])) {
$args['parent'] = '';
}
$newKey = $this->generateKey($args['slug'], $args['parent'], false, $args['key']);
// If the page is draft then the created time is the current
@ -213,6 +221,9 @@ class dbPages extends dbJSON
// Remove the old key
unset( $this->db[$args['key']] );
// Reindex Orphan Children
$this->reindexChildren($args['key'], $newKey);
// Checksum MD5
$dataForDb['md5file'] = md5_file(PATH_PAGES.$newKey.DS.FILENAME);
@ -228,6 +239,19 @@ class dbPages extends dbJSON
return $newKey;
}
// This function reindex the orphan children with the new parent key
// If a page has subpages and the page change his key is necesarry check the children key
public function reindexChildren($oldParentKey, $newParentKey) {
$tmp = $this->db;
foreach ($tmp as $key=>$fields) {
if (Text::startsWith($key, $oldParentKey.'/')) {
$newKey = Text::replace($oldParentKey.'/', $newParentKey.'/', $key);
$this->db[$newKey] = $this->db[$key];
unset($this->db[$key]);
}
}
}
public function delete($key)
{
// This is need it, because if the key is empty the Filesystem::deleteRecursive is going to delete PATH_PAGES

View File

@ -167,7 +167,6 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
}
// Generate the global variable $pagesByParent, defined on 69.pages.php
// (boolean) $allPages, TRUE include all status, FALSE only include published status
function buildPagesByParent($publishedPages=true, $staticPages=true) {
global $dbPages;
global $pagesByParent;

View File

@ -151,6 +151,7 @@ class Text {
}
// Replace all occurrences of the search string with the replacement string.
// replace("%body%", "black", "<body text='%body%'>");
public static function replace($search, $replace, $string)
{
return str_replace($search,$replace,$string);