Passed
Push — master ( a9798a...74f31b )
by John
14:36 queued 12s
created
lib/public/User/GetQuotaEvent.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -32,41 +32,41 @@
 block discarded – undo
32 32
  * @since 20.0.0
33 33
  */
34 34
 class GetQuotaEvent extends Event {
35
-	/** @var IUser */
36
-	private $user;
37
-	/** @var string|null */
38
-	private $quota = null;
35
+    /** @var IUser */
36
+    private $user;
37
+    /** @var string|null */
38
+    private $quota = null;
39 39
 
40
-	/**
41
-	 * @since 20.0.0
42
-	 */
43
-	public function __construct(IUser $user) {
44
-		parent::__construct();
45
-		$this->user = $user;
46
-	}
40
+    /**
41
+     * @since 20.0.0
42
+     */
43
+    public function __construct(IUser $user) {
44
+        parent::__construct();
45
+        $this->user = $user;
46
+    }
47 47
 
48
-	/**
49
-	 * @since 20.0.0
50
-	 */
51
-	public function getUser(): IUser {
52
-		return $this->user;
53
-	}
48
+    /**
49
+     * @since 20.0.0
50
+     */
51
+    public function getUser(): IUser {
52
+        return $this->user;
53
+    }
54 54
 
55
-	/**
56
-	 * Get the set quota as human readable string, or null if no overwrite is set
57
-	 *
58
-	 * @since 20.0.0
59
-	 */
60
-	public function getQuota(): ?string {
61
-		return $this->quota;
62
-	}
55
+    /**
56
+     * Get the set quota as human readable string, or null if no overwrite is set
57
+     *
58
+     * @since 20.0.0
59
+     */
60
+    public function getQuota(): ?string {
61
+        return $this->quota;
62
+    }
63 63
 
64
-	/**
65
-	 * Set the quota overwrite as human readable string
66
-	 *
67
-	 * @since 20.0.0
68
-	 */
69
-	public function setQuota(string $quota): void {
70
-		$this->quota = $quota;
71
-	}
64
+    /**
65
+     * Set the quota overwrite as human readable string
66
+     *
67
+     * @since 20.0.0
68
+     */
69
+    public function setQuota(string $quota): void {
70
+        $this->quota = $quota;
71
+    }
72 72
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -40,40 +40,40 @@
 block discarded – undo
40 40
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
41 41
 
42 42
 class AdditionalScriptsMiddleware extends Middleware {
43
-	/** @var EventDispatcherInterface */
44
-	private $legacyDispatcher;
45
-	/** @var IUserSession */
46
-	private $userSession;
47
-	/** @var IEventDispatcher */
48
-	private $dispatcher;
43
+    /** @var EventDispatcherInterface */
44
+    private $legacyDispatcher;
45
+    /** @var IUserSession */
46
+    private $userSession;
47
+    /** @var IEventDispatcher */
48
+    private $dispatcher;
49 49
 
50
-	public function __construct(EventDispatcherInterface $legacyDispatcher, IUserSession $userSession, IEventDispatcher $dispatcher) {
51
-		$this->legacyDispatcher = $legacyDispatcher;
52
-		$this->userSession = $userSession;
53
-		$this->dispatcher = $dispatcher;
54
-	}
50
+    public function __construct(EventDispatcherInterface $legacyDispatcher, IUserSession $userSession, IEventDispatcher $dispatcher) {
51
+        $this->legacyDispatcher = $legacyDispatcher;
52
+        $this->userSession = $userSession;
53
+        $this->dispatcher = $dispatcher;
54
+    }
55 55
 
56
-	public function afterController($controller, $methodName, Response $response): Response {
57
-		if ($response instanceof TemplateResponse) {
58
-			if (!$controller instanceof PublicShareController) {
59
-				/*
56
+    public function afterController($controller, $methodName, Response $response): Response {
57
+        if ($response instanceof TemplateResponse) {
58
+            if (!$controller instanceof PublicShareController) {
59
+                /*
60 60
 				 * The old event was not dispatched on the public share controller as there was
61 61
 				 * OCA\Files_Sharing::loadAdditionalScripts for that. This is kept for compatibility reasons
62 62
 				 * only for the old event as this is now also included in BeforeTemplateRenderedEvent
63 63
 				 */
64
-				$this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent());
65
-			}
64
+                $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent());
65
+            }
66 66
 
67
-			if (!($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn()) {
68
-				$this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent());
69
-				$isLoggedIn = true;
70
-			} else {
71
-				$isLoggedIn = false;
72
-			}
67
+            if (!($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn()) {
68
+                $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent());
69
+                $isLoggedIn = true;
70
+            } else {
71
+                $isLoggedIn = false;
72
+            }
73 73
 
74
-			$this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response));
75
-		}
74
+            $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response));
75
+        }
76 76
 
77
-		return $response;
78
-	}
77
+        return $response;
78
+    }
79 79
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -37,32 +37,32 @@
 block discarded – undo
37 37
  * @since 20.0.0
38 38
  */
39 39
 class BeforeTemplateRenderedEvent extends Event {
40
-	/** @var bool */
41
-	private $loggedIn;
42
-	/** @var TemplateResponse */
43
-	private $response;
40
+    /** @var bool */
41
+    private $loggedIn;
42
+    /** @var TemplateResponse */
43
+    private $response;
44 44
 
45
-	/**
46
-	 * @since 20.0.0
47
-	 */
48
-	public function __construct(bool $loggedIn, TemplateResponse $response) {
49
-		parent::__construct();
45
+    /**
46
+     * @since 20.0.0
47
+     */
48
+    public function __construct(bool $loggedIn, TemplateResponse $response) {
49
+        parent::__construct();
50 50
 
51
-		$this->loggedIn = $loggedIn;
52
-		$this->response = $response;
53
-	}
51
+        $this->loggedIn = $loggedIn;
52
+        $this->response = $response;
53
+    }
54 54
 
55
-	/**
56
-	 * @since 20.0.0
57
-	 */
58
-	public function isLoggedIn(): bool {
59
-		return $this->loggedIn;
60
-	}
55
+    /**
56
+     * @since 20.0.0
57
+     */
58
+    public function isLoggedIn(): bool {
59
+        return $this->loggedIn;
60
+    }
61 61
 
62
-	/**
63
-	 * @since 20.0.0
64
-	 */
65
-	public function getResponse(): TemplateResponse {
66
-		return $this->response;
67
-	}
62
+    /**
63
+     * @since 20.0.0
64
+     */
65
+    public function getResponse(): TemplateResponse {
66
+        return $this->response;
67
+    }
68 68
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Helper.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -36,95 +36,95 @@
 block discarded – undo
36 36
 use OCP\Files\Cache\ICacheEntry;
37 37
 
38 38
 class Helper {
39
-	/**
40
-	 * Retrieves the contents of a trash bin directory.
41
-	 *
42
-	 * @param string $dir path to the directory inside the trashbin
43
-	 * or empty to retrieve the root of the trashbin
44
-	 * @param string $user
45
-	 * @param string $sortAttribute attribute to sort on or empty to disable sorting
46
-	 * @param bool $sortDescending true for descending sort, false otherwise
47
-	 * @return \OCP\Files\FileInfo[]
48
-	 */
49
-	public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) {
50
-		$result = [];
51
-		$timestamp = null;
39
+    /**
40
+     * Retrieves the contents of a trash bin directory.
41
+     *
42
+     * @param string $dir path to the directory inside the trashbin
43
+     * or empty to retrieve the root of the trashbin
44
+     * @param string $user
45
+     * @param string $sortAttribute attribute to sort on or empty to disable sorting
46
+     * @param bool $sortDescending true for descending sort, false otherwise
47
+     * @return \OCP\Files\FileInfo[]
48
+     */
49
+    public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) {
50
+        $result = [];
51
+        $timestamp = null;
52 52
 
53
-		$view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
53
+        $view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
54 54
 
55
-		if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
56
-			throw new \Exception('Directory does not exists');
57
-		}
55
+        if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
56
+            throw new \Exception('Directory does not exists');
57
+        }
58 58
 
59
-		$mount = $view->getMount($dir);
60
-		$storage = $mount->getStorage();
61
-		$absoluteDir = $view->getAbsolutePath($dir);
62
-		$internalPath = $mount->getInternalPath($absoluteDir);
59
+        $mount = $view->getMount($dir);
60
+        $storage = $mount->getStorage();
61
+        $absoluteDir = $view->getAbsolutePath($dir);
62
+        $internalPath = $mount->getInternalPath($absoluteDir);
63 63
 
64
-		$originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user);
65
-		$dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir)));
66
-		foreach ($dirContent as $entry) {
67
-			$entryName = $entry->getName();
68
-			$name = $entryName;
69
-			if ($dir === '' || $dir === '/') {
70
-				$pathparts = pathinfo($entryName);
71
-				$timestamp = substr($pathparts['extension'], 1);
72
-				$name = $pathparts['filename'];
73
-			} elseif ($timestamp === null) {
74
-				// for subfolders we need to calculate the timestamp only once
75
-				$parts = explode('/', ltrim($dir, '/'));
76
-				$timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
77
-			}
78
-			$originalPath = '';
79
-			$originalName = substr($entryName, 0, -strlen($timestamp) - 2);
80
-			if (isset($originalLocations[$originalName][$timestamp])) {
81
-				$originalPath = $originalLocations[$originalName][$timestamp];
82
-				if (substr($originalPath, -1) === '/') {
83
-					$originalPath = substr($originalPath, 0, -1);
84
-				}
85
-			}
86
-			$type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file';
87
-			$i = [
88
-				'name' => $name,
89
-				'mtime' => $timestamp,
90
-				'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name),
91
-				'type' => $type,
92
-				'directory' => ($dir === '/') ? '' : $dir,
93
-				'size' => $entry->getSize(),
94
-				'etag' => '',
95
-				'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
96
-				'fileid' => $entry->getId(),
97
-			];
98
-			if ($originalPath) {
99
-				if ($originalPath !== '.') {
100
-					$i['extraData'] = $originalPath . '/' . $originalName;
101
-				} else {
102
-					$i['extraData'] = $originalName;
103
-				}
104
-			}
105
-			$result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
106
-		}
64
+        $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user);
65
+        $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir)));
66
+        foreach ($dirContent as $entry) {
67
+            $entryName = $entry->getName();
68
+            $name = $entryName;
69
+            if ($dir === '' || $dir === '/') {
70
+                $pathparts = pathinfo($entryName);
71
+                $timestamp = substr($pathparts['extension'], 1);
72
+                $name = $pathparts['filename'];
73
+            } elseif ($timestamp === null) {
74
+                // for subfolders we need to calculate the timestamp only once
75
+                $parts = explode('/', ltrim($dir, '/'));
76
+                $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
77
+            }
78
+            $originalPath = '';
79
+            $originalName = substr($entryName, 0, -strlen($timestamp) - 2);
80
+            if (isset($originalLocations[$originalName][$timestamp])) {
81
+                $originalPath = $originalLocations[$originalName][$timestamp];
82
+                if (substr($originalPath, -1) === '/') {
83
+                    $originalPath = substr($originalPath, 0, -1);
84
+                }
85
+            }
86
+            $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file';
87
+            $i = [
88
+                'name' => $name,
89
+                'mtime' => $timestamp,
90
+                'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name),
91
+                'type' => $type,
92
+                'directory' => ($dir === '/') ? '' : $dir,
93
+                'size' => $entry->getSize(),
94
+                'etag' => '',
95
+                'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
96
+                'fileid' => $entry->getId(),
97
+            ];
98
+            if ($originalPath) {
99
+                if ($originalPath !== '.') {
100
+                    $i['extraData'] = $originalPath . '/' . $originalName;
101
+                } else {
102
+                    $i['extraData'] = $originalName;
103
+                }
104
+            }
105
+            $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
106
+        }
107 107
 
108
-		if ($sortAttribute !== '') {
109
-			return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending);
110
-		}
111
-		return $result;
112
-	}
108
+        if ($sortAttribute !== '') {
109
+            return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending);
110
+        }
111
+        return $result;
112
+    }
113 113
 
114
-	/**
115
-	 * Format file infos for JSON
116
-	 *
117
-	 * @param \OCP\Files\FileInfo[] $fileInfos file infos
118
-	 */
119
-	public static function formatFileInfos($fileInfos) {
120
-		$files = [];
121
-		foreach ($fileInfos as $i) {
122
-			$entry = \OCA\Files\Helper::formatFileInfo($i);
123
-			$entry['id'] = $i->getId();
124
-			$entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image
125
-			$entry['permissions'] = \OCP\Constants::PERMISSION_READ;
126
-			$files[] = $entry;
127
-		}
128
-		return $files;
129
-	}
114
+    /**
115
+     * Format file infos for JSON
116
+     *
117
+     * @param \OCP\Files\FileInfo[] $fileInfos file infos
118
+     */
119
+    public static function formatFileInfos($fileInfos) {
120
+        $files = [];
121
+        foreach ($fileInfos as $i) {
122
+            $entry = \OCA\Files\Helper::formatFileInfo($i);
123
+            $entry['id'] = $i->getId();
124
+            $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image
125
+            $entry['permissions'] = \OCP\Constants::PERMISSION_READ;
126
+            $files[] = $entry;
127
+        }
128
+        return $files;
129
+    }
130 130
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Expiration.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -32,143 +32,143 @@
 block discarded – undo
32 32
 
33 33
 class Expiration {
34 34
 
35
-	// how long do we keep files in the trash bin if no other value is defined in the config file (unit: days)
36
-	public const DEFAULT_RETENTION_OBLIGATION = 30;
37
-	public const NO_OBLIGATION = -1;
38
-
39
-	/** @var ITimeFactory */
40
-	private $timeFactory;
41
-
42
-	/** @var string */
43
-	private $retentionObligation;
44
-
45
-	/** @var int */
46
-	private $minAge;
47
-
48
-	/** @var int */
49
-	private $maxAge;
50
-
51
-	/** @var bool */
52
-	private $canPurgeToSaveSpace;
53
-
54
-	public function __construct(IConfig $config,ITimeFactory $timeFactory) {
55
-		$this->timeFactory = $timeFactory;
56
-		$this->setRetentionObligation($config->getSystemValue('trashbin_retention_obligation', 'auto'));
57
-	}
58
-
59
-	public function setRetentionObligation(string $obligation) {
60
-		$this->retentionObligation = $obligation;
61
-
62
-		if ($this->retentionObligation !== 'disabled') {
63
-			$this->parseRetentionObligation();
64
-		}
65
-	}
66
-
67
-	/**
68
-	 * Is trashbin expiration enabled
69
-	 * @return bool
70
-	 */
71
-	public function isEnabled() {
72
-		return $this->retentionObligation !== 'disabled';
73
-	}
74
-
75
-	/**
76
-	 * Check if given timestamp in expiration range
77
-	 * @param int $timestamp
78
-	 * @param bool $quotaExceeded
79
-	 * @return bool
80
-	 */
81
-	public function isExpired($timestamp, $quotaExceeded = false) {
82
-		// No expiration if disabled
83
-		if (!$this->isEnabled()) {
84
-			return false;
85
-		}
86
-
87
-		// Purge to save space (if allowed)
88
-		if ($quotaExceeded && $this->canPurgeToSaveSpace) {
89
-			return true;
90
-		}
91
-
92
-		$time = $this->timeFactory->getTime();
93
-		// Never expire dates in future e.g. misconfiguration or negative time
94
-		// adjustment
95
-		if ($time < $timestamp) {
96
-			return false;
97
-		}
98
-
99
-		// Purge as too old
100
-		if ($this->maxAge !== self::NO_OBLIGATION) {
101
-			$maxTimestamp = $time - ($this->maxAge * 86400);
102
-			$isOlderThanMax = $timestamp < $maxTimestamp;
103
-		} else {
104
-			$isOlderThanMax = false;
105
-		}
106
-
107
-		if ($this->minAge !== self::NO_OBLIGATION) {
108
-			// older than Min obligation and we are running out of quota?
109
-			$minTimestamp = $time - ($this->minAge * 86400);
110
-			$isMinReached = ($timestamp < $minTimestamp) && $quotaExceeded;
111
-		} else {
112
-			$isMinReached = false;
113
-		}
114
-
115
-		return $isOlderThanMax || $isMinReached;
116
-	}
117
-
118
-	/**
119
-	 * @return bool|int
120
-	 */
121
-	public function getMaxAgeAsTimestamp() {
122
-		$maxAge = false;
123
-		if ($this->isEnabled() && $this->maxAge !== self::NO_OBLIGATION) {
124
-			$time = $this->timeFactory->getTime();
125
-			$maxAge = $time - ($this->maxAge * 86400);
126
-		}
127
-		return $maxAge;
128
-	}
129
-
130
-	private function parseRetentionObligation() {
131
-		$splitValues = explode(',', $this->retentionObligation);
132
-		if (!isset($splitValues[0])) {
133
-			$minValue = self::DEFAULT_RETENTION_OBLIGATION;
134
-		} else {
135
-			$minValue = trim($splitValues[0]);
136
-		}
137
-
138
-		if (!isset($splitValues[1]) && $minValue === 'auto') {
139
-			$maxValue = 'auto';
140
-		} elseif (!isset($splitValues[1])) {
141
-			$maxValue = self::DEFAULT_RETENTION_OBLIGATION;
142
-		} else {
143
-			$maxValue = trim($splitValues[1]);
144
-		}
145
-
146
-		if ($minValue === 'auto' && $maxValue === 'auto') {
147
-			// Default: Keep for 30 days but delete anytime if space needed
148
-			$this->minAge = self::DEFAULT_RETENTION_OBLIGATION;
149
-			$this->maxAge = self::NO_OBLIGATION;
150
-			$this->canPurgeToSaveSpace = true;
151
-		} elseif ($minValue !== 'auto' && $maxValue === 'auto') {
152
-			// Keep for X days but delete anytime if space needed
153
-			$this->minAge = (int)$minValue;
154
-			$this->maxAge = self::NO_OBLIGATION;
155
-			$this->canPurgeToSaveSpace = true;
156
-		} elseif ($minValue === 'auto' && $maxValue !== 'auto') {
157
-			// Delete anytime if space needed, Delete all older than max automatically
158
-			$this->minAge = self::NO_OBLIGATION;
159
-			$this->maxAge = (int)$maxValue;
160
-			$this->canPurgeToSaveSpace = true;
161
-		} elseif ($minValue !== 'auto' && $maxValue !== 'auto') {
162
-			// Delete all older than max OR older than min if space needed
163
-
164
-			// Max < Min as per https://github.com/owncloud/core/issues/16300
165
-			if ($maxValue < $minValue) {
166
-				$maxValue = $minValue;
167
-			}
168
-
169
-			$this->minAge = (int)$minValue;
170
-			$this->maxAge = (int)$maxValue;
171
-			$this->canPurgeToSaveSpace = false;
172
-		}
173
-	}
35
+    // how long do we keep files in the trash bin if no other value is defined in the config file (unit: days)
36
+    public const DEFAULT_RETENTION_OBLIGATION = 30;
37
+    public const NO_OBLIGATION = -1;
38
+
39
+    /** @var ITimeFactory */
40
+    private $timeFactory;
41
+
42
+    /** @var string */
43
+    private $retentionObligation;
44
+
45
+    /** @var int */
46
+    private $minAge;
47
+
48
+    /** @var int */
49
+    private $maxAge;
50
+
51
+    /** @var bool */
52
+    private $canPurgeToSaveSpace;
53
+
54
+    public function __construct(IConfig $config,ITimeFactory $timeFactory) {
55
+        $this->timeFactory = $timeFactory;
56
+        $this->setRetentionObligation($config->getSystemValue('trashbin_retention_obligation', 'auto'));
57
+    }
58
+
59
+    public function setRetentionObligation(string $obligation) {
60
+        $this->retentionObligation = $obligation;
61
+
62
+        if ($this->retentionObligation !== 'disabled') {
63
+            $this->parseRetentionObligation();
64
+        }
65
+    }
66
+
67
+    /**
68
+     * Is trashbin expiration enabled
69
+     * @return bool
70
+     */
71
+    public function isEnabled() {
72
+        return $this->retentionObligation !== 'disabled';
73
+    }
74
+
75
+    /**
76
+     * Check if given timestamp in expiration range
77
+     * @param int $timestamp
78
+     * @param bool $quotaExceeded
79
+     * @return bool
80
+     */
81
+    public function isExpired($timestamp, $quotaExceeded = false) {
82
+        // No expiration if disabled
83
+        if (!$this->isEnabled()) {
84
+            return false;
85
+        }
86
+
87
+        // Purge to save space (if allowed)
88
+        if ($quotaExceeded && $this->canPurgeToSaveSpace) {
89
+            return true;
90
+        }
91
+
92
+        $time = $this->timeFactory->getTime();
93
+        // Never expire dates in future e.g. misconfiguration or negative time
94
+        // adjustment
95
+        if ($time < $timestamp) {
96
+            return false;
97
+        }
98
+
99
+        // Purge as too old
100
+        if ($this->maxAge !== self::NO_OBLIGATION) {
101
+            $maxTimestamp = $time - ($this->maxAge * 86400);
102
+            $isOlderThanMax = $timestamp < $maxTimestamp;
103
+        } else {
104
+            $isOlderThanMax = false;
105
+        }
106
+
107
+        if ($this->minAge !== self::NO_OBLIGATION) {
108
+            // older than Min obligation and we are running out of quota?
109
+            $minTimestamp = $time - ($this->minAge * 86400);
110
+            $isMinReached = ($timestamp < $minTimestamp) && $quotaExceeded;
111
+        } else {
112
+            $isMinReached = false;
113
+        }
114
+
115
+        return $isOlderThanMax || $isMinReached;
116
+    }
117
+
118
+    /**
119
+     * @return bool|int
120
+     */
121
+    public function getMaxAgeAsTimestamp() {
122
+        $maxAge = false;
123
+        if ($this->isEnabled() && $this->maxAge !== self::NO_OBLIGATION) {
124
+            $time = $this->timeFactory->getTime();
125
+            $maxAge = $time - ($this->maxAge * 86400);
126
+        }
127
+        return $maxAge;
128
+    }
129
+
130
+    private function parseRetentionObligation() {
131
+        $splitValues = explode(',', $this->retentionObligation);
132
+        if (!isset($splitValues[0])) {
133
+            $minValue = self::DEFAULT_RETENTION_OBLIGATION;
134
+        } else {
135
+            $minValue = trim($splitValues[0]);
136
+        }
137
+
138
+        if (!isset($splitValues[1]) && $minValue === 'auto') {
139
+            $maxValue = 'auto';
140
+        } elseif (!isset($splitValues[1])) {
141
+            $maxValue = self::DEFAULT_RETENTION_OBLIGATION;
142
+        } else {
143
+            $maxValue = trim($splitValues[1]);
144
+        }
145
+
146
+        if ($minValue === 'auto' && $maxValue === 'auto') {
147
+            // Default: Keep for 30 days but delete anytime if space needed
148
+            $this->minAge = self::DEFAULT_RETENTION_OBLIGATION;
149
+            $this->maxAge = self::NO_OBLIGATION;
150
+            $this->canPurgeToSaveSpace = true;
151
+        } elseif ($minValue !== 'auto' && $maxValue === 'auto') {
152
+            // Keep for X days but delete anytime if space needed
153
+            $this->minAge = (int)$minValue;
154
+            $this->maxAge = self::NO_OBLIGATION;
155
+            $this->canPurgeToSaveSpace = true;
156
+        } elseif ($minValue === 'auto' && $maxValue !== 'auto') {
157
+            // Delete anytime if space needed, Delete all older than max automatically
158
+            $this->minAge = self::NO_OBLIGATION;
159
+            $this->maxAge = (int)$maxValue;
160
+            $this->canPurgeToSaveSpace = true;
161
+        } elseif ($minValue !== 'auto' && $maxValue !== 'auto') {
162
+            // Delete all older than max OR older than min if space needed
163
+
164
+            // Max < Min as per https://github.com/owncloud/core/issues/16300
165
+            if ($maxValue < $minValue) {
166
+                $maxValue = $minValue;
167
+            }
168
+
169
+            $this->minAge = (int)$minValue;
170
+            $this->maxAge = (int)$maxValue;
171
+            $this->canPurgeToSaveSpace = false;
172
+        }
173
+    }
174 174
 }
Please login to merge, or discard this patch.
apps/encryption/lib/Settings/Admin.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -40,89 +40,89 @@
 block discarded – undo
40 40
 
41 41
 class Admin implements ISettings {
42 42
 
43
-	/** @var IL10N */
44
-	private $l;
45
-
46
-	/** @var ILogger */
47
-	private $logger;
48
-
49
-	/** @var IUserSession */
50
-	private $userSession;
51
-
52
-	/** @var IConfig */
53
-	private $config;
54
-
55
-	/** @var IUserManager */
56
-	private $userManager;
57
-
58
-	/** @var ISession */
59
-	private $session;
60
-
61
-	public function __construct(
62
-		IL10N $l,
63
-		ILogger $logger,
64
-		IUserSession $userSession,
65
-		IConfig $config,
66
-		IUserManager $userManager,
67
-		ISession $session
68
-	) {
69
-		$this->l = $l;
70
-		$this->logger = $logger;
71
-		$this->userSession = $userSession;
72
-		$this->config = $config;
73
-		$this->userManager = $userManager;
74
-		$this->session = $session;
75
-	}
76
-
77
-	/**
78
-	 * @return TemplateResponse
79
-	 */
80
-	public function getForm() {
81
-		$crypt = new Crypt(
82
-			$this->logger,
83
-			$this->userSession,
84
-			$this->config,
85
-			$this->l);
86
-
87
-		$util = new Util(
88
-			new View(),
89
-			$crypt,
90
-			$this->logger,
91
-			$this->userSession,
92
-			$this->config,
93
-			$this->userManager);
94
-
95
-		// Check if an adminRecovery account is enabled for recovering files after lost pwd
96
-		$recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled', '0');
97
-		$session = new Session($this->session);
98
-
99
-		$encryptHomeStorage = $util->shouldEncryptHomeStorage();
100
-
101
-		$parameters = [
102
-			'recoveryEnabled' => $recoveryAdminEnabled,
103
-			'initStatus' => $session->getStatus(),
104
-			'encryptHomeStorage' => $encryptHomeStorage,
105
-			'masterKeyEnabled' => $util->isMasterKeyEnabled(),
106
-		];
107
-
108
-		return new TemplateResponse('encryption', 'settings-admin', $parameters, '');
109
-	}
110
-
111
-	/**
112
-	 * @return string the section ID, e.g. 'sharing'
113
-	 */
114
-	public function getSection() {
115
-		return 'security';
116
-	}
117
-
118
-	/**
119
-	 * @return int whether the form should be rather on the top or bottom of
120
-	 * the admin section. The forms are arranged in ascending order of the
121
-	 * priority values. It is required to return a value between 0 and 100.
122
-	 *
123
-	 * E.g.: 70
124
-	 */
125
-	public function getPriority() {
126
-		return 11;
127
-	}
43
+    /** @var IL10N */
44
+    private $l;
45
+
46
+    /** @var ILogger */
47
+    private $logger;
48
+
49
+    /** @var IUserSession */
50
+    private $userSession;
51
+
52
+    /** @var IConfig */
53
+    private $config;
54
+
55
+    /** @var IUserManager */
56
+    private $userManager;
57
+
58
+    /** @var ISession */
59
+    private $session;
60
+
61
+    public function __construct(
62
+        IL10N $l,
63
+        ILogger $logger,
64
+        IUserSession $userSession,
65
+        IConfig $config,
66
+        IUserManager $userManager,
67
+        ISession $session
68
+    ) {
69
+        $this->l = $l;
70
+        $this->logger = $logger;
71
+        $this->userSession = $userSession;
72
+        $this->config = $config;
73
+        $this->userManager = $userManager;
74
+        $this->session = $session;
75
+    }
76
+
77
+    /**
78
+     * @return TemplateResponse
79
+     */
80
+    public function getForm() {
81
+        $crypt = new Crypt(
82
+            $this->logger,
83
+            $this->userSession,
84
+            $this->config,
85
+            $this->l);
86
+
87
+        $util = new Util(
88
+            new View(),
89
+            $crypt,
90
+            $this->logger,
91
+            $this->userSession,
92
+            $this->config,
93
+            $this->userManager);
94
+
95
+        // Check if an adminRecovery account is enabled for recovering files after lost pwd
96
+        $recoveryAdminEnabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled', '0');
97
+        $session = new Session($this->session);
98
+
99
+        $encryptHomeStorage = $util->shouldEncryptHomeStorage();
100
+
101
+        $parameters = [
102
+            'recoveryEnabled' => $recoveryAdminEnabled,
103
+            'initStatus' => $session->getStatus(),
104
+            'encryptHomeStorage' => $encryptHomeStorage,
105
+            'masterKeyEnabled' => $util->isMasterKeyEnabled(),
106
+        ];
107
+
108
+        return new TemplateResponse('encryption', 'settings-admin', $parameters, '');
109
+    }
110
+
111
+    /**
112
+     * @return string the section ID, e.g. 'sharing'
113
+     */
114
+    public function getSection() {
115
+        return 'security';
116
+    }
117
+
118
+    /**
119
+     * @return int whether the form should be rather on the top or bottom of
120
+     * the admin section. The forms are arranged in ascending order of the
121
+     * priority values. It is required to return a value between 0 and 100.
122
+     *
123
+     * E.g.: 70
124
+     */
125
+    public function getPriority() {
126
+        return 11;
127
+    }
128 128
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Settings/Admin.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -33,64 +33,64 @@
 block discarded – undo
33 33
 
34 34
 class Admin implements ISettings {
35 35
 
36
-	/** @var IManager */
37
-	private $encryptionManager;
36
+    /** @var IManager */
37
+    private $encryptionManager;
38 38
 
39
-	/** @var GlobalStoragesService */
40
-	private $globalStoragesService;
39
+    /** @var GlobalStoragesService */
40
+    private $globalStoragesService;
41 41
 
42
-	/** @var BackendService */
43
-	private $backendService;
42
+    /** @var BackendService */
43
+    private $backendService;
44 44
 
45
-	/** @var GlobalAuth	 */
46
-	private $globalAuth;
45
+    /** @var GlobalAuth	 */
46
+    private $globalAuth;
47 47
 
48
-	public function __construct(
49
-		IManager $encryptionManager,
50
-		GlobalStoragesService $globalStoragesService,
51
-		BackendService $backendService,
52
-		GlobalAuth $globalAuth
53
-	) {
54
-		$this->encryptionManager = $encryptionManager;
55
-		$this->globalStoragesService = $globalStoragesService;
56
-		$this->backendService = $backendService;
57
-		$this->globalAuth = $globalAuth;
58
-	}
48
+    public function __construct(
49
+        IManager $encryptionManager,
50
+        GlobalStoragesService $globalStoragesService,
51
+        BackendService $backendService,
52
+        GlobalAuth $globalAuth
53
+    ) {
54
+        $this->encryptionManager = $encryptionManager;
55
+        $this->globalStoragesService = $globalStoragesService;
56
+        $this->backendService = $backendService;
57
+        $this->globalAuth = $globalAuth;
58
+    }
59 59
 
60
-	/**
61
-	 * @return TemplateResponse
62
-	 */
63
-	public function getForm() {
64
-		$parameters = [
65
-			'encryptionEnabled' => $this->encryptionManager->isEnabled(),
66
-			'visibilityType' => BackendService::VISIBILITY_ADMIN,
67
-			'storages' => $this->globalStoragesService->getStorages(),
68
-			'backends' => $this->backendService->getAvailableBackends(),
69
-			'authMechanisms' => $this->backendService->getAuthMechanisms(),
70
-			'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
71
-			'allowUserMounting' => $this->backendService->isUserMountingAllowed(),
72
-			'globalCredentials' => $this->globalAuth->getAuth(''),
73
-			'globalCredentialsUid' => '',
74
-		];
60
+    /**
61
+     * @return TemplateResponse
62
+     */
63
+    public function getForm() {
64
+        $parameters = [
65
+            'encryptionEnabled' => $this->encryptionManager->isEnabled(),
66
+            'visibilityType' => BackendService::VISIBILITY_ADMIN,
67
+            'storages' => $this->globalStoragesService->getStorages(),
68
+            'backends' => $this->backendService->getAvailableBackends(),
69
+            'authMechanisms' => $this->backendService->getAuthMechanisms(),
70
+            'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
71
+            'allowUserMounting' => $this->backendService->isUserMountingAllowed(),
72
+            'globalCredentials' => $this->globalAuth->getAuth(''),
73
+            'globalCredentialsUid' => '',
74
+        ];
75 75
 
76
-		return new TemplateResponse('files_external', 'settings', $parameters, '');
77
-	}
76
+        return new TemplateResponse('files_external', 'settings', $parameters, '');
77
+    }
78 78
 
79
-	/**
80
-	 * @return string the section ID, e.g. 'sharing'
81
-	 */
82
-	public function getSection() {
83
-		return 'externalstorages';
84
-	}
79
+    /**
80
+     * @return string the section ID, e.g. 'sharing'
81
+     */
82
+    public function getSection() {
83
+        return 'externalstorages';
84
+    }
85 85
 
86
-	/**
87
-	 * @return int whether the form should be rather on the top or bottom of
88
-	 * the admin section. The forms are arranged in ascending order of the
89
-	 * priority values. It is required to return a value between 0 and 100.
90
-	 *
91
-	 * E.g.: 70
92
-	 */
93
-	public function getPriority() {
94
-		return 40;
95
-	}
86
+    /**
87
+     * @return int whether the form should be rather on the top or bottom of
88
+     * the admin section. The forms are arranged in ascending order of the
89
+     * priority values. It is required to return a value between 0 and 100.
90
+     *
91
+     * E.g.: 70
92
+     */
93
+    public function getPriority() {
94
+        return 40;
95
+    }
96 96
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Settings/Personal.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -34,71 +34,71 @@
 block discarded – undo
34 34
 
35 35
 class Personal implements ISettings {
36 36
 
37
-	/** @var IManager */
38
-	private $encryptionManager;
37
+    /** @var IManager */
38
+    private $encryptionManager;
39 39
 
40
-	/** @var UserGlobalStoragesService */
41
-	private $userGlobalStoragesService;
40
+    /** @var UserGlobalStoragesService */
41
+    private $userGlobalStoragesService;
42 42
 
43
-	/** @var BackendService */
44
-	private $backendService;
43
+    /** @var BackendService */
44
+    private $backendService;
45 45
 
46
-	/** @var GlobalAuth	 */
47
-	private $globalAuth;
46
+    /** @var GlobalAuth	 */
47
+    private $globalAuth;
48 48
 
49
-	/** @var IUserSession */
50
-	private $userSession;
49
+    /** @var IUserSession */
50
+    private $userSession;
51 51
 
52
-	public function __construct(
53
-		IManager $encryptionManager,
54
-		UserGlobalStoragesService $userGlobalStoragesService,
55
-		BackendService $backendService,
56
-		GlobalAuth $globalAuth,
57
-		IUserSession $userSession
58
-	) {
59
-		$this->encryptionManager = $encryptionManager;
60
-		$this->userGlobalStoragesService = $userGlobalStoragesService;
61
-		$this->backendService = $backendService;
62
-		$this->globalAuth = $globalAuth;
63
-		$this->userSession = $userSession;
64
-	}
52
+    public function __construct(
53
+        IManager $encryptionManager,
54
+        UserGlobalStoragesService $userGlobalStoragesService,
55
+        BackendService $backendService,
56
+        GlobalAuth $globalAuth,
57
+        IUserSession $userSession
58
+    ) {
59
+        $this->encryptionManager = $encryptionManager;
60
+        $this->userGlobalStoragesService = $userGlobalStoragesService;
61
+        $this->backendService = $backendService;
62
+        $this->globalAuth = $globalAuth;
63
+        $this->userSession = $userSession;
64
+    }
65 65
 
66
-	/**
67
-	 * @return TemplateResponse
68
-	 */
69
-	public function getForm() {
70
-		$uid = $this->userSession->getUser()->getUID();
66
+    /**
67
+     * @return TemplateResponse
68
+     */
69
+    public function getForm() {
70
+        $uid = $this->userSession->getUser()->getUID();
71 71
 
72
-		$parameters = [
73
-			'encryptionEnabled' => $this->encryptionManager->isEnabled(),
74
-			'visibilityType' => BackendService::VISIBILITY_PERSONAL,
75
-			'storages' => $this->userGlobalStoragesService->getStorages(),
76
-			'backends' => $this->backendService->getAvailableBackends(),
77
-			'authMechanisms' => $this->backendService->getAuthMechanisms(),
78
-			'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
79
-			'allowUserMounting' => $this->backendService->isUserMountingAllowed(),
80
-			'globalCredentials' => $this->globalAuth->getAuth($uid),
81
-			'globalCredentialsUid' => $uid,
82
-		];
72
+        $parameters = [
73
+            'encryptionEnabled' => $this->encryptionManager->isEnabled(),
74
+            'visibilityType' => BackendService::VISIBILITY_PERSONAL,
75
+            'storages' => $this->userGlobalStoragesService->getStorages(),
76
+            'backends' => $this->backendService->getAvailableBackends(),
77
+            'authMechanisms' => $this->backendService->getAuthMechanisms(),
78
+            'dependencies' => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
79
+            'allowUserMounting' => $this->backendService->isUserMountingAllowed(),
80
+            'globalCredentials' => $this->globalAuth->getAuth($uid),
81
+            'globalCredentialsUid' => $uid,
82
+        ];
83 83
 
84
-		return new TemplateResponse('files_external', 'settings', $parameters, '');
85
-	}
84
+        return new TemplateResponse('files_external', 'settings', $parameters, '');
85
+    }
86 86
 
87
-	/**
88
-	 * @return string the section ID, e.g. 'sharing'
89
-	 */
90
-	public function getSection() {
91
-		return 'externalstorages';
92
-	}
87
+    /**
88
+     * @return string the section ID, e.g. 'sharing'
89
+     */
90
+    public function getSection() {
91
+        return 'externalstorages';
92
+    }
93 93
 
94
-	/**
95
-	 * @return int whether the form should be rather on the top or bottom of
96
-	 * the admin section. The forms are arranged in ascending order of the
97
-	 * priority values. It is required to return a value between 0 and 100.
98
-	 *
99
-	 * E.g.: 70
100
-	 */
101
-	public function getPriority() {
102
-		return 40;
103
-	}
94
+    /**
95
+     * @return int whether the form should be rather on the top or bottom of
96
+     * the admin section. The forms are arranged in ascending order of the
97
+     * priority values. It is required to return a value between 0 and 100.
98
+     *
99
+     * E.g.: 70
100
+     */
101
+    public function getPriority() {
102
+        return 40;
103
+    }
104 104
 }
Please login to merge, or discard this patch.
apps/updatenotification/lib/UpdateChecker.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -32,60 +32,60 @@
 block discarded – undo
32 32
 use OC\Updater\VersionCheck;
33 33
 
34 34
 class UpdateChecker {
35
-	/** @var VersionCheck */
36
-	private $updater;
37
-	/** @var ChangesCheck */
38
-	private $changesCheck;
35
+    /** @var VersionCheck */
36
+    private $updater;
37
+    /** @var ChangesCheck */
38
+    private $changesCheck;
39 39
 
40
-	/**
41
-	 * @param VersionCheck $updater
42
-	 */
43
-	public function __construct(VersionCheck $updater, ChangesCheck $changesCheck) {
44
-		$this->updater = $updater;
45
-		$this->changesCheck = $changesCheck;
46
-	}
40
+    /**
41
+     * @param VersionCheck $updater
42
+     */
43
+    public function __construct(VersionCheck $updater, ChangesCheck $changesCheck) {
44
+        $this->updater = $updater;
45
+        $this->changesCheck = $changesCheck;
46
+    }
47 47
 
48
-	/**
49
-	 * @return array
50
-	 */
51
-	public function getUpdateState(): array {
52
-		$data = $this->updater->check();
53
-		$result = [];
48
+    /**
49
+     * @return array
50
+     */
51
+    public function getUpdateState(): array {
52
+        $data = $this->updater->check();
53
+        $result = [];
54 54
 
55
-		if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
56
-			$result['updateAvailable'] = true;
57
-			$result['updateVersion'] = $data['version'];
58
-			$result['updateVersionString'] = $data['versionstring'];
59
-			$result['updaterEnabled'] = $data['autoupdater'] === '1';
60
-			$result['versionIsEol'] = $data['eol'] === '1';
61
-			if (strpos($data['web'], 'https://') === 0) {
62
-				$result['updateLink'] = $data['web'];
63
-			}
64
-			if (strpos($data['url'], 'https://') === 0) {
65
-				$result['downloadLink'] = $data['url'];
66
-			}
67
-			if (strpos($data['changes'], 'https://') === 0) {
68
-				try {
69
-					$result['changes'] = $this->changesCheck->check($data['changes'], $data['version']);
70
-				} catch (\Exception $e) {
71
-					// no info, not a problem
72
-				}
73
-			}
55
+        if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
56
+            $result['updateAvailable'] = true;
57
+            $result['updateVersion'] = $data['version'];
58
+            $result['updateVersionString'] = $data['versionstring'];
59
+            $result['updaterEnabled'] = $data['autoupdater'] === '1';
60
+            $result['versionIsEol'] = $data['eol'] === '1';
61
+            if (strpos($data['web'], 'https://') === 0) {
62
+                $result['updateLink'] = $data['web'];
63
+            }
64
+            if (strpos($data['url'], 'https://') === 0) {
65
+                $result['downloadLink'] = $data['url'];
66
+            }
67
+            if (strpos($data['changes'], 'https://') === 0) {
68
+                try {
69
+                    $result['changes'] = $this->changesCheck->check($data['changes'], $data['version']);
70
+                } catch (\Exception $e) {
71
+                    // no info, not a problem
72
+                }
73
+            }
74 74
 
75
-			return $result;
76
-		}
75
+            return $result;
76
+        }
77 77
 
78
-		return [];
79
-	}
78
+        return [];
79
+    }
80 80
 
81
-	/**
82
-	 * @param array $data
83
-	 */
84
-	public function populateJavaScriptVariables(array $data) {
85
-		$data['array']['oc_updateState'] = json_encode([
86
-			'updateAvailable' => true,
87
-			'updateVersion' => $this->getUpdateState()['updateVersionString'],
88
-			'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
89
-		]);
90
-	}
81
+    /**
82
+     * @param array $data
83
+     */
84
+    public function populateJavaScriptVariables(array $data) {
85
+        $data['array']['oc_updateState'] = json_encode([
86
+            'updateAvailable' => true,
87
+            'updateVersion' => $this->getUpdateState()['updateVersionString'],
88
+            'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
89
+        ]);
90
+    }
91 91
 }
Please login to merge, or discard this patch.