Passed
Push — master ( a5191c...b6d8fc )
by John
14:28 queued 13s
created
lib/private/Repair/RepairInvalidShares.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -33,89 +33,89 @@
 block discarded – undo
33 33
  * Repairs shares with invalid data
34 34
  */
35 35
 class RepairInvalidShares implements IRepairStep {
36
-	public const CHUNK_SIZE = 200;
37
-
38
-	/** @var \OCP\IConfig */
39
-	protected $config;
40
-
41
-	/** @var \OCP\IDBConnection */
42
-	protected $connection;
43
-
44
-	/**
45
-	 * @param \OCP\IConfig $config
46
-	 * @param \OCP\IDBConnection $connection
47
-	 */
48
-	public function __construct($config, $connection) {
49
-		$this->connection = $connection;
50
-		$this->config = $config;
51
-	}
52
-
53
-	public function getName() {
54
-		return 'Repair invalid shares';
55
-	}
56
-
57
-	/**
58
-	 * Adjust file share permissions
59
-	 */
60
-	private function adjustFileSharePermissions(IOutput $out) {
61
-		$mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE;
62
-		$builder = $this->connection->getQueryBuilder();
63
-
64
-		$permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask);
65
-		$builder
66
-			->update('share')
67
-			->set('permissions', $permsFunc)
68
-			->where($builder->expr()->eq('item_type', $builder->expr()->literal('file')))
69
-			->andWhere($builder->expr()->neq('permissions', $permsFunc));
70
-
71
-		$updatedEntries = $builder->execute();
72
-		if ($updatedEntries > 0) {
73
-			$out->info('Fixed file share permissions for ' . $updatedEntries . ' shares');
74
-		}
75
-	}
76
-
77
-	/**
78
-	 * Remove shares where the parent share does not exist anymore
79
-	 */
80
-	private function removeSharesNonExistingParent(IOutput $out) {
81
-		$deletedEntries = 0;
82
-
83
-		$query = $this->connection->getQueryBuilder();
84
-		$query->select('s1.parent')
85
-			->from('share', 's1')
86
-			->where($query->expr()->isNotNull('s1.parent'))
87
-				->andWhere($query->expr()->isNull('s2.id'))
88
-			->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'))
89
-			->groupBy('s1.parent')
90
-			->setMaxResults(self::CHUNK_SIZE);
91
-
92
-		$deleteQuery = $this->connection->getQueryBuilder();
93
-		$deleteQuery->delete('share')
94
-			->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent')));
95
-
96
-		$deletedInLastChunk = self::CHUNK_SIZE;
97
-		while ($deletedInLastChunk === self::CHUNK_SIZE) {
98
-			$deletedInLastChunk = 0;
99
-			$result = $query->execute();
100
-			while ($row = $result->fetch()) {
101
-				$deletedInLastChunk++;
102
-				$deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent'])
103
-					->execute();
104
-			}
105
-			$result->closeCursor();
106
-		}
107
-
108
-		if ($deletedEntries) {
109
-			$out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist');
110
-		}
111
-	}
112
-
113
-	public function run(IOutput $out) {
114
-		$ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
115
-		if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) {
116
-			$this->adjustFileSharePermissions($out);
117
-		}
118
-
119
-		$this->removeSharesNonExistingParent($out);
120
-	}
36
+    public const CHUNK_SIZE = 200;
37
+
38
+    /** @var \OCP\IConfig */
39
+    protected $config;
40
+
41
+    /** @var \OCP\IDBConnection */
42
+    protected $connection;
43
+
44
+    /**
45
+     * @param \OCP\IConfig $config
46
+     * @param \OCP\IDBConnection $connection
47
+     */
48
+    public function __construct($config, $connection) {
49
+        $this->connection = $connection;
50
+        $this->config = $config;
51
+    }
52
+
53
+    public function getName() {
54
+        return 'Repair invalid shares';
55
+    }
56
+
57
+    /**
58
+     * Adjust file share permissions
59
+     */
60
+    private function adjustFileSharePermissions(IOutput $out) {
61
+        $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE;
62
+        $builder = $this->connection->getQueryBuilder();
63
+
64
+        $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask);
65
+        $builder
66
+            ->update('share')
67
+            ->set('permissions', $permsFunc)
68
+            ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file')))
69
+            ->andWhere($builder->expr()->neq('permissions', $permsFunc));
70
+
71
+        $updatedEntries = $builder->execute();
72
+        if ($updatedEntries > 0) {
73
+            $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares');
74
+        }
75
+    }
76
+
77
+    /**
78
+     * Remove shares where the parent share does not exist anymore
79
+     */
80
+    private function removeSharesNonExistingParent(IOutput $out) {
81
+        $deletedEntries = 0;
82
+
83
+        $query = $this->connection->getQueryBuilder();
84
+        $query->select('s1.parent')
85
+            ->from('share', 's1')
86
+            ->where($query->expr()->isNotNull('s1.parent'))
87
+                ->andWhere($query->expr()->isNull('s2.id'))
88
+            ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'))
89
+            ->groupBy('s1.parent')
90
+            ->setMaxResults(self::CHUNK_SIZE);
91
+
92
+        $deleteQuery = $this->connection->getQueryBuilder();
93
+        $deleteQuery->delete('share')
94
+            ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent')));
95
+
96
+        $deletedInLastChunk = self::CHUNK_SIZE;
97
+        while ($deletedInLastChunk === self::CHUNK_SIZE) {
98
+            $deletedInLastChunk = 0;
99
+            $result = $query->execute();
100
+            while ($row = $result->fetch()) {
101
+                $deletedInLastChunk++;
102
+                $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent'])
103
+                    ->execute();
104
+            }
105
+            $result->closeCursor();
106
+        }
107
+
108
+        if ($deletedEntries) {
109
+            $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist');
110
+        }
111
+    }
112
+
113
+    public function run(IOutput $out) {
114
+        $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
115
+        if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) {
116
+            $this->adjustFileSharePermissions($out);
117
+        }
118
+
119
+        $this->removeSharesNonExistingParent($out);
120
+    }
121 121
 }
Please login to merge, or discard this patch.
lib/private/Files/Cache/NullWatcher.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -24,30 +24,30 @@
 block discarded – undo
24 24
 namespace OC\Files\Cache;
25 25
 
26 26
 class NullWatcher extends Watcher {
27
-	private $policy;
27
+    private $policy;
28 28
 
29
-	public function __construct() {
30
-	}
29
+    public function __construct() {
30
+    }
31 31
 
32
-	public function setPolicy($policy) {
33
-		$this->policy = $policy;
34
-	}
32
+    public function setPolicy($policy) {
33
+        $this->policy = $policy;
34
+    }
35 35
 
36
-	public function getPolicy() {
37
-		return $this->policy;
38
-	}
36
+    public function getPolicy() {
37
+        return $this->policy;
38
+    }
39 39
 
40
-	public function checkUpdate($path, $cachedEntry = null) {
41
-		return false;
42
-	}
40
+    public function checkUpdate($path, $cachedEntry = null) {
41
+        return false;
42
+    }
43 43
 
44
-	public function update($path, $cachedData) {
45
-	}
44
+    public function update($path, $cachedData) {
45
+    }
46 46
 
47
-	public function needsUpdate($path, $cachedData) {
48
-		return false;
49
-	}
47
+    public function needsUpdate($path, $cachedData) {
48
+        return false;
49
+    }
50 50
 
51
-	public function cleanFolder($path) {
52
-	}
51
+    public function cleanFolder($path) {
52
+    }
53 53
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Check/RequestRemoteAddress.php 1 patch
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -27,146 +27,146 @@
 block discarded – undo
27 27
 
28 28
 class RequestRemoteAddress implements ICheck {
29 29
 
30
-	/** @var IL10N */
31
-	protected $l;
32
-
33
-	/** @var IRequest */
34
-	protected $request;
35
-
36
-	/**
37
-	 * @param IL10N $l
38
-	 * @param IRequest $request
39
-	 */
40
-	public function __construct(IL10N $l, IRequest $request) {
41
-		$this->l = $l;
42
-		$this->request = $request;
43
-	}
44
-
45
-	/**
46
-	 * @param string $operator
47
-	 * @param string $value
48
-	 * @return bool
49
-	 */
50
-	public function executeCheck($operator, $value) {
51
-		$actualValue = $this->request->getRemoteAddress();
52
-		$decodedValue = explode('/', $value);
53
-
54
-		if ($operator === 'matchesIPv4') {
55
-			return $this->matchIPv4($actualValue, $decodedValue[0], $decodedValue[1]);
56
-		} elseif ($operator === '!matchesIPv4') {
57
-			return !$this->matchIPv4($actualValue, $decodedValue[0], $decodedValue[1]);
58
-		} elseif ($operator === 'matchesIPv6') {
59
-			return $this->matchIPv6($actualValue, $decodedValue[0], $decodedValue[1]);
60
-		} else {
61
-			return !$this->matchIPv6($actualValue, $decodedValue[0], $decodedValue[1]);
62
-		}
63
-	}
64
-
65
-	/**
66
-	 * @param string $operator
67
-	 * @param string $value
68
-	 * @throws \UnexpectedValueException
69
-	 */
70
-	public function validateCheck($operator, $value) {
71
-		if (!in_array($operator, ['matchesIPv4', '!matchesIPv4', 'matchesIPv6', '!matchesIPv6'])) {
72
-			throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
73
-		}
74
-
75
-		$decodedValue = explode('/', $value);
76
-		if (count($decodedValue) !== 2) {
77
-			throw new \UnexpectedValueException($this->l->t('The given IP range is invalid'), 2);
78
-		}
79
-
80
-		if (in_array($operator, ['matchesIPv4', '!matchesIPv4'])) {
81
-			if (!filter_var($decodedValue[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
82
-				throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv4'), 3);
83
-			}
84
-			if ($decodedValue[1] > 32 || $decodedValue[1] <= 0) {
85
-				throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv4'), 4);
86
-			}
87
-		} else {
88
-			if (!filter_var($decodedValue[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
89
-				throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv6'), 3);
90
-			}
91
-			if ($decodedValue[1] > 128 || $decodedValue[1] <= 0) {
92
-				throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv6'), 4);
93
-			}
94
-		}
95
-	}
96
-
97
-	/**
98
-	 * Based on https://stackoverflow.com/a/594134
99
-	 * @param string $ip
100
-	 * @param string $rangeIp
101
-	 * @param int $bits
102
-	 * @return bool
103
-	 */
104
-	protected function matchIPv4($ip, $rangeIp, $bits) {
105
-		$rangeDecimal = ip2long($rangeIp);
106
-		$ipDecimal = ip2long($ip);
107
-		$mask = -1 << (32 - $bits);
108
-		return ($ipDecimal & $mask) === ($rangeDecimal & $mask);
109
-	}
110
-
111
-	/**
112
-	 * Based on https://stackoverflow.com/a/7951507
113
-	 * @param string $ip
114
-	 * @param string $rangeIp
115
-	 * @param int $bits
116
-	 * @return bool
117
-	 */
118
-	protected function matchIPv6($ip, $rangeIp, $bits) {
119
-		$ipNet = inet_pton($ip);
120
-		$binaryIp = $this->ipv6ToBits($ipNet);
121
-		$ipNetBits = substr($binaryIp, 0, $bits);
122
-
123
-		$rangeNet = inet_pton($rangeIp);
124
-		$binaryRange = $this->ipv6ToBits($rangeNet);
125
-		$rangeNetBits = substr($binaryRange, 0, $bits);
126
-
127
-		return $ipNetBits === $rangeNetBits;
128
-	}
129
-
130
-	/**
131
-	 * Based on https://stackoverflow.com/a/7951507
132
-	 * @param string $packedIp
133
-	 * @return string
134
-	 */
135
-	protected function ipv6ToBits($packedIp) {
136
-		$unpackedIp = unpack('A16', $packedIp);
137
-		$unpackedIp = str_split($unpackedIp[1]);
138
-		$binaryIp = '';
139
-		foreach ($unpackedIp as $char) {
140
-			$binaryIp .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
141
-		}
142
-		return str_pad($binaryIp, 128, '0', STR_PAD_RIGHT);
143
-	}
144
-
145
-	/**
146
-	 * returns a list of Entities the checker supports. The values must match
147
-	 * the class name of the entity.
148
-	 *
149
-	 * An empty result means the check is universally available.
150
-	 *
151
-	 * @since 18.0.0
152
-	 */
153
-	public function supportedEntities(): array {
154
-		return [];
155
-	}
156
-
157
-	/**
158
-	 * returns whether the operation can be used in the requested scope.
159
-	 *
160
-	 * Scope IDs are defined as constants in OCP\WorkflowEngine\IManager. At
161
-	 * time of writing these are SCOPE_ADMIN and SCOPE_USER.
162
-	 *
163
-	 * For possibly unknown future scopes the recommended behaviour is: if
164
-	 * user scope is permitted, the default behaviour should return `true`,
165
-	 * otherwise `false`.
166
-	 *
167
-	 * @since 18.0.0
168
-	 */
169
-	public function isAvailableForScope(int $scope): bool {
170
-		return true;
171
-	}
30
+    /** @var IL10N */
31
+    protected $l;
32
+
33
+    /** @var IRequest */
34
+    protected $request;
35
+
36
+    /**
37
+     * @param IL10N $l
38
+     * @param IRequest $request
39
+     */
40
+    public function __construct(IL10N $l, IRequest $request) {
41
+        $this->l = $l;
42
+        $this->request = $request;
43
+    }
44
+
45
+    /**
46
+     * @param string $operator
47
+     * @param string $value
48
+     * @return bool
49
+     */
50
+    public function executeCheck($operator, $value) {
51
+        $actualValue = $this->request->getRemoteAddress();
52
+        $decodedValue = explode('/', $value);
53
+
54
+        if ($operator === 'matchesIPv4') {
55
+            return $this->matchIPv4($actualValue, $decodedValue[0], $decodedValue[1]);
56
+        } elseif ($operator === '!matchesIPv4') {
57
+            return !$this->matchIPv4($actualValue, $decodedValue[0], $decodedValue[1]);
58
+        } elseif ($operator === 'matchesIPv6') {
59
+            return $this->matchIPv6($actualValue, $decodedValue[0], $decodedValue[1]);
60
+        } else {
61
+            return !$this->matchIPv6($actualValue, $decodedValue[0], $decodedValue[1]);
62
+        }
63
+    }
64
+
65
+    /**
66
+     * @param string $operator
67
+     * @param string $value
68
+     * @throws \UnexpectedValueException
69
+     */
70
+    public function validateCheck($operator, $value) {
71
+        if (!in_array($operator, ['matchesIPv4', '!matchesIPv4', 'matchesIPv6', '!matchesIPv6'])) {
72
+            throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
73
+        }
74
+
75
+        $decodedValue = explode('/', $value);
76
+        if (count($decodedValue) !== 2) {
77
+            throw new \UnexpectedValueException($this->l->t('The given IP range is invalid'), 2);
78
+        }
79
+
80
+        if (in_array($operator, ['matchesIPv4', '!matchesIPv4'])) {
81
+            if (!filter_var($decodedValue[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
82
+                throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv4'), 3);
83
+            }
84
+            if ($decodedValue[1] > 32 || $decodedValue[1] <= 0) {
85
+                throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv4'), 4);
86
+            }
87
+        } else {
88
+            if (!filter_var($decodedValue[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
89
+                throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv6'), 3);
90
+            }
91
+            if ($decodedValue[1] > 128 || $decodedValue[1] <= 0) {
92
+                throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv6'), 4);
93
+            }
94
+        }
95
+    }
96
+
97
+    /**
98
+     * Based on https://stackoverflow.com/a/594134
99
+     * @param string $ip
100
+     * @param string $rangeIp
101
+     * @param int $bits
102
+     * @return bool
103
+     */
104
+    protected function matchIPv4($ip, $rangeIp, $bits) {
105
+        $rangeDecimal = ip2long($rangeIp);
106
+        $ipDecimal = ip2long($ip);
107
+        $mask = -1 << (32 - $bits);
108
+        return ($ipDecimal & $mask) === ($rangeDecimal & $mask);
109
+    }
110
+
111
+    /**
112
+     * Based on https://stackoverflow.com/a/7951507
113
+     * @param string $ip
114
+     * @param string $rangeIp
115
+     * @param int $bits
116
+     * @return bool
117
+     */
118
+    protected function matchIPv6($ip, $rangeIp, $bits) {
119
+        $ipNet = inet_pton($ip);
120
+        $binaryIp = $this->ipv6ToBits($ipNet);
121
+        $ipNetBits = substr($binaryIp, 0, $bits);
122
+
123
+        $rangeNet = inet_pton($rangeIp);
124
+        $binaryRange = $this->ipv6ToBits($rangeNet);
125
+        $rangeNetBits = substr($binaryRange, 0, $bits);
126
+
127
+        return $ipNetBits === $rangeNetBits;
128
+    }
129
+
130
+    /**
131
+     * Based on https://stackoverflow.com/a/7951507
132
+     * @param string $packedIp
133
+     * @return string
134
+     */
135
+    protected function ipv6ToBits($packedIp) {
136
+        $unpackedIp = unpack('A16', $packedIp);
137
+        $unpackedIp = str_split($unpackedIp[1]);
138
+        $binaryIp = '';
139
+        foreach ($unpackedIp as $char) {
140
+            $binaryIp .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
141
+        }
142
+        return str_pad($binaryIp, 128, '0', STR_PAD_RIGHT);
143
+    }
144
+
145
+    /**
146
+     * returns a list of Entities the checker supports. The values must match
147
+     * the class name of the entity.
148
+     *
149
+     * An empty result means the check is universally available.
150
+     *
151
+     * @since 18.0.0
152
+     */
153
+    public function supportedEntities(): array {
154
+        return [];
155
+    }
156
+
157
+    /**
158
+     * returns whether the operation can be used in the requested scope.
159
+     *
160
+     * Scope IDs are defined as constants in OCP\WorkflowEngine\IManager. At
161
+     * time of writing these are SCOPE_ADMIN and SCOPE_USER.
162
+     *
163
+     * For possibly unknown future scopes the recommended behaviour is: if
164
+     * user scope is permitted, the default behaviour should return `true`,
165
+     * otherwise `false`.
166
+     *
167
+     * @since 18.0.0
168
+     */
169
+    public function isAvailableForScope(int $scope): bool {
170
+        return true;
171
+    }
172 172
 }
Please login to merge, or discard this patch.
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/systemtags/lib/Activity/Listener.php 1 patch
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -44,224 +44,224 @@
 block discarded – undo
44 44
 use OCP\SystemTag\TagNotFoundException;
45 45
 
46 46
 class Listener {
47
-	/** @var IGroupManager */
48
-	protected $groupManager;
49
-	/** @var IManager */
50
-	protected $activityManager;
51
-	/** @var IUserSession */
52
-	protected $session;
53
-	/** @var IConfig */
54
-	protected $config;
55
-	/** @var \OCP\SystemTag\ISystemTagManager */
56
-	protected $tagManager;
57
-	/** @var \OCP\App\IAppManager */
58
-	protected $appManager;
59
-	/** @var \OCP\Files\Config\IMountProviderCollection */
60
-	protected $mountCollection;
61
-	/** @var \OCP\Files\IRootFolder */
62
-	protected $rootFolder;
63
-	/** @var IShareHelper */
64
-	protected $shareHelper;
47
+    /** @var IGroupManager */
48
+    protected $groupManager;
49
+    /** @var IManager */
50
+    protected $activityManager;
51
+    /** @var IUserSession */
52
+    protected $session;
53
+    /** @var IConfig */
54
+    protected $config;
55
+    /** @var \OCP\SystemTag\ISystemTagManager */
56
+    protected $tagManager;
57
+    /** @var \OCP\App\IAppManager */
58
+    protected $appManager;
59
+    /** @var \OCP\Files\Config\IMountProviderCollection */
60
+    protected $mountCollection;
61
+    /** @var \OCP\Files\IRootFolder */
62
+    protected $rootFolder;
63
+    /** @var IShareHelper */
64
+    protected $shareHelper;
65 65
 
66
-	/**
67
-	 * Listener constructor.
68
-	 *
69
-	 * @param IGroupManager $groupManager
70
-	 * @param IManager $activityManager
71
-	 * @param IUserSession $session
72
-	 * @param IConfig $config
73
-	 * @param ISystemTagManager $tagManager
74
-	 * @param IAppManager $appManager
75
-	 * @param IMountProviderCollection $mountCollection
76
-	 * @param IRootFolder $rootFolder
77
-	 * @param IShareHelper $shareHelper
78
-	 */
79
-	public function __construct(IGroupManager $groupManager,
80
-								IManager $activityManager,
81
-								IUserSession $session,
82
-								IConfig $config,
83
-								ISystemTagManager $tagManager,
84
-								IAppManager $appManager,
85
-								IMountProviderCollection $mountCollection,
86
-								IRootFolder $rootFolder,
87
-								IShareHelper $shareHelper) {
88
-		$this->groupManager = $groupManager;
89
-		$this->activityManager = $activityManager;
90
-		$this->session = $session;
91
-		$this->config = $config;
92
-		$this->tagManager = $tagManager;
93
-		$this->appManager = $appManager;
94
-		$this->mountCollection = $mountCollection;
95
-		$this->rootFolder = $rootFolder;
96
-		$this->shareHelper = $shareHelper;
97
-	}
66
+    /**
67
+     * Listener constructor.
68
+     *
69
+     * @param IGroupManager $groupManager
70
+     * @param IManager $activityManager
71
+     * @param IUserSession $session
72
+     * @param IConfig $config
73
+     * @param ISystemTagManager $tagManager
74
+     * @param IAppManager $appManager
75
+     * @param IMountProviderCollection $mountCollection
76
+     * @param IRootFolder $rootFolder
77
+     * @param IShareHelper $shareHelper
78
+     */
79
+    public function __construct(IGroupManager $groupManager,
80
+                                IManager $activityManager,
81
+                                IUserSession $session,
82
+                                IConfig $config,
83
+                                ISystemTagManager $tagManager,
84
+                                IAppManager $appManager,
85
+                                IMountProviderCollection $mountCollection,
86
+                                IRootFolder $rootFolder,
87
+                                IShareHelper $shareHelper) {
88
+        $this->groupManager = $groupManager;
89
+        $this->activityManager = $activityManager;
90
+        $this->session = $session;
91
+        $this->config = $config;
92
+        $this->tagManager = $tagManager;
93
+        $this->appManager = $appManager;
94
+        $this->mountCollection = $mountCollection;
95
+        $this->rootFolder = $rootFolder;
96
+        $this->shareHelper = $shareHelper;
97
+    }
98 98
 
99
-	/**
100
-	 * @param ManagerEvent $event
101
-	 */
102
-	public function event(ManagerEvent $event) {
103
-		$actor = $this->session->getUser();
104
-		if ($actor instanceof IUser) {
105
-			$actor = $actor->getUID();
106
-		} else {
107
-			$actor = '';
108
-		}
109
-		$tag = $event->getTag();
99
+    /**
100
+     * @param ManagerEvent $event
101
+     */
102
+    public function event(ManagerEvent $event) {
103
+        $actor = $this->session->getUser();
104
+        if ($actor instanceof IUser) {
105
+            $actor = $actor->getUID();
106
+        } else {
107
+            $actor = '';
108
+        }
109
+        $tag = $event->getTag();
110 110
 
111
-		$activity = $this->activityManager->generateEvent();
112
-		$activity->setApp('systemtags')
113
-			->setType('systemtags')
114
-			->setAuthor($actor)
115
-			->setObject('systemtag', (int)$tag->getId(), $tag->getName());
116
-		if ($event->getEvent() === ManagerEvent::EVENT_CREATE) {
117
-			$activity->setSubject(Provider::CREATE_TAG, [
118
-				$actor,
119
-				$this->prepareTagAsParameter($event->getTag()),
120
-			]);
121
-		} elseif ($event->getEvent() === ManagerEvent::EVENT_UPDATE) {
122
-			$activity->setSubject(Provider::UPDATE_TAG, [
123
-				$actor,
124
-				$this->prepareTagAsParameter($event->getTag()),
125
-				$this->prepareTagAsParameter($event->getTagBefore()),
126
-			]);
127
-		} elseif ($event->getEvent() === ManagerEvent::EVENT_DELETE) {
128
-			$activity->setSubject(Provider::DELETE_TAG, [
129
-				$actor,
130
-				$this->prepareTagAsParameter($event->getTag()),
131
-			]);
132
-		} else {
133
-			return;
134
-		}
111
+        $activity = $this->activityManager->generateEvent();
112
+        $activity->setApp('systemtags')
113
+            ->setType('systemtags')
114
+            ->setAuthor($actor)
115
+            ->setObject('systemtag', (int)$tag->getId(), $tag->getName());
116
+        if ($event->getEvent() === ManagerEvent::EVENT_CREATE) {
117
+            $activity->setSubject(Provider::CREATE_TAG, [
118
+                $actor,
119
+                $this->prepareTagAsParameter($event->getTag()),
120
+            ]);
121
+        } elseif ($event->getEvent() === ManagerEvent::EVENT_UPDATE) {
122
+            $activity->setSubject(Provider::UPDATE_TAG, [
123
+                $actor,
124
+                $this->prepareTagAsParameter($event->getTag()),
125
+                $this->prepareTagAsParameter($event->getTagBefore()),
126
+            ]);
127
+        } elseif ($event->getEvent() === ManagerEvent::EVENT_DELETE) {
128
+            $activity->setSubject(Provider::DELETE_TAG, [
129
+                $actor,
130
+                $this->prepareTagAsParameter($event->getTag()),
131
+            ]);
132
+        } else {
133
+            return;
134
+        }
135 135
 
136
-		$group = $this->groupManager->get('admin');
137
-		if ($group instanceof IGroup) {
138
-			foreach ($group->getUsers() as $user) {
139
-				$activity->setAffectedUser($user->getUID());
140
-				$this->activityManager->publish($activity);
141
-			}
142
-		}
136
+        $group = $this->groupManager->get('admin');
137
+        if ($group instanceof IGroup) {
138
+            foreach ($group->getUsers() as $user) {
139
+                $activity->setAffectedUser($user->getUID());
140
+                $this->activityManager->publish($activity);
141
+            }
142
+        }
143 143
 
144 144
 
145
-		if ($actor !== '' && ($event->getEvent() === ManagerEvent::EVENT_CREATE || $event->getEvent() === ManagerEvent::EVENT_UPDATE)) {
146
-			$this->updateLastUsedTags($actor, $event->getTag());
147
-		}
148
-	}
145
+        if ($actor !== '' && ($event->getEvent() === ManagerEvent::EVENT_CREATE || $event->getEvent() === ManagerEvent::EVENT_UPDATE)) {
146
+            $this->updateLastUsedTags($actor, $event->getTag());
147
+        }
148
+    }
149 149
 
150
-	/**
151
-	 * @param MapperEvent $event
152
-	 */
153
-	public function mapperEvent(MapperEvent $event) {
154
-		$tagIds = $event->getTags();
155
-		if ($event->getObjectType() !== 'files' || empty($tagIds)
156
-			|| !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN])
157
-			|| !$this->appManager->isInstalled('activity')) {
158
-			// System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy)
159
-			return;
160
-		}
150
+    /**
151
+     * @param MapperEvent $event
152
+     */
153
+    public function mapperEvent(MapperEvent $event) {
154
+        $tagIds = $event->getTags();
155
+        if ($event->getObjectType() !== 'files' || empty($tagIds)
156
+            || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN])
157
+            || !$this->appManager->isInstalled('activity')) {
158
+            // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy)
159
+            return;
160
+        }
161 161
 
162
-		try {
163
-			$tags = $this->tagManager->getTagsByIds($tagIds);
164
-		} catch (TagNotFoundException $e) {
165
-			// User assigned/unassigned a non-existing tag, ignore...
166
-			return;
167
-		}
162
+        try {
163
+            $tags = $this->tagManager->getTagsByIds($tagIds);
164
+        } catch (TagNotFoundException $e) {
165
+            // User assigned/unassigned a non-existing tag, ignore...
166
+            return;
167
+        }
168 168
 
169
-		if (empty($tags)) {
170
-			return;
171
-		}
169
+        if (empty($tags)) {
170
+            return;
171
+        }
172 172
 
173
-		// Get all mount point owners
174
-		$cache = $this->mountCollection->getMountCache();
175
-		$mounts = $cache->getMountsForFileId($event->getObjectId());
176
-		if (empty($mounts)) {
177
-			return;
178
-		}
173
+        // Get all mount point owners
174
+        $cache = $this->mountCollection->getMountCache();
175
+        $mounts = $cache->getMountsForFileId($event->getObjectId());
176
+        if (empty($mounts)) {
177
+            return;
178
+        }
179 179
 
180
-		$users = [];
181
-		foreach ($mounts as $mount) {
182
-			$owner = $mount->getUser()->getUID();
183
-			$ownerFolder = $this->rootFolder->getUserFolder($owner);
184
-			$nodes = $ownerFolder->getById($event->getObjectId());
185
-			if (!empty($nodes)) {
186
-				/** @var Node $node */
187
-				$node = array_shift($nodes);
188
-				$al = $this->shareHelper->getPathsForAccessList($node);
189
-				$users += $al['users'];
190
-			}
191
-		}
180
+        $users = [];
181
+        foreach ($mounts as $mount) {
182
+            $owner = $mount->getUser()->getUID();
183
+            $ownerFolder = $this->rootFolder->getUserFolder($owner);
184
+            $nodes = $ownerFolder->getById($event->getObjectId());
185
+            if (!empty($nodes)) {
186
+                /** @var Node $node */
187
+                $node = array_shift($nodes);
188
+                $al = $this->shareHelper->getPathsForAccessList($node);
189
+                $users += $al['users'];
190
+            }
191
+        }
192 192
 
193
-		$actor = $this->session->getUser();
194
-		if ($actor instanceof IUser) {
195
-			$actor = $actor->getUID();
196
-		} else {
197
-			$actor = '';
198
-		}
193
+        $actor = $this->session->getUser();
194
+        if ($actor instanceof IUser) {
195
+            $actor = $actor->getUID();
196
+        } else {
197
+            $actor = '';
198
+        }
199 199
 
200
-		$activity = $this->activityManager->generateEvent();
201
-		$activity->setApp('systemtags')
202
-			->setType('systemtags')
203
-			->setAuthor($actor)
204
-			->setObject($event->getObjectType(), (int) $event->getObjectId());
200
+        $activity = $this->activityManager->generateEvent();
201
+        $activity->setApp('systemtags')
202
+            ->setType('systemtags')
203
+            ->setAuthor($actor)
204
+            ->setObject($event->getObjectType(), (int) $event->getObjectId());
205 205
 
206
-		foreach ($users as $user => $path) {
207
-			$user = (string)$user; // numerical ids could be ints which are not accepted everywhere
208
-			$activity->setAffectedUser($user);
206
+        foreach ($users as $user => $path) {
207
+            $user = (string)$user; // numerical ids could be ints which are not accepted everywhere
208
+            $activity->setAffectedUser($user);
209 209
 
210
-			foreach ($tags as $tag) {
211
-				// don't publish activity for non-admins if tag is invisible
212
-				if (!$tag->isUserVisible() && !$this->groupManager->isAdmin($user)) {
213
-					continue;
214
-				}
215
-				if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) {
216
-					$activity->setSubject(Provider::ASSIGN_TAG, [
217
-						$actor,
218
-						$path,
219
-						$this->prepareTagAsParameter($tag),
220
-					]);
221
-				} elseif ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) {
222
-					$activity->setSubject(Provider::UNASSIGN_TAG, [
223
-						$actor,
224
-						$path,
225
-						$this->prepareTagAsParameter($tag),
226
-					]);
227
-				}
210
+            foreach ($tags as $tag) {
211
+                // don't publish activity for non-admins if tag is invisible
212
+                if (!$tag->isUserVisible() && !$this->groupManager->isAdmin($user)) {
213
+                    continue;
214
+                }
215
+                if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) {
216
+                    $activity->setSubject(Provider::ASSIGN_TAG, [
217
+                        $actor,
218
+                        $path,
219
+                        $this->prepareTagAsParameter($tag),
220
+                    ]);
221
+                } elseif ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) {
222
+                    $activity->setSubject(Provider::UNASSIGN_TAG, [
223
+                        $actor,
224
+                        $path,
225
+                        $this->prepareTagAsParameter($tag),
226
+                    ]);
227
+                }
228 228
 
229
-				$this->activityManager->publish($activity);
230
-			}
231
-		}
229
+                $this->activityManager->publish($activity);
230
+            }
231
+        }
232 232
 
233
-		if ($actor !== '' && $event->getEvent() === MapperEvent::EVENT_ASSIGN) {
234
-			foreach ($tags as $tag) {
235
-				$this->updateLastUsedTags($actor, $tag);
236
-			}
237
-		}
238
-	}
233
+        if ($actor !== '' && $event->getEvent() === MapperEvent::EVENT_ASSIGN) {
234
+            foreach ($tags as $tag) {
235
+                $this->updateLastUsedTags($actor, $tag);
236
+            }
237
+        }
238
+    }
239 239
 
240
-	/**
241
-	 * @param string $actor
242
-	 * @param ISystemTag $tag
243
-	 */
244
-	protected function updateLastUsedTags($actor, ISystemTag $tag) {
245
-		$lastUsedTags = $this->config->getUserValue($actor, 'systemtags', 'last_used', '[]');
246
-		$lastUsedTags = json_decode($lastUsedTags, true);
240
+    /**
241
+     * @param string $actor
242
+     * @param ISystemTag $tag
243
+     */
244
+    protected function updateLastUsedTags($actor, ISystemTag $tag) {
245
+        $lastUsedTags = $this->config->getUserValue($actor, 'systemtags', 'last_used', '[]');
246
+        $lastUsedTags = json_decode($lastUsedTags, true);
247 247
 
248
-		array_unshift($lastUsedTags, $tag->getId());
249
-		array_unique($lastUsedTags);
250
-		$lastUsedTags = array_slice($lastUsedTags, 0, 10);
248
+        array_unshift($lastUsedTags, $tag->getId());
249
+        array_unique($lastUsedTags);
250
+        $lastUsedTags = array_slice($lastUsedTags, 0, 10);
251 251
 
252
-		$this->config->setUserValue($actor, 'systemtags', 'last_used', json_encode($lastUsedTags));
253
-	}
252
+        $this->config->setUserValue($actor, 'systemtags', 'last_used', json_encode($lastUsedTags));
253
+    }
254 254
 
255
-	/**
256
-	 * @param ISystemTag $tag
257
-	 * @return string
258
-	 */
259
-	protected function prepareTagAsParameter(ISystemTag $tag) {
260
-		return json_encode([
261
-			'id' => $tag->getId(),
262
-			'name' => $tag->getName(),
263
-			'assignable' => $tag->isUserAssignable(),
264
-			'visible' => $tag->isUserVisible(),
265
-		]);
266
-	}
255
+    /**
256
+     * @param ISystemTag $tag
257
+     * @return string
258
+     */
259
+    protected function prepareTagAsParameter(ISystemTag $tag) {
260
+        return json_encode([
261
+            'id' => $tag->getId(),
262
+            'name' => $tag->getName(),
263
+            'assignable' => $tag->isUserAssignable(),
264
+            'visible' => $tag->isUserVisible(),
265
+        ]);
266
+    }
267 267
 }
Please login to merge, or discard this patch.