Save to new file if hash is changed. Ref #16
This commit is contained in:
parent
0b7c7198c1
commit
7f02dac318
@ -18,16 +18,10 @@ class DocumentController extends Controller{
|
||||
public static function create($args){
|
||||
$uid = self::preDispatch();
|
||||
$view = new \OC\Files\View('/' . $uid . '/files');
|
||||
$name = '/New Document.odt';
|
||||
$fileNum = 0;
|
||||
$path = Helper::getNewFileName($view, '/New Document.odt');
|
||||
|
||||
while ($view->file_exists($name)){
|
||||
$fileNum += 1;
|
||||
$name = preg_replace('/(\.odt|\(\d+\)\.odt)$/', ' (' .$fileNum . ').odt', $name);
|
||||
};
|
||||
|
||||
$view->file_put_contents(
|
||||
$name,
|
||||
$path,
|
||||
base64_decode(self::ODT_TEMPLATE)
|
||||
);
|
||||
}
|
||||
|
@ -82,6 +82,14 @@ class SessionController extends Controller{
|
||||
throw new \Exception('Document does not exist or is not writable for this user');
|
||||
}
|
||||
|
||||
if ($view->file_exists($path)){
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
if ($view->file_put_contents($path, $content)){
|
||||
//Document saved successfully. Cleaning session data
|
||||
Session::cleanUp($sessionID);
|
||||
|
@ -15,10 +15,20 @@ class Helper{
|
||||
|
||||
const APP_ID = 'documents';
|
||||
|
||||
public static function getNewFileName($view, $path){
|
||||
$fileNum = 0;
|
||||
|
||||
while ($view->file_exists($path)){
|
||||
$fileNum += 1;
|
||||
$path = preg_replace('/(\.odt|\(\d+\)\.odt)$/', ' (' .$fileNum . ').odt', $path);
|
||||
};
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
public static function getRandomColor(){
|
||||
$str = dechex(floor(rand(0, 16777215)));
|
||||
$str = str_pad($str, 6, "0", STR_PAD_LEFT);
|
||||
return '#' . $str;
|
||||
return '#' . str_pad($str, 6, "0", STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public static function debugLog($message){
|
||||
|
Loading…
x
Reference in New Issue
Block a user