1
0
mirror of https://github.com/typemill/typemill.git synced 2025-08-05 21:57:31 +02:00

Fix error with folders transform posts and page

This commit is contained in:
trendschau
2022-04-09 15:29:03 +02:00
parent f2a474a3cc
commit dfb356d902
16 changed files with 155 additions and 12 deletions

View File

@@ -296,17 +296,28 @@ class ControllerAuthorMetaApi extends ControllerAuthor
}
# if folder has changed and contains pages instead of posts or posts instead of pages
if($this->item->elementType == "folder" && isset($metaInput['contains']) && $this->hasChanged($metaInput, $metaPage['meta'], 'contains'))
if($this->item->elementType == "folder" && isset($metaInput['contains']) && isset($metaPage['meta']['contains']) && $this->hasChanged($metaInput, $metaPage['meta'], 'contains'))
{
$structure = true;
if($writeMeta->folderContainsFolders($this->item))
{
return $response->withJson(array('errors' => ['message' => 'The folder contains another folder so we cannot transform it. Please make sure there are only files in this folder.']),422);
}
if($metaInput['contains'] == "posts")
{
$writeMeta->transformPagesToPosts($this->item);
if(!$writeMeta->transformPagesToPosts($this->item))
{
return $response->withJson(array('errors' => ['message' => 'One or more files could not be transformed.']),422);
}
}
if($metaInput['contains'] == "pages")
{
$writeMeta->transformPostsToPages($this->item);
if(!$writeMeta->transformPostsToPages($this->item))
{
return $response->withJson(array('errors' => ['message' => 'One or more files could not be transformed.']),422);
}
}
}

View File

@@ -258,9 +258,10 @@ class WriteMeta extends WriteYaml
return $description;
}
public function transformPagesToPosts($folder){
public function transformPagesToPosts($folder)
{
$filetypes = array('md', 'txt', 'yaml');
$result = true;
foreach($folder->folderContent as $page)
{
@@ -294,13 +295,11 @@ class WriteMeta extends WriteYaml
# create new file-name without filetype
$newFile = $this->basePath . 'content' . $folder->path . DIRECTORY_SEPARATOR . $datetime . '-' . $page->slug;
$result = true;
foreach($filetypes as $filetype)
{
$oldFilePath = $oldFile . '.' . $filetype;
$newFilePath = $newFile . '.' . $filetype;
#check if file with filetype exists and rename
if($oldFilePath != $newFilePath && file_exists($oldFilePath))
{
@@ -315,12 +314,15 @@ class WriteMeta extends WriteYaml
}
}
}
return $result;
}
public function transformPostsToPages($folder){
public function transformPostsToPages($folder)
{
$filetypes = array('md', 'txt', 'yaml');
$index = 0;
$result = true;
foreach($folder->folderContent as $page)
{
@@ -337,8 +339,6 @@ class WriteMeta extends WriteYaml
# create new file-name without filetype
$newFile = $this->basePath . 'content' . $folder->path . DIRECTORY_SEPARATOR . $order . '-' . $page->slug;
$result = true;
foreach($filetypes as $filetype)
{
$oldFilePath = $oldFile . '.' . $filetype;
@@ -360,5 +360,20 @@ class WriteMeta extends WriteYaml
$index++;
}
return $result;
}
public function folderContainsFolders($folder)
{
foreach($folder->folderContent as $page)
{
if($page->elementType == 'folder')
{
return true;
}
}
return false;
}
}