Merge branch 'backgroundJob'

This commit is contained in:
brantje 2016-10-16 13:28:19 +02:00
commit 94d4f30948
No known key found for this signature in database
GPG key ID: 5FF1D117F918687F
6 changed files with 108 additions and 27 deletions

View file

@ -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');

View file

@ -5,7 +5,7 @@
<description>A password manager for Nextcloud</description>
<licence>AGPL</licence>
<author>Sander Brand</author>
<version>1.0.2.24</version>
<version>1.0.2.25</version>
<namespace>Passman</namespace>
<category>other</category>
<website>https://github.com/nextcloud/passman/</website>
@ -15,4 +15,9 @@
<owncloud min-version="9" max-version="11" />
<nextcloud min-version="9" max-version="11" />
</dependencies>
<background-jobs>
<job>OCA\Passman\BackgroundJob\ExpireCredentials</job>
</background-jobs>
</info>

View file

@ -0,0 +1,52 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Joas Schilling <coding@schilljs.com>
*
* @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 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();
}
}

View file

@ -1,23 +0,0 @@
<?php
/**
* Nextcloud - passman
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <brantje@gmail.com>
* @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();
}
}

View file

@ -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());

View file

@ -0,0 +1,48 @@
<?php
/**
*
* @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
* @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 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);
}
}