diff --git a/appinfo/app.php b/appinfo/app.php index d7f99536..6e415c3b 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -49,5 +49,3 @@ $manager->registerExtension(function() { * The string has to match the app's folder name */ Util::addTranslations('passman'); - -\OCP\BackgroundJob::addRegularTask('\OCA\Passman\Cron\ExpireCredentials', 'run'); \ No newline at end of file diff --git a/appinfo/info.xml b/appinfo/info.xml index be0c72d2..1c9bd0ca 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -5,7 +5,7 @@ A password manager for Nextcloud AGPL Sander Brand - 1.0.2.24 + 1.0.2.25 Passman other https://github.com/nextcloud/passman/ @@ -15,4 +15,9 @@ + + + + OCA\Passman\BackgroundJob\ExpireCredentials + \ No newline at end of file diff --git a/lib/BackgroundJob/ExpireCredentials.php b/lib/BackgroundJob/ExpireCredentials.php new file mode 100644 index 00000000..2c430a10 --- /dev/null +++ b/lib/BackgroundJob/ExpireCredentials.php @@ -0,0 +1,52 @@ + + * + * @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 + * + */ + +namespace OCA\Passman\BackgroundJob; + +use OC\BackgroundJob\TimedJob; +use \OCA\Passman\AppInfo\Application; +use OCP\IConfig; + +/** + * Class ExpireCredentials + * + * @package OCA\Passman\BackgroundJob + */ +class ExpireCredentials extends TimedJob { + /** @var IConfig */ + protected $config; + + /** + * @param IConfig $config + */ + public function __construct(IConfig $config) { + // Run once per minute + $this->setInterval(60); + $this->config = $config; + } + + protected function run($argument) { + $app = new Application(); + $container = $app->getContainer(); + $container->query('CronService')->expireCredentials(); + } +} diff --git a/lib/Cron/ExpireCredentials.php b/lib/Cron/ExpireCredentials.php deleted file mode 100644 index d52259cd..00000000 --- a/lib/Cron/ExpireCredentials.php +++ /dev/null @@ -1,23 +0,0 @@ - - * @copyright Sander Brand 2016 - */ - - -namespace OCA\Passman\Cron; -use OCA\Passman\Service\CredentialService; -use OCA\Passman\Utility\Utils; -use \OCA\Passman\AppInfo\Application; -class ExpireCredentials { - public static function run() { - $app = new Application(); - $container = $app->getContainer(); - $container->query('CronService')->expireCredentials(); - } -} \ No newline at end of file diff --git a/lib/Service/CronService.php b/lib/Service/CronService.php index dd4aa085..75f8f189 100644 --- a/lib/Service/CronService.php +++ b/lib/Service/CronService.php @@ -33,7 +33,8 @@ class CronService { $this->activityService = $activityService; $this->db = $db; } - //@TODO rename to a general name with sub tasks + + public function expireCredentials() { $this->logger->info('Passman cron test', array('app' => 'passman')); $expired_credentials = $this->credentialService->getExpiredCredentials($this->utils->getTime()); diff --git a/tests/unit/BackgroundJob/ExpireCredentialsTest.php b/tests/unit/BackgroundJob/ExpireCredentialsTest.php new file mode 100644 index 00000000..2d0af91d --- /dev/null +++ b/tests/unit/BackgroundJob/ExpireCredentialsTest.php @@ -0,0 +1,48 @@ +. + * + */ + +namespace OCA\Passman\Tests\BackgroundJob; + +use PHPUnit_Framework_TestCase; +use OCA\Passman\BackgroundJob\ExpireCredentials; +use OCP\IConfig; + +/** + * Class ExpireActivitiesTest + * + * @group DB + * @package OCA\Passman\Tests\BackgroundJob + * @covers ExpireCredentials + */ +class ExpireCredentialsTest extends PHPUnit_Framework_TestCase { + public function testRun() { + $backgroundJob = new ExpireCredentials( + $this->getMockBuilder(IConfig::class)->getMock() + ); + + $jobList = $this->getMockBuilder('\OCP\BackgroundJob\IJobList')->getMock(); + + /** @var \OC\BackgroundJob\JobList $jobList */ + $backgroundJob->execute($jobList); + $this->assertTrue(true); + } +}