diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-02-08 15:18:54 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-02-08 15:18:54 +0100 |
commit | c0a2817accea23837ab85b8ba31aabc7fbb20fc3 (patch) | |
tree | 7ccfc4ffd83c9ab21538706b969d444019701981 | |
parent | 36f5229b006668c989399d91a0ff849f82b9b8cf (diff) | |
download | wcms-c0a2817accea23837ab85b8ba31aabc7fbb20fc3.tar.gz wcms-c0a2817accea23837ab85b8ba31aabc7fbb20fc3.zip |
new feature : duplicate close #14
-rw-r--r-- | MANUAL.md | 10 | ||||
-rw-r--r-- | app/class/Controllerpage.php | 42 | ||||
-rw-r--r-- | app/class/Page.php | 9 | ||||
-rw-r--r-- | app/class/Routes.php | 2 |
4 files changed, 63 insertions, 0 deletions
@@ -491,6 +491,12 @@ Type thoses commands after a __page_id__ Command used to add a page in the database. +##### /add:id + + /add:<page_id> + +Will create a new page, as a copy of `<page_id>`. + ##### /edit Command used to edit a page. If you're not logged in, it will ask for your credentials. @@ -511,6 +517,10 @@ Simply download the page as a JSON object file. Reserved to users that can edit Show a `var_dump` of the page object. This could be usefull for debbuging. +##### /duplicate + + <pageid>/duplicate:<newpageid> + #### Home commands diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php index 585db0a..92632fc 100644 --- a/app/class/Controllerpage.php +++ b/app/class/Controllerpage.php @@ -230,6 +230,16 @@ class Controllerpage extends Controller } } + public function addascopy(string $id, string $copy) + { + $id = idclean($id); + if($this->copy($copy, $id)) { + $this->routedirect('pageedit', ['page' => $this->page->id()]); + } else { + $this->routedirect('pageread/', ['page' => $id]); + } + } + public function confirmdelete($id) { $this->setpage($id, 'pageconfirmdelete'); @@ -304,6 +314,38 @@ class Controllerpage extends Controller $this->routedirect('home'); } + public function duplicate(string $srcid, string $targetid) + { + $targetid = idclean($targetid); + if ($this->copy($srcid, $targetid)) { + $this->routedirect('pageread/', ['page' => $targetid]); + } else { + $this->routedirect('pageread/', ['page' => idclean($srcid)]); + + } + } + + /** + * Copy a page to a new ID + * + * @param string $srcid Source page ID + * @param string $targetid Target page ID + */ + public function copy(string $srcid, string $targetid) + { + if ($this->user->iseditor()) { + $this->page = $this->pagemanager->get($srcid); + if($this->page !== false && $this->canedit() && $this->pagemanager->get($targetid) === false) { + $this->page->setid($targetid); + $this->page->setdatecreation(true); // Reset date of creation + $this->page->addauthor($this->user->id()); + $this->pagemanager->add($this->page); + return true; + } + } + return false; + } + public function update($id) { $this->setpage($id, 'pageupdate'); diff --git a/app/class/Page.php b/app/class/Page.php index e4692e3..c30352c 100644 --- a/app/class/Page.php +++ b/app/class/Page.php @@ -444,10 +444,19 @@ class Page extends Dbitem } } + /** + * DateTimeImmutable : set date + * string ISO8601 : set date + * true : reset to now + * + * @param string|DateTimeImmutable|true $datecreation Set or reset date of creation + */ public function setdatecreation($datecreation) { if ($datecreation instanceof DateTimeImmutable) { $this->datecreation = $datecreation; + } elseif ($datecreation === true) { + $this->datecreation = new DateTimeImmutable(null, timezone_open("Europe/Paris")); } else { $this->datecreation = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $datecreation, new DateTimeZone('Europe/Paris')); } diff --git a/app/class/Routes.php b/app/class/Routes.php index 277d478..e71bf59 100644 --- a/app/class/Routes.php +++ b/app/class/Routes.php @@ -50,6 +50,7 @@ class Routes ['GET', '/[cid:page]/', 'Controllerpage#read', 'pageread/'], ['GET', '/[cid:page]', 'Controllerpage#read', 'pageread'], ['GET', '/[cid:page]/add', 'Controllerpage#add', 'pageadd'], + ['GET', '/[cid:page]/add:[cid:copy]', 'Controllerpage#addascopy', 'pageaddascopy'], ['GET', '/[cid:page]/edit', 'Controllerpage#edit', 'pageedit'], ['GET', '/[cid:page]/render', 'Controllerpage#render', 'pagerender'], ['GET', '/[cid:page]/log', 'Controllerpage#log', 'pagelog'], @@ -59,6 +60,7 @@ class Routes ['POST', '/[cid:page]/removeeditby', 'Controllerpage#removeeditby', 'pageremoveeditby'], ['GET', '/[cid:page]/delete', 'Controllerpage#confirmdelete', 'pageconfirmdelete'], ['POST', '/[cid:page]/delete', 'Controllerpage#delete', 'pagedelete'], + ['GET', '/[cid:page]/duplicate:[cid:duplicate]', 'Controllerpage#duplicate', 'pageduplicate'], ['GET', '/[cid:page]/[*]', 'Controllerpage#pagedirect', 'pageread/etoile'], ]); |