@@ -36,64 +36,64 @@ |
||
36 | 36 | use Symfony\Component\Console\Output\OutputInterface; |
37 | 37 | |
38 | 38 | class ExiprationNotification extends Command { |
39 | - /** @var NotificationManager */ |
|
40 | - private $notificationManager; |
|
41 | - /** @var IDBConnection */ |
|
42 | - private $connection; |
|
43 | - /** @var ITimeFactory */ |
|
44 | - private $time; |
|
45 | - /** @var ShareManager */ |
|
46 | - private $shareManager; |
|
39 | + /** @var NotificationManager */ |
|
40 | + private $notificationManager; |
|
41 | + /** @var IDBConnection */ |
|
42 | + private $connection; |
|
43 | + /** @var ITimeFactory */ |
|
44 | + private $time; |
|
45 | + /** @var ShareManager */ |
|
46 | + private $shareManager; |
|
47 | 47 | |
48 | - public function __construct(ITimeFactory $time, |
|
49 | - NotificationManager $notificationManager, |
|
50 | - IDBConnection $connection, |
|
51 | - ShareManager $shareManager) { |
|
52 | - parent::__construct(); |
|
48 | + public function __construct(ITimeFactory $time, |
|
49 | + NotificationManager $notificationManager, |
|
50 | + IDBConnection $connection, |
|
51 | + ShareManager $shareManager) { |
|
52 | + parent::__construct(); |
|
53 | 53 | |
54 | - $this->notificationManager = $notificationManager; |
|
55 | - $this->connection = $connection; |
|
56 | - $this->time = $time; |
|
57 | - $this->shareManager = $shareManager; |
|
58 | - } |
|
54 | + $this->notificationManager = $notificationManager; |
|
55 | + $this->connection = $connection; |
|
56 | + $this->time = $time; |
|
57 | + $this->shareManager = $shareManager; |
|
58 | + } |
|
59 | 59 | |
60 | - protected function configure() { |
|
61 | - $this |
|
62 | - ->setName('sharing:expiration-notification') |
|
63 | - ->setDescription('Notify share initiators when a share will expire the next day.'); |
|
64 | - } |
|
60 | + protected function configure() { |
|
61 | + $this |
|
62 | + ->setName('sharing:expiration-notification') |
|
63 | + ->setDescription('Notify share initiators when a share will expire the next day.'); |
|
64 | + } |
|
65 | 65 | |
66 | - public function execute(InputInterface $input, OutputInterface $output): int { |
|
67 | - //Current time |
|
68 | - $minTime = $this->time->getDateTime(); |
|
69 | - $minTime->add(new \DateInterval('P1D')); |
|
70 | - $minTime->setTime(0,0,0); |
|
66 | + public function execute(InputInterface $input, OutputInterface $output): int { |
|
67 | + //Current time |
|
68 | + $minTime = $this->time->getDateTime(); |
|
69 | + $minTime->add(new \DateInterval('P1D')); |
|
70 | + $minTime->setTime(0,0,0); |
|
71 | 71 | |
72 | - $maxTime = clone $minTime; |
|
73 | - $maxTime->setTime(23, 59, 59); |
|
72 | + $maxTime = clone $minTime; |
|
73 | + $maxTime->setTime(23, 59, 59); |
|
74 | 74 | |
75 | - $shares = $this->shareManager->getAllShares(); |
|
75 | + $shares = $this->shareManager->getAllShares(); |
|
76 | 76 | |
77 | - $now = $this->time->getDateTime(); |
|
77 | + $now = $this->time->getDateTime(); |
|
78 | 78 | |
79 | - /** @var IShare $share */ |
|
80 | - foreach ($shares as $share) { |
|
81 | - if ($share->getExpirationDate() === null |
|
82 | - || $share->getExpirationDate()->getTimestamp() < $minTime->getTimestamp() |
|
83 | - || $share->getExpirationDate()->getTimestamp() > $maxTime->getTimestamp()) { |
|
84 | - continue; |
|
85 | - } |
|
79 | + /** @var IShare $share */ |
|
80 | + foreach ($shares as $share) { |
|
81 | + if ($share->getExpirationDate() === null |
|
82 | + || $share->getExpirationDate()->getTimestamp() < $minTime->getTimestamp() |
|
83 | + || $share->getExpirationDate()->getTimestamp() > $maxTime->getTimestamp()) { |
|
84 | + continue; |
|
85 | + } |
|
86 | 86 | |
87 | - $notification = $this->notificationManager->createNotification(); |
|
88 | - $notification->setApp('files_sharing') |
|
89 | - ->setDateTime($now) |
|
90 | - ->setObject('share', $share->getFullId()) |
|
91 | - ->setSubject('expiresTomorrow'); |
|
87 | + $notification = $this->notificationManager->createNotification(); |
|
88 | + $notification->setApp('files_sharing') |
|
89 | + ->setDateTime($now) |
|
90 | + ->setObject('share', $share->getFullId()) |
|
91 | + ->setSubject('expiresTomorrow'); |
|
92 | 92 | |
93 | - // Only send to initiator for now |
|
94 | - $notification->setUser($share->getSharedBy()); |
|
95 | - $this->notificationManager->notify($notification); |
|
96 | - } |
|
97 | - return 0; |
|
98 | - } |
|
93 | + // Only send to initiator for now |
|
94 | + $notification->setUser($share->getSharedBy()); |
|
95 | + $this->notificationManager->notify($notification); |
|
96 | + } |
|
97 | + return 0; |
|
98 | + } |
|
99 | 99 | } |
@@ -37,145 +37,145 @@ |
||
37 | 37 | */ |
38 | 38 | class CleanupRemoteStorages extends Command { |
39 | 39 | |
40 | - /** |
|
41 | - * @var IDBConnection |
|
42 | - */ |
|
43 | - protected $connection; |
|
44 | - |
|
45 | - public function __construct(IDBConnection $connection) { |
|
46 | - $this->connection = $connection; |
|
47 | - parent::__construct(); |
|
48 | - } |
|
49 | - |
|
50 | - protected function configure() { |
|
51 | - $this |
|
52 | - ->setName('sharing:cleanup-remote-storages') |
|
53 | - ->setDescription('Cleanup shared storage entries that have no matching entry in the shares_external table') |
|
54 | - ->addOption( |
|
55 | - 'dry-run', |
|
56 | - null, |
|
57 | - InputOption::VALUE_NONE, |
|
58 | - 'only show which storages would be deleted' |
|
59 | - ); |
|
60 | - } |
|
61 | - |
|
62 | - public function execute(InputInterface $input, OutputInterface $output): int { |
|
63 | - $remoteStorages = $this->getRemoteStorages(); |
|
64 | - |
|
65 | - $output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked'); |
|
66 | - |
|
67 | - $remoteShareIds = $this->getRemoteShareIds(); |
|
68 | - |
|
69 | - $output->writeln(count($remoteShareIds) . ' remote share(s) exist'); |
|
70 | - |
|
71 | - foreach ($remoteShareIds as $id => $remoteShareId) { |
|
72 | - if (isset($remoteStorages[$remoteShareId])) { |
|
73 | - if ($input->getOption('dry-run') || $output->isVerbose()) { |
|
74 | - $output->writeln("<info>$remoteShareId belongs to remote share $id</info>"); |
|
75 | - } |
|
76 | - |
|
77 | - unset($remoteStorages[$remoteShareId]); |
|
78 | - } else { |
|
79 | - $output->writeln("<comment>$remoteShareId for share $id has no matching storage, yet</comment>"); |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - if (empty($remoteStorages)) { |
|
84 | - $output->writeln('<info>no storages deleted</info>'); |
|
85 | - } else { |
|
86 | - $dryRun = $input->getOption('dry-run'); |
|
87 | - foreach ($remoteStorages as $id => $numericId) { |
|
88 | - if ($dryRun) { |
|
89 | - $output->writeln("<error>$id [$numericId] can be deleted</error>"); |
|
90 | - $this->countFiles($numericId, $output); |
|
91 | - } else { |
|
92 | - $this->deleteStorage($id, $numericId, $output); |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
96 | - return 0; |
|
97 | - } |
|
98 | - |
|
99 | - public function countFiles($numericId, OutputInterface $output) { |
|
100 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
101 | - $queryBuilder->select($queryBuilder->func()->count('fileid')) |
|
102 | - ->from('filecache') |
|
103 | - ->where($queryBuilder->expr()->eq( |
|
104 | - 'storage', |
|
105 | - $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR), |
|
106 | - IQueryBuilder::PARAM_STR) |
|
107 | - ); |
|
108 | - $result = $queryBuilder->execute(); |
|
109 | - $count = $result->fetchColumn(); |
|
110 | - $output->writeln("$count files can be deleted for storage $numericId"); |
|
111 | - } |
|
112 | - |
|
113 | - public function deleteStorage($id, $numericId, OutputInterface $output) { |
|
114 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
115 | - $queryBuilder->delete('storages') |
|
116 | - ->where($queryBuilder->expr()->eq( |
|
117 | - 'id', |
|
118 | - $queryBuilder->createNamedParameter($id, IQueryBuilder::PARAM_STR), |
|
119 | - IQueryBuilder::PARAM_STR) |
|
120 | - ); |
|
121 | - $output->write("deleting $id [$numericId] ... "); |
|
122 | - $count = $queryBuilder->execute(); |
|
123 | - $output->writeln("deleted $count storage"); |
|
124 | - $this->deleteFiles($numericId, $output); |
|
125 | - } |
|
126 | - |
|
127 | - public function deleteFiles($numericId, OutputInterface $output) { |
|
128 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
129 | - $queryBuilder->delete('filecache') |
|
130 | - ->where($queryBuilder->expr()->eq( |
|
131 | - 'storage', |
|
132 | - $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR), |
|
133 | - IQueryBuilder::PARAM_STR) |
|
134 | - ); |
|
135 | - $output->write("deleting files for storage $numericId ... "); |
|
136 | - $count = $queryBuilder->execute(); |
|
137 | - $output->writeln("deleted $count files"); |
|
138 | - } |
|
139 | - |
|
140 | - public function getRemoteStorages() { |
|
141 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
142 | - $queryBuilder->select(['id', 'numeric_id']) |
|
143 | - ->from('storages') |
|
144 | - ->where($queryBuilder->expr()->like( |
|
145 | - 'id', |
|
146 | - // match all 'shared::' + 32 characters storages |
|
147 | - $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)), |
|
148 | - IQueryBuilder::PARAM_STR) |
|
149 | - ) |
|
150 | - ->andWhere($queryBuilder->expr()->notLike( |
|
151 | - 'id', |
|
152 | - // but not the ones starting with a '/', they are for normal shares |
|
153 | - $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'), |
|
154 | - IQueryBuilder::PARAM_STR) |
|
155 | - )->orderBy('numeric_id'); |
|
156 | - $query = $queryBuilder->execute(); |
|
157 | - |
|
158 | - $remoteStorages = []; |
|
159 | - |
|
160 | - while ($row = $query->fetch()) { |
|
161 | - $remoteStorages[$row['id']] = $row['numeric_id']; |
|
162 | - } |
|
163 | - |
|
164 | - return $remoteStorages; |
|
165 | - } |
|
166 | - |
|
167 | - public function getRemoteShareIds() { |
|
168 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
169 | - $queryBuilder->select(['id', 'share_token', 'remote']) |
|
170 | - ->from('share_external'); |
|
171 | - $query = $queryBuilder->execute(); |
|
172 | - |
|
173 | - $remoteShareIds = []; |
|
174 | - |
|
175 | - while ($row = $query->fetch()) { |
|
176 | - $remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']); |
|
177 | - } |
|
178 | - |
|
179 | - return $remoteShareIds; |
|
180 | - } |
|
40 | + /** |
|
41 | + * @var IDBConnection |
|
42 | + */ |
|
43 | + protected $connection; |
|
44 | + |
|
45 | + public function __construct(IDBConnection $connection) { |
|
46 | + $this->connection = $connection; |
|
47 | + parent::__construct(); |
|
48 | + } |
|
49 | + |
|
50 | + protected function configure() { |
|
51 | + $this |
|
52 | + ->setName('sharing:cleanup-remote-storages') |
|
53 | + ->setDescription('Cleanup shared storage entries that have no matching entry in the shares_external table') |
|
54 | + ->addOption( |
|
55 | + 'dry-run', |
|
56 | + null, |
|
57 | + InputOption::VALUE_NONE, |
|
58 | + 'only show which storages would be deleted' |
|
59 | + ); |
|
60 | + } |
|
61 | + |
|
62 | + public function execute(InputInterface $input, OutputInterface $output): int { |
|
63 | + $remoteStorages = $this->getRemoteStorages(); |
|
64 | + |
|
65 | + $output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked'); |
|
66 | + |
|
67 | + $remoteShareIds = $this->getRemoteShareIds(); |
|
68 | + |
|
69 | + $output->writeln(count($remoteShareIds) . ' remote share(s) exist'); |
|
70 | + |
|
71 | + foreach ($remoteShareIds as $id => $remoteShareId) { |
|
72 | + if (isset($remoteStorages[$remoteShareId])) { |
|
73 | + if ($input->getOption('dry-run') || $output->isVerbose()) { |
|
74 | + $output->writeln("<info>$remoteShareId belongs to remote share $id</info>"); |
|
75 | + } |
|
76 | + |
|
77 | + unset($remoteStorages[$remoteShareId]); |
|
78 | + } else { |
|
79 | + $output->writeln("<comment>$remoteShareId for share $id has no matching storage, yet</comment>"); |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + if (empty($remoteStorages)) { |
|
84 | + $output->writeln('<info>no storages deleted</info>'); |
|
85 | + } else { |
|
86 | + $dryRun = $input->getOption('dry-run'); |
|
87 | + foreach ($remoteStorages as $id => $numericId) { |
|
88 | + if ($dryRun) { |
|
89 | + $output->writeln("<error>$id [$numericId] can be deleted</error>"); |
|
90 | + $this->countFiles($numericId, $output); |
|
91 | + } else { |
|
92 | + $this->deleteStorage($id, $numericId, $output); |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | + return 0; |
|
97 | + } |
|
98 | + |
|
99 | + public function countFiles($numericId, OutputInterface $output) { |
|
100 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
101 | + $queryBuilder->select($queryBuilder->func()->count('fileid')) |
|
102 | + ->from('filecache') |
|
103 | + ->where($queryBuilder->expr()->eq( |
|
104 | + 'storage', |
|
105 | + $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR), |
|
106 | + IQueryBuilder::PARAM_STR) |
|
107 | + ); |
|
108 | + $result = $queryBuilder->execute(); |
|
109 | + $count = $result->fetchColumn(); |
|
110 | + $output->writeln("$count files can be deleted for storage $numericId"); |
|
111 | + } |
|
112 | + |
|
113 | + public function deleteStorage($id, $numericId, OutputInterface $output) { |
|
114 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
115 | + $queryBuilder->delete('storages') |
|
116 | + ->where($queryBuilder->expr()->eq( |
|
117 | + 'id', |
|
118 | + $queryBuilder->createNamedParameter($id, IQueryBuilder::PARAM_STR), |
|
119 | + IQueryBuilder::PARAM_STR) |
|
120 | + ); |
|
121 | + $output->write("deleting $id [$numericId] ... "); |
|
122 | + $count = $queryBuilder->execute(); |
|
123 | + $output->writeln("deleted $count storage"); |
|
124 | + $this->deleteFiles($numericId, $output); |
|
125 | + } |
|
126 | + |
|
127 | + public function deleteFiles($numericId, OutputInterface $output) { |
|
128 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
129 | + $queryBuilder->delete('filecache') |
|
130 | + ->where($queryBuilder->expr()->eq( |
|
131 | + 'storage', |
|
132 | + $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR), |
|
133 | + IQueryBuilder::PARAM_STR) |
|
134 | + ); |
|
135 | + $output->write("deleting files for storage $numericId ... "); |
|
136 | + $count = $queryBuilder->execute(); |
|
137 | + $output->writeln("deleted $count files"); |
|
138 | + } |
|
139 | + |
|
140 | + public function getRemoteStorages() { |
|
141 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
142 | + $queryBuilder->select(['id', 'numeric_id']) |
|
143 | + ->from('storages') |
|
144 | + ->where($queryBuilder->expr()->like( |
|
145 | + 'id', |
|
146 | + // match all 'shared::' + 32 characters storages |
|
147 | + $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)), |
|
148 | + IQueryBuilder::PARAM_STR) |
|
149 | + ) |
|
150 | + ->andWhere($queryBuilder->expr()->notLike( |
|
151 | + 'id', |
|
152 | + // but not the ones starting with a '/', they are for normal shares |
|
153 | + $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'), |
|
154 | + IQueryBuilder::PARAM_STR) |
|
155 | + )->orderBy('numeric_id'); |
|
156 | + $query = $queryBuilder->execute(); |
|
157 | + |
|
158 | + $remoteStorages = []; |
|
159 | + |
|
160 | + while ($row = $query->fetch()) { |
|
161 | + $remoteStorages[$row['id']] = $row['numeric_id']; |
|
162 | + } |
|
163 | + |
|
164 | + return $remoteStorages; |
|
165 | + } |
|
166 | + |
|
167 | + public function getRemoteShareIds() { |
|
168 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
169 | + $queryBuilder->select(['id', 'share_token', 'remote']) |
|
170 | + ->from('share_external'); |
|
171 | + $query = $queryBuilder->execute(); |
|
172 | + |
|
173 | + $remoteShareIds = []; |
|
174 | + |
|
175 | + while ($row = $query->fetch()) { |
|
176 | + $remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']); |
|
177 | + } |
|
178 | + |
|
179 | + return $remoteShareIds; |
|
180 | + } |
|
181 | 181 | } |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | public function execute(InputInterface $input, OutputInterface $output): int { |
63 | 63 | $remoteStorages = $this->getRemoteStorages(); |
64 | 64 | |
65 | - $output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked'); |
|
65 | + $output->writeln(count($remoteStorages).' remote storage(s) need(s) to be checked'); |
|
66 | 66 | |
67 | 67 | $remoteShareIds = $this->getRemoteShareIds(); |
68 | 68 | |
69 | - $output->writeln(count($remoteShareIds) . ' remote share(s) exist'); |
|
69 | + $output->writeln(count($remoteShareIds).' remote share(s) exist'); |
|
70 | 70 | |
71 | 71 | foreach ($remoteShareIds as $id => $remoteShareId) { |
72 | 72 | if (isset($remoteStorages[$remoteShareId])) { |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | ->where($queryBuilder->expr()->like( |
145 | 145 | 'id', |
146 | 146 | // match all 'shared::' + 32 characters storages |
147 | - $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)), |
|
147 | + $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::').str_repeat('_', 32)), |
|
148 | 148 | IQueryBuilder::PARAM_STR) |
149 | 149 | ) |
150 | 150 | ->andWhere($queryBuilder->expr()->notLike( |
151 | 151 | 'id', |
152 | 152 | // but not the ones starting with a '/', they are for normal shares |
153 | - $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'), |
|
153 | + $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/').'%'), |
|
154 | 154 | IQueryBuilder::PARAM_STR) |
155 | 155 | )->orderBy('numeric_id'); |
156 | 156 | $query = $queryBuilder->execute(); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $remoteShareIds = []; |
174 | 174 | |
175 | 175 | while ($row = $query->fetch()) { |
176 | - $remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']); |
|
176 | + $remoteShareIds[$row['id']] = 'shared::'.md5($row['share_token'].'@'.$row['remote']); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | return $remoteShareIds; |
@@ -35,48 +35,48 @@ |
||
35 | 35 | |
36 | 36 | class Index extends Command { |
37 | 37 | |
38 | - /** @var Manager */ |
|
39 | - private $manager; |
|
38 | + /** @var Manager */ |
|
39 | + private $manager; |
|
40 | 40 | |
41 | - public function __construct(Manager $manager) { |
|
42 | - $this->manager = $manager; |
|
43 | - parent::__construct(); |
|
44 | - } |
|
41 | + public function __construct(Manager $manager) { |
|
42 | + $this->manager = $manager; |
|
43 | + parent::__construct(); |
|
44 | + } |
|
45 | 45 | |
46 | - protected function configure() { |
|
47 | - $this |
|
48 | - ->setName('workflows:list') |
|
49 | - ->setDescription('Lists configured workflows') |
|
50 | - ->addArgument( |
|
51 | - 'scope', |
|
52 | - InputArgument::OPTIONAL, |
|
53 | - 'Lists workflows for "admin", "user"', |
|
54 | - 'admin' |
|
55 | - ) |
|
56 | - ->addArgument( |
|
57 | - 'scopeId', |
|
58 | - InputArgument::OPTIONAL, |
|
59 | - 'User IDs when the scope is "user"', |
|
60 | - null |
|
61 | - ); |
|
62 | - } |
|
46 | + protected function configure() { |
|
47 | + $this |
|
48 | + ->setName('workflows:list') |
|
49 | + ->setDescription('Lists configured workflows') |
|
50 | + ->addArgument( |
|
51 | + 'scope', |
|
52 | + InputArgument::OPTIONAL, |
|
53 | + 'Lists workflows for "admin", "user"', |
|
54 | + 'admin' |
|
55 | + ) |
|
56 | + ->addArgument( |
|
57 | + 'scopeId', |
|
58 | + InputArgument::OPTIONAL, |
|
59 | + 'User IDs when the scope is "user"', |
|
60 | + null |
|
61 | + ); |
|
62 | + } |
|
63 | 63 | |
64 | - protected function mappedScope(string $scope): int { |
|
65 | - static $scopes = [ |
|
66 | - 'admin' => IManager::SCOPE_ADMIN, |
|
67 | - 'user' => IManager::SCOPE_USER, |
|
68 | - ]; |
|
69 | - return $scopes[$scope] ?? -1; |
|
70 | - } |
|
64 | + protected function mappedScope(string $scope): int { |
|
65 | + static $scopes = [ |
|
66 | + 'admin' => IManager::SCOPE_ADMIN, |
|
67 | + 'user' => IManager::SCOPE_USER, |
|
68 | + ]; |
|
69 | + return $scopes[$scope] ?? -1; |
|
70 | + } |
|
71 | 71 | |
72 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
73 | - $ops = $this->manager->getAllOperations( |
|
74 | - new ScopeContext( |
|
75 | - $this->mappedScope($input->getArgument('scope')), |
|
76 | - $input->getArgument('scopeId') |
|
77 | - ) |
|
78 | - ); |
|
79 | - $output->writeln(\json_encode($ops)); |
|
80 | - return 0; |
|
81 | - } |
|
72 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
73 | + $ops = $this->manager->getAllOperations( |
|
74 | + new ScopeContext( |
|
75 | + $this->mappedScope($input->getArgument('scope')), |
|
76 | + $input->getArgument('scopeId') |
|
77 | + ) |
|
78 | + ); |
|
79 | + $output->writeln(\json_encode($ops)); |
|
80 | + return 0; |
|
81 | + } |
|
82 | 82 | } |
@@ -33,51 +33,51 @@ |
||
33 | 33 | * Delete all file entries that have no matching entries in the storage table. |
34 | 34 | */ |
35 | 35 | class DeleteOrphanedFiles extends Command { |
36 | - public const CHUNK_SIZE = 200; |
|
36 | + public const CHUNK_SIZE = 200; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var IDBConnection |
|
40 | - */ |
|
41 | - protected $connection; |
|
38 | + /** |
|
39 | + * @var IDBConnection |
|
40 | + */ |
|
41 | + protected $connection; |
|
42 | 42 | |
43 | - public function __construct(IDBConnection $connection) { |
|
44 | - $this->connection = $connection; |
|
45 | - parent::__construct(); |
|
46 | - } |
|
43 | + public function __construct(IDBConnection $connection) { |
|
44 | + $this->connection = $connection; |
|
45 | + parent::__construct(); |
|
46 | + } |
|
47 | 47 | |
48 | - protected function configure() { |
|
49 | - $this |
|
50 | - ->setName('files:cleanup') |
|
51 | - ->setDescription('cleanup filecache'); |
|
52 | - } |
|
48 | + protected function configure() { |
|
49 | + $this |
|
50 | + ->setName('files:cleanup') |
|
51 | + ->setDescription('cleanup filecache'); |
|
52 | + } |
|
53 | 53 | |
54 | - public function execute(InputInterface $input, OutputInterface $output): int { |
|
55 | - $deletedEntries = 0; |
|
54 | + public function execute(InputInterface $input, OutputInterface $output): int { |
|
55 | + $deletedEntries = 0; |
|
56 | 56 | |
57 | - $query = $this->connection->getQueryBuilder(); |
|
58 | - $query->select('fc.fileid') |
|
59 | - ->from('filecache', 'fc') |
|
60 | - ->where($query->expr()->isNull('s.numeric_id')) |
|
61 | - ->leftJoin('fc', 'storages', 's', $query->expr()->eq('fc.storage', 's.numeric_id')) |
|
62 | - ->setMaxResults(self::CHUNK_SIZE); |
|
57 | + $query = $this->connection->getQueryBuilder(); |
|
58 | + $query->select('fc.fileid') |
|
59 | + ->from('filecache', 'fc') |
|
60 | + ->where($query->expr()->isNull('s.numeric_id')) |
|
61 | + ->leftJoin('fc', 'storages', 's', $query->expr()->eq('fc.storage', 's.numeric_id')) |
|
62 | + ->setMaxResults(self::CHUNK_SIZE); |
|
63 | 63 | |
64 | - $deleteQuery = $this->connection->getQueryBuilder(); |
|
65 | - $deleteQuery->delete('filecache') |
|
66 | - ->where($deleteQuery->expr()->eq('fileid', $deleteQuery->createParameter('objectid'))); |
|
64 | + $deleteQuery = $this->connection->getQueryBuilder(); |
|
65 | + $deleteQuery->delete('filecache') |
|
66 | + ->where($deleteQuery->expr()->eq('fileid', $deleteQuery->createParameter('objectid'))); |
|
67 | 67 | |
68 | - $deletedInLastChunk = self::CHUNK_SIZE; |
|
69 | - while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
70 | - $deletedInLastChunk = 0; |
|
71 | - $result = $query->execute(); |
|
72 | - while ($row = $result->fetch()) { |
|
73 | - $deletedInLastChunk++; |
|
74 | - $deletedEntries += $deleteQuery->setParameter('objectid', (int) $row['fileid']) |
|
75 | - ->execute(); |
|
76 | - } |
|
77 | - $result->closeCursor(); |
|
78 | - } |
|
68 | + $deletedInLastChunk = self::CHUNK_SIZE; |
|
69 | + while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
70 | + $deletedInLastChunk = 0; |
|
71 | + $result = $query->execute(); |
|
72 | + while ($row = $result->fetch()) { |
|
73 | + $deletedInLastChunk++; |
|
74 | + $deletedEntries += $deleteQuery->setParameter('objectid', (int) $row['fileid']) |
|
75 | + ->execute(); |
|
76 | + } |
|
77 | + $result->closeCursor(); |
|
78 | + } |
|
79 | 79 | |
80 | - $output->writeln("$deletedEntries orphaned file cache entries deleted"); |
|
81 | - return 0; |
|
82 | - } |
|
80 | + $output->writeln("$deletedEntries orphaned file cache entries deleted"); |
|
81 | + return 0; |
|
82 | + } |
|
83 | 83 | } |
@@ -44,243 +44,243 @@ |
||
44 | 44 | |
45 | 45 | class ScanAppData extends Base { |
46 | 46 | |
47 | - /** @var IRootFolder */ |
|
48 | - protected $root; |
|
49 | - /** @var IConfig */ |
|
50 | - protected $config; |
|
51 | - /** @var float */ |
|
52 | - protected $execTime = 0; |
|
53 | - /** @var int */ |
|
54 | - protected $foldersCounter = 0; |
|
55 | - /** @var int */ |
|
56 | - protected $filesCounter = 0; |
|
57 | - |
|
58 | - public function __construct(IRootFolder $rootFolder, IConfig $config) { |
|
59 | - parent::__construct(); |
|
60 | - |
|
61 | - $this->root = $rootFolder; |
|
62 | - $this->config = $config; |
|
63 | - } |
|
64 | - |
|
65 | - protected function configure() { |
|
66 | - parent::configure(); |
|
67 | - |
|
68 | - $this |
|
69 | - ->setName('files:scan-app-data') |
|
70 | - ->setDescription('rescan the AppData folder'); |
|
71 | - |
|
72 | - $this->addArgument('folder', InputArgument::OPTIONAL, 'The appdata subfolder to scan', ''); |
|
73 | - } |
|
74 | - |
|
75 | - public function checkScanWarning($fullPath, OutputInterface $output) { |
|
76 | - $normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath)); |
|
77 | - $path = basename($fullPath); |
|
78 | - |
|
79 | - if ($normalizedPath !== $path) { |
|
80 | - $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - protected function scanFiles(OutputInterface $output, string $folder): int { |
|
85 | - try { |
|
86 | - $appData = $this->getAppDataFolder(); |
|
87 | - } catch (NotFoundException $e) { |
|
88 | - $output->writeln('<error>NoAppData folder found</error>'); |
|
89 | - return 1; |
|
90 | - } |
|
91 | - |
|
92 | - if ($folder !== '') { |
|
93 | - try { |
|
94 | - $appData = $appData->get($folder); |
|
95 | - } catch (NotFoundException $e) { |
|
96 | - $output->writeln('<error>Could not find folder: ' . $folder . '</error>'); |
|
97 | - return 1; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - $connection = $this->reconnectToDatabase($output); |
|
102 | - $scanner = new \OC\Files\Utils\Scanner(null, $connection, \OC::$server->query(IEventDispatcher::class), \OC::$server->getLogger()); |
|
103 | - |
|
104 | - # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
|
105 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
106 | - $output->writeln("\tFile <info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
|
107 | - ++$this->filesCounter; |
|
108 | - $this->abortIfInterrupted(); |
|
109 | - }); |
|
110 | - |
|
111 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
112 | - $output->writeln("\tFolder <info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
|
113 | - ++$this->foldersCounter; |
|
114 | - $this->abortIfInterrupted(); |
|
115 | - }); |
|
116 | - |
|
117 | - $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
118 | - $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')', OutputInterface::VERBOSITY_VERBOSE); |
|
119 | - }); |
|
120 | - |
|
121 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
122 | - $this->checkScanWarning($path, $output); |
|
123 | - }); |
|
124 | - |
|
125 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
126 | - $this->checkScanWarning($path, $output); |
|
127 | - }); |
|
128 | - |
|
129 | - try { |
|
130 | - $scanner->scan($appData->getPath()); |
|
131 | - } catch (ForbiddenException $e) { |
|
132 | - $output->writeln('<error>Storage not writable</error>'); |
|
133 | - $output->writeln('<info>Make sure you\'re running the scan command only as the user the web server runs as</info>'); |
|
134 | - return 1; |
|
135 | - } catch (InterruptedException $e) { |
|
136 | - # exit the function if ctrl-c has been pressed |
|
137 | - $output->writeln('<info>Interrupted by user</info>'); |
|
138 | - return 1; |
|
139 | - } catch (NotFoundException $e) { |
|
140 | - $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
141 | - return 1; |
|
142 | - } catch (\Exception $e) { |
|
143 | - $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
144 | - $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
145 | - return 1; |
|
146 | - } |
|
147 | - |
|
148 | - return 0; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
153 | - # restrict the verbosity level to VERBOSITY_VERBOSE |
|
154 | - if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { |
|
155 | - $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
156 | - } |
|
157 | - |
|
158 | - $output->writeln('Scanning AppData for files'); |
|
159 | - $output->writeln(''); |
|
160 | - |
|
161 | - $folder = $input->getArgument('folder'); |
|
162 | - |
|
163 | - $this->initTools(); |
|
164 | - |
|
165 | - $exitCode = $this->scanFiles($output, $folder); |
|
166 | - if ($exitCode === 0) { |
|
167 | - $this->presentStats($output); |
|
168 | - } |
|
169 | - return $exitCode; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Initialises some useful tools for the Command |
|
174 | - */ |
|
175 | - protected function initTools() { |
|
176 | - // Start the timer |
|
177 | - $this->execTime = -microtime(true); |
|
178 | - // Convert PHP errors to exceptions |
|
179 | - set_error_handler([$this, 'exceptionErrorHandler'], E_ALL); |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Processes PHP errors as exceptions in order to be able to keep track of problems |
|
184 | - * |
|
185 | - * @see https://secure.php.net/manual/en/function.set-error-handler.php |
|
186 | - * |
|
187 | - * @param int $severity the level of the error raised |
|
188 | - * @param string $message |
|
189 | - * @param string $file the filename that the error was raised in |
|
190 | - * @param int $line the line number the error was raised |
|
191 | - * |
|
192 | - * @throws \ErrorException |
|
193 | - */ |
|
194 | - public function exceptionErrorHandler($severity, $message, $file, $line) { |
|
195 | - if (!(error_reporting() & $severity)) { |
|
196 | - // This error code is not included in error_reporting |
|
197 | - return; |
|
198 | - } |
|
199 | - throw new \ErrorException($message, 0, $severity, $file, $line); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @param OutputInterface $output |
|
204 | - */ |
|
205 | - protected function presentStats(OutputInterface $output) { |
|
206 | - // Stop the timer |
|
207 | - $this->execTime += microtime(true); |
|
208 | - |
|
209 | - $headers = [ |
|
210 | - 'Folders', 'Files', 'Elapsed time' |
|
211 | - ]; |
|
212 | - |
|
213 | - $this->showSummary($headers, null, $output); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Shows a summary of operations |
|
218 | - * |
|
219 | - * @param string[] $headers |
|
220 | - * @param string[] $rows |
|
221 | - * @param OutputInterface $output |
|
222 | - */ |
|
223 | - protected function showSummary($headers, $rows, OutputInterface $output) { |
|
224 | - $niceDate = $this->formatExecTime(); |
|
225 | - if (!$rows) { |
|
226 | - $rows = [ |
|
227 | - $this->foldersCounter, |
|
228 | - $this->filesCounter, |
|
229 | - $niceDate, |
|
230 | - ]; |
|
231 | - } |
|
232 | - $table = new Table($output); |
|
233 | - $table |
|
234 | - ->setHeaders($headers) |
|
235 | - ->setRows([$rows]); |
|
236 | - $table->render(); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * Formats microtime into a human readable format |
|
242 | - * |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - protected function formatExecTime() { |
|
246 | - $secs = round($this->execTime); |
|
247 | - # convert seconds into HH:MM:SS form |
|
248 | - return sprintf('%02d:%02d:%02d', ($secs/3600), ($secs/60%60), $secs%60); |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @return \OCP\IDBConnection |
|
253 | - */ |
|
254 | - protected function reconnectToDatabase(OutputInterface $output) { |
|
255 | - /** @var Connection | IDBConnection $connection*/ |
|
256 | - $connection = \OC::$server->getDatabaseConnection(); |
|
257 | - try { |
|
258 | - $connection->close(); |
|
259 | - } catch (\Exception $ex) { |
|
260 | - $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
261 | - } |
|
262 | - while (!$connection->isConnected()) { |
|
263 | - try { |
|
264 | - $connection->connect(); |
|
265 | - } catch (\Exception $ex) { |
|
266 | - $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
267 | - sleep(60); |
|
268 | - } |
|
269 | - } |
|
270 | - return $connection; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * @return \OCP\Files\Folder |
|
275 | - * @throws NotFoundException |
|
276 | - */ |
|
277 | - private function getAppDataFolder() { |
|
278 | - $instanceId = $this->config->getSystemValue('instanceid', null); |
|
279 | - |
|
280 | - if ($instanceId === null) { |
|
281 | - throw new NotFoundException(); |
|
282 | - } |
|
283 | - |
|
284 | - return $this->root->get('appdata_'.$instanceId); |
|
285 | - } |
|
47 | + /** @var IRootFolder */ |
|
48 | + protected $root; |
|
49 | + /** @var IConfig */ |
|
50 | + protected $config; |
|
51 | + /** @var float */ |
|
52 | + protected $execTime = 0; |
|
53 | + /** @var int */ |
|
54 | + protected $foldersCounter = 0; |
|
55 | + /** @var int */ |
|
56 | + protected $filesCounter = 0; |
|
57 | + |
|
58 | + public function __construct(IRootFolder $rootFolder, IConfig $config) { |
|
59 | + parent::__construct(); |
|
60 | + |
|
61 | + $this->root = $rootFolder; |
|
62 | + $this->config = $config; |
|
63 | + } |
|
64 | + |
|
65 | + protected function configure() { |
|
66 | + parent::configure(); |
|
67 | + |
|
68 | + $this |
|
69 | + ->setName('files:scan-app-data') |
|
70 | + ->setDescription('rescan the AppData folder'); |
|
71 | + |
|
72 | + $this->addArgument('folder', InputArgument::OPTIONAL, 'The appdata subfolder to scan', ''); |
|
73 | + } |
|
74 | + |
|
75 | + public function checkScanWarning($fullPath, OutputInterface $output) { |
|
76 | + $normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath)); |
|
77 | + $path = basename($fullPath); |
|
78 | + |
|
79 | + if ($normalizedPath !== $path) { |
|
80 | + $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + protected function scanFiles(OutputInterface $output, string $folder): int { |
|
85 | + try { |
|
86 | + $appData = $this->getAppDataFolder(); |
|
87 | + } catch (NotFoundException $e) { |
|
88 | + $output->writeln('<error>NoAppData folder found</error>'); |
|
89 | + return 1; |
|
90 | + } |
|
91 | + |
|
92 | + if ($folder !== '') { |
|
93 | + try { |
|
94 | + $appData = $appData->get($folder); |
|
95 | + } catch (NotFoundException $e) { |
|
96 | + $output->writeln('<error>Could not find folder: ' . $folder . '</error>'); |
|
97 | + return 1; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + $connection = $this->reconnectToDatabase($output); |
|
102 | + $scanner = new \OC\Files\Utils\Scanner(null, $connection, \OC::$server->query(IEventDispatcher::class), \OC::$server->getLogger()); |
|
103 | + |
|
104 | + # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
|
105 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
106 | + $output->writeln("\tFile <info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
|
107 | + ++$this->filesCounter; |
|
108 | + $this->abortIfInterrupted(); |
|
109 | + }); |
|
110 | + |
|
111 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
112 | + $output->writeln("\tFolder <info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
|
113 | + ++$this->foldersCounter; |
|
114 | + $this->abortIfInterrupted(); |
|
115 | + }); |
|
116 | + |
|
117 | + $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
118 | + $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')', OutputInterface::VERBOSITY_VERBOSE); |
|
119 | + }); |
|
120 | + |
|
121 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
122 | + $this->checkScanWarning($path, $output); |
|
123 | + }); |
|
124 | + |
|
125 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
126 | + $this->checkScanWarning($path, $output); |
|
127 | + }); |
|
128 | + |
|
129 | + try { |
|
130 | + $scanner->scan($appData->getPath()); |
|
131 | + } catch (ForbiddenException $e) { |
|
132 | + $output->writeln('<error>Storage not writable</error>'); |
|
133 | + $output->writeln('<info>Make sure you\'re running the scan command only as the user the web server runs as</info>'); |
|
134 | + return 1; |
|
135 | + } catch (InterruptedException $e) { |
|
136 | + # exit the function if ctrl-c has been pressed |
|
137 | + $output->writeln('<info>Interrupted by user</info>'); |
|
138 | + return 1; |
|
139 | + } catch (NotFoundException $e) { |
|
140 | + $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
141 | + return 1; |
|
142 | + } catch (\Exception $e) { |
|
143 | + $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
144 | + $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
145 | + return 1; |
|
146 | + } |
|
147 | + |
|
148 | + return 0; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
153 | + # restrict the verbosity level to VERBOSITY_VERBOSE |
|
154 | + if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { |
|
155 | + $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
156 | + } |
|
157 | + |
|
158 | + $output->writeln('Scanning AppData for files'); |
|
159 | + $output->writeln(''); |
|
160 | + |
|
161 | + $folder = $input->getArgument('folder'); |
|
162 | + |
|
163 | + $this->initTools(); |
|
164 | + |
|
165 | + $exitCode = $this->scanFiles($output, $folder); |
|
166 | + if ($exitCode === 0) { |
|
167 | + $this->presentStats($output); |
|
168 | + } |
|
169 | + return $exitCode; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Initialises some useful tools for the Command |
|
174 | + */ |
|
175 | + protected function initTools() { |
|
176 | + // Start the timer |
|
177 | + $this->execTime = -microtime(true); |
|
178 | + // Convert PHP errors to exceptions |
|
179 | + set_error_handler([$this, 'exceptionErrorHandler'], E_ALL); |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Processes PHP errors as exceptions in order to be able to keep track of problems |
|
184 | + * |
|
185 | + * @see https://secure.php.net/manual/en/function.set-error-handler.php |
|
186 | + * |
|
187 | + * @param int $severity the level of the error raised |
|
188 | + * @param string $message |
|
189 | + * @param string $file the filename that the error was raised in |
|
190 | + * @param int $line the line number the error was raised |
|
191 | + * |
|
192 | + * @throws \ErrorException |
|
193 | + */ |
|
194 | + public function exceptionErrorHandler($severity, $message, $file, $line) { |
|
195 | + if (!(error_reporting() & $severity)) { |
|
196 | + // This error code is not included in error_reporting |
|
197 | + return; |
|
198 | + } |
|
199 | + throw new \ErrorException($message, 0, $severity, $file, $line); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @param OutputInterface $output |
|
204 | + */ |
|
205 | + protected function presentStats(OutputInterface $output) { |
|
206 | + // Stop the timer |
|
207 | + $this->execTime += microtime(true); |
|
208 | + |
|
209 | + $headers = [ |
|
210 | + 'Folders', 'Files', 'Elapsed time' |
|
211 | + ]; |
|
212 | + |
|
213 | + $this->showSummary($headers, null, $output); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Shows a summary of operations |
|
218 | + * |
|
219 | + * @param string[] $headers |
|
220 | + * @param string[] $rows |
|
221 | + * @param OutputInterface $output |
|
222 | + */ |
|
223 | + protected function showSummary($headers, $rows, OutputInterface $output) { |
|
224 | + $niceDate = $this->formatExecTime(); |
|
225 | + if (!$rows) { |
|
226 | + $rows = [ |
|
227 | + $this->foldersCounter, |
|
228 | + $this->filesCounter, |
|
229 | + $niceDate, |
|
230 | + ]; |
|
231 | + } |
|
232 | + $table = new Table($output); |
|
233 | + $table |
|
234 | + ->setHeaders($headers) |
|
235 | + ->setRows([$rows]); |
|
236 | + $table->render(); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * Formats microtime into a human readable format |
|
242 | + * |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + protected function formatExecTime() { |
|
246 | + $secs = round($this->execTime); |
|
247 | + # convert seconds into HH:MM:SS form |
|
248 | + return sprintf('%02d:%02d:%02d', ($secs/3600), ($secs/60%60), $secs%60); |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @return \OCP\IDBConnection |
|
253 | + */ |
|
254 | + protected function reconnectToDatabase(OutputInterface $output) { |
|
255 | + /** @var Connection | IDBConnection $connection*/ |
|
256 | + $connection = \OC::$server->getDatabaseConnection(); |
|
257 | + try { |
|
258 | + $connection->close(); |
|
259 | + } catch (\Exception $ex) { |
|
260 | + $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
261 | + } |
|
262 | + while (!$connection->isConnected()) { |
|
263 | + try { |
|
264 | + $connection->connect(); |
|
265 | + } catch (\Exception $ex) { |
|
266 | + $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
267 | + sleep(60); |
|
268 | + } |
|
269 | + } |
|
270 | + return $connection; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * @return \OCP\Files\Folder |
|
275 | + * @throws NotFoundException |
|
276 | + */ |
|
277 | + private function getAppDataFolder() { |
|
278 | + $instanceId = $this->config->getSystemValue('instanceid', null); |
|
279 | + |
|
280 | + if ($instanceId === null) { |
|
281 | + throw new NotFoundException(); |
|
282 | + } |
|
283 | + |
|
284 | + return $this->root->get('appdata_'.$instanceId); |
|
285 | + } |
|
286 | 286 | } |
@@ -45,74 +45,74 @@ |
||
45 | 45 | |
46 | 46 | class TransferOwnership extends Command { |
47 | 47 | |
48 | - /** @var IUserManager */ |
|
49 | - private $userManager; |
|
48 | + /** @var IUserManager */ |
|
49 | + private $userManager; |
|
50 | 50 | |
51 | - /** @var OwnershipTransferService */ |
|
52 | - private $transferService; |
|
51 | + /** @var OwnershipTransferService */ |
|
52 | + private $transferService; |
|
53 | 53 | |
54 | - public function __construct(IUserManager $userManager, |
|
55 | - OwnershipTransferService $transferService) { |
|
56 | - parent::__construct(); |
|
57 | - $this->userManager = $userManager; |
|
58 | - $this->transferService = $transferService; |
|
59 | - } |
|
54 | + public function __construct(IUserManager $userManager, |
|
55 | + OwnershipTransferService $transferService) { |
|
56 | + parent::__construct(); |
|
57 | + $this->userManager = $userManager; |
|
58 | + $this->transferService = $transferService; |
|
59 | + } |
|
60 | 60 | |
61 | - protected function configure() { |
|
62 | - $this |
|
63 | - ->setName('files:transfer-ownership') |
|
64 | - ->setDescription('All files and folders are moved to another user - shares are moved as well.') |
|
65 | - ->addArgument( |
|
66 | - 'source-user', |
|
67 | - InputArgument::REQUIRED, |
|
68 | - 'owner of files which shall be moved' |
|
69 | - ) |
|
70 | - ->addArgument( |
|
71 | - 'destination-user', |
|
72 | - InputArgument::REQUIRED, |
|
73 | - 'user who will be the new owner of the files' |
|
74 | - ) |
|
75 | - ->addOption( |
|
76 | - 'path', |
|
77 | - null, |
|
78 | - InputOption::VALUE_REQUIRED, |
|
79 | - 'selectively provide the path to transfer. For example --path="folder_name"', |
|
80 | - '' |
|
81 | - )->addOption( |
|
82 | - 'move', |
|
83 | - null, |
|
84 | - InputOption::VALUE_NONE, |
|
85 | - 'move data from source user to root directory of destination user, which must be empty' |
|
86 | - ); |
|
87 | - } |
|
61 | + protected function configure() { |
|
62 | + $this |
|
63 | + ->setName('files:transfer-ownership') |
|
64 | + ->setDescription('All files and folders are moved to another user - shares are moved as well.') |
|
65 | + ->addArgument( |
|
66 | + 'source-user', |
|
67 | + InputArgument::REQUIRED, |
|
68 | + 'owner of files which shall be moved' |
|
69 | + ) |
|
70 | + ->addArgument( |
|
71 | + 'destination-user', |
|
72 | + InputArgument::REQUIRED, |
|
73 | + 'user who will be the new owner of the files' |
|
74 | + ) |
|
75 | + ->addOption( |
|
76 | + 'path', |
|
77 | + null, |
|
78 | + InputOption::VALUE_REQUIRED, |
|
79 | + 'selectively provide the path to transfer. For example --path="folder_name"', |
|
80 | + '' |
|
81 | + )->addOption( |
|
82 | + 'move', |
|
83 | + null, |
|
84 | + InputOption::VALUE_NONE, |
|
85 | + 'move data from source user to root directory of destination user, which must be empty' |
|
86 | + ); |
|
87 | + } |
|
88 | 88 | |
89 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
90 | - $sourceUserObject = $this->userManager->get($input->getArgument('source-user')); |
|
91 | - $destinationUserObject = $this->userManager->get($input->getArgument('destination-user')); |
|
89 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
90 | + $sourceUserObject = $this->userManager->get($input->getArgument('source-user')); |
|
91 | + $destinationUserObject = $this->userManager->get($input->getArgument('destination-user')); |
|
92 | 92 | |
93 | - if (!$sourceUserObject instanceof IUser) { |
|
94 | - $output->writeln("<error>Unknown source user " . $input->getArgument('source-user') . "</error>"); |
|
95 | - return 1; |
|
96 | - } |
|
93 | + if (!$sourceUserObject instanceof IUser) { |
|
94 | + $output->writeln("<error>Unknown source user " . $input->getArgument('source-user') . "</error>"); |
|
95 | + return 1; |
|
96 | + } |
|
97 | 97 | |
98 | - if (!$destinationUserObject instanceof IUser) { |
|
99 | - $output->writeln("<error>Unknown destination user " . $input->getArgument('destination-user') . "</error>"); |
|
100 | - return 1; |
|
101 | - } |
|
98 | + if (!$destinationUserObject instanceof IUser) { |
|
99 | + $output->writeln("<error>Unknown destination user " . $input->getArgument('destination-user') . "</error>"); |
|
100 | + return 1; |
|
101 | + } |
|
102 | 102 | |
103 | - try { |
|
104 | - $this->transferService->transfer( |
|
105 | - $sourceUserObject, |
|
106 | - $destinationUserObject, |
|
107 | - ltrim($input->getOption('path'), '/'), |
|
108 | - $output, |
|
109 | - $input->getOption('move') === true |
|
110 | - ); |
|
111 | - } catch (TransferOwnershipException $e) { |
|
112 | - $output->writeln("<error>" . $e->getMessage() . "</error>"); |
|
113 | - return $e->getCode() !== 0 ? $e->getCode() : 1; |
|
114 | - } |
|
103 | + try { |
|
104 | + $this->transferService->transfer( |
|
105 | + $sourceUserObject, |
|
106 | + $destinationUserObject, |
|
107 | + ltrim($input->getOption('path'), '/'), |
|
108 | + $output, |
|
109 | + $input->getOption('move') === true |
|
110 | + ); |
|
111 | + } catch (TransferOwnershipException $e) { |
|
112 | + $output->writeln("<error>" . $e->getMessage() . "</error>"); |
|
113 | + return $e->getCode() !== 0 ? $e->getCode() : 1; |
|
114 | + } |
|
115 | 115 | |
116 | - return 0; |
|
117 | - } |
|
116 | + return 0; |
|
117 | + } |
|
118 | 118 | } |
@@ -51,275 +51,275 @@ |
||
51 | 51 | |
52 | 52 | class Scan extends Base { |
53 | 53 | |
54 | - /** @var IUserManager $userManager */ |
|
55 | - private $userManager; |
|
56 | - /** @var float */ |
|
57 | - protected $execTime = 0; |
|
58 | - /** @var int */ |
|
59 | - protected $foldersCounter = 0; |
|
60 | - /** @var int */ |
|
61 | - protected $filesCounter = 0; |
|
62 | - |
|
63 | - public function __construct(IUserManager $userManager) { |
|
64 | - $this->userManager = $userManager; |
|
65 | - parent::__construct(); |
|
66 | - } |
|
67 | - |
|
68 | - protected function configure() { |
|
69 | - parent::configure(); |
|
70 | - |
|
71 | - $this |
|
72 | - ->setName('files:scan') |
|
73 | - ->setDescription('rescan filesystem') |
|
74 | - ->addArgument( |
|
75 | - 'user_id', |
|
76 | - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
77 | - 'will rescan all files of the given user(s)' |
|
78 | - ) |
|
79 | - ->addOption( |
|
80 | - 'path', |
|
81 | - 'p', |
|
82 | - InputArgument::OPTIONAL, |
|
83 | - 'limit rescan to this path, eg. --path="/alice/files/Music", the user_id is determined by the path and the user_id parameter and --all are ignored' |
|
84 | - ) |
|
85 | - ->addOption( |
|
86 | - 'all', |
|
87 | - null, |
|
88 | - InputOption::VALUE_NONE, |
|
89 | - 'will rescan all files of all known users' |
|
90 | - )->addOption( |
|
91 | - 'unscanned', |
|
92 | - null, |
|
93 | - InputOption::VALUE_NONE, |
|
94 | - 'only scan files which are marked as not fully scanned' |
|
95 | - )->addOption( |
|
96 | - 'shallow', |
|
97 | - null, |
|
98 | - InputOption::VALUE_NONE, |
|
99 | - 'do not scan folders recursively' |
|
100 | - )->addOption( |
|
101 | - 'home-only', |
|
102 | - null, |
|
103 | - InputOption::VALUE_NONE, |
|
104 | - 'only scan the home storage, ignoring any mounted external storage or share' |
|
105 | - ); |
|
106 | - } |
|
107 | - |
|
108 | - public function checkScanWarning($fullPath, OutputInterface $output) { |
|
109 | - $normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath)); |
|
110 | - $path = basename($fullPath); |
|
111 | - |
|
112 | - if ($normalizedPath !== $path) { |
|
113 | - $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - protected function scanFiles($user, $path, OutputInterface $output, $backgroundScan = false, $recursive = true, $homeOnly = false) { |
|
118 | - $connection = $this->reconnectToDatabase($output); |
|
119 | - $scanner = new \OC\Files\Utils\Scanner($user, $connection, \OC::$server->query(IEventDispatcher::class), \OC::$server->getLogger()); |
|
120 | - |
|
121 | - # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
|
122 | - |
|
123 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
124 | - $output->writeln("\tFile\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
|
125 | - ++$this->filesCounter; |
|
126 | - $this->abortIfInterrupted(); |
|
127 | - }); |
|
128 | - |
|
129 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
130 | - $output->writeln("\tFolder\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
|
131 | - ++$this->foldersCounter; |
|
132 | - $this->abortIfInterrupted(); |
|
133 | - }); |
|
134 | - |
|
135 | - $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
136 | - $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')', OutputInterface::VERBOSITY_VERBOSE); |
|
137 | - }); |
|
138 | - |
|
139 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
140 | - $this->checkScanWarning($path, $output); |
|
141 | - }); |
|
142 | - |
|
143 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
144 | - $this->checkScanWarning($path, $output); |
|
145 | - }); |
|
146 | - |
|
147 | - try { |
|
148 | - if ($backgroundScan) { |
|
149 | - $scanner->backgroundScan($path); |
|
150 | - } else { |
|
151 | - $scanner->scan($path, $recursive, $homeOnly ? [$this, 'filterHomeMount'] : null); |
|
152 | - } |
|
153 | - } catch (ForbiddenException $e) { |
|
154 | - $output->writeln("<error>Home storage for user $user not writable</error>"); |
|
155 | - $output->writeln('Make sure you\'re running the scan command only as the user the web server runs as'); |
|
156 | - } catch (InterruptedException $e) { |
|
157 | - # exit the function if ctrl-c has been pressed |
|
158 | - $output->writeln('Interrupted by user'); |
|
159 | - } catch (NotFoundException $e) { |
|
160 | - $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
161 | - } catch (\Exception $e) { |
|
162 | - $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
163 | - $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - public function filterHomeMount(IMountPoint $mountPoint) { |
|
168 | - // any mountpoint inside '/$user/files/' |
|
169 | - return substr_count($mountPoint->getMountPoint(), '/') <= 3; |
|
170 | - } |
|
171 | - |
|
172 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
173 | - $inputPath = $input->getOption('path'); |
|
174 | - if ($inputPath) { |
|
175 | - $inputPath = '/' . trim($inputPath, '/'); |
|
176 | - list(, $user,) = explode('/', $inputPath, 3); |
|
177 | - $users = [$user]; |
|
178 | - } elseif ($input->getOption('all')) { |
|
179 | - $users = $this->userManager->search(''); |
|
180 | - } else { |
|
181 | - $users = $input->getArgument('user_id'); |
|
182 | - } |
|
183 | - |
|
184 | - # restrict the verbosity level to VERBOSITY_VERBOSE |
|
185 | - if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { |
|
186 | - $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
187 | - } |
|
188 | - |
|
189 | - # check quantity of users to be process and show it on the command line |
|
190 | - $users_total = count($users); |
|
191 | - if ($users_total === 0) { |
|
192 | - $output->writeln('<error>Please specify the user id to scan, --all to scan for all users or --path=...</error>'); |
|
193 | - return 1; |
|
194 | - } |
|
195 | - |
|
196 | - $this->initTools(); |
|
197 | - |
|
198 | - $user_count = 0; |
|
199 | - foreach ($users as $user) { |
|
200 | - if (is_object($user)) { |
|
201 | - $user = $user->getUID(); |
|
202 | - } |
|
203 | - $path = $inputPath ? $inputPath : '/' . $user; |
|
204 | - ++$user_count; |
|
205 | - if ($this->userManager->userExists($user)) { |
|
206 | - $output->writeln("Starting scan for user $user_count out of $users_total ($user)"); |
|
207 | - $this->scanFiles($user, $path, $output, $input->getOption('unscanned'), !$input->getOption('shallow'), $input->getOption('home-only')); |
|
208 | - $output->writeln('', OutputInterface::VERBOSITY_VERBOSE); |
|
209 | - } else { |
|
210 | - $output->writeln("<error>Unknown user $user_count $user</error>"); |
|
211 | - $output->writeln('', OutputInterface::VERBOSITY_VERBOSE); |
|
212 | - } |
|
213 | - |
|
214 | - try { |
|
215 | - $this->abortIfInterrupted(); |
|
216 | - } catch (InterruptedException $e) { |
|
217 | - break; |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - $this->presentStats($output); |
|
222 | - return 0; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Initialises some useful tools for the Command |
|
227 | - */ |
|
228 | - protected function initTools() { |
|
229 | - // Start the timer |
|
230 | - $this->execTime = -microtime(true); |
|
231 | - // Convert PHP errors to exceptions |
|
232 | - set_error_handler([$this, 'exceptionErrorHandler'], E_ALL); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Processes PHP errors as exceptions in order to be able to keep track of problems |
|
237 | - * |
|
238 | - * @see https://secure.php.net/manual/en/function.set-error-handler.php |
|
239 | - * |
|
240 | - * @param int $severity the level of the error raised |
|
241 | - * @param string $message |
|
242 | - * @param string $file the filename that the error was raised in |
|
243 | - * @param int $line the line number the error was raised |
|
244 | - * |
|
245 | - * @throws \ErrorException |
|
246 | - */ |
|
247 | - public function exceptionErrorHandler($severity, $message, $file, $line) { |
|
248 | - if (!(error_reporting() & $severity)) { |
|
249 | - // This error code is not included in error_reporting |
|
250 | - return; |
|
251 | - } |
|
252 | - throw new \ErrorException($message, 0, $severity, $file, $line); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * @param OutputInterface $output |
|
257 | - */ |
|
258 | - protected function presentStats(OutputInterface $output) { |
|
259 | - // Stop the timer |
|
260 | - $this->execTime += microtime(true); |
|
261 | - |
|
262 | - $headers = [ |
|
263 | - 'Folders', 'Files', 'Elapsed time' |
|
264 | - ]; |
|
265 | - |
|
266 | - $this->showSummary($headers, null, $output); |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * Shows a summary of operations |
|
271 | - * |
|
272 | - * @param string[] $headers |
|
273 | - * @param string[] $rows |
|
274 | - * @param OutputInterface $output |
|
275 | - */ |
|
276 | - protected function showSummary($headers, $rows, OutputInterface $output) { |
|
277 | - $niceDate = $this->formatExecTime(); |
|
278 | - if (!$rows) { |
|
279 | - $rows = [ |
|
280 | - $this->foldersCounter, |
|
281 | - $this->filesCounter, |
|
282 | - $niceDate, |
|
283 | - ]; |
|
284 | - } |
|
285 | - $table = new Table($output); |
|
286 | - $table |
|
287 | - ->setHeaders($headers) |
|
288 | - ->setRows([$rows]); |
|
289 | - $table->render(); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * Formats microtime into a human readable format |
|
295 | - * |
|
296 | - * @return string |
|
297 | - */ |
|
298 | - protected function formatExecTime() { |
|
299 | - $secs = round($this->execTime); |
|
300 | - # convert seconds into HH:MM:SS form |
|
301 | - return sprintf('%02d:%02d:%02d', ($secs/3600), ($secs/60%60), $secs%60); |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @return \OCP\IDBConnection |
|
306 | - */ |
|
307 | - protected function reconnectToDatabase(OutputInterface $output) { |
|
308 | - /** @var Connection | IDBConnection $connection */ |
|
309 | - $connection = \OC::$server->getDatabaseConnection(); |
|
310 | - try { |
|
311 | - $connection->close(); |
|
312 | - } catch (\Exception $ex) { |
|
313 | - $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
314 | - } |
|
315 | - while (!$connection->isConnected()) { |
|
316 | - try { |
|
317 | - $connection->connect(); |
|
318 | - } catch (\Exception $ex) { |
|
319 | - $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
320 | - sleep(60); |
|
321 | - } |
|
322 | - } |
|
323 | - return $connection; |
|
324 | - } |
|
54 | + /** @var IUserManager $userManager */ |
|
55 | + private $userManager; |
|
56 | + /** @var float */ |
|
57 | + protected $execTime = 0; |
|
58 | + /** @var int */ |
|
59 | + protected $foldersCounter = 0; |
|
60 | + /** @var int */ |
|
61 | + protected $filesCounter = 0; |
|
62 | + |
|
63 | + public function __construct(IUserManager $userManager) { |
|
64 | + $this->userManager = $userManager; |
|
65 | + parent::__construct(); |
|
66 | + } |
|
67 | + |
|
68 | + protected function configure() { |
|
69 | + parent::configure(); |
|
70 | + |
|
71 | + $this |
|
72 | + ->setName('files:scan') |
|
73 | + ->setDescription('rescan filesystem') |
|
74 | + ->addArgument( |
|
75 | + 'user_id', |
|
76 | + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
77 | + 'will rescan all files of the given user(s)' |
|
78 | + ) |
|
79 | + ->addOption( |
|
80 | + 'path', |
|
81 | + 'p', |
|
82 | + InputArgument::OPTIONAL, |
|
83 | + 'limit rescan to this path, eg. --path="/alice/files/Music", the user_id is determined by the path and the user_id parameter and --all are ignored' |
|
84 | + ) |
|
85 | + ->addOption( |
|
86 | + 'all', |
|
87 | + null, |
|
88 | + InputOption::VALUE_NONE, |
|
89 | + 'will rescan all files of all known users' |
|
90 | + )->addOption( |
|
91 | + 'unscanned', |
|
92 | + null, |
|
93 | + InputOption::VALUE_NONE, |
|
94 | + 'only scan files which are marked as not fully scanned' |
|
95 | + )->addOption( |
|
96 | + 'shallow', |
|
97 | + null, |
|
98 | + InputOption::VALUE_NONE, |
|
99 | + 'do not scan folders recursively' |
|
100 | + )->addOption( |
|
101 | + 'home-only', |
|
102 | + null, |
|
103 | + InputOption::VALUE_NONE, |
|
104 | + 'only scan the home storage, ignoring any mounted external storage or share' |
|
105 | + ); |
|
106 | + } |
|
107 | + |
|
108 | + public function checkScanWarning($fullPath, OutputInterface $output) { |
|
109 | + $normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath)); |
|
110 | + $path = basename($fullPath); |
|
111 | + |
|
112 | + if ($normalizedPath !== $path) { |
|
113 | + $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + protected function scanFiles($user, $path, OutputInterface $output, $backgroundScan = false, $recursive = true, $homeOnly = false) { |
|
118 | + $connection = $this->reconnectToDatabase($output); |
|
119 | + $scanner = new \OC\Files\Utils\Scanner($user, $connection, \OC::$server->query(IEventDispatcher::class), \OC::$server->getLogger()); |
|
120 | + |
|
121 | + # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
|
122 | + |
|
123 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
124 | + $output->writeln("\tFile\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
|
125 | + ++$this->filesCounter; |
|
126 | + $this->abortIfInterrupted(); |
|
127 | + }); |
|
128 | + |
|
129 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
130 | + $output->writeln("\tFolder\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
|
131 | + ++$this->foldersCounter; |
|
132 | + $this->abortIfInterrupted(); |
|
133 | + }); |
|
134 | + |
|
135 | + $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
136 | + $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')', OutputInterface::VERBOSITY_VERBOSE); |
|
137 | + }); |
|
138 | + |
|
139 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
140 | + $this->checkScanWarning($path, $output); |
|
141 | + }); |
|
142 | + |
|
143 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
144 | + $this->checkScanWarning($path, $output); |
|
145 | + }); |
|
146 | + |
|
147 | + try { |
|
148 | + if ($backgroundScan) { |
|
149 | + $scanner->backgroundScan($path); |
|
150 | + } else { |
|
151 | + $scanner->scan($path, $recursive, $homeOnly ? [$this, 'filterHomeMount'] : null); |
|
152 | + } |
|
153 | + } catch (ForbiddenException $e) { |
|
154 | + $output->writeln("<error>Home storage for user $user not writable</error>"); |
|
155 | + $output->writeln('Make sure you\'re running the scan command only as the user the web server runs as'); |
|
156 | + } catch (InterruptedException $e) { |
|
157 | + # exit the function if ctrl-c has been pressed |
|
158 | + $output->writeln('Interrupted by user'); |
|
159 | + } catch (NotFoundException $e) { |
|
160 | + $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
161 | + } catch (\Exception $e) { |
|
162 | + $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
163 | + $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + public function filterHomeMount(IMountPoint $mountPoint) { |
|
168 | + // any mountpoint inside '/$user/files/' |
|
169 | + return substr_count($mountPoint->getMountPoint(), '/') <= 3; |
|
170 | + } |
|
171 | + |
|
172 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
173 | + $inputPath = $input->getOption('path'); |
|
174 | + if ($inputPath) { |
|
175 | + $inputPath = '/' . trim($inputPath, '/'); |
|
176 | + list(, $user,) = explode('/', $inputPath, 3); |
|
177 | + $users = [$user]; |
|
178 | + } elseif ($input->getOption('all')) { |
|
179 | + $users = $this->userManager->search(''); |
|
180 | + } else { |
|
181 | + $users = $input->getArgument('user_id'); |
|
182 | + } |
|
183 | + |
|
184 | + # restrict the verbosity level to VERBOSITY_VERBOSE |
|
185 | + if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { |
|
186 | + $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
187 | + } |
|
188 | + |
|
189 | + # check quantity of users to be process and show it on the command line |
|
190 | + $users_total = count($users); |
|
191 | + if ($users_total === 0) { |
|
192 | + $output->writeln('<error>Please specify the user id to scan, --all to scan for all users or --path=...</error>'); |
|
193 | + return 1; |
|
194 | + } |
|
195 | + |
|
196 | + $this->initTools(); |
|
197 | + |
|
198 | + $user_count = 0; |
|
199 | + foreach ($users as $user) { |
|
200 | + if (is_object($user)) { |
|
201 | + $user = $user->getUID(); |
|
202 | + } |
|
203 | + $path = $inputPath ? $inputPath : '/' . $user; |
|
204 | + ++$user_count; |
|
205 | + if ($this->userManager->userExists($user)) { |
|
206 | + $output->writeln("Starting scan for user $user_count out of $users_total ($user)"); |
|
207 | + $this->scanFiles($user, $path, $output, $input->getOption('unscanned'), !$input->getOption('shallow'), $input->getOption('home-only')); |
|
208 | + $output->writeln('', OutputInterface::VERBOSITY_VERBOSE); |
|
209 | + } else { |
|
210 | + $output->writeln("<error>Unknown user $user_count $user</error>"); |
|
211 | + $output->writeln('', OutputInterface::VERBOSITY_VERBOSE); |
|
212 | + } |
|
213 | + |
|
214 | + try { |
|
215 | + $this->abortIfInterrupted(); |
|
216 | + } catch (InterruptedException $e) { |
|
217 | + break; |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + $this->presentStats($output); |
|
222 | + return 0; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Initialises some useful tools for the Command |
|
227 | + */ |
|
228 | + protected function initTools() { |
|
229 | + // Start the timer |
|
230 | + $this->execTime = -microtime(true); |
|
231 | + // Convert PHP errors to exceptions |
|
232 | + set_error_handler([$this, 'exceptionErrorHandler'], E_ALL); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Processes PHP errors as exceptions in order to be able to keep track of problems |
|
237 | + * |
|
238 | + * @see https://secure.php.net/manual/en/function.set-error-handler.php |
|
239 | + * |
|
240 | + * @param int $severity the level of the error raised |
|
241 | + * @param string $message |
|
242 | + * @param string $file the filename that the error was raised in |
|
243 | + * @param int $line the line number the error was raised |
|
244 | + * |
|
245 | + * @throws \ErrorException |
|
246 | + */ |
|
247 | + public function exceptionErrorHandler($severity, $message, $file, $line) { |
|
248 | + if (!(error_reporting() & $severity)) { |
|
249 | + // This error code is not included in error_reporting |
|
250 | + return; |
|
251 | + } |
|
252 | + throw new \ErrorException($message, 0, $severity, $file, $line); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * @param OutputInterface $output |
|
257 | + */ |
|
258 | + protected function presentStats(OutputInterface $output) { |
|
259 | + // Stop the timer |
|
260 | + $this->execTime += microtime(true); |
|
261 | + |
|
262 | + $headers = [ |
|
263 | + 'Folders', 'Files', 'Elapsed time' |
|
264 | + ]; |
|
265 | + |
|
266 | + $this->showSummary($headers, null, $output); |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * Shows a summary of operations |
|
271 | + * |
|
272 | + * @param string[] $headers |
|
273 | + * @param string[] $rows |
|
274 | + * @param OutputInterface $output |
|
275 | + */ |
|
276 | + protected function showSummary($headers, $rows, OutputInterface $output) { |
|
277 | + $niceDate = $this->formatExecTime(); |
|
278 | + if (!$rows) { |
|
279 | + $rows = [ |
|
280 | + $this->foldersCounter, |
|
281 | + $this->filesCounter, |
|
282 | + $niceDate, |
|
283 | + ]; |
|
284 | + } |
|
285 | + $table = new Table($output); |
|
286 | + $table |
|
287 | + ->setHeaders($headers) |
|
288 | + ->setRows([$rows]); |
|
289 | + $table->render(); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * Formats microtime into a human readable format |
|
295 | + * |
|
296 | + * @return string |
|
297 | + */ |
|
298 | + protected function formatExecTime() { |
|
299 | + $secs = round($this->execTime); |
|
300 | + # convert seconds into HH:MM:SS form |
|
301 | + return sprintf('%02d:%02d:%02d', ($secs/3600), ($secs/60%60), $secs%60); |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @return \OCP\IDBConnection |
|
306 | + */ |
|
307 | + protected function reconnectToDatabase(OutputInterface $output) { |
|
308 | + /** @var Connection | IDBConnection $connection */ |
|
309 | + $connection = \OC::$server->getDatabaseConnection(); |
|
310 | + try { |
|
311 | + $connection->close(); |
|
312 | + } catch (\Exception $ex) { |
|
313 | + $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
314 | + } |
|
315 | + while (!$connection->isConnected()) { |
|
316 | + try { |
|
317 | + $connection->connect(); |
|
318 | + } catch (\Exception $ex) { |
|
319 | + $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
320 | + sleep(60); |
|
321 | + } |
|
322 | + } |
|
323 | + return $connection; |
|
324 | + } |
|
325 | 325 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $path = basename($fullPath); |
111 | 111 | |
112 | 112 | if ($normalizedPath !== $path) { |
113 | - $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
113 | + $output->writeln("\t<error>Entry \"".$fullPath.'" will not be accessible due to incompatible encoding</error>'); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
@@ -120,27 +120,27 @@ discard block |
||
120 | 120 | |
121 | 121 | # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
122 | 122 | |
123 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
123 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) { |
|
124 | 124 | $output->writeln("\tFile\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
125 | 125 | ++$this->filesCounter; |
126 | 126 | $this->abortIfInterrupted(); |
127 | 127 | }); |
128 | 128 | |
129 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
129 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { |
|
130 | 130 | $output->writeln("\tFolder\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
131 | 131 | ++$this->foldersCounter; |
132 | 132 | $this->abortIfInterrupted(); |
133 | 133 | }); |
134 | 134 | |
135 | - $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
136 | - $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')', OutputInterface::VERBOSITY_VERBOSE); |
|
135 | + $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function(StorageNotAvailableException $e) use ($output) { |
|
136 | + $output->writeln('Error while scanning, storage not available ('.$e->getMessage().')', OutputInterface::VERBOSITY_VERBOSE); |
|
137 | 137 | }); |
138 | 138 | |
139 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
139 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) { |
|
140 | 140 | $this->checkScanWarning($path, $output); |
141 | 141 | }); |
142 | 142 | |
143 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
143 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { |
|
144 | 144 | $this->checkScanWarning($path, $output); |
145 | 145 | }); |
146 | 146 | |
@@ -157,10 +157,10 @@ discard block |
||
157 | 157 | # exit the function if ctrl-c has been pressed |
158 | 158 | $output->writeln('Interrupted by user'); |
159 | 159 | } catch (NotFoundException $e) { |
160 | - $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
160 | + $output->writeln('<error>Path not found: '.$e->getMessage().'</error>'); |
|
161 | 161 | } catch (\Exception $e) { |
162 | - $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
163 | - $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
162 | + $output->writeln('<error>Exception during scan: '.$e->getMessage().'</error>'); |
|
163 | + $output->writeln('<error>'.$e->getTraceAsString().'</error>'); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | protected function execute(InputInterface $input, OutputInterface $output): int { |
173 | 173 | $inputPath = $input->getOption('path'); |
174 | 174 | if ($inputPath) { |
175 | - $inputPath = '/' . trim($inputPath, '/'); |
|
175 | + $inputPath = '/'.trim($inputPath, '/'); |
|
176 | 176 | list(, $user,) = explode('/', $inputPath, 3); |
177 | 177 | $users = [$user]; |
178 | 178 | } elseif ($input->getOption('all')) { |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | if (is_object($user)) { |
201 | 201 | $user = $user->getUID(); |
202 | 202 | } |
203 | - $path = $inputPath ? $inputPath : '/' . $user; |
|
203 | + $path = $inputPath ? $inputPath : '/'.$user; |
|
204 | 204 | ++$user_count; |
205 | 205 | if ($this->userManager->userExists($user)) { |
206 | 206 | $output->writeln("Starting scan for user $user_count out of $users_total ($user)"); |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | protected function formatExecTime() { |
299 | 299 | $secs = round($this->execTime); |
300 | 300 | # convert seconds into HH:MM:SS form |
301 | - return sprintf('%02d:%02d:%02d', ($secs/3600), ($secs/60%60), $secs%60); |
|
301 | + return sprintf('%02d:%02d:%02d', ($secs / 3600), ($secs / 60 % 60), $secs % 60); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -34,65 +34,65 @@ |
||
34 | 34 | |
35 | 35 | class Check extends Command { |
36 | 36 | |
37 | - /** |
|
38 | - * @var Installer $installer |
|
39 | - */ |
|
40 | - private $installer; |
|
37 | + /** |
|
38 | + * @var Installer $installer |
|
39 | + */ |
|
40 | + private $installer; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var AppManager $appManager |
|
44 | - */ |
|
45 | - private $appManager; |
|
42 | + /** |
|
43 | + * @var AppManager $appManager |
|
44 | + */ |
|
45 | + private $appManager; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @var UpdateChecker $updateChecker |
|
49 | - */ |
|
50 | - private $updateChecker; |
|
47 | + /** |
|
48 | + * @var UpdateChecker $updateChecker |
|
49 | + */ |
|
50 | + private $updateChecker; |
|
51 | 51 | |
52 | - public function __construct(AppManager $appManager, UpdateChecker $updateChecker, Installer $installer) { |
|
53 | - parent::__construct(); |
|
54 | - $this->installer = $installer; |
|
55 | - $this->appManager = $appManager; |
|
56 | - $this->updateChecker = $updateChecker; |
|
57 | - } |
|
52 | + public function __construct(AppManager $appManager, UpdateChecker $updateChecker, Installer $installer) { |
|
53 | + parent::__construct(); |
|
54 | + $this->installer = $installer; |
|
55 | + $this->appManager = $appManager; |
|
56 | + $this->updateChecker = $updateChecker; |
|
57 | + } |
|
58 | 58 | |
59 | - protected function configure() { |
|
60 | - $this |
|
61 | - ->setName('update:check') |
|
62 | - ->setDescription('Check for server and app updates') |
|
63 | - ; |
|
64 | - } |
|
59 | + protected function configure() { |
|
60 | + $this |
|
61 | + ->setName('update:check') |
|
62 | + ->setDescription('Check for server and app updates') |
|
63 | + ; |
|
64 | + } |
|
65 | 65 | |
66 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
67 | - $updatesAvailableCount = 0; |
|
66 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
67 | + $updatesAvailableCount = 0; |
|
68 | 68 | |
69 | - // Server |
|
70 | - $r = $this->updateChecker->getUpdateState(); |
|
71 | - if (isset($r['updateAvailable']) && $r['updateAvailable']) { |
|
72 | - $output->writeln($r['updateVersionString'] . ' is available. Get more information on how to update at '. $r['updateLink'] . '.'); |
|
73 | - $updatesAvailableCount += 1; |
|
74 | - } |
|
69 | + // Server |
|
70 | + $r = $this->updateChecker->getUpdateState(); |
|
71 | + if (isset($r['updateAvailable']) && $r['updateAvailable']) { |
|
72 | + $output->writeln($r['updateVersionString'] . ' is available. Get more information on how to update at '. $r['updateLink'] . '.'); |
|
73 | + $updatesAvailableCount += 1; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - // Apps |
|
78 | - $apps = $this->appManager->getInstalledApps(); |
|
79 | - foreach ($apps as $app) { |
|
80 | - $update = $this->installer->isUpdateAvailable($app); |
|
81 | - if ($update !== false) { |
|
82 | - $output->writeln('Update for ' . $app . ' to version ' . $update . ' is available.'); |
|
83 | - $updatesAvailableCount += 1; |
|
84 | - } |
|
85 | - } |
|
77 | + // Apps |
|
78 | + $apps = $this->appManager->getInstalledApps(); |
|
79 | + foreach ($apps as $app) { |
|
80 | + $update = $this->installer->isUpdateAvailable($app); |
|
81 | + if ($update !== false) { |
|
82 | + $output->writeln('Update for ' . $app . ' to version ' . $update . ' is available.'); |
|
83 | + $updatesAvailableCount += 1; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - // Report summary |
|
88 | - if ($updatesAvailableCount === 0) { |
|
89 | - $output->writeln('<info>Everything up to date</info>'); |
|
90 | - } elseif ($updatesAvailableCount === 1) { |
|
91 | - $output->writeln('<comment>1 update available</comment>'); |
|
92 | - } else { |
|
93 | - $output->writeln('<comment>' . $updatesAvailableCount . ' updates available</comment>'); |
|
94 | - } |
|
87 | + // Report summary |
|
88 | + if ($updatesAvailableCount === 0) { |
|
89 | + $output->writeln('<info>Everything up to date</info>'); |
|
90 | + } elseif ($updatesAvailableCount === 1) { |
|
91 | + $output->writeln('<comment>1 update available</comment>'); |
|
92 | + } else { |
|
93 | + $output->writeln('<comment>' . $updatesAvailableCount . ' updates available</comment>'); |
|
94 | + } |
|
95 | 95 | |
96 | - return 0; |
|
97 | - } |
|
96 | + return 0; |
|
97 | + } |
|
98 | 98 | } |
@@ -33,43 +33,43 @@ |
||
33 | 33 | |
34 | 34 | class SyncFederationAddressBooks extends Command { |
35 | 35 | |
36 | - /** @var \OCA\Federation\SyncFederationAddressBooks */ |
|
37 | - private $syncService; |
|
36 | + /** @var \OCA\Federation\SyncFederationAddressBooks */ |
|
37 | + private $syncService; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param \OCA\Federation\SyncFederationAddressBooks $syncService |
|
41 | - */ |
|
42 | - public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) { |
|
43 | - parent::__construct(); |
|
39 | + /** |
|
40 | + * @param \OCA\Federation\SyncFederationAddressBooks $syncService |
|
41 | + */ |
|
42 | + public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) { |
|
43 | + parent::__construct(); |
|
44 | 44 | |
45 | - $this->syncService = $syncService; |
|
46 | - } |
|
45 | + $this->syncService = $syncService; |
|
46 | + } |
|
47 | 47 | |
48 | - protected function configure() { |
|
49 | - $this |
|
50 | - ->setName('federation:sync-addressbooks') |
|
51 | - ->setDescription('Synchronizes addressbooks of all federated clouds'); |
|
52 | - } |
|
48 | + protected function configure() { |
|
49 | + $this |
|
50 | + ->setName('federation:sync-addressbooks') |
|
51 | + ->setDescription('Synchronizes addressbooks of all federated clouds'); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param InputInterface $input |
|
56 | - * @param OutputInterface $output |
|
57 | - * @return int |
|
58 | - */ |
|
59 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
60 | - $progress = new ProgressBar($output); |
|
61 | - $progress->start(); |
|
62 | - $this->syncService->syncThemAll(function ($url, $ex) use ($progress, $output) { |
|
63 | - if ($ex instanceof \Exception) { |
|
64 | - $output->writeln("Error while syncing $url : " . $ex->getMessage()); |
|
65 | - } else { |
|
66 | - $progress->advance(); |
|
67 | - } |
|
68 | - }); |
|
54 | + /** |
|
55 | + * @param InputInterface $input |
|
56 | + * @param OutputInterface $output |
|
57 | + * @return int |
|
58 | + */ |
|
59 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
60 | + $progress = new ProgressBar($output); |
|
61 | + $progress->start(); |
|
62 | + $this->syncService->syncThemAll(function ($url, $ex) use ($progress, $output) { |
|
63 | + if ($ex instanceof \Exception) { |
|
64 | + $output->writeln("Error while syncing $url : " . $ex->getMessage()); |
|
65 | + } else { |
|
66 | + $progress->advance(); |
|
67 | + } |
|
68 | + }); |
|
69 | 69 | |
70 | - $progress->finish(); |
|
71 | - $output->writeln(''); |
|
70 | + $progress->finish(); |
|
71 | + $output->writeln(''); |
|
72 | 72 | |
73 | - return 0; |
|
74 | - } |
|
73 | + return 0; |
|
74 | + } |
|
75 | 75 | } |
@@ -59,9 +59,9 @@ |
||
59 | 59 | protected function execute(InputInterface $input, OutputInterface $output): int { |
60 | 60 | $progress = new ProgressBar($output); |
61 | 61 | $progress->start(); |
62 | - $this->syncService->syncThemAll(function ($url, $ex) use ($progress, $output) { |
|
62 | + $this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) { |
|
63 | 63 | if ($ex instanceof \Exception) { |
64 | - $output->writeln("Error while syncing $url : " . $ex->getMessage()); |
|
64 | + $output->writeln("Error while syncing $url : ".$ex->getMessage()); |
|
65 | 65 | } else { |
66 | 66 | $progress->advance(); |
67 | 67 | } |