setName('dav:remove-invalid-shares') ->setDescription('Remove invalid dav shares'); } protected function execute(InputInterface $input, OutputInterface $output): int { $query = $this->connection->getQueryBuilder(); $result = $query->selectDistinct('principaluri') ->from('dav_shares') ->execute(); while ($row = $result->fetch()) { $principaluri = $row['principaluri']; $p = $this->principalBackend->getPrincipalByPath($principaluri); if ($p === null) { $this->deleteSharesForPrincipal($principaluri); } } $result->closeCursor(); return self::SUCCESS; } /** * @param string $principaluri */ private function deleteSharesForPrincipal($principaluri): void { $delete = $this->connection->getQueryBuilder(); $delete->delete('dav_shares') ->where($delete->expr()->eq('principaluri', $delete->createNamedParameter($principaluri))); $delete->execute(); } }