mirror of
https://github.com/nextcloud/server.git
synced 2026-06-13 18:50:47 -04:00
Merge pull request #22211 from owncloud/versions-hook-info
versions provide more information when throwing hooks
This commit is contained in:
commit
75bbd4f8b6
2 changed files with 16 additions and 9 deletions
|
|
@ -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'];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue