summaryrefslogtreecommitdiffstats
path: root/apps/files_versions
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-03-26 09:30:18 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-03-26 16:34:56 +0100
commitb80ebc96748b45fd2e0ba9323308657c4b00b7ec (patch)
treeec20e0ffa2f86b9b54939a83a785407319f94559 /apps/files_versions
parent62403d0932be7d620c7bdadc6b4e13eb496fcd6f (diff)
downloadnextcloud-server-b80ebc96748b45fd2e0ba9323308657c4b00b7ec.tar.gz
nextcloud-server-b80ebc96748b45fd2e0ba9323308657c4b00b7ec.zip
Use the short array syntax, everywhere
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/files_versions')
-rw-r--r--apps/files_versions/lib/Storage.php62
-rw-r--r--apps/files_versions/tests/Command/CleanupTest.php8
-rw-r--r--apps/files_versions/tests/VersioningTest.php190
3 files changed, 130 insertions, 130 deletions
diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php
index 8df98d087d8..b1d6c689c61 100644
--- a/apps/files_versions/lib/Storage.php
+++ b/apps/files_versions/lib/Storage.php
@@ -67,24 +67,24 @@ class Storage {
const DELETE_TRIGGER_QUOTA_EXCEEDED = 2;
// files for which we can remove the versions after the delete operation was successful
- private static $deletedFiles = array();
+ private static $deletedFiles = [];
- private static $sourcePathAndUser = array();
+ private static $sourcePathAndUser = [];
- private static $max_versions_per_interval = array(
+ private static $max_versions_per_interval = [
//first 10sec, one version every 2sec
- 1 => array('intervalEndsAfter' => 10, 'step' => 2),
+ 1 => ['intervalEndsAfter' => 10, 'step' => 2],
//next minute, one version every 10sec
- 2 => array('intervalEndsAfter' => 60, 'step' => 10),
+ 2 => ['intervalEndsAfter' => 60, 'step' => 10],
//next hour, one version every minute
- 3 => array('intervalEndsAfter' => 3600, 'step' => 60),
+ 3 => ['intervalEndsAfter' => 3600, 'step' => 60],
//next 24h, one version every hour
- 4 => array('intervalEndsAfter' => 86400, 'step' => 3600),
+ 4 => ['intervalEndsAfter' => 86400, 'step' => 3600],
//next 30days, one version per day
- 5 => array('intervalEndsAfter' => 2592000, 'step' => 86400),
+ 5 => ['intervalEndsAfter' => 2592000, 'step' => 86400],
//until the end one version per week
- 6 => array('intervalEndsAfter' => -1, 'step' => 604800),
- );
+ 6 => ['intervalEndsAfter' => -1, 'step' => 604800],
+ ];
/** @var \OCA\Files_Versions\AppInfo\Application */
private static $application;
@@ -129,7 +129,7 @@ class Storage {
*/
public static function setSourcePathAndUser($source) {
list($uid, $path) = self::getUidAndFilename($source);
- self::$sourcePathAndUser[$source] = array('uid' => $uid, 'path' => $path);
+ self::$sourcePathAndUser[$source] = ['uid' => $uid, 'path' => $path];
}
/**
@@ -147,7 +147,7 @@ class Storage {
} else {
$uid = $path = false;
}
- return array($uid, $path);
+ return [$uid, $path];
}
/**
@@ -215,9 +215,9 @@ class Storage {
*/
public static function markDeletedFile($path) {
list($uid, $filename) = self::getUidAndFilename($path);
- self::$deletedFiles[$path] = array(
+ self::$deletedFiles[$path] = [
'uid' => $uid,
- 'filename' => $filename);
+ 'filename' => $filename];
}
/**
@@ -253,9 +253,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'], 'trigger' => self::DELETE_TRIGGER_MASTER_REMOVED));
+ \OC_Hook::emit('\OCP\Versions', 'preDelete', ['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'], 'trigger' => self::DELETE_TRIGGER_MASTER_REMOVED));
+ \OC_Hook::emit('\OCP\Versions', 'delete', ['path' => $path . $v['version'], 'trigger' => self::DELETE_TRIGGER_MASTER_REMOVED]);
}
}
}
@@ -378,11 +378,11 @@ class Storage {
$node = $userFolder->get($file);
// TODO: move away from those legacy hooks!
- \OC_Hook::emit('\OCP\Versions', 'rollback', array(
+ \OC_Hook::emit('\OCP\Versions', 'rollback', [
'path' => $filename,
'revision' => $revision,
'node' => $node,
- ));
+ ]);
return true;
} else if ($versionCreated) {
self::deleteVersion($users_view, $version);
@@ -439,7 +439,7 @@ class Storage {
* @return array versions newest version first
*/
public static function getVersions($uid, $filename, $userFullPath = '') {
- $versions = array();
+ $versions = [];
if (empty($filename)) {
return $versions;
}
@@ -518,9 +518,9 @@ class Storage {
$view = new View('/' . $uid . '/files_versions');
if (!empty($toDelete)) {
foreach ($toDelete as $version) {
- \OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_RETENTION_CONSTRAINT));
+ \OC_Hook::emit('\OCP\Versions', 'preDelete', ['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'], 'trigger' => self::DELETE_TRIGGER_RETENTION_CONSTRAINT));
+ \OC_Hook::emit('\OCP\Versions', 'delete', ['path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_RETENTION_CONSTRAINT]);
}
}
}
@@ -559,8 +559,8 @@ class Storage {
*/
private static function getAllVersions($uid) {
$view = new View('/' . $uid . '/');
- $dirs = array(self::VERSIONS_ROOT);
- $versions = array();
+ $dirs = [self::VERSIONS_ROOT];
+ $versions = [];
while (!empty($dirs)) {
$dir = array_pop($dirs);
@@ -577,7 +577,7 @@ class Storage {
$version = substr($filePath, $versionsBegin + 2);
$relpath = substr($filePath, $relPathStart, $versionsBegin - $relPathStart);
$key = $version . '#' . $relpath;
- $versions[$key] = array('path' => $relpath, 'timestamp' => $version);
+ $versions[$key] = ['path' => $relpath, 'timestamp' => $version];
}
}
}
@@ -585,7 +585,7 @@ class Storage {
// newest version first
krsort($versions);
- $result = array();
+ $result = [];
foreach ($versions as $key => $value) {
$size = $view->filesize(self::VERSIONS_ROOT.'/'.$value['path'].'.v'.$value['timestamp']);
@@ -638,7 +638,7 @@ class Storage {
*/
protected static function getAutoExpireList($time, $versions) {
$size = 0;
- $toDelete = array(); // versions we want to delete
+ $toDelete = []; // versions we want to delete
$interval = 1;
$step = Storage::$max_versions_per_interval[$interval]['step'];
@@ -682,7 +682,7 @@ class Storage {
}
}
- return array($toDelete, $size);
+ return [$toDelete, $size];
}
/**
@@ -791,9 +791,9 @@ class Storage {
$logger = \OC::$server->getLogger();
foreach($toDelete as $key => $path) {
- \OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
+ \OC_Hook::emit('\OCP\Versions', 'preDelete', ['path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]);
self::deleteVersion($versionsFileview, $path);
- \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
+ \OC_Hook::emit('\OCP\Versions', 'delete', ['path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]);
unset($allVersions[$key]); // update array with the versions we keep
$logger->info('Expire: ' . $path, ['app' => 'files_versions']);
}
@@ -808,9 +808,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'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
+ \OC_Hook::emit('\OCP\Versions', 'preDelete', ['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'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
+ \OC_Hook::emit('\OCP\Versions', 'delete', ['path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]);
\OC::$server->getLogger()->info('running out of space! Delete oldest version: ' . $version['path'].'.v'.$version['version'], ['app' => 'files_versions']);
$versionsSize -= $version['size'];
$availableSpace += $version['size'];
diff --git a/apps/files_versions/tests/Command/CleanupTest.php b/apps/files_versions/tests/Command/CleanupTest.php
index b5ed6c33a07..94f54f96d89 100644
--- a/apps/files_versions/tests/Command/CleanupTest.php
+++ b/apps/files_versions/tests/Command/CleanupTest.php
@@ -90,10 +90,10 @@ class CleanupTest extends TestCase {
}
public function dataTestDeleteVersions() {
- return array(
- array(true),
- array(false)
- );
+ return [
+ [true],
+ [false]
+ ];
}
diff --git a/apps/files_versions/tests/VersioningTest.php b/apps/files_versions/tests/VersioningTest.php
index 53179bd6b30..c7eaec0a699 100644
--- a/apps/files_versions/tests/VersioningTest.php
+++ b/apps/files_versions/tests/VersioningTest.php
@@ -159,121 +159,121 @@ class VersioningTest extends \Test\TestCase {
}
public function versionsProvider() {
- return array(
+ return [
// first set of versions uniformly distributed versions
- array(
- array(
+ [
+ [
// first slice (10sec) keep one version every 2 seconds
- array("version" => 4999999, "path" => "keep", "size" => 1),
- array("version" => 4999998, "path" => "delete", "size" => 1),
- array("version" => 4999997, "path" => "keep", "size" => 1),
- array("version" => 4999995, "path" => "keep", "size" => 1),
- array("version" => 4999994, "path" => "delete", "size" => 1),
+ ["version" => 4999999, "path" => "keep", "size" => 1],
+ ["version" => 4999998, "path" => "delete", "size" => 1],
+ ["version" => 4999997, "path" => "keep", "size" => 1],
+ ["version" => 4999995, "path" => "keep", "size" => 1],
+ ["version" => 4999994, "path" => "delete", "size" => 1],
//next slice (60sec) starts at 4999990 keep one version every 10 secons
- array("version" => 4999988, "path" => "keep", "size" => 1),
- array("version" => 4999978, "path" => "keep", "size" => 1),
- array("version" => 4999975, "path" => "delete", "size" => 1),
- array("version" => 4999972, "path" => "delete", "size" => 1),
- array("version" => 4999967, "path" => "keep", "size" => 1),
- array("version" => 4999958, "path" => "delete", "size" => 1),
- array("version" => 4999957, "path" => "keep", "size" => 1),
+ ["version" => 4999988, "path" => "keep", "size" => 1],
+ ["version" => 4999978, "path" => "keep", "size" => 1],
+ ["version" => 4999975, "path" => "delete", "size" => 1],
+ ["version" => 4999972, "path" => "delete", "size" => 1],
+ ["version" => 4999967, "path" => "keep", "size" => 1],
+ ["version" => 4999958, "path" => "delete", "size" => 1],
+ ["version" => 4999957, "path" => "keep", "size" => 1],
//next slice (3600sec) start at 4999940 keep one version every 60 seconds
- array("version" => 4999900, "path" => "keep", "size" => 1),
- array("version" => 4999841, "path" => "delete", "size" => 1),
- array("version" => 4999840, "path" => "keep", "size" => 1),
- array("version" => 4999780, "path" => "keep", "size" => 1),
- array("version" => 4996401, "path" => "keep", "size" => 1),
+ ["version" => 4999900, "path" => "keep", "size" => 1],
+ ["version" => 4999841, "path" => "delete", "size" => 1],
+ ["version" => 4999840, "path" => "keep", "size" => 1],
+ ["version" => 4999780, "path" => "keep", "size" => 1],
+ ["version" => 4996401, "path" => "keep", "size" => 1],
// next slice (86400sec) start at 4996400 keep one version every 3600 seconds
- array("version" => 4996350, "path" => "delete", "size" => 1),
- array("version" => 4992800, "path" => "keep", "size" => 1),
- array("version" => 4989800, "path" => "delete", "size" => 1),
- array("version" => 4989700, "path" => "delete", "size" => 1),
- array("version" => 4989200, "path" => "keep", "size" => 1),
+ ["version" => 4996350, "path" => "delete", "size" => 1],
+ ["version" => 4992800, "path" => "keep", "size" => 1],
+ ["version" => 4989800, "path" => "delete", "size" => 1],
+ ["version" => 4989700, "path" => "delete", "size" => 1],
+ ["version" => 4989200, "path" => "keep", "size" => 1],
// next slice (2592000sec) start at 4913600 keep one version every 86400 seconds
- array("version" => 4913600, "path" => "keep", "size" => 1),
- array("version" => 4852800, "path" => "delete", "size" => 1),
- array("version" => 4827201, "path" => "delete", "size" => 1),
- array("version" => 4827200, "path" => "keep", "size" => 1),
- array("version" => 4777201, "path" => "delete", "size" => 1),
- array("version" => 4777501, "path" => "delete", "size" => 1),
- array("version" => 4740000, "path" => "keep", "size" => 1),
+ ["version" => 4913600, "path" => "keep", "size" => 1],
+ ["version" => 4852800, "path" => "delete", "size" => 1],
+ ["version" => 4827201, "path" => "delete", "size" => 1],
+ ["version" => 4827200, "path" => "keep", "size" => 1],
+ ["version" => 4777201, "path" => "delete", "size" => 1],
+ ["version" => 4777501, "path" => "delete", "size" => 1],
+ ["version" => 4740000, "path" => "keep", "size" => 1],
// final slice starts at 2408000 keep one version every 604800 secons
- array("version" => 2408000, "path" => "keep", "size" => 1),
- array("version" => 1803201, "path" => "delete", "size" => 1),
- array("version" => 1803200, "path" => "keep", "size" => 1),
- array("version" => 1800199, "path" => "delete", "size" => 1),
- array("version" => 1800100, "path" => "delete", "size" => 1),
- array("version" => 1198300, "path" => "keep", "size" => 1),
- ),
+ ["version" => 2408000, "path" => "keep", "size" => 1],
+ ["version" => 1803201, "path" => "delete", "size" => 1],
+ ["version" => 1803200, "path" => "keep", "size" => 1],
+ ["version" => 1800199, "path" => "delete", "size" => 1],
+ ["version" => 1800100, "path" => "delete", "size" => 1],
+ ["version" => 1198300, "path" => "keep", "size" => 1],
+ ],
16 // size of all deleted files (every file has the size 1)
- ),
+ ],
// second set of versions, here we have only really old versions
- array(
- array(
+ [
+ [
// first slice (10sec) keep one version every 2 seconds
// next slice (60sec) starts at 4999990 keep one version every 10 secons
// next slice (3600sec) start at 4999940 keep one version every 60 seconds
// next slice (86400sec) start at 4996400 keep one version every 3600 seconds
- array("version" => 4996400, "path" => "keep", "size" => 1),
- array("version" => 4996350, "path" => "delete", "size" => 1),
- array("version" => 4996350, "path" => "delete", "size" => 1),
- array("version" => 4992800, "path" => "keep", "size" => 1),
- array("version" => 4989800, "path" => "delete", "size" => 1),
- array("version" => 4989700, "path" => "delete", "size" => 1),
- array("version" => 4989200, "path" => "keep", "size" => 1),
+ ["version" => 4996400, "path" => "keep", "size" => 1],
+ ["version" => 4996350, "path" => "delete", "size" => 1],
+ ["version" => 4996350, "path" => "delete", "size" => 1],
+ ["version" => 4992800, "path" => "keep", "size" => 1],
+ ["version" => 4989800, "path" => "delete", "size" => 1],
+ ["version" => 4989700, "path" => "delete", "size" => 1],
+ ["version" => 4989200, "path" => "keep", "size" => 1],
// next slice (2592000sec) start at 4913600 keep one version every 86400 seconds
- array("version" => 4913600, "path" => "keep", "size" => 1),
- array("version" => 4852800, "path" => "delete", "size" => 1),
- array("version" => 4827201, "path" => "delete", "size" => 1),
- array("version" => 4827200, "path" => "keep", "size" => 1),
- array("version" => 4777201, "path" => "delete", "size" => 1),
- array("version" => 4777501, "path" => "delete", "size" => 1),
- array("version" => 4740000, "path" => "keep", "size" => 1),
+ ["version" => 4913600, "path" => "keep", "size" => 1],
+ ["version" => 4852800, "path" => "delete", "size" => 1],
+ ["version" => 4827201, "path" => "delete", "size" => 1],
+ ["version" => 4827200, "path" => "keep", "size" => 1],
+ ["version" => 4777201, "path" => "delete", "size" => 1],
+ ["version" => 4777501, "path" => "delete", "size" => 1],
+ ["version" => 4740000, "path" => "keep", "size" => 1],
// final slice starts at 2408000 keep one version every 604800 secons
- array("version" => 2408000, "path" => "keep", "size" => 1),
- array("version" => 1803201, "path" => "delete", "size" => 1),
- array("version" => 1803200, "path" => "keep", "size" => 1),
- array("version" => 1800199, "path" => "delete", "size" => 1),
- array("version" => 1800100, "path" => "delete", "size" => 1),
- array("version" => 1198300, "path" => "keep", "size" => 1),
- ),
+ ["version" => 2408000, "path" => "keep", "size" => 1],
+ ["version" => 1803201, "path" => "delete", "size" => 1],
+ ["version" => 1803200, "path" => "keep", "size" => 1],
+ ["version" => 1800199, "path" => "delete", "size" => 1],
+ ["version" => 1800100, "path" => "delete", "size" => 1],
+ ["version" => 1198300, "path" => "keep", "size" => 1],
+ ],
11 // size of all deleted files (every file has the size 1)
- ),
+ ],
// third set of versions, with some gaps between
- array(
- array(
+ [
+ [
// first slice (10sec) keep one version every 2 seconds
- array("version" => 4999999, "path" => "keep", "size" => 1),
- array("version" => 4999998, "path" => "delete", "size" => 1),
- array("version" => 4999997, "path" => "keep", "size" => 1),
- array("version" => 4999995, "path" => "keep", "size" => 1),
- array("version" => 4999994, "path" => "delete", "size" => 1),
+ ["version" => 4999999, "path" => "keep", "size" => 1],
+ ["version" => 4999998, "path" => "delete", "size" => 1],
+ ["version" => 4999997, "path" => "keep", "size" => 1],
+ ["version" => 4999995, "path" => "keep", "size" => 1],
+ ["version" => 4999994, "path" => "delete", "size" => 1],
//next slice (60sec) starts at 4999990 keep one version every 10 secons
- array("version" => 4999988, "path" => "keep", "size" => 1),
- array("version" => 4999978, "path" => "keep", "size" => 1),
+ ["version" => 4999988, "path" => "keep", "size" => 1],
+ ["version" => 4999978, "path" => "keep", "size" => 1],
//next slice (3600sec) start at 4999940 keep one version every 60 seconds
// next slice (86400sec) start at 4996400 keep one version every 3600 seconds
- array("version" => 4989200, "path" => "keep", "size" => 1),
+ ["version" => 4989200, "path" => "keep", "size" => 1],
// next slice (2592000sec) start at 4913600 keep one version every 86400 seconds
- array("version" => 4913600, "path" => "keep", "size" => 1),
- array("version" => 4852800, "path" => "delete", "size" => 1),
- array("version" => 4827201, "path" => "delete", "size" => 1),
- array("version" => 4827200, "path" => "keep", "size" => 1),
- array("version" => 4777201, "path" => "delete", "size" => 1),
- array("version" => 4777501, "path" => "delete", "size" => 1),
- array("version" => 4740000, "path" => "keep", "size" => 1),
+ ["version" => 4913600, "path" => "keep", "size" => 1],
+ ["version" => 4852800, "path" => "delete", "size" => 1],
+ ["version" => 4827201, "path" => "delete", "size" => 1],
+ ["version" => 4827200, "path" => "keep", "size" => 1],
+ ["version" => 4777201, "path" => "delete", "size" => 1],
+ ["version" => 4777501, "path" => "delete", "size" => 1],
+ ["version" => 4740000, "path" => "keep", "size" => 1],
// final slice starts at 2408000 keep one version every 604800 secons
- array("version" => 2408000, "path" => "keep", "size" => 1),
- array("version" => 1803201, "path" => "delete", "size" => 1),
- array("version" => 1803200, "path" => "keep", "size" => 1),
- array("version" => 1800199, "path" => "delete", "size" => 1),
- array("version" => 1800100, "path" => "delete", "size" => 1),
- array("version" => 1198300, "path" => "keep", "size" => 1),
- ),
+ ["version" => 2408000, "path" => "keep", "size" => 1],
+ ["version" => 1803201, "path" => "delete", "size" => 1],
+ ["version" => 1803200, "path" => "keep", "size" => 1],
+ ["version" => 1800199, "path" => "delete", "size" => 1],
+ ["version" => 1800100, "path" => "delete", "size" => 1],
+ ["version" => 1198300, "path" => "keep", "size" => 1],
+ ],
9 // size of all deleted files (every file has the size 1)
- ),
+ ],
- );
+ ];
}
public function testRename() {
@@ -647,8 +647,8 @@ class VersioningTest extends \Test\TestCase {
}
public function testRestoreCrossStorage() {
- $storage2 = new Temporary(array());
- \OC\Files\Filesystem::mount($storage2, array(), self::TEST_VERSIONS_USER . '/files/sub');
+ $storage2 = new Temporary([]);
+ \OC\Files\Filesystem::mount($storage2, [], self::TEST_VERSIONS_USER . '/files/sub');
$this->doTestRestore();
}
@@ -787,13 +787,13 @@ class VersioningTest extends \Test\TestCase {
$this->assertEquals('test file', $this->rootView->file_get_contents($filePath));
$info1 = $this->rootView->getFileInfo($filePath);
- $params = array();
+ $params = [];
$this->connectMockHooks('rollback', $params);
$this->assertTrue(\OCA\Files_Versions\Storage::rollback('sub/test.txt', $t2, $this->user1));
- $expectedParams = array(
+ $expectedParams = [
'path' => '/sub/test.txt',
- );
+ ];
$this->assertEquals($expectedParams['path'], $params['path']);
$this->assertTrue(array_key_exists('revision', $params));