1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Roeland Jago Douma <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
6
|
|
|
* @license AGPL-3.0 |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
namespace OC\Repair; |
22
|
|
|
|
23
|
|
|
use OC\Hooks\BasicEmitter; |
24
|
|
|
use OCP\IDBConnection; |
25
|
|
|
use Doctrine\DBAL\Platforms\OraclePlatform; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Class AvatarPermissions |
29
|
|
|
* |
30
|
|
|
* @package OC\Repair |
31
|
|
|
*/ |
32
|
|
|
class AvatarPermissions extends BasicEmitter implements \OC\RepairStep { |
33
|
|
|
/** @var IDBConnection */ |
34
|
|
|
private $connection; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* AvatarPermissions constructor. |
38
|
|
|
* |
39
|
|
|
* @param IDBConnection $connection |
40
|
|
|
*/ |
41
|
|
|
public function __construct(IDBConnection $connection) { |
42
|
|
|
$this->connection = $connection; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
public function getName() { |
49
|
|
|
return 'Fix permissions so avatars can be stored again'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function run() { |
53
|
|
|
$this->fixUserRootPermissions(); |
54
|
|
|
$this->fixAvatarPermissions(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Make sure all user roots have permissions 23 (all but share) |
59
|
|
|
*/ |
60
|
|
|
protected function fixUserRootPermissions() { |
61
|
|
|
$qb = $this->connection->getQueryBuilder(); |
62
|
|
|
$qb2 = $this->connection->getQueryBuilder(); |
63
|
|
|
|
64
|
|
|
$qb->select('numeric_id') |
65
|
|
|
->from('storages') |
66
|
|
|
->where($qb->expr()->like('id', $qb2->createParameter('like'))); |
67
|
|
|
|
68
|
|
|
if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { |
|
|
|
|
69
|
|
|
// '' is null on oracle |
70
|
|
|
$path = $qb2->expr()->isNull('path'); |
71
|
|
|
} else { |
72
|
|
|
$path = $qb2->expr()->eq('path', $qb2->createNamedParameter('')); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$qb2->update('filecache') |
76
|
|
|
->set('permissions', $qb2->createNamedParameter(23)) |
77
|
|
|
->where($path) |
78
|
|
|
->andWhere($qb2->expr()->in('storage', $qb2->createFunction($qb->getSQL()))) |
79
|
|
|
->andWhere($qb2->expr()->neq('permissions', $qb2->createNamedParameter(23))) |
80
|
|
|
->setParameter('like', 'home::%'); |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
$qb2->execute(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Make sure all avatar files in the user roots have permission 27 |
88
|
|
|
*/ |
89
|
|
|
protected function fixAvatarPermissions() { |
90
|
|
|
$qb = $this->connection->getQueryBuilder(); |
91
|
|
|
$qb2 = $this->connection->getQueryBuilder(); |
92
|
|
|
|
93
|
|
|
$qb->select('numeric_id') |
94
|
|
|
->from('storages') |
95
|
|
|
->where($qb->expr()->like('id', $qb2->createParameter('like'))); |
96
|
|
|
|
97
|
|
|
$qb2->update('filecache') |
98
|
|
|
->set('permissions', $qb2->createNamedParameter(27)) |
99
|
|
|
->where($qb2->expr()->like('path', $qb2->createNamedParameter('avatar.%'))) |
100
|
|
|
->andWhere($qb2->expr()->in('storage', $qb2->createFunction($qb->getSQL()))) |
101
|
|
|
->andWhere($qb2->expr()->neq('permissions', $qb2->createNamedParameter(27))) |
102
|
|
|
->setParameter('like', 'home::%'); |
103
|
|
|
|
104
|
|
|
$qb2->execute(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.