Completed
Pull Request — master (#3643)
by Christoph
12:28
created
apps/files_versions/lib/Storage.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 
54 54
 class Storage {
55 55
 
56
-	const DEFAULTENABLED=true;
57
-	const DEFAULTMAXSIZE=50; // unit: percentage; 50% of available disk space/quota
56
+	const DEFAULTENABLED = true;
57
+	const DEFAULTMAXSIZE = 50; // unit: percentage; 50% of available disk space/quota
58 58
 	const VERSIONS_ROOT = 'files_versions/';
59 59
 
60 60
 	const DELETE_TRIGGER_MASTER_REMOVED = 0;
@@ -68,17 +68,17 @@  discard block
 block discarded – undo
68 68
 
69 69
 	private static $max_versions_per_interval = array(
70 70
 		//first 10sec, one version every 2sec
71
-		1 => array('intervalEndsAfter' => 10,      'step' => 2),
71
+		1 => array('intervalEndsAfter' => 10, 'step' => 2),
72 72
 		//next minute, one version every 10sec
73
-		2 => array('intervalEndsAfter' => 60,      'step' => 10),
73
+		2 => array('intervalEndsAfter' => 60, 'step' => 10),
74 74
 		//next hour, one version every minute
75
-		3 => array('intervalEndsAfter' => 3600,    'step' => 60),
75
+		3 => array('intervalEndsAfter' => 3600, 'step' => 60),
76 76
 		//next 24h, one version every hour
77
-		4 => array('intervalEndsAfter' => 86400,   'step' => 3600),
77
+		4 => array('intervalEndsAfter' => 86400, 'step' => 3600),
78 78
 		//next 30days, one version per day
79 79
 		5 => array('intervalEndsAfter' => 2592000, 'step' => 86400),
80 80
 		//until the end one version per week
81
-		6 => array('intervalEndsAfter' => -1,      'step' => 604800),
81
+		6 => array('intervalEndsAfter' => -1, 'step' => 604800),
82 82
 	);
83 83
 
84 84
 	/** @var \OCA\Files_Versions\AppInfo\Application */
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 			$uid = User::getUser();
103 103
 		}
104 104
 		Filesystem::initMountPoints($uid);
105
-		if ( $uid != User::getUser() ) {
105
+		if ($uid != User::getUser()) {
106 106
 			$info = Filesystem::getFileInfo($filename);
107 107
 			$ownerView = new View('/'.$uid.'/files');
108 108
 			try {
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 * @return int versions size
153 153
 	 */
154 154
 	private static function getVersionsSize($user) {
155
-		$view = new View('/' . $user);
155
+		$view = new View('/'.$user);
156 156
 		$fileInfo = $view->getFileInfo('/files_versions');
157 157
 		return isset($fileInfo['size']) ? $fileInfo['size'] : 0;
158 158
 	}
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	 * store a new version of a file.
162 162
 	 */
163 163
 	public static function store($filename) {
164
-		if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
164
+		if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') {
165 165
 
166 166
 			// if the file gets streamed we need to remove the .part extension
167 167
 			// to get the right target
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
 			}
172 172
 
173 173
 			// we only handle existing files
174
-			if (! Filesystem::file_exists($filename) || Filesystem::is_dir($filename)) {
174
+			if (!Filesystem::file_exists($filename) || Filesystem::is_dir($filename)) {
175 175
 				return false;
176 176
 			}
177 177
 
178 178
 			list($uid, $filename) = self::getUidAndFilename($filename);
179 179
 
180
-			$files_view = new View('/'.$uid .'/files');
180
+			$files_view = new View('/'.$uid.'/files');
181 181
 			$users_view = new View('/'.$uid);
182 182
 
183 183
 			// no use making versions for empty files
@@ -191,10 +191,10 @@  discard block
 block discarded – undo
191 191
 			self::scheduleExpire($uid, $filename);
192 192
 
193 193
 			// store a new version of a file
194
-			$mtime = $users_view->filemtime('files/' . $filename);
195
-			$users_view->copy('files/' . $filename, 'files_versions/' . $filename . '.v' . $mtime);
194
+			$mtime = $users_view->filemtime('files/'.$filename);
195
+			$users_view->copy('files/'.$filename, 'files_versions/'.$filename.'.v'.$mtime);
196 196
 			// call getFileInfo to enforce a file cache entry for the new version
197
-			$users_view->getFileInfo('files_versions/' . $filename . '.v' . $mtime);
197
+			$users_view->getFileInfo('files_versions/'.$filename.'.v'.$mtime);
198 198
 		}
199 199
 	}
200 200
 
@@ -238,14 +238,14 @@  discard block
 block discarded – undo
238 238
 
239 239
 		if (!Filesystem::file_exists($path)) {
240 240
 
241
-			$view = new View('/' . $uid . '/files_versions');
241
+			$view = new View('/'.$uid.'/files_versions');
242 242
 
243 243
 			$versions = self::getVersions($uid, $filename);
244 244
 			if (!empty($versions)) {
245 245
 				foreach ($versions as $v) {
246
-					\OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $path . $v['version'], 'trigger' => self::DELETE_TRIGGER_MASTER_REMOVED));
247
-					self::deleteVersion($view, $filename . '.v' . $v['version']);
248
-					\OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $path . $v['version'], 'trigger' => self::DELETE_TRIGGER_MASTER_REMOVED));
246
+					\OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $path.$v['version'], 'trigger' => self::DELETE_TRIGGER_MASTER_REMOVED));
247
+					self::deleteVersion($view, $filename.'.v'.$v['version']);
248
+					\OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $path.$v['version'], 'trigger' => self::DELETE_TRIGGER_MASTER_REMOVED));
249 249
 				}
250 250
 			}
251 251
 		}
@@ -279,33 +279,33 @@  discard block
 block discarded – undo
279 279
 		$rootView = new View('');
280 280
 
281 281
 		// did we move a directory ?
282
-		if ($rootView->is_dir('/' . $targetOwner . '/files/' . $targetPath)) {
282
+		if ($rootView->is_dir('/'.$targetOwner.'/files/'.$targetPath)) {
283 283
 			// does the directory exists for versions too ?
284
-			if ($rootView->is_dir('/' . $sourceOwner . '/files_versions/' . $sourcePath)) {
284
+			if ($rootView->is_dir('/'.$sourceOwner.'/files_versions/'.$sourcePath)) {
285 285
 				// create missing dirs if necessary
286
-				self::createMissingDirectories($targetPath, new View('/'. $targetOwner));
286
+				self::createMissingDirectories($targetPath, new View('/'.$targetOwner));
287 287
 
288 288
 				// move the directory containing the versions
289 289
 				$rootView->$operation(
290
-					'/' . $sourceOwner . '/files_versions/' . $sourcePath,
291
-					'/' . $targetOwner . '/files_versions/' . $targetPath
290
+					'/'.$sourceOwner.'/files_versions/'.$sourcePath,
291
+					'/'.$targetOwner.'/files_versions/'.$targetPath
292 292
 				);
293 293
 			}
294
-		} else if ($versions = Storage::getVersions($sourceOwner, '/' . $sourcePath)) {
294
+		} else if ($versions = Storage::getVersions($sourceOwner, '/'.$sourcePath)) {
295 295
 			// create missing dirs if necessary
296
-			self::createMissingDirectories($targetPath, new View('/'. $targetOwner));
296
+			self::createMissingDirectories($targetPath, new View('/'.$targetOwner));
297 297
 
298 298
 			foreach ($versions as $v) {
299 299
 				// move each version one by one to the target directory
300 300
 				$rootView->$operation(
301
-					'/' . $sourceOwner . '/files_versions/' . $sourcePath.'.v' . $v['version'],
302
-					'/' . $targetOwner . '/files_versions/' . $targetPath.'.v'.$v['version']
301
+					'/'.$sourceOwner.'/files_versions/'.$sourcePath.'.v'.$v['version'],
302
+					'/'.$targetOwner.'/files_versions/'.$targetPath.'.v'.$v['version']
303 303
 				);
304 304
 			}
305 305
 		}
306 306
 
307 307
 		// if we moved versions directly for a file, schedule expiration check for that file
308
-		if (!$rootView->is_dir('/' . $targetOwner . '/files/' . $targetPath)) {
308
+		if (!$rootView->is_dir('/'.$targetOwner.'/files/'.$targetPath)) {
309 309
 			self::scheduleExpire($targetOwner, $targetPath);
310 310
 		}
311 311
 
@@ -320,16 +320,16 @@  discard block
 block discarded – undo
320 320
 	 */
321 321
 	public static function rollback($file, $revision) {
322 322
 
323
-		if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
323
+		if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') {
324 324
 			// add expected leading slash
325
-			$file = '/' . ltrim($file, '/');
325
+			$file = '/'.ltrim($file, '/');
326 326
 			list($uid, $filename) = self::getUidAndFilename($file);
327 327
 			if ($uid === null || trim($filename, '/') === '') {
328 328
 				return false;
329 329
 			}
330 330
 
331 331
 			$users_view = new View('/'.$uid);
332
-			$files_view = new View('/'. User::getUser().'/files');
332
+			$files_view = new View('/'.User::getUser().'/files');
333 333
 
334 334
 			$versionCreated = false;
335 335
 
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 				$versionCreated = true;
348 348
 			}
349 349
 
350
-			$fileToRestore =  'files_versions' . $filename . '.v' . $revision;
350
+			$fileToRestore = 'files_versions'.$filename.'.v'.$revision;
351 351
 
352 352
 			// Restore encrypted version of the old file for the newly restored file
353 353
 			// This has to happen manually here since the file is manually copied below
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 			);
364 364
 
365 365
 			// rollback
366
-			if (self::copyFileContents($users_view, $fileToRestore, 'files' . $filename)) {
366
+			if (self::copyFileContents($users_view, $fileToRestore, 'files'.$filename)) {
367 367
 				$files_view->touch($file, $revision);
368 368
 				Storage::scheduleExpire($uid, $file);
369 369
 				\OC_Hook::emit('\OCP\Versions', 'rollback', array(
@@ -431,12 +431,12 @@  discard block
 block discarded – undo
431 431
 			return $versions;
432 432
 		}
433 433
 		// fetch for old versions
434
-		$view = new View('/' . $uid . '/');
434
+		$view = new View('/'.$uid.'/');
435 435
 
436 436
 		$pathinfo = pathinfo($filename);
437 437
 		$versionedFile = $pathinfo['basename'];
438 438
 
439
-		$dir = Filesystem::normalizePath(self::VERSIONS_ROOT . '/' . $pathinfo['dirname']);
439
+		$dir = Filesystem::normalizePath(self::VERSIONS_ROOT.'/'.$pathinfo['dirname']);
440 440
 
441 441
 		$dirContent = false;
442 442
 		if ($view->is_dir($dir)) {
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 						$pathparts = pathinfo($entryName);
457 457
 						$timestamp = substr($pathparts['extension'], 1);
458 458
 						$filename = $pathparts['filename'];
459
-						$key = $timestamp . '#' . $filename;
459
+						$key = $timestamp.'#'.$filename;
460 460
 						$versions[$key]['version'] = $timestamp;
461 461
 						$versions[$key]['humanReadableTimestamp'] = self::getHumanReadableTimestamp($timestamp);
462 462
 						if (empty($userFullPath)) {
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
 						} else {
465 465
 							$versions[$key]['preview'] = \OC::$server->getURLGenerator('files_version.Preview.getPreview', ['file' => $userFullPath, 'version' => $timestamp]);
466 466
 						}
467
-						$versions[$key]['path'] = Filesystem::normalizePath($pathinfo['dirname'] . '/' . $filename);
467
+						$versions[$key]['path'] = Filesystem::normalizePath($pathinfo['dirname'].'/'.$filename);
468 468
 						$versions[$key]['name'] = $versionedFile;
469
-						$versions[$key]['size'] = $view->filesize($dir . '/' . $entryName);
469
+						$versions[$key]['size'] = $view->filesize($dir.'/'.$entryName);
470 470
 						$versions[$key]['mimetype'] = \OC::$server->getMimeTypeDetector()->detectPath($versionedFile);
471 471
 					}
472 472
 				}
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 	 * Expire versions that older than max version retention time
485 485
 	 * @param string $uid
486 486
 	 */
487
-	public static function expireOlderThanMaxForUser($uid){
487
+	public static function expireOlderThanMaxForUser($uid) {
488 488
 		$expiration = self::getExpiration();
489 489
 		$threshold = $expiration->getMaxAgeAsTimestamp();
490 490
 		$versions = self::getAllVersions($uid);
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 
495 495
 		$toDelete = [];
496 496
 		foreach (array_reverse($versions['all']) as $key => $version) {
497
-			if (intval($version['version'])<$threshold) {
497
+			if (intval($version['version']) < $threshold) {
498 498
 				$toDelete[$key] = $version;
499 499
 			} else {
500 500
 				//Versions are sorted by time - nothing mo to iterate.
@@ -502,11 +502,11 @@  discard block
 block discarded – undo
502 502
 			}
503 503
 		}
504 504
 
505
-		$view = new View('/' . $uid . '/files_versions');
505
+		$view = new View('/'.$uid.'/files_versions');
506 506
 		if (!empty($toDelete)) {
507 507
 			foreach ($toDelete as $version) {
508 508
 				\OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_RETENTION_CONSTRAINT));
509
-				self::deleteVersion($view, $version['path'] . '.v' . $version['version']);
509
+				self::deleteVersion($view, $version['path'].'.v'.$version['version']);
510 510
 				\OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_RETENTION_CONSTRAINT));
511 511
 			}
512 512
 		}
@@ -522,19 +522,19 @@  discard block
 block discarded – undo
522 522
 		$diff = time() - $timestamp;
523 523
 
524 524
 		if ($diff < 60) { // first minute
525
-			return  $diff . " seconds ago";
525
+			return  $diff." seconds ago";
526 526
 		} elseif ($diff < 3600) { //first hour
527
-			return round($diff / 60) . " minutes ago";
527
+			return round($diff / 60)." minutes ago";
528 528
 		} elseif ($diff < 86400) { // first day
529
-			return round($diff / 3600) . " hours ago";
529
+			return round($diff / 3600)." hours ago";
530 530
 		} elseif ($diff < 604800) { //first week
531
-			return round($diff / 86400) . " days ago";
531
+			return round($diff / 86400)." days ago";
532 532
 		} elseif ($diff < 2419200) { //first month
533
-			return round($diff / 604800) . " weeks ago";
533
+			return round($diff / 604800)." weeks ago";
534 534
 		} elseif ($diff < 29030400) { // first year
535
-			return round($diff / 2419200) . " months ago";
535
+			return round($diff / 2419200)." months ago";
536 536
 		} else {
537
-			return round($diff / 29030400) . " years ago";
537
+			return round($diff / 29030400)." years ago";
538 538
 		}
539 539
 
540 540
 	}
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 	 * @return array with contains two arrays 'all' which contains all versions sorted by age and 'by_file' which contains all versions sorted by filename
546 546
 	 */
547 547
 	private static function getAllVersions($uid) {
548
-		$view = new View('/' . $uid . '/');
548
+		$view = new View('/'.$uid.'/');
549 549
 		$dirs = array(self::VERSIONS_ROOT);
550 550
 		$versions = array();
551 551
 
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
 
556 556
 			foreach ($files as $file) {
557 557
 				$fileData = $file->getData();
558
-				$filePath = $dir . '/' . $fileData['name'];
558
+				$filePath = $dir.'/'.$fileData['name'];
559 559
 				if ($file['type'] === 'dir') {
560 560
 					array_push($dirs, $filePath);
561 561
 				} else {
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 					$relPathStart = strlen(self::VERSIONS_ROOT);
564 564
 					$version = substr($filePath, $versionsBegin + 2);
565 565
 					$relpath = substr($filePath, $relPathStart, $versionsBegin - $relPathStart);
566
-					$key = $version . '#' . $relpath;
566
+					$key = $version.'#'.$relpath;
567 567
 					$versions[$key] = array('path' => $relpath, 'timestamp' => $version);
568 568
 				}
569 569
 			}
@@ -604,13 +604,13 @@  discard block
 block discarded – undo
604 604
 			list($toDelete, $size) = self::getAutoExpireList($time, $versions);
605 605
 		} else {
606 606
 			$size = 0;
607
-			$toDelete = [];  // versions we want to delete
607
+			$toDelete = []; // versions we want to delete
608 608
 		}
609 609
 
610 610
 		foreach ($versions as $key => $version) {
611 611
 			if ($expiration->isExpired($version['version'], $quotaExceeded) && !isset($toDelete[$key])) {
612 612
 				$size += $version['size'];
613
-				$toDelete[$key] = $version['path'] . '.v' . $version['version'];
613
+				$toDelete[$key] = $version['path'].'.v'.$version['version'];
614 614
 			}
615 615
 		}
616 616
 
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
 	 */
626 626
 	protected static function getAutoExpireList($time, $versions) {
627 627
 		$size = 0;
628
-		$toDelete = array();  // versions we want to delete
628
+		$toDelete = array(); // versions we want to delete
629 629
 
630 630
 		$interval = 1;
631 631
 		$step = Storage::$max_versions_per_interval[$interval]['step'];
@@ -647,9 +647,9 @@  discard block
 block discarded – undo
647 647
 				if ($nextInterval == -1 || $prevTimestamp > $nextInterval) {
648 648
 					if ($version['version'] > $nextVersion) {
649 649
 						//distance between two version too small, mark to delete
650
-						$toDelete[$key] = $version['path'] . '.v' . $version['version'];
650
+						$toDelete[$key] = $version['path'].'.v'.$version['version'];
651 651
 						$size += $version['size'];
652
-						\OCP\Util::writeLog('files_versions', 'Mark to expire '. $version['path'] .' next version should be ' . $nextVersion . " or smaller. (prevTimestamp: " . $prevTimestamp . "; step: " . $step, \OCP\Util::INFO);
652
+						\OCP\Util::writeLog('files_versions', 'Mark to expire '.$version['path'].' next version should be '.$nextVersion." or smaller. (prevTimestamp: ".$prevTimestamp."; step: ".$step, \OCP\Util::INFO);
653 653
 					} else {
654 654
 						$nextVersion = $version['version'] - $step;
655 655
 						$prevTimestamp = $version['version'];
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 		$config = \OC::$server->getConfig();
698 698
 		$expiration = self::getExpiration();
699 699
 
700
-		if($config->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' && $expiration->isEnabled()) {
700
+		if ($config->getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true' && $expiration->isEnabled()) {
701 701
 
702 702
 			if (!Filesystem::file_exists($filename)) {
703 703
 				return false;
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
 			$user = \OC::$server->getUserManager()->get($uid);
715 715
 			$softQuota = true;
716 716
 			$quota = $user->getQuota();
717
-			if ( $quota === null || $quota === 'none' ) {
717
+			if ($quota === null || $quota === 'none') {
718 718
 				$quota = Filesystem::free_space('/');
719 719
 				$softQuota = false;
720 720
 			} else {
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
 			// subtract size of files and current versions size from quota
729 729
 			if ($quota >= 0) {
730 730
 				if ($softQuota) {
731
-					$files_view = new View('/' . $uid . '/files');
731
+					$files_view = new View('/'.$uid.'/files');
732 732
 					$rootInfo = $files_view->getFileInfo('/', false);
733 733
 					$free = $quota - $rootInfo['size']; // remaining free space for user
734 734
 					if ($free > 0) {
@@ -765,18 +765,18 @@  discard block
 block discarded – undo
765 765
 				$versionsSize = $versionsSize - $sizeOfDeletedVersions;
766 766
 			}
767 767
 
768
-			foreach($toDelete as $key => $path) {
768
+			foreach ($toDelete as $key => $path) {
769 769
 				\OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
770 770
 				self::deleteVersion($versionsFileview, $path);
771 771
 				\OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
772 772
 				unset($allVersions[$key]); // update array with the versions we keep
773
-				\OCP\Util::writeLog('files_versions', "Expire: " . $path, \OCP\Util::INFO);
773
+				\OCP\Util::writeLog('files_versions', "Expire: ".$path, \OCP\Util::INFO);
774 774
 			}
775 775
 
776 776
 			// Check if enough space is available after versions are rearranged.
777 777
 			// If not we delete the oldest versions until we meet the size limit for versions,
778 778
 			// but always keep the two latest versions
779
-			$numOfVersions = count($allVersions) -2 ;
779
+			$numOfVersions = count($allVersions) - 2;
780 780
 			$i = 0;
781 781
 			// sort oldest first and make sure that we start at the first element
782 782
 			ksort($allVersions);
@@ -784,9 +784,9 @@  discard block
 block discarded – undo
784 784
 			while ($availableSpace < 0 && $i < $numOfVersions) {
785 785
 				$version = current($allVersions);
786 786
 				\OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
787
-				self::deleteVersion($versionsFileview, $version['path'] . '.v' . $version['version']);
787
+				self::deleteVersion($versionsFileview, $version['path'].'.v'.$version['version']);
788 788
 				\OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
789
-				\OCP\Util::writeLog('files_versions', 'running out of space! Delete oldest version: ' . $version['path'].'.v'.$version['version'] , \OCP\Util::INFO);
789
+				\OCP\Util::writeLog('files_versions', 'running out of space! Delete oldest version: '.$version['path'].'.v'.$version['version'], \OCP\Util::INFO);
790 790
 				$versionsSize -= $version['size'];
791 791
 				$availableSpace += $version['size'];
792 792
 				next($allVersions);
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
 		$dirParts = explode('/', $dirname);
813 813
 		$dir = "/files_versions";
814 814
 		foreach ($dirParts as $part) {
815
-			$dir = $dir . '/' . $part;
815
+			$dir = $dir.'/'.$part;
816 816
 			if (!$view->file_exists($dir)) {
817 817
 				$view->mkdir($dir);
818 818
 			}
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
 	 * Static workaround
824 824
 	 * @return Expiration
825 825
 	 */
826
-	protected static function getExpiration(){
826
+	protected static function getExpiration() {
827 827
 		if (is_null(self::$application)) {
828 828
 			self::$application = new Application();
829 829
 		}
Please login to merge, or discard this patch.
apps/files_versions/lib/Controller/PreviewController.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
 		$y = 44,
79 79
 		$version = ''
80 80
 	) {
81
-		if($file === '' || $version === '' || $x === 0 || $y === 0) {
81
+		if ($file === '' || $version === '' || $x === 0 || $y === 0) {
82 82
 			return new DataResponse([], Http::STATUS_BAD_REQUEST);
83 83
 		}
84 84
 
Please login to merge, or discard this patch.
apps/files_versions/lib/Command/ExpireVersions.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@
 block discarded – undo
115 115
 		\OC_Util::setupFS($user);
116 116
 
117 117
 		// Check if this user has a version directory
118
-		$view = new \OC\Files\View('/' . $user);
118
+		$view = new \OC\Files\View('/'.$user);
119 119
 		if (!$view->is_dir('/files_versions')) {
120 120
 			return false;
121 121
 		}
Please login to merge, or discard this patch.
apps/files_versions/lib/Command/CleanUp.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -107,8 +107,8 @@
 block discarded – undo
107 107
 	protected function deleteVersions($user) {
108 108
 		\OC_Util::tearDownFS();
109 109
 		\OC_Util::setupFS($user);
110
-		if ($this->rootFolder->nodeExists('/' . $user . '/files_versions')) {
111
-			$this->rootFolder->get('/' . $user . '/files_versions')->delete();
110
+		if ($this->rootFolder->nodeExists('/'.$user.'/files_versions')) {
111
+			$this->rootFolder->get('/'.$user.'/files_versions')->delete();
112 112
 		}
113 113
 	}
114 114
 
Please login to merge, or discard this patch.
apps/files_versions/lib/BackgroundJob/ExpireVersions.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@
 block discarded – undo
86 86
 		\OC_Util::setupFS($user);
87 87
 
88 88
 		// Check if this user has a versions directory
89
-		$view = new \OC\Files\View('/' . $user);
89
+		$view = new \OC\Files\View('/'.$user);
90 90
 		if (!$view->is_dir('/files_versions')) {
91 91
 			return false;
92 92
 		}
Please login to merge, or discard this patch.
apps/files_versions/lib/Hooks.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 	/**
54 54
 	 * listen to write event.
55 55
 	 */
56
-	public static function write_hook( $params ) {
56
+	public static function write_hook($params) {
57 57
 
58 58
 		if (\OCP\App::isEnabled('files_versions')) {
59 59
 			$path = $params[\OC\Files\Filesystem::signal_param_path];
60
-			if($path<>'') {
60
+			if ($path <> '') {
61 61
 				Storage::store($path);
62 62
 			}
63 63
 		}
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 
76 76
 		if (\OCP\App::isEnabled('files_versions')) {
77 77
 			$path = $params[\OC\Files\Filesystem::signal_param_path];
78
-			if($path<>'') {
78
+			if ($path <> '') {
79 79
 				Storage::delete($path);
80 80
 			}
81 81
 		}
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 */
88 88
 	public static function pre_remove_hook($params) {
89 89
 		$path = $params[\OC\Files\Filesystem::signal_param_path];
90
-			if($path<>'') {
90
+			if ($path <> '') {
91 91
 				Storage::markDeletedFile($path);
92 92
 			}
93 93
 	}
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		if (\OCP\App::isEnabled('files_versions')) {
105 105
 			$oldpath = $params['oldpath'];
106 106
 			$newpath = $params['newpath'];
107
-			if($oldpath<>'' && $newpath<>'') {
107
+			if ($oldpath <> '' && $newpath <> '') {
108 108
 				Storage::renameOrCopy($oldpath, $newpath, 'rename');
109 109
 			}
110 110
 		}
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 		if (\OCP\App::isEnabled('files_versions')) {
123 123
 			$oldpath = $params['oldpath'];
124 124
 			$newpath = $params['newpath'];
125
-			if($oldpath<>'' && $newpath<>'') {
125
+			if ($oldpath <> '' && $newpath <> '') {
126 126
 				Storage::renameOrCopy($oldpath, $newpath, 'copy');
127 127
 			}
128 128
 		}
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 
142 142
 			// if we rename a movable mount point, then the versions don't have
143 143
 			// to be renamed
144
-			$absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files' . $params['oldpath']);
144
+			$absOldPath = \OC\Files\Filesystem::normalizePath('/'.\OCP\User::getUser().'/files'.$params['oldpath']);
145 145
 			$manager = \OC\Files\Filesystem::getMountManager();
146 146
 			$mount = $manager->find($absOldPath);
147 147
 			$internalPath = $mount->getInternalPath($absOldPath);
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 				return;
150 150
 			}
151 151
 
152
-			$view = new \OC\Files\View(\OCP\User::getUser() . '/files');
152
+			$view = new \OC\Files\View(\OCP\User::getUser().'/files');
153 153
 			if ($view->file_exists($params['newpath'])) {
154 154
 				Storage::store($params['newpath']);
155 155
 			} else {
Please login to merge, or discard this patch.
apps/files_versions/lib/Expiration.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	/** @var bool */
46 46
 	private $canPurgeToSaveSpace;
47 47
 
48
-	public function __construct(IConfig $config,ITimeFactory $timeFactory){
48
+	public function __construct(IConfig $config, ITimeFactory $timeFactory) {
49 49
 		$this->timeFactory = $timeFactory;
50 50
 		$this->retentionObligation = $config->getSystemValue('versions_retention_obligation', 'auto');
51 51
 
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
 	 * Is versions expiration enabled
59 59
 	 * @return bool
60 60
 	 */
61
-	public function isEnabled(){
61
+	public function isEnabled() {
62 62
 		return $this->retentionObligation !== 'disabled';
63 63
 	}
64 64
 
65 65
 	/**
66 66
 	 * Is default expiration active
67 67
 	 */
68
-	public function shouldAutoExpire(){
68
+	public function shouldAutoExpire() {
69 69
 		return $this->minAge === self::NO_OBLIGATION
70 70
 				|| $this->maxAge === self::NO_OBLIGATION;
71 71
 	}
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 * @param bool $quotaExceeded
77 77
 	 * @return bool
78 78
 	 */
79
-	public function isExpired($timestamp, $quotaExceeded = false){
79
+	public function isExpired($timestamp, $quotaExceeded = false) {
80 80
 		// No expiration if disabled
81 81
 		if (!$this->isEnabled()) {
82 82
 			return false;
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		$time = $this->timeFactory->getTime();
91 91
 		// Never expire dates in future e.g. misconfiguration or negative time
92 92
 		// adjustment
93
-		if ($time<$timestamp) {
93
+		if ($time < $timestamp) {
94 94
 			return false;
95 95
 		}
96 96
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 * Get maximal retention obligation as a timestamp
118 118
 	 * @return int
119 119
 	 */
120
-	public function getMaxAgeAsTimestamp(){
120
+	public function getMaxAgeAsTimestamp() {
121 121
 		$maxAge = false;
122 122
 		if ($this->isEnabled() && $this->maxAge !== self::NO_OBLIGATION) {
123 123
 			$time = $this->timeFactory->getTime();
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	* Read versions_retention_obligation, validate it 
131 131
 	* and set private members accordingly
132 132
 	*/
133
-	private function parseRetentionObligation(){
133
+	private function parseRetentionObligation() {
134 134
 		$splitValues = explode(',', $this->retentionObligation);
135 135
 		if (!isset($splitValues[0])) {
136 136
 			$minValue = 'auto';
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 		if (!ctype_digit($minValue) && $minValue !== 'auto') {
150 150
 			$isValid = false;
151 151
 			\OC::$server->getLogger()->warning(
152
-					$minValue . ' is not a valid value for minimal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
152
+					$minValue.' is not a valid value for minimal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
153 153
 					['app'=>'files_versions']
154 154
 			);
155 155
 		}
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
 		if (!ctype_digit($maxValue) && $maxValue !== 'auto') {
158 158
 			$isValid = false;
159 159
 			\OC::$server->getLogger()->warning(
160
-					$maxValue . ' is not a valid value for maximal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
160
+					$maxValue.' is not a valid value for maximal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
161 161
 					['app'=>'files_versions']
162 162
 			);
163 163
 		}
164 164
 
165
-		if (!$isValid){
165
+		if (!$isValid) {
166 166
 			$minValue = 'auto';
167 167
 			$maxValue = 'auto';
168 168
 		}
Please login to merge, or discard this patch.
apps/files_versions/download.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@
 block discarded – undo
29 29
 OCP\JSON::checkLoggedIn();
30 30
 
31 31
 $file = $_GET['file'];
32
-$revision=(int)$_GET['revision'];
32
+$revision = (int) $_GET['revision'];
33 33
 
34 34
 try {
35 35
 	list($uid, $filename) = OCA\Files_Versions\Storage::getUidAndFilename($file);
36
-} catch(\OCP\Files\NotFoundException $e) {
36
+} catch (\OCP\Files\NotFoundException $e) {
37 37
 	header("HTTP/1.1 404 Not Found");
38 38
 	$tmpl = new OCP\Template('', '404', 'guest');
39 39
 	$tmpl->assign('file', '');
Please login to merge, or discard this patch.
config/config.sample.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
  *   ubos-raspberry-pi.local and ubos-raspberry-pi-2.local
68 68
  */
69 69
 'trusted_domains' =>
70
-  array (
70
+  array(
71 71
     'demo.example.org',
72 72
     'otherdomain.example.org',
73 73
   ),
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
  *
193 193
  * Defaults to ``60*60*24*15`` seconds (15 days)
194 194
  */
195
-'remember_login_cookie_lifetime' => 60*60*24*15,
195
+'remember_login_cookie_lifetime' => 60 * 60 * 24 * 15,
196 196
 
197 197
 /**
198 198
  * The lifetime of a session after inactivity.
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
  *
1119 1119
  * Defaults to ``60*60*24`` (1 day)
1120 1120
  */
1121
-'cache_chunk_gc_ttl' => 60*60*24,
1121
+'cache_chunk_gc_ttl' => 60 * 60 * 24,
1122 1122
 
1123 1123
 /**
1124 1124
  * Using Object Store with Nextcloud
@@ -1426,7 +1426,7 @@  discard block
 block discarded – undo
1426 1426
  * Defaults to ``60*60`` seconds (1 hour) or the php
1427 1427
  *             max_execution_time, whichever is higher.
1428 1428
  */
1429
-'filelocking.ttl' => 60*60,
1429
+'filelocking.ttl' => 60 * 60,
1430 1430
 
1431 1431
 /**
1432 1432
  * Memory caching backend for file locking
Please login to merge, or discard this patch.