aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-02-08 21:06:03 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-02-08 21:06:03 +0100
commit75bbd4f8b64209eaf120f1382d7cec6286e68c84 (patch)
tree4ce6847e3bb4e4466fa48073f39a9a3379824a92
parent698a6b07a833246f62aa950833c7d931ea1c8a63 (diff)
parentd2d664470216193785300ccf99adc4478f776a88 (diff)
downloadnextcloud-server-75bbd4f8b64209eaf120f1382d7cec6286e68c84.tar.gz
nextcloud-server-75bbd4f8b64209eaf120f1382d7cec6286e68c84.zip
Merge pull request #22211 from owncloud/versions-hook-info
versions provide more information when throwing hooks
-rw-r--r--apps/files_versions/lib/storage.php21
-rw-r--r--apps/files_versions/tests/versions.php4
2 files changed, 16 insertions, 9 deletions
diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php
index 35b3110928b..88a4126dabd 100644
--- a/apps/files_versions/lib/storage.php
+++ b/apps/files_versions/lib/storage.php
@@ -52,6 +52,10 @@ class Storage {
const DEFAULTMAXSIZE=50; // unit: percentage; 50% of available disk space/quota
const VERSIONS_ROOT = 'files_versions/';
+ const DELETE_TRIGGER_MASTER_REMOVED = 0;
+ const DELETE_TRIGGER_RETENTION_CONSTRAINT = 1;
+ const DELETE_TRIGGER_QUOTA_EXCEEDED = 2;
+
// files for which we can remove the versions after the delete operation was successful
private static $deletedFiles = array();
@@ -210,9 +214,9 @@ class Storage {
$versions = self::getVersions($uid, $filename);
if (!empty($versions)) {
foreach ($versions as $v) {
- \OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $path . $v['version']));
+ \OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $path . $v['version'], 'trigger' => self::DELETE_TRIGGER_MASTER_REMOVED));
self::deleteVersion($view, $filename . '.v' . $v['version']);
- \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $path . $v['version']));
+ \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $path . $v['version'], 'trigger' => self::DELETE_TRIGGER_MASTER_REMOVED));
}
}
}
@@ -309,6 +313,7 @@ class Storage {
Storage::scheduleExpire($uid, $file);
\OC_Hook::emit('\OCP\Versions', 'rollback', array(
'path' => $filename,
+ 'revision' => $revision,
));
return true;
} else if ($versionCreated) {
@@ -444,9 +449,9 @@ class Storage {
$view = new \OC\Files\View('/' . $uid . '/files_versions');
if (!empty($toDelete)) {
foreach ($toDelete as $version) {
- \OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $version['path'].'.v'.$version['version']));
+ \OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_RETENTION_CONSTRAINT));
self::deleteVersion($view, $version['path'] . '.v' . $version['version']);
- \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $version['path'].'.v'.$version['version']));
+ \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_RETENTION_CONSTRAINT));
}
}
}
@@ -705,9 +710,9 @@ class Storage {
}
foreach($toDelete as $key => $path) {
- \OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $path));
+ \OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
self::deleteVersion($versionsFileview, $path);
- \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $path));
+ \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
unset($allVersions[$key]); // update array with the versions we keep
\OCP\Util::writeLog('files_versions', "Expire: " . $path, \OCP\Util::DEBUG);
}
@@ -722,9 +727,9 @@ class Storage {
reset($allVersions);
while ($availableSpace < 0 && $i < $numOfVersions) {
$version = current($allVersions);
- \OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $version['path'].'.v'.$version['version']));
+ \OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
self::deleteVersion($versionsFileview, $version['path'] . '.v' . $version['version']);
- \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $version['path'].'.v'.$version['version']));
+ \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
\OCP\Util::writeLog('files_versions', 'running out of space! Delete oldest version: ' . $version['path'].'.v'.$version['version'] , \OCP\Util::DEBUG);
$versionsSize -= $version['size'];
$availableSpace += $version['size'];
diff --git a/apps/files_versions/tests/versions.php b/apps/files_versions/tests/versions.php
index b85877cebd3..d7d9c7a4fb4 100644
--- a/apps/files_versions/tests/versions.php
+++ b/apps/files_versions/tests/versions.php
@@ -652,7 +652,9 @@ class Test_Files_Versioning extends \Test\TestCase {
'path' => '/sub/test.txt',
);
- $this->assertEquals($expectedParams, $params);
+ $this->assertEquals($expectedParams['path'], $params['path']);
+ $this->assertTrue(array_key_exists('revision', $params));
+ $this->assertTrue($params['revision'] > 0);
$this->assertEquals('version2', $this->rootView->file_get_contents($filePath));
$info2 = $this->rootView->getFileInfo($filePath);