2018-04-23 15:02:53 +03:00
|
|
|
<?php
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2018-05-24 10:27:40 +03:00
|
|
|
declare(strict_types=1);
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2018-04-23 15:02:53 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018, ownCloud GmbH
|
2019-12-03 21:57:53 +03:00
|
|
|
*
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
*
|
2018-04-23 15:02:53 +03:00
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2018-04-23 15:02:53 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-05-24 10:27:40 +03:00
|
|
|
namespace OCA\DAV\Command;
|
2018-04-23 15:02:53 +03:00
|
|
|
|
|
|
|
use OCA\DAV\Connector\Sabre\Principal;
|
|
|
|
use OCP\IDBConnection;
|
2018-05-24 10:27:40 +03:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2018-04-23 15:02:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RemoveInvalidShares - removes shared calendars and addressbook which
|
|
|
|
* have no matching principal. Happened because of a bug in the calendar app.
|
|
|
|
*/
|
2018-05-24 10:27:40 +03:00
|
|
|
class RemoveInvalidShares extends Command {
|
2018-04-23 15:02:53 +03:00
|
|
|
|
|
|
|
/** @var IDBConnection */
|
|
|
|
private $connection;
|
|
|
|
/** @var Principal */
|
|
|
|
private $principalBackend;
|
|
|
|
|
|
|
|
public function __construct(IDBConnection $connection,
|
|
|
|
Principal $principalBackend) {
|
2018-05-24 10:27:40 +03:00
|
|
|
parent::__construct();
|
|
|
|
|
2018-04-23 15:02:53 +03:00
|
|
|
$this->connection = $connection;
|
|
|
|
$this->principalBackend = $principalBackend;
|
|
|
|
}
|
|
|
|
|
2018-05-24 10:27:40 +03:00
|
|
|
protected function configure() {
|
|
|
|
$this
|
|
|
|
->setName('dav:remove-invalid-shares')
|
|
|
|
->setDescription('Remove invalid dav shares');
|
2018-04-23 15:02:53 +03:00
|
|
|
}
|
|
|
|
|
2018-05-24 10:27:40 +03:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) {
|
2018-04-23 15:02:53 +03:00
|
|
|
$query = $this->connection->getQueryBuilder();
|
|
|
|
$result = $query->selectDistinct('principaluri')
|
|
|
|
->from('dav_shares')
|
|
|
|
->execute();
|
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
while ($row = $result->fetch()) {
|
2018-04-23 15:02:53 +03:00
|
|
|
$principaluri = $row['principaluri'];
|
|
|
|
$p = $this->principalBackend->getPrincipalByPath($principaluri);
|
|
|
|
if ($p === null) {
|
|
|
|
$this->deleteSharesForPrincipal($principaluri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$result->closeCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $principaluri
|
|
|
|
*/
|
|
|
|
private function deleteSharesForPrincipal($principaluri) {
|
|
|
|
$delete = $this->connection->getQueryBuilder();
|
|
|
|
$delete->delete('dav_shares')
|
|
|
|
->where($delete->expr()->eq('principaluri', $delete->createNamedParameter($principaluri)));
|
|
|
|
$delete->execute();
|
|
|
|
}
|
|
|
|
}
|