diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2019-01-14 19:24:19 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2019-01-14 19:24:19 +0100 |
commit | 8130427ec508f1d66553b52052c840c311081061 (patch) | |
tree | 23bab28db0f649618aa6bea024dcee84a9a25308 /app/class | |
parent | eb30a63c819ca50ebbc896eb293a0745dcd043be (diff) | |
download | wcms-8130427ec508f1d66553b52052c840c311081061.tar.gz wcms-8130427ec508f1d66553b52052c840c311081061.zip |
fix save art out of session
Diffstat (limited to 'app/class')
-rw-r--r-- | app/class/controllerart.php | 76 | ||||
-rw-r--r-- | app/class/controllerconnect.php | 36 |
2 files changed, 68 insertions, 44 deletions
diff --git a/app/class/controllerart.php b/app/class/controllerart.php index 00b7558..20ef634 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -33,13 +33,19 @@ class Controllerart extends Controller public function importart() { - $art = $this->artmanager->get($this->art); + if (isset($_SESSION['artupdate']) && $_SESSION['artupdate']['id'] == $this->art->id()) { + $art = new Art2($_SESSION['artupdate']); + unset($_SESSION['artupdate']); + } else { + $art = $this->artmanager->get($this->art); + } if ($art !== false) { $this->art = $art; return true; } else { return false; } + } @@ -104,9 +110,9 @@ class Controllerart extends Controller } else { $page = ['head' => $this->art->renderhead(), 'body' => $this->art->renderbody()]; } - if($canread) { + if ($canread) { $this->art->addaffcount(); - if($this->user->level() < 2) { + if ($this->user->level() < 2) { $this->art->addvisitcount(); } } @@ -208,40 +214,56 @@ class Controllerart extends Controller public function update($id) { $this->setart($id, 'artupdate'); - $_SESSION['workspace']['showrightpanel'] = isset($_POST['workspace']['showrightpanel']); - $_SESSION['workspace']['showleftpanel'] = isset($_POST['workspace']['showleftpanel']); - - if (!empty($_POST['fontsize']) && $_POST['fontsize'] !== Config::fontsize()) { - Config::setfontsize($_POST['fontsize']); - Config::savejson(); - } - + $this->movepanels(); + $this->fontsize(); $date = new DateTimeImmutable($_POST['pdate'] . $_POST['ptime'], new DateTimeZone('Europe/Paris')); $date = ['date' => $date]; - if ($this->importart() && $this->canedit()) { + if ($this->importart()) { + if ($this->canedit()) { + + // Check if someone esle edited the page during the editing. + $oldart = clone $this->art; + $this->art->hydrate($_POST); - $oldart = clone $this->art; - $this->art->hydrate($_POST); + if (self::COMBINE && $_POST['thisdatemodif'] === $oldart->datemodif('string')) { - if (self::COMBINE) { - if ($_POST['thisdatemodif'] === $oldart->datemodif('string')) { - $compare = $this->artmanager->combine($this->art, $oldart); - if (!empty($compare['diff'])) { - $this->art->hydrate($compare['mergeart']); - } } - } - $this->art->hydrate($date); - $this->art->updateedited(); - $this->art->addauthor($this->user->id()); - $this->artmanager->update($this->art); - $this->routedirect('artedit', ['art' => $this->art->id()]); - + $this->art->hydrate($date); + $this->art->updateedited(); + $this->art->addauthor($this->user->id()); + + + $this->artmanager->update($this->art); + + $this->routedirect('artedit', ['art' => $this->art->id()]); + //$this->showtemplate('updatemerge', $compare); + } else { + // If the editor session finished during the editing, let's try to reconnect to save the editing + $_SESSION['artupdate'] = $_POST; + $_SESSION['artupdate']['id'] = $this->art->id(); + $this->routedirect('connect'); + } + + } + $this->routedirect('art'); + } + + public function movepanels() + { + $_SESSION['workspace']['showrightpanel'] = isset($_POST['workspace']['showrightpanel']); + $_SESSION['workspace']['showleftpanel'] = isset($_POST['workspace']['showleftpanel']); + } + + public function fontsize() + { + if (!empty($_POST['fontsize']) && $_POST['fontsize'] !== Config::fontsize()) { + Config::setfontsize($_POST['fontsize']); + Config::savejson(); } } diff --git a/app/class/controllerconnect.php b/app/class/controllerconnect.php index 2e3f976..d0e3ee5 100644 --- a/app/class/controllerconnect.php +++ b/app/class/controllerconnect.php @@ -6,31 +6,33 @@ class Controllerconnect extends Controller public function log() { if (isset($_POST['log'])) { - if (isset($_POST['id'])) { - $id = $_POST['id']; - } else { - $id = null; - } + $id = $_POST['id'] ?? null; + $route = $_POST['route'] ?? 'home'; if ($_POST['log'] === 'login') { - $this->login($id); + $this->login($route, $id); } elseif ($_POST['log'] === 'logout') { - $this->logout($id); + $this->logout($route, $id); } } - } public function connect() { - $this->showtemplate('connect', []); + if(isset($_SESSION['artupdate'])) { + $artupdate['route'] = 'artedit'; + $artupdate['id'] = $_SESSION['artupdate']['id']; + } else { + $artupdate = [$route = 'home']; + } + $this->showtemplate('connect', $artupdate); } - public function login($id) + public function login($route, $id = null) { if (isset($_POST['pass'])) { $this->user = $this->usermanager->login($_POST['pass']); @@ -41,21 +43,21 @@ class Controllerconnect extends Controller } } - if (!empty($id)) { - $this->routedirect('artread/', ['art' => $id]); + if ($id !== null) { + $this->routedirect($route, ['art' => $id]); } else { - $this->routedirect('home'); + $this->routedirect($route); } } - public function logout($id) + public function logout($route, $id = null) { $this->user = $this->usermanager->logout(); $this->usermanager->writesession($this->user); - if (!empty($id)) { - $this->routedirect('artread/', ['art' => $id]); + if ($id !== null && $route !== 'home') { + $this->routedirect($route, ['art' => $id]); } else { - $this->routedirect('home'); + $this->routedirect($route); } } |