Cleanup previews in the backgroundtags/v14.0.0beta1
@@ -25,13 +25,11 @@ | |||
*/ | |||
namespace OCA\Theming\Tests; | |||
use OC\Files\AppData\AppData; | |||
use OCA\Theming\IconBuilder; | |||
use OCA\Theming\ThemingDefaults; | |||
use OCA\Theming\Util; | |||
use OCP\App\IAppManager; | |||
use OCP\AppFramework\Http\NotFoundResponse; | |||
use OCP\Files\IAppData; | |||
use OCP\Files\IRootFolder; | |||
use OCP\Files\NotFoundException; | |||
use OCP\IConfig; | |||
use PHPUnit\Framework\Error\Warning; | |||
@@ -41,7 +39,7 @@ class IconBuilderTest extends TestCase { | |||
/** @var IConfig */ | |||
protected $config; | |||
/** @var IAppData */ | |||
/** @var AppData */ | |||
protected $appData; | |||
/** @var ThemingDefaults */ | |||
protected $themingDefaults; | |||
@@ -56,7 +54,7 @@ class IconBuilderTest extends TestCase { | |||
parent::setUp(); | |||
$this->config = $this->getMockBuilder(IConfig::class)->getMock(); | |||
$this->appData = $this->createMock(IAppData::class); | |||
$this->appData = $this->createMock(AppData::class); | |||
$this->themingDefaults = $this->getMockBuilder('OCA\Theming\ThemingDefaults') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->appManager = $this->getMockBuilder('OCP\App\IAppManager')->getMock(); | |||
@@ -127,6 +125,10 @@ class IconBuilderTest extends TestCase { | |||
$this->themingDefaults->expects($this->once()) | |||
->method('getColorPrimary') | |||
->willReturn($color); | |||
$this->appData->expects($this->once()) | |||
->method('getFolder') | |||
->with('images') | |||
->willThrowException(new NotFoundException()); | |||
$expectedIcon = new \Imagick(realpath(dirname(__FILE__)). "/data/" . $file); | |||
$icon = new \Imagick(); | |||
@@ -156,6 +158,10 @@ class IconBuilderTest extends TestCase { | |||
$this->themingDefaults->expects($this->once()) | |||
->method('getColorPrimary') | |||
->willReturn($color); | |||
$this->appData->expects($this->once()) | |||
->method('getFolder') | |||
->with('images') | |||
->willThrowException(new NotFoundException()); | |||
$expectedIcon = new \Imagick(realpath(dirname(__FILE__)). "/data/" . $file); | |||
$actualIcon = $this->iconBuilder->getFavicon($app); |
@@ -790,6 +790,7 @@ return array( | |||
'OC\\PreviewManager' => $baseDir . '/lib/private/PreviewManager.php', | |||
'OC\\PreviewNotAvailableException' => $baseDir . '/lib/private/PreviewNotAvailableException.php', | |||
'OC\\Preview\\BMP' => $baseDir . '/lib/private/Preview/BMP.php', | |||
'OC\\Preview\\BackgroundCleanupJob' => $baseDir . '/lib/private/Preview/BackgroundCleanupJob.php', | |||
'OC\\Preview\\Bitmap' => $baseDir . '/lib/private/Preview/Bitmap.php', | |||
'OC\\Preview\\Font' => $baseDir . '/lib/private/Preview/Font.php', | |||
'OC\\Preview\\GIF' => $baseDir . '/lib/private/Preview/GIF.php', | |||
@@ -837,6 +838,7 @@ return array( | |||
'OC\\Repair\\NC11\\FixMountStorages' => $baseDir . '/lib/private/Repair/NC11/FixMountStorages.php', | |||
'OC\\Repair\\NC13\\AddLogRotateJob' => $baseDir . '/lib/private/Repair/NC13/AddLogRotateJob.php', | |||
'OC\\Repair\\NC13\\RepairInvalidPaths' => $baseDir . '/lib/private/Repair/NC13/RepairInvalidPaths.php', | |||
'OC\\Repair\\NC14\\AddPreviewBackgroundCleanupJob' => $baseDir . '/lib/private/Repair/NC14/AddPreviewBackgroundCleanupJob.php', | |||
'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php', | |||
'OC\\Repair\\Owncloud\\DropAccountTermsTable' => $baseDir . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php', | |||
'OC\\Repair\\Owncloud\\SaveAccountsTableData' => $baseDir . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php', |
@@ -820,6 +820,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c | |||
'OC\\PreviewManager' => __DIR__ . '/../../..' . '/lib/private/PreviewManager.php', | |||
'OC\\PreviewNotAvailableException' => __DIR__ . '/../../..' . '/lib/private/PreviewNotAvailableException.php', | |||
'OC\\Preview\\BMP' => __DIR__ . '/../../..' . '/lib/private/Preview/BMP.php', | |||
'OC\\Preview\\BackgroundCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Preview/BackgroundCleanupJob.php', | |||
'OC\\Preview\\Bitmap' => __DIR__ . '/../../..' . '/lib/private/Preview/Bitmap.php', | |||
'OC\\Preview\\Font' => __DIR__ . '/../../..' . '/lib/private/Preview/Font.php', | |||
'OC\\Preview\\GIF' => __DIR__ . '/../../..' . '/lib/private/Preview/GIF.php', | |||
@@ -867,6 +868,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c | |||
'OC\\Repair\\NC11\\FixMountStorages' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/FixMountStorages.php', | |||
'OC\\Repair\\NC13\\AddLogRotateJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC13/AddLogRotateJob.php', | |||
'OC\\Repair\\NC13\\RepairInvalidPaths' => __DIR__ . '/../../..' . '/lib/private/Repair/NC13/RepairInvalidPaths.php', | |||
'OC\\Repair\\NC14\\AddPreviewBackgroundCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC14/AddPreviewBackgroundCleanupJob.php', | |||
'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php', | |||
'OC\\Repair\\Owncloud\\DropAccountTermsTable' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php', | |||
'OC\\Repair\\Owncloud\\SaveAccountsTableData' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php', |
@@ -1,4 +1,5 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
@@ -31,6 +32,7 @@ use OC\SystemConfig; | |||
use OCP\Files\Node; | |||
use OCP\Files\NotFoundException; | |||
use OCP\Files\NotPermittedException; | |||
use OCP\Files\SimpleFS\ISimpleFolder; | |||
class AppData implements IAppData { | |||
@@ -55,7 +57,7 @@ class AppData implements IAppData { | |||
*/ | |||
public function __construct(IRootFolder $rootFolder, | |||
SystemConfig $systemConfig, | |||
$appId) { | |||
string $appId) { | |||
$this->rootFolder = $rootFolder; | |||
$this->config = $systemConfig; | |||
@@ -66,7 +68,7 @@ class AppData implements IAppData { | |||
* @return Folder | |||
* @throws \RuntimeException | |||
*/ | |||
private function getAppDataFolder() { | |||
private function getAppDataFolder(): Folder { | |||
if ($this->folder === null) { | |||
$instanceId = $this->config->getValue('instanceid', null); | |||
if ($instanceId === null) { | |||
@@ -101,20 +103,20 @@ class AppData implements IAppData { | |||
return $this->folder; | |||
} | |||
public function getFolder($name) { | |||
public function getFolder(string $name): ISimpleFolder { | |||
$node = $this->getAppDataFolder()->get($name); | |||
/** @var Folder $node */ | |||
return new SimpleFolder($node); | |||
} | |||
public function newFolder($name) { | |||
public function newFolder(string $name): ISimpleFolder { | |||
$folder = $this->getAppDataFolder()->newFolder($name); | |||
return new SimpleFolder($folder); | |||
} | |||
public function getDirectoryListing() { | |||
public function getDirectoryListing(): array { | |||
$listing = $this->getAppDataFolder()->getDirectoryListing(); | |||
$fileListing = array_map(function(Node $folder) { | |||
@@ -128,4 +130,8 @@ class AppData implements IAppData { | |||
return array_values($fileListing); | |||
} | |||
public function getId(): int { | |||
return $this->getAppDataFolder()->getId(); | |||
} | |||
} |
@@ -1,4 +1,5 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
@@ -44,7 +45,7 @@ class Factory { | |||
* @param string $appId | |||
* @return AppData | |||
*/ | |||
public function get($appId) { | |||
public function get(string $appId): AppData { | |||
return new AppData($this->rootFolder, $this->config, $appId); | |||
} | |||
} |
@@ -0,0 +1,91 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
* @author Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
* @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, | |||
* along with this program. If not, see <http://www.gnu.org/licenses/> | |||
* | |||
*/ | |||
namespace OC\Preview; | |||
use OC\BackgroundJob\TimedJob; | |||
use OC\Files\AppData\Factory; | |||
use OCP\DB\QueryBuilder\IQueryBuilder; | |||
use OCP\Files\NotFoundException; | |||
use OCP\Files\NotPermittedException; | |||
use OCP\IDBConnection; | |||
class BackgroundCleanupJob extends TimedJob { | |||
/** @var IDBConnection */ | |||
private $connection; | |||
/** @var Factory */ | |||
private $appDataFactory; | |||
/** @var bool */ | |||
private $isCLI; | |||
public function __construct(IDBConnection $connection, | |||
Factory $appDataFactory, | |||
bool $isCLI) { | |||
// Run at most once an hour | |||
$this->setInterval(3600); | |||
$this->connection = $connection; | |||
$this->appDataFactory = $appDataFactory; | |||
$this->isCLI = $isCLI; | |||
} | |||
public function run($argument) { | |||
$previews = $this->appDataFactory->get('preview'); | |||
$previewFodlerId = $previews->getId(); | |||
$qb = $this->connection->getQueryBuilder(); | |||
$qb->select('a.name') | |||
->from('filecache', 'a') | |||
->leftJoin('a', 'filecache', 'b', $qb->expr()->eq( | |||
$qb->expr()->castColumn('a.name', IQueryBuilder::PARAM_INT), 'b.fileid' | |||
)) | |||
->where( | |||
$qb->expr()->isNull('b.fileid') | |||
)->andWhere( | |||
$qb->expr()->eq('a.parent', $qb->createNamedParameter($previewFodlerId)) | |||
); | |||
if (!$this->isCLI) { | |||
$qb->setMaxResults(10); | |||
} | |||
$cursor = $qb->execute(); | |||
while ($row = $cursor->fetch()) { | |||
try { | |||
$preview = $previews->getFolder($row['name']); | |||
$preview->delete(); | |||
} catch (NotFoundException $e) { | |||
// continue | |||
} catch (NotPermittedException $e) { | |||
// continue | |||
} | |||
} | |||
$cursor->closeCursor(); | |||
} | |||
} |
@@ -1,4 +1,5 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
@@ -22,7 +23,6 @@ | |||
*/ | |||
namespace OC\Preview; | |||
use OCP\Files\File; | |||
use OCP\Files\Node; | |||
use OCP\Files\Folder; | |||
use OCP\Files\IAppData; | |||
@@ -39,9 +39,6 @@ class Watcher { | |||
/** @var IAppData */ | |||
private $appData; | |||
/** @var int[] */ | |||
private $toDelete = []; | |||
/** | |||
* Watcher constructor. | |||
* | |||
@@ -58,47 +55,10 @@ class Watcher { | |||
} | |||
try { | |||
$folder = $this->appData->getFolder($node->getId()); | |||
$folder = $this->appData->getFolder((string)$node->getId()); | |||
$folder->delete(); | |||
} catch (NotFoundException $e) { | |||
//Nothing to do | |||
} | |||
} | |||
public function preDelete(Node $node) { | |||
// To avoid cycles | |||
if ($this->toDelete !== []) { | |||
return; | |||
} | |||
if ($node instanceof File) { | |||
$this->toDelete[] = $node->getId(); | |||
return; | |||
} | |||
/** @var Folder $node */ | |||
$this->deleteFolder($node); | |||
} | |||
private function deleteFolder(Folder $folder) { | |||
$nodes = $folder->getDirectoryListing(); | |||
foreach ($nodes as $node) { | |||
if ($node instanceof File) { | |||
$this->toDelete[] = $node->getId(); | |||
} else if ($node instanceof Folder) { | |||
$this->deleteFolder($node); | |||
} | |||
} | |||
} | |||
public function postDelete(Node $node) { | |||
foreach ($this->toDelete as $fid) { | |||
try { | |||
$folder = $this->appData->getFolder($fid); | |||
$folder->delete(); | |||
} catch (NotFoundException $e) { | |||
// continue | |||
} | |||
} | |||
} | |||
} |
@@ -1,4 +1,5 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
@@ -49,7 +50,7 @@ class WatcherConnector { | |||
/** | |||
* @return Watcher | |||
*/ | |||
private function getWatcher() { | |||
private function getWatcher(): Watcher { | |||
return \OC::$server->query(Watcher::class); | |||
} | |||
@@ -59,14 +60,6 @@ class WatcherConnector { | |||
$this->root->listen('\OC\Files', 'postWrite', function (Node $node) { | |||
$this->getWatcher()->postWrite($node); | |||
}); | |||
$this->root->listen('\OC\Files', 'preDelete', function (Node $node) { | |||
$this->getWatcher()->preDelete($node); | |||
}); | |||
$this->root->listen('\OC\Files', 'postDelete', function (Node $node) { | |||
$this->getWatcher()->postDelete($node); | |||
}); | |||
} | |||
} | |||
} |
@@ -36,6 +36,7 @@ use OC\Repair\Collation; | |||
use OC\Repair\MoveUpdaterStepFile; | |||
use OC\Repair\NC11\FixMountStorages; | |||
use OC\Repair\NC13\AddLogRotateJob; | |||
use OC\Repair\NC14\AddPreviewBackgroundCleanupJob; | |||
use OC\Repair\OldGroupMembershipShares; | |||
use OC\Repair\Owncloud\DropAccountTermsTable; | |||
use OC\Repair\Owncloud\SaveAccountsTableData; | |||
@@ -132,7 +133,8 @@ class Repair implements IOutput{ | |||
new FixMountStorages(\OC::$server->getDatabaseConnection()), | |||
new RepairInvalidPaths(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), | |||
new AddLogRotateJob(\OC::$server->getJobList()), | |||
new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)) | |||
new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)), | |||
new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), | |||
]; | |||
} | |||
@@ -0,0 +1,48 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
* @author Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* 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 | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OC\Repair\NC14; | |||
use OC\Preview\BackgroundCleanupJob; | |||
use OCP\BackgroundJob\IJobList; | |||
use OCP\Migration\IOutput; | |||
use OCP\Migration\IRepairStep; | |||
class AddPreviewBackgroundCleanupJob implements IRepairStep { | |||
/** @var IJobList */ | |||
private $jobList; | |||
public function __construct(IJobList $jobList) { | |||
$this->jobList = $jobList; | |||
} | |||
public function getName(): string { | |||
return 'Add preview background cleanup job'; | |||
} | |||
public function run(IOutput $output) { | |||
$this->jobList->add(BackgroundCleanupJob::class); | |||
} | |||
} |
@@ -47,6 +47,7 @@ use OC\App\AppStore\Bundles\BundleFetcher; | |||
use OC\Authentication\Token\DefaultTokenCleanupJob; | |||
use OC\Authentication\Token\DefaultTokenProvider; | |||
use OC\Log\Rotate; | |||
use OC\Preview\BackgroundCleanupJob; | |||
use OCP\Defaults; | |||
use OCP\IL10N; | |||
use OCP\ILogger; | |||
@@ -419,6 +420,7 @@ class Setup { | |||
$jobList = \OC::$server->getJobList(); | |||
$jobList->add(DefaultTokenCleanupJob::class); | |||
$jobList->add(Rotate::class); | |||
$jobList->add(BackgroundCleanupJob::class); | |||
} | |||
/** |
@@ -42,7 +42,7 @@ interface ISimpleRoot { | |||
* @throws \RuntimeException | |||
* @since 11.0.0 | |||
*/ | |||
public function getFolder($name); | |||
public function getFolder(string $name): ISimpleFolder; | |||
/** | |||
* Get all the Folders | |||
@@ -52,7 +52,7 @@ interface ISimpleRoot { | |||
* @throws \RuntimeException | |||
* @since 11.0.0 | |||
*/ | |||
public function getDirectoryListing(); | |||
public function getDirectoryListing(): array; | |||
/** | |||
* Create a new folder named $name | |||
@@ -63,5 +63,5 @@ interface ISimpleRoot { | |||
* @throws \RuntimeException | |||
* @since 11.0.0 | |||
*/ | |||
public function newFolder($name); | |||
public function newFolder(string $name): ISimpleFolder; | |||
} |
@@ -23,6 +23,7 @@ | |||
namespace Tests\Core\Controller; | |||
use OC\Core\Controller\CssController; | |||
use OC\Files\AppData\AppData; | |||
use OC\Files\AppData\Factory; | |||
use OCP\AppFramework\Http; | |||
use OCP\AppFramework\Http\FileDisplayResponse; | |||
@@ -51,7 +52,7 @@ class CssControllerTest extends TestCase { | |||
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */ | |||
$factory = $this->createMock(Factory::class); | |||
$this->appData = $this->createMock(IAppData::class); | |||
$this->appData = $this->createMock(AppData::class); | |||
$factory->expects($this->once()) | |||
->method('get') | |||
->with('css') |
@@ -23,6 +23,7 @@ | |||
namespace Tests\Core\Controller; | |||
use OC\Core\Controller\JsController; | |||
use OC\Files\AppData\AppData; | |||
use OC\Files\AppData\Factory; | |||
use OCP\AppFramework\Http; | |||
use OCP\AppFramework\Http\FileDisplayResponse; | |||
@@ -51,7 +52,7 @@ class JsControllerTest extends TestCase { | |||
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */ | |||
$factory = $this->createMock(Factory::class); | |||
$this->appData = $this->createMock(IAppData::class); | |||
$this->appData = $this->createMock(AppData::class); | |||
$factory->expects($this->once()) | |||
->method('get') | |||
->with('js') |
@@ -23,6 +23,7 @@ namespace Test\App\AppStore\Fetcher; | |||
use OC\App\AppStore\Fetcher\AppFetcher; | |||
use OC\App\CompareVersion; | |||
use OC\Files\AppData\AppData; | |||
use OC\Files\AppData\Factory; | |||
use OCP\AppFramework\Utility\ITimeFactory; | |||
use OCP\Files\IAppData; | |||
@@ -63,7 +64,7 @@ EOD; | |||
/** @var Factory|PHPUnit_Framework_MockObject_MockObject $factory */ | |||
$factory = $this->createMock(Factory::class); | |||
$this->appData = $this->createMock(IAppData::class); | |||
$this->appData = $this->createMock(AppData::class); | |||
$factory->expects($this->once()) | |||
->method('get') | |||
->with('appstore') |
@@ -22,6 +22,7 @@ | |||
namespace Test\App\AppStore\Fetcher; | |||
use OC\App\AppStore\Fetcher\Fetcher; | |||
use OC\Files\AppData\AppData; | |||
use OC\Files\AppData\Factory; | |||
use OCP\AppFramework\Utility\ITimeFactory; | |||
use OCP\Files\IAppData; | |||
@@ -58,7 +59,7 @@ abstract class FetcherBase extends TestCase { | |||
public function setUp() { | |||
parent::setUp(); | |||
$this->appDataFactory = $this->createMock(Factory::class); | |||
$this->appData = $this->createMock(IAppData::class); | |||
$this->appData = $this->createMock(AppData::class); | |||
$this->appDataFactory->expects($this->once()) | |||
->method('get') | |||
->with('appstore') |
@@ -0,0 +1,159 @@ | |||
<?php | |||
/** | |||
* @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
* @author Roeland Jago Douma <roeland@famdouma.nl> | |||
* | |||
* @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, | |||
* along with this program. If not, see <http://www.gnu.org/licenses/> | |||
* | |||
*/ | |||
namespace Test\Preview; | |||
use OC\Files\AppData\Factory; | |||
use OC\Preview\BackgroundCleanupJob; | |||
use OC\PreviewManager; | |||
use OCP\Files\IRootFolder; | |||
use OCP\IDBConnection; | |||
use Test\Traits\MountProviderTrait; | |||
use Test\Traits\UserTrait; | |||
/** | |||
* Class BackgroundCleanupJobTest | |||
* | |||
* @group DB | |||
* | |||
* @package Test\Preview | |||
*/ | |||
class BackgroundCleanupJobTest extends \Test\TestCase { | |||
use MountProviderTrait; | |||
use UserTrait; | |||
/** @var string */ | |||
private $userId; | |||
/** @var bool */ | |||
private $trashEnabled; | |||
/** @var Factory */ | |||
private $appDataFactory; | |||
/** @var IDBConnection */ | |||
private $connection; | |||
/** @var PreviewManager */ | |||
private $previewManager; | |||
/** @var IRootFolder */ | |||
private $rootFolder; | |||
public function setUp() { | |||
parent::setUp(); | |||
$this->userId = $this->getUniqueID(); | |||
$this->createUser($this->userId, $this->userId); | |||
$storage = new \OC\Files\Storage\Temporary([]); | |||
$this->registerMount($this->userId, $storage, ''); | |||
$this->loginAsUser($this->userId); | |||
$this->logout(); | |||
$this->loginAsUser($this->userId); | |||
$appManager = \OC::$server->getAppManager(); | |||
$this->trashEnabled = $appManager->isEnabledForUser('files_trashbin', $this->userId); | |||
$appManager->disableApp('files_trashbin'); | |||
$this->appDataFactory = \OC::$server->query(Factory::class); | |||
$this->connection = \OC::$server->getDatabaseConnection(); | |||
$this->previewManager = \OC::$server->getPreviewManager(); | |||
$this->rootFolder = \OC::$server->getRootFolder(); | |||
} | |||
public function tearDown() { | |||
if ($this->trashEnabled) { | |||
$appManager = \OC::$server->getAppManager(); | |||
$appManager->enableApp('files_trashbin'); | |||
} | |||
$this->logout(); | |||
return parent::tearDown(); | |||
} | |||
private function setup11Previews(): array { | |||
$userFolder = $this->rootFolder->getUserFolder($this->userId); | |||
$files = []; | |||
for ($i = 0; $i < 11; $i++) { | |||
$file = $userFolder->newFile($i.'.txt'); | |||
$file->putContent('hello world!'); | |||
$this->previewManager->getPreview($file); | |||
$files[] = $file; | |||
} | |||
return $files; | |||
} | |||
public function testCleanupSystemCron() { | |||
$files = $this->setup11Previews(); | |||
$preview = $this->appDataFactory->get('preview'); | |||
$previews = $preview->getDirectoryListing(); | |||
$this->assertCount(11, $previews); | |||
$job = new BackgroundCleanupJob($this->connection, $this->appDataFactory, true); | |||
$job->run([]); | |||
foreach ($files as $file) { | |||
$file->delete(); | |||
} | |||
$this->assertCount(11, $previews); | |||
$job->run([]); | |||
$previews = $preview->getDirectoryListing(); | |||
$this->assertCount(0, $previews); | |||
} | |||
public function testCleanupAjax() { | |||
$files = $this->setup11Previews(); | |||
$preview = $this->appDataFactory->get('preview'); | |||
$previews = $preview->getDirectoryListing(); | |||
$this->assertCount(11, $previews); | |||
$job = new BackgroundCleanupJob($this->connection, $this->appDataFactory, false); | |||
$job->run([]); | |||
foreach ($files as $file) { | |||
$file->delete(); | |||
} | |||
$this->assertCount(11, $previews); | |||
$job->run([]); | |||
$previews = $preview->getDirectoryListing(); | |||
$this->assertCount(1, $previews); | |||
$job->run([]); | |||
$previews = $preview->getDirectoryListing(); | |||
$this->assertCount(0, $previews); | |||
} | |||
} |
@@ -21,6 +21,7 @@ | |||
namespace Test\Security\IdentityProof; | |||
use OC\Files\AppData\AppData; | |||
use OC\Files\AppData\Factory; | |||
use OC\Security\IdentityProof\Key; | |||
use OC\Security\IdentityProof\Manager; | |||
@@ -50,7 +51,7 @@ class ManagerTest extends TestCase { | |||
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */ | |||
$this->factory = $this->createMock(Factory::class); | |||
$this->appData = $this->createMock(IAppData::class); | |||
$this->appData = $this->createMock(AppData::class); | |||
$this->config = $this->createMock(IConfig::class); | |||
$this->factory->expects($this->any()) | |||
->method('get') |
@@ -23,6 +23,7 @@ | |||
namespace Test\Template; | |||
use OC\Files\AppData\AppData; | |||
use OC\Files\AppData\Factory; | |||
use OCP\Files\IAppData; | |||
use OCP\ICacheFactory; | |||
@@ -51,7 +52,7 @@ class CSSResourceLocatorTest extends \Test\TestCase { | |||
parent::setUp(); | |||
$this->logger = $this->createMock(ILogger::class); | |||
$this->appData = $this->createMock(IAppData::class); | |||
$this->appData = $this->createMock(AppData::class); | |||
$this->urlGenerator = $this->createMock(IURLGenerator::class); | |||
$this->config = $this->createMock(IConfig::class); | |||
$this->cacheFactory = $this->createMock(ICacheFactory::class); |
@@ -23,6 +23,7 @@ | |||
namespace Test\Template; | |||
use OC\Files\AppData\AppData; | |||
use OC\Files\AppData\Factory; | |||
use OC\Template\SCSSCacher; | |||
use OCA\Theming\ThemingDefaults; | |||
@@ -58,7 +59,7 @@ class SCSSCacherTest extends \Test\TestCase { | |||
protected function setUp() { | |||
parent::setUp(); | |||
$this->logger = $this->createMock(ILogger::class); | |||
$this->appData = $this->createMock(IAppData::class); | |||
$this->appData = $this->createMock(AppData::class); | |||
/** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */ | |||
$factory = $this->createMock(Factory::class); |
@@ -29,7 +29,7 @@ | |||
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel | |||
// when updating major/minor version number. | |||
$OC_Version = array(14, 0, 0, 2); | |||
$OC_Version = array(14, 0, 0, 3); | |||
// The human readable string | |||
$OC_VersionString = '14.0.0 alpha'; |