Skip to content

Commit 26c1e33

Browse files
committed
Move repairstep to a custom command
People that have issues can run it manually Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent f9a64d3 commit 26c1e33

6 files changed

Lines changed: 24 additions & 39 deletions

File tree

apps/dav/appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<step>OCA\DAV\Migration\FixBirthdayCalendarComponent</step>
2929
<step>OCA\DAV\Migration\CalDAVRemoveEmptyValue</step>
3030
<step>OCA\DAV\Migration\BuildCalendarSearchIndex</step>
31-
<step>OCA\DAV\Repair\RemoveInvalidShares</step>
3231
</post-migration>
3332
</repair-steps>
3433

@@ -37,6 +36,7 @@
3736
<command>OCA\DAV\Command\CreateCalendar</command>
3837
<command>OCA\DAV\Command\SyncBirthdayCalendar</command>
3938
<command>OCA\DAV\Command\SyncSystemAddressBook</command>
39+
<command>OCA\DAV\Command\RemoveInvalidShares</command>
4040
</commands>
4141

4242
<settings>

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
'OCA\\DAV\\CardDAV\\Xml\\Groups' => $baseDir . '/../lib/CardDAV/Xml/Groups.php',
6666
'OCA\\DAV\\Command\\CreateAddressBook' => $baseDir . '/../lib/Command/CreateAddressBook.php',
6767
'OCA\\DAV\\Command\\CreateCalendar' => $baseDir . '/../lib/Command/CreateCalendar.php',
68+
'OCA\\DAV\\Command\\RemoveInvalidShares' => $baseDir . '/../lib/Command/RemoveInvalidShares.php',
6869
'OCA\\DAV\\Command\\SyncBirthdayCalendar' => $baseDir . '/../lib/Command/SyncBirthdayCalendar.php',
6970
'OCA\\DAV\\Command\\SyncSystemAddressBook' => $baseDir . '/../lib/Command/SyncSystemAddressBook.php',
7071
'OCA\\DAV\\Comments\\CommentNode' => $baseDir . '/../lib/Comments/CommentNode.php',
@@ -142,7 +143,6 @@
142143
'OCA\\DAV\\Migration\\Version1004Date20170924124212' => $baseDir . '/../lib/Migration/Version1004Date20170924124212.php',
143144
'OCA\\DAV\\Migration\\Version1004Date20170926103422' => $baseDir . '/../lib/Migration/Version1004Date20170926103422.php',
144145
'OCA\\DAV\\Migration\\Version1005Date20180413093149' => $baseDir . '/../lib/Migration/Version1005Date20180413093149.php',
145-
'OCA\\DAV\\Repair\\RemoveInvalidShares' => $baseDir . '/../lib/Repair/RemoveInvalidShares.php',
146146
'OCA\\DAV\\RootCollection' => $baseDir . '/../lib/RootCollection.php',
147147
'OCA\\DAV\\Server' => $baseDir . '/../lib/Server.php',
148148
'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class ComposerStaticInitDAV
8080
'OCA\\DAV\\CardDAV\\Xml\\Groups' => __DIR__ . '/..' . '/../lib/CardDAV/Xml/Groups.php',
8181
'OCA\\DAV\\Command\\CreateAddressBook' => __DIR__ . '/..' . '/../lib/Command/CreateAddressBook.php',
8282
'OCA\\DAV\\Command\\CreateCalendar' => __DIR__ . '/..' . '/../lib/Command/CreateCalendar.php',
83+
'OCA\\DAV\\Command\\RemoveInvalidShares' => __DIR__ . '/..' . '/../lib/Command/RemoveInvalidShares.php',
8384
'OCA\\DAV\\Command\\SyncBirthdayCalendar' => __DIR__ . '/..' . '/../lib/Command/SyncBirthdayCalendar.php',
8485
'OCA\\DAV\\Command\\SyncSystemAddressBook' => __DIR__ . '/..' . '/../lib/Command/SyncSystemAddressBook.php',
8586
'OCA\\DAV\\Comments\\CommentNode' => __DIR__ . '/..' . '/../lib/Comments/CommentNode.php',
@@ -157,7 +158,6 @@ class ComposerStaticInitDAV
157158
'OCA\\DAV\\Migration\\Version1004Date20170924124212' => __DIR__ . '/..' . '/../lib/Migration/Version1004Date20170924124212.php',
158159
'OCA\\DAV\\Migration\\Version1004Date20170926103422' => __DIR__ . '/..' . '/../lib/Migration/Version1004Date20170926103422.php',
159160
'OCA\\DAV\\Migration\\Version1005Date20180413093149' => __DIR__ . '/..' . '/../lib/Migration/Version1005Date20180413093149.php',
160-
'OCA\\DAV\\Repair\\RemoveInvalidShares' => __DIR__ . '/..' . '/../lib/Repair/RemoveInvalidShares.php',
161161
'OCA\\DAV\\RootCollection' => __DIR__ . '/..' . '/../lib/RootCollection.php',
162162
'OCA\\DAV\\Server' => __DIR__ . '/..' . '/../lib/Server.php',
163163
'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php',

apps/dav/lib/Repair/RemoveInvalidShares.php renamed to apps/dav/lib/Command/RemoveInvalidShares.php

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* @author Thomas Müller <thomas.mueller@tmit.eu>
45
*
@@ -19,58 +20,40 @@
1920
*
2021
*/
2122

22-
namespace OCA\DAV\Repair;
23+
namespace OCA\DAV\Command;
2324

2425
use OCA\DAV\Connector\Sabre\Principal;
2526
use OCP\IDBConnection;
26-
use OCP\ILogger;
27-
use OCP\Migration\IOutput;
28-
use OCP\Migration\IRepairStep;
27+
use Symfony\Component\Console\Command\Command;
28+
use Symfony\Component\Console\Input\InputInterface;
29+
use Symfony\Component\Console\Output\OutputInterface;
2930

3031
/**
3132
* Class RemoveInvalidShares - removes shared calendars and addressbook which
3233
* have no matching principal. Happened because of a bug in the calendar app.
33-
*
34-
* @package OCA\DAV\Repair
3534
*/
36-
class RemoveInvalidShares implements IRepairStep {
35+
class RemoveInvalidShares extends Command {
3736

3837
/** @var IDBConnection */
3938
private $connection;
4039
/** @var Principal */
4140
private $principalBackend;
4241

43-
/**
44-
* RemoveInvalidShares constructor.
45-
*
46-
* @param IDBConnection $connection
47-
* @param Principal $principalBackend
48-
*/
4942
public function __construct(IDBConnection $connection,
5043
Principal $principalBackend) {
44+
parent::__construct();
45+
5146
$this->connection = $connection;
5247
$this->principalBackend = $principalBackend;
5348
}
5449

55-
/**
56-
* Returns the step's name
57-
*
58-
* @return string
59-
* @since 9.1.0
60-
*/
61-
public function getName() {
62-
return 'Remove invalid calendar and addressbook shares';
50+
protected function configure() {
51+
$this
52+
->setName('dav:remove-invalid-shares')
53+
->setDescription('Remove invalid dav shares');
6354
}
6455

65-
/**
66-
* Run repair step.
67-
* Must throw exception on error.
68-
*
69-
* @param IOutput $output
70-
* @throws \Exception in case of failure
71-
* @since 9.1.0
72-
*/
73-
public function run(IOutput $output) {
56+
protected function execute(InputInterface $input, OutputInterface $output) {
7457
$query = $this->connection->getQueryBuilder();
7558
$result = $query->selectDistinct('principaluri')
7659
->from('dav_shares')
@@ -80,7 +63,6 @@ public function run(IOutput $output) {
8063
$principaluri = $row['principaluri'];
8164
$p = $this->principalBackend->getPrincipalByPath($principaluri);
8265
if ($p === null) {
83-
$output->info(" ... for principal '$principaluri'");
8466
$this->deleteSharesForPrincipal($principaluri);
8567
}
8668
}

apps/dav/tests/unit/Repair/RemoveInvalidSharesTest.php renamed to apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
*/
2121

2222

23-
namespace OCA\DAV\Tests\Unit\Repair;
23+
namespace OCA\DAV\Tests\Unit\Command;
2424

2525

2626
use OCA\DAV\Connector\Sabre\Principal;
27-
use OCA\DAV\Repair\RemoveInvalidShares;
27+
use OCA\DAV\Command\RemoveInvalidShares;
2828
use OCP\Migration\IOutput;
29+
use Symfony\Component\Console\Input\InputInterface;
30+
use Symfony\Component\Console\Output\OutputInterface;
2931
use Test\TestCase;
3032

3133
/**
@@ -57,8 +59,7 @@ public function test() {
5759
$output = $this->createMock(IOutput::class);
5860

5961
$repair = new RemoveInvalidShares($db, $principal);
60-
$this->assertEquals("Remove invalid calendar and addressbook shares", $repair->getName());
61-
$repair->run($output);
62+
$this->invokePrivate($repair, 'run', [$this->createMock(InputInterface::class), $this->createMock(OutputInterface::class)]);
6263

6364
$query = $db->getQueryBuilder();
6465
$result = $query->select('*')->from('dav_shares')

lib/private/Repair.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
use OC\Repair\RepairInvalidShares;
4848
use OC\Template\JSCombiner;
4949
use OC\Template\SCSSCacher;
50+
use OCA\DAV\Connector\Sabre\Principal;
51+
use OCA\DAV\Repair\RemoveInvalidShares;
5052
use OCP\AppFramework\QueryException;
5153
use OCP\Migration\IOutput;
5254
use OCP\Migration\IRepairStep;
@@ -146,7 +148,7 @@ public static function getRepairSteps() {
146148
*/
147149
public static function getExpensiveRepairSteps() {
148150
return [
149-
new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager())
151+
new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()),
150152
];
151153
}
152154

0 commit comments

Comments
 (0)