mirror of
https://github.com/nextcloud/server.git
synced 2026-06-12 18:21:40 -04:00
fix(previewCleanup): Also cleanup the database
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
This commit is contained in:
parent
2cb2ffe608
commit
ffca01a648
2 changed files with 22 additions and 6 deletions
|
|
@ -10,19 +10,21 @@ declare(strict_types=1);
|
|||
namespace OC\Core\Command\Preview;
|
||||
|
||||
use OC\Core\Command\Base;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\Files\NotPermittedException;
|
||||
use OCP\IDBConnection;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Cleanup extends Base {
|
||||
|
||||
public function __construct(
|
||||
private IRootFolder $rootFolder,
|
||||
private LoggerInterface $logger,
|
||||
private readonly IRootFolder $rootFolder,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly IDBConnection $connection,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
|
@ -30,7 +32,7 @@ class Cleanup extends Base {
|
|||
protected function configure(): void {
|
||||
$this
|
||||
->setName('preview:cleanup')
|
||||
->setDescription('Removes existing preview files');
|
||||
->setDescription('Removes existing preview files and their database entries');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
|
|
@ -45,7 +47,6 @@ class Cleanup extends Base {
|
|||
|
||||
/** @var Folder $previewFolder */
|
||||
$previewFolder = $appDataFolder->get('preview');
|
||||
|
||||
} catch (NotFoundException $e) {
|
||||
$this->logger->error("Previews can't be removed: appdata folder can't be found", ['exception' => $e]);
|
||||
$output->writeln("Previews can't be removed: preview folder isn't deletable");
|
||||
|
|
@ -59,9 +60,20 @@ class Cleanup extends Base {
|
|||
}
|
||||
|
||||
try {
|
||||
// Delete preview folder
|
||||
$previewFolder->delete();
|
||||
$this->logger->debug('Preview folder deleted');
|
||||
$output->writeln('Preview folder deleted', OutputInterface::VERBOSITY_VERBOSE);
|
||||
|
||||
// Clear DB entries for previews
|
||||
$appDataDirectoryName = $this->rootFolder->getAppDataDirectoryName();
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$query->delete('filecache')
|
||||
->where($query->expr()->like('path', $query->createNamedParameter($appDataDirectoryName . '/preview/%', IQueryBuilder::PARAM_STR)));
|
||||
$deletedRows = $query->executeStatement();
|
||||
|
||||
$this->logger->debug("Deleted $deletedRows preview entries from database");
|
||||
$output->writeln("Deleted $deletedRows preview entries from database", OutputInterface::VERBOSITY_VERBOSE);
|
||||
} catch (NotFoundException $e) {
|
||||
$output->writeln("Previews weren't deleted: preview folder was not found while deleting it");
|
||||
$this->logger->error("Previews weren't deleted: preview folder was not found while deleting it", ['exception' => $e]);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use OCP\Files\Folder;
|
|||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\Files\NotPermittedException;
|
||||
use OCP\IDBConnection;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
|
@ -20,6 +21,7 @@ use Test\TestCase;
|
|||
class CleanupTest extends TestCase {
|
||||
private IRootFolder&MockObject $rootFolder;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
private IDBConnection&MockObject $connection;
|
||||
private InputInterface&MockObject $input;
|
||||
private OutputInterface&MockObject $output;
|
||||
private Cleanup $repair;
|
||||
|
|
@ -28,9 +30,11 @@ class CleanupTest extends TestCase {
|
|||
parent::setUp();
|
||||
$this->rootFolder = $this->createMock(IRootFolder::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->connection = $this->createMock(IDBConnection::class);
|
||||
$this->repair = new Cleanup(
|
||||
$this->rootFolder,
|
||||
$this->logger,
|
||||
$this->connection,
|
||||
);
|
||||
|
||||
$this->input = $this->createMock(InputInterface::class);
|
||||
|
|
@ -50,7 +54,7 @@ class CleanupTest extends TestCase {
|
|||
$appDataFolder->expects($this->once())->method('get')->with('preview')->willReturn($previewFolder);
|
||||
$appDataFolder->expects($this->once())->method('newFolder')->with('preview');
|
||||
|
||||
$this->rootFolder->expects($this->once())
|
||||
$this->rootFolder->expects($this->atLeastOnce())
|
||||
->method('getAppDataDirectoryName')
|
||||
->willReturn('appdata_some_id');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue