|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Vincent Petry <[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 OCP\Files\IRootFolder; |
|
24
|
|
|
use OCP\IDBConnection; |
|
25
|
|
|
use OCP\IL10N; |
|
26
|
|
|
use OCP\ILogger; |
|
27
|
|
|
use OCP\IUserManager; |
|
28
|
|
|
use OCP\Migration\IOutput; |
|
29
|
|
|
use OCP\Migration\IRepairStep; |
|
30
|
|
|
use OCP\IUser; |
|
31
|
|
|
use OC\Avatar; |
|
32
|
|
|
use OCP\IConfig; |
|
33
|
|
|
use OCP\IAvatarManager; |
|
34
|
|
|
use OCP\Files\NotFoundException; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Move avatars outside of their homes to the new location |
|
38
|
|
|
* |
|
39
|
|
|
* @package OC\Repair |
|
40
|
|
|
*/ |
|
41
|
|
|
class MoveAvatarOutsideHome implements IRepairStep { |
|
42
|
|
|
/** @var \OCP\IConfig */ |
|
43
|
|
|
protected $config; |
|
44
|
|
|
|
|
45
|
|
|
/** @var IDBConnection */ |
|
46
|
|
|
private $connection; |
|
47
|
|
|
|
|
48
|
|
|
/** @var IUserManager */ |
|
49
|
|
|
private $userManager; |
|
50
|
|
|
|
|
51
|
|
|
/** @var IAvatarManager */ |
|
52
|
|
|
private $avatarManager; |
|
53
|
|
|
|
|
54
|
|
|
/** @var IRootFolder */ |
|
55
|
|
|
private $rootFolder; |
|
56
|
|
|
|
|
57
|
|
|
/** @var \OCP\ILogger */ |
|
58
|
|
|
private $logger; |
|
59
|
|
|
|
|
60
|
|
|
/** @var \OCP\IL10N */ |
|
61
|
|
|
private $l; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param IConfig $config config |
|
65
|
|
|
* @param IDBConnection $connection database connection |
|
66
|
|
|
* @param IUserManager $userManager user manager |
|
67
|
|
|
* @param IAvatarManager $avatarManager |
|
68
|
|
|
* @param IRootFolder $rootFolder |
|
69
|
|
|
* @param IL10N $l10n |
|
70
|
|
|
* @param ILogger $logger |
|
71
|
|
|
*/ |
|
72
|
|
View Code Duplication |
public function __construct( |
|
73
|
|
|
IConfig $config, |
|
74
|
|
|
IDBConnection $connection, |
|
75
|
|
|
IUserManager $userManager, |
|
76
|
|
|
IAvatarManager $avatarManager, |
|
77
|
|
|
IRootFolder $rootFolder, |
|
78
|
|
|
IL10N $l10n, |
|
79
|
|
|
ILogger $logger |
|
80
|
|
|
) { |
|
81
|
|
|
$this->config = $config; |
|
82
|
|
|
$this->connection = $connection; |
|
83
|
|
|
$this->userManager = $userManager; |
|
84
|
|
|
$this->avatarManager = $avatarManager; |
|
85
|
|
|
$this->rootFolder = $rootFolder; |
|
86
|
|
|
$this->l = $l10n; |
|
87
|
|
|
$this->logger = $logger; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getName() { |
|
94
|
|
|
return 'Move user avatars outside the homes to the new location'; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Move avatars outside of their homes |
|
99
|
|
|
* |
|
100
|
|
|
* @param IOutput $out |
|
101
|
|
|
* @param IUser $user |
|
102
|
|
|
*/ |
|
103
|
|
|
private function moveAvatars(IOutput $out, IUser $user) { |
|
|
|
|
|
|
104
|
|
|
$userId = $user->getUID(); |
|
105
|
|
|
|
|
106
|
|
|
\OC\Files\Filesystem::initMountPoints($userId); |
|
107
|
|
|
|
|
108
|
|
|
// call get instead of getUserFolder to avoid needless skeleton copy |
|
109
|
|
|
try { |
|
110
|
|
|
$oldAvatarUserFolder = $this->rootFolder->get('/' . $userId); |
|
111
|
|
|
$oldAvatar = new Avatar($oldAvatarUserFolder, $this->l, $user, $this->logger); |
|
|
|
|
|
|
112
|
|
|
if ($oldAvatar->exists()) { |
|
113
|
|
|
$newAvatarsUserFolder = $this->avatarManager->getAvatarFolder($userId); |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
// get original file |
|
116
|
|
|
$oldAvatarFile = $oldAvatar->getFile(-1); |
|
117
|
|
|
$oldAvatarFile->move($newAvatarsUserFolder->getPath() . '/' . $oldAvatarFile->getName()); |
|
118
|
|
|
$oldAvatar->remove(); |
|
119
|
|
|
} |
|
120
|
|
|
} catch (NotFoundException $e) { |
|
121
|
|
|
// not all users have a home, ignore |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
\OC_Util::tearDownFS(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @param IOutput $output |
|
129
|
|
|
*/ |
|
130
|
|
View Code Duplication |
public function run(IOutput $output) { |
|
131
|
|
|
$ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
132
|
|
|
if (version_compare($ocVersionFromBeforeUpdate, '9.2.0.2', '<')) { |
|
133
|
|
|
$function = function(IUser $user) use ($output) { |
|
134
|
|
|
$this->moveAvatars($output, $user); |
|
135
|
|
|
$output->advance(); |
|
136
|
|
|
}; |
|
137
|
|
|
|
|
138
|
|
|
$output->startProgress($this->userManager->countSeenUsers()); |
|
139
|
|
|
|
|
140
|
|
|
$this->userManager->callForSeenUsers($function); |
|
141
|
|
|
|
|
142
|
|
|
$output->finishProgress(); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.