Skip to content

Commit 6221d7e

Browse files
page update: verify versions match before db storing
and throw a exception in case of mismatch
1 parent 348cf22 commit 6221d7e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

app/class/Modelpage.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,22 @@ public function flushrendercache(): void
358358

359359
/**
360360
* Update a page in the database
361+
* Check if page version match the one stored in database
361362
*
362363
* @param Page $page The page that is going to be updated
363364
*
364365
* @throws Databaseexception in case of error
366+
* @throws RangeException If original page version is invalid
365367
*/
366368
public function update(Page $page): void
367369
{
370+
$oldpage = $this->get($page);
371+
if ($page->version() !== $oldpage->version()) {
372+
$vnew = $page->version();
373+
$vold = $oldpage->version();
374+
throw new Databaseexception("page version ($vnew) does not match original page in database ($vold)");
375+
}
376+
368377
$pagedata = new Document($page->dry());
369378
$pagedata->setId($page->id());
370379
$this->updatedoc($pagedata);

0 commit comments

Comments
 (0)