From f96944b8670c59aa58b3eeae6f486aae3c885683 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Sat, 21 Sep 2013 00:01:11 +0300 Subject: [PATCH] Add -conflict postfix for files modified externally --- ajax/sessionController.php | 2 +- lib/helper.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ajax/sessionController.php b/ajax/sessionController.php index 04f90b3a..f477dea4 100644 --- a/ajax/sessionController.php +++ b/ajax/sessionController.php @@ -86,7 +86,7 @@ class SessionController extends Controller{ $currentHash = sha1($view->file_get_contents($path)); if ($currentHash !== $session['genesis_hash']){ // Original file was modified externally. Save to a new one - $path = Helper::getNewFileName($view, $path); + $path = Helper::getNewFileName($view, $path, '-conflict'); } } diff --git a/lib/helper.php b/lib/helper.php index 8b4743a4..5ceeb1b0 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -15,12 +15,12 @@ class Helper{ const APP_ID = 'documents'; - public static function getNewFileName($view, $path){ + public static function getNewFileName($view, $path, $prepend = ' '){ $fileNum = 0; while ($view->file_exists($path)){ $fileNum += 1; - $path = preg_replace('/(\.odt|\(\d+\)\.odt)$/', ' (' .$fileNum . ').odt', $path); + $path = preg_replace('/(\.odt|' . $prepend . '\(\d+\)\.odt)$/', $prepend . '(' .$fileNum . ').odt', $path); }; return $path;