X Tutup
Skip to content

Commit ae48185

Browse files
committed
allow scope by user in troubleshoot transfer
1 parent 0405d40 commit ae48185

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

apps/files/lib/Command/TroubleshootTransferOwnership.php

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,20 @@ protected function configure() {
7070
'f',
7171
InputOption::VALUE_NONE,
7272
'perform auto-fix for found problems'
73+
)
74+
->addOption(
75+
'uid',
76+
'u',
77+
InputArgument::OPTIONAL,
78+
'scope for particular user',
79+
null
7380
);
7481
}
7582

7683
public function execute(InputInterface $input, OutputInterface $output) {
7784
$type = $input->getArgument('type');
7885
$fix = $input->getOption('fix');
86+
$scopeUid = $input->getOption('uid');
7987

8088
$allowedOps = \explode("|", $this->allowedOps);
8189
if (!\in_array($type, $allowedOps)) {
@@ -86,10 +94,10 @@ public function execute(InputInterface $input, OutputInterface $output) {
8694
}
8795

8896
if ($type == 'all' || $type == 'invalid-initiator') {
89-
$this->findInvalidReshareInitiator($input, $output, $fix);
97+
$this->findInvalidReshareInitiator($input, $output, $fix, $scopeUid);
9098
}
9199
if ($type == 'all' || $type == 'invalid-owner') {
92-
$this->findInvalidShareOwner($input, $output, $fix);
100+
$this->findInvalidShareOwner($input, $output, $fix, $scopeUid);
93101
}
94102

95103
return 0;
@@ -103,8 +111,9 @@ public function execute(InputInterface $input, OutputInterface $output) {
103111
* @param InputInterface $input
104112
* @param OutputInterface $output
105113
* @param boolean $fix
114+
* @param $scopeUid
106115
*/
107-
protected function findInvalidShareOwner(InputInterface $input, OutputInterface $output, $fix) {
116+
protected function findInvalidShareOwner(InputInterface $input, OutputInterface $output, $fix, $scopeUid) {
108117
$output->writeln([
109118
"<info>==========================</>",
110119
"<info>Searching for shares that have invalid uid_owner, meaning share uid_owner that does not match associated file storage id.</>",
@@ -115,8 +124,8 @@ protected function findInvalidShareOwner(InputInterface $input, OutputInterface
115124
$invalidSharesCount = 0;
116125

117126
$shareStorages = \array_merge(
118-
$this->getAllInvalidShareStorages('home::'),
119-
$this->getAllInvalidShareStorages('object::user:')
127+
$this->getAllInvalidShareStorages('home::', $scopeUid),
128+
$this->getAllInvalidShareStorages('object::user:', $scopeUid)
120129
);
121130

122131
$tableRows = [];
@@ -177,8 +186,9 @@ protected function findInvalidShareOwner(InputInterface $input, OutputInterface
177186
* @param InputInterface $input
178187
* @param OutputInterface $output
179188
* @param boolean $fix
189+
* @param $scopeUid
180190
*/
181-
protected function findInvalidReshareInitiator(InputInterface $input, OutputInterface $output, $fix) {
191+
protected function findInvalidReshareInitiator(InputInterface $input, OutputInterface $output, $fix, $scopeUid) {
182192
$output->writeln([
183193
"<info>==========================</>",
184194
"<info>Searching for reshares that have invalid uid_initiator(resharer), meaning resharer which does not have the received share mounted anymore (that he reshared with other user).</>",
@@ -188,7 +198,12 @@ protected function findInvalidReshareInitiator(InputInterface $input, OutputInte
188198

189199
$runExceptions = 0;
190200
$invalidReshareInitiatorCount = 0;
191-
$resharers = $this->getAllResharers();
201+
202+
if ($scopeUid == null) {
203+
$resharers = $this->getAllResharers();
204+
} else {
205+
$resharers = [['uid_initiator' => $scopeUid]];
206+
}
192207

193208
$resharesToFix = [];
194209
foreach ($resharers as $resharer) {
@@ -201,6 +216,7 @@ protected function findInvalidReshareInitiator(InputInterface $input, OutputInte
201216
]);
202217
$tableRows = [];
203218
try {
219+
$this->setupFS($resharerUid);
204220
$userFolder = $this->getUserFolder($resharerUid);
205221

206222
// extract all reshares for this user and check if they have mount node
@@ -218,16 +234,17 @@ protected function findInvalidReshareInitiator(InputInterface $input, OutputInte
218234
$table->render();
219235
$output->writeln("");
220236
}
237+
$this->tearDownFS();
221238
} catch (\Exception $e) {
222239
$runExceptions = $runExceptions + 1;
223240
$table->setRows($tableRows);
224241
$table->render();
225242
$output->writeln("<info>Encountered error for user {$resharer['uid_initiator']}, command might need to be retried: </info>");
226243
$output->writeln("<error>{$e->getMessage()}: </error>");
227244
$output->writeln("<error>{$e->getTraceAsString()}: </error>");
228-
$output->writeln("<info>Waiting 1 seconds after error before continuing with next user..</info>");
245+
$output->writeln("<info>Waiting 5 seconds after error before continuing with next user..</info>");
229246
$output->writeln("");
230-
\sleep(1);
247+
\sleep(5);
231248
}
232249
}
233250

@@ -287,7 +304,7 @@ protected function getResharesForUser($userId) {
287304
return $reshares;
288305
}
289306

290-
protected function getAllInvalidShareStorages($storageType) {
307+
protected function getAllInvalidShareStorages($storageType, $scopeUid) {
291308
$query = $this->connection->getQueryBuilder();
292309

293310
if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
@@ -320,6 +337,10 @@ protected function getAllInvalidShareStorages($storageType) {
320337
'st.id'
321338
));
322339

340+
if ($scopeUid !== null) {
341+
$query->andWhere($query->expr()->eq('s.uid_owner', $query->createNamedParameter($scopeUid)));
342+
}
343+
323344
$cursor = $query->execute();
324345
$shareStorages = $cursor->fetchAll();
325346
$cursor->closeCursor();
@@ -370,4 +391,12 @@ protected function deleteCorruptedShare($shareData) {
370391
protected function getUserFolder($uid) {
371392
return \OC::$server->getUserFolder($uid);
372393
}
394+
395+
protected function tearDownFS() {
396+
\OC_Util::tearDownFS();
397+
}
398+
399+
protected function setupFS($user) {
400+
\OC_Util::setupFS($user);
401+
}
373402
}

0 commit comments

Comments
 (0)
X Tutup