aboutsummaryrefslogtreecommitdiff
path: root/app/class/Controllerpage.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/class/Controllerpage.php')
-rw-r--r--app/class/Controllerpage.php42
1 files changed, 42 insertions, 0 deletions
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');