From 020545feb3f3d8ce9efd5ec69b59020a5318dcf3 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Fri, 15 Mar 2024 15:11:51 +0100 Subject: [PATCH] add conflict management --- index.php | 20 ++++++++++++++++++-- note.php | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index bd0ed37..777938c 100644 --- a/index.php +++ b/index.php @@ -35,9 +35,23 @@ function savenote($title, $content) { global $dir; - file_put_contents($dir . '/' . $title, $content); + $path = $dir . '/' . $title; + $lastchanged = filemtime($path); + $previous = $_POST['lastchanged']; + if ( (int)$lastchanged > (int)$previous) + { + $tempcontent = file_get_contents($path); + if ($tempcontent != $content) + { + $temptitle = $title . '_' . $lastchanged; + file_put_contents($dir . '/' . $temptitle, $tempcontent); + array_unshift($_SESSION['index'], $dir . '/' . $temptitle); + echo '
Conflict detected. See backup: ' . $temptitle . '
'; + } + } + file_put_contents($path, $content); removefromindex($title); - array_unshift($_SESSION['index'], $dir . '/' . $title); + array_unshift($_SESSION['index'], $path); } function linksdiv($content) @@ -138,6 +152,8 @@ $content = file_get_contents($dir . '/' . $title); } + clearstatcache(); + $lastchanged = filemtime($dir . '/' . $title); $lines = substr_count($content, "\r\n"); $words = substr_count($content, " ") + $lines; $chars = strlen($content); diff --git a/note.php b/note.php index 89f79f5..190bb7c 100644 --- a/note.php +++ b/note.php @@ -6,6 +6,7 @@ +