From dfb356d9025f00ad2b032d3aae55517bc69e14a4 Mon Sep 17 00:00:00 2001 From: trendschau Date: Sat, 9 Apr 2022 15:29:03 +0200 Subject: [PATCH] Fix error with folders transform posts and page --- content/02-de/00-berlin/00-wedding.md | 4 +++ content/02-de/00-berlin/00-wedding.yaml | 9 +++++ content/02-de/00-berlin/01-neukoelln.md | 4 +++ content/02-de/00-berlin/01-neukoelln.yaml | 9 +++++ content/02-de/00-berlin/index.md | 4 +++ content/02-de/00-berlin/index.yaml | 17 ++++++++++ content/02-de/index.md | 4 +++ content/02-de/index.yaml | 11 +++++++ .../03-uk/00-berlin/202204081422-wedding.md | 4 +++ .../03-uk/00-berlin/202204081422-wedding.yaml | 9 +++++ content/03-uk/00-berlin/index.md | 4 +++ content/03-uk/00-berlin/index.yaml | 17 ++++++++++ content/03-uk/index.md | 4 +++ content/03-uk/index.yaml | 17 ++++++++++ .../Controllers/ControllerAuthorMetaApi.php | 17 ++++++++-- system/Models/WriteMeta.php | 33 ++++++++++++++----- 16 files changed, 155 insertions(+), 12 deletions(-) create mode 100644 content/02-de/00-berlin/00-wedding.md create mode 100644 content/02-de/00-berlin/00-wedding.yaml create mode 100644 content/02-de/00-berlin/01-neukoelln.md create mode 100644 content/02-de/00-berlin/01-neukoelln.yaml create mode 100644 content/02-de/00-berlin/index.md create mode 100644 content/02-de/00-berlin/index.yaml create mode 100644 content/02-de/index.md create mode 100644 content/02-de/index.yaml create mode 100644 content/03-uk/00-berlin/202204081422-wedding.md create mode 100644 content/03-uk/00-berlin/202204081422-wedding.yaml create mode 100644 content/03-uk/00-berlin/index.md create mode 100644 content/03-uk/00-berlin/index.yaml create mode 100644 content/03-uk/index.md create mode 100644 content/03-uk/index.yaml diff --git a/content/02-de/00-berlin/00-wedding.md b/content/02-de/00-berlin/00-wedding.md new file mode 100644 index 0000000..5931efc --- /dev/null +++ b/content/02-de/00-berlin/00-wedding.md @@ -0,0 +1,4 @@ +# Wedding + +Content + diff --git a/content/02-de/00-berlin/00-wedding.yaml b/content/02-de/00-berlin/00-wedding.yaml new file mode 100644 index 0000000..2fc965b --- /dev/null +++ b/content/02-de/00-berlin/00-wedding.yaml @@ -0,0 +1,9 @@ +meta: + title: Wedding + description: Content + owner: trendschau + author: 'Sebastian Schürmanns' + created: '2022-04-08' + time: 13-41-43 + navtitle: Wedding + modified: '2022-04-08' diff --git a/content/02-de/00-berlin/01-neukoelln.md b/content/02-de/00-berlin/01-neukoelln.md new file mode 100644 index 0000000..3c79076 --- /dev/null +++ b/content/02-de/00-berlin/01-neukoelln.md @@ -0,0 +1,4 @@ +# Neukölln + +Content + diff --git a/content/02-de/00-berlin/01-neukoelln.yaml b/content/02-de/00-berlin/01-neukoelln.yaml new file mode 100644 index 0000000..2b24f18 --- /dev/null +++ b/content/02-de/00-berlin/01-neukoelln.yaml @@ -0,0 +1,9 @@ +meta: + title: Neukölln + description: Content + owner: trendschau + author: 'Sebastian Schürmanns' + created: '2022-04-08' + time: 13-41-39 + navtitle: Neukölln + modified: '2022-04-08' diff --git a/content/02-de/00-berlin/index.md b/content/02-de/00-berlin/index.md new file mode 100644 index 0000000..707d991 --- /dev/null +++ b/content/02-de/00-berlin/index.md @@ -0,0 +1,4 @@ +# Berlin + +Content + diff --git a/content/02-de/00-berlin/index.yaml b/content/02-de/00-berlin/index.yaml new file mode 100644 index 0000000..9013416 --- /dev/null +++ b/content/02-de/00-berlin/index.yaml @@ -0,0 +1,17 @@ +meta: + navtitle: Berlina + title: Berlin + description: Content + heroimage: null + heroimagealt: null + hide: false + noindex: false + owner: trendschau + author: 'Sebastian Schürmanns' + allowedrole: null + alloweduser: null + manualdate: null + modified: '2022-04-08' + created: '2022-04-08' + time: 13-41-04 + contains: pages diff --git a/content/02-de/index.md b/content/02-de/index.md new file mode 100644 index 0000000..f4c287c --- /dev/null +++ b/content/02-de/index.md @@ -0,0 +1,4 @@ +# de + +Content + diff --git a/content/02-de/index.yaml b/content/02-de/index.yaml new file mode 100644 index 0000000..ea844de --- /dev/null +++ b/content/02-de/index.yaml @@ -0,0 +1,11 @@ +meta: + title: de + description: Content + owner: trendschau + author: 'Sebastian Schürmanns' + created: '2022-04-08' + time: 13-40-55 + navtitle: Deutschland + modified: '2022-04-08' + hide: false + noindex: false diff --git a/content/03-uk/00-berlin/202204081422-wedding.md b/content/03-uk/00-berlin/202204081422-wedding.md new file mode 100644 index 0000000..5931efc --- /dev/null +++ b/content/03-uk/00-berlin/202204081422-wedding.md @@ -0,0 +1,4 @@ +# Wedding + +Content + diff --git a/content/03-uk/00-berlin/202204081422-wedding.yaml b/content/03-uk/00-berlin/202204081422-wedding.yaml new file mode 100644 index 0000000..26f5098 --- /dev/null +++ b/content/03-uk/00-berlin/202204081422-wedding.yaml @@ -0,0 +1,9 @@ +meta: + title: Wedding + description: Content + owner: trendschau + author: 'Sebastian Schürmanns' + created: '2022-04-08' + time: 14-22-35 + navtitle: Wedding + modified: '2022-04-08' diff --git a/content/03-uk/00-berlin/index.md b/content/03-uk/00-berlin/index.md new file mode 100644 index 0000000..707d991 --- /dev/null +++ b/content/03-uk/00-berlin/index.md @@ -0,0 +1,4 @@ +# Berlin + +Content + diff --git a/content/03-uk/00-berlin/index.yaml b/content/03-uk/00-berlin/index.yaml new file mode 100644 index 0000000..579c2eb --- /dev/null +++ b/content/03-uk/00-berlin/index.yaml @@ -0,0 +1,17 @@ +meta: + navtitle: Berlin + title: Berlin + description: Content + heroimage: null + heroimagealt: null + hide: false + noindex: false + owner: trendschau + author: 'Sebastian Schürmanns' + allowedrole: null + alloweduser: null + manualdate: null + modified: '2022-04-08' + created: '2022-04-08' + time: 14-22-11 + contains: posts diff --git a/content/03-uk/index.md b/content/03-uk/index.md new file mode 100644 index 0000000..6f8a373 --- /dev/null +++ b/content/03-uk/index.md @@ -0,0 +1,4 @@ +# uk + +Content + diff --git a/content/03-uk/index.yaml b/content/03-uk/index.yaml new file mode 100644 index 0000000..f17c3ab --- /dev/null +++ b/content/03-uk/index.yaml @@ -0,0 +1,17 @@ +meta: + navtitle: change + title: uk + description: Content + heroimage: null + heroimagealt: null + hide: false + noindex: false + owner: trendschau + author: 'Sebastian Schürmanns' + allowedrole: null + alloweduser: null + manualdate: null + modified: '2022-04-08' + created: '2022-04-08' + time: 14-03-22 + contains: pages diff --git a/system/Controllers/ControllerAuthorMetaApi.php b/system/Controllers/ControllerAuthorMetaApi.php index ab36e3f..f96c6a4 100644 --- a/system/Controllers/ControllerAuthorMetaApi.php +++ b/system/Controllers/ControllerAuthorMetaApi.php @@ -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); + } } } diff --git a/system/Models/WriteMeta.php b/system/Models/WriteMeta.php index e92b8b1..57eff60 100644 --- a/system/Models/WriteMeta.php +++ b/system/Models/WriteMeta.php @@ -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; } } \ No newline at end of file