Skip to content

Commit

Permalink
Use TimedJob from OCP instead of OC
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Dec 5, 2022
1 parent 944be79 commit a0f6a65
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 28 deletions.
10 changes: 7 additions & 3 deletions apps/admin_audit/lib/BackgroundJobs/Rotate.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
*/
namespace OCA\AdminAudit\BackgroundJobs;

use OC\BackgroundJob\TimedJob;
use OCP\BackgroundJob\TimedJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\Log\RotationTrait;

Expand All @@ -37,13 +38,16 @@ class Rotate extends TimedJob {
/** @var IConfig */
private $config;

public function __construct(IConfig $config) {
public function __construct(ITimeFactory $time,
IConfig $config) {
parent::__construct($time);

$this->config = $config;

$this->setInterval(60 * 60 * 3);
}

protected function run($argument) {
protected function run($argument): void {
$default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
$this->filePath = $this->config->getAppValue('admin_audit', 'logfile', $default);

Expand Down
15 changes: 9 additions & 6 deletions apps/files/lib/BackgroundJob/CleanupDirectEditingTokens.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
Expand All @@ -23,18 +26,18 @@
*/
namespace OCA\Files\BackgroundJob;

use OC\BackgroundJob\TimedJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\DirectEditing\IManager;

class CleanupDirectEditingTokens extends TimedJob {
private const INTERVAL_MINUTES = 15 * 60;

/**
* @var IManager
*/
private $manager;
private IManager $manager;

public function __construct(IManager $manager) {
public function __construct(ITimeFactory $time,
IManager $manager) {
parent::__construct($time);
$this->interval = self::INTERVAL_MINUTES;
$this->manager = $manager;
}
Expand Down
8 changes: 5 additions & 3 deletions apps/files/lib/BackgroundJob/CleanupFileLocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
*/
namespace OCA\Files\BackgroundJob;

use OC\BackgroundJob\TimedJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OC\Lock\DBLockingProvider;

/**
* Clean up all file locks that are expired for the DB file locking provider
*/
class CleanupFileLocks extends TimedJob {

/**
* Default interval in minutes
*
Expand All @@ -41,7 +41,9 @@ class CleanupFileLocks extends TimedJob {
/**
* sets the correct interval for this timed job
*/
public function __construct() {
public function __construct(ITimeFactory $time) {
parent::__construct($time);

$this->interval = $this->defaultIntervalMin * 60;
}

Expand Down
6 changes: 4 additions & 2 deletions apps/files/lib/BackgroundJob/DeleteOrphanedItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
*/
namespace OCA\Files\BackgroundJob;

use OC\BackgroundJob\TimedJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\DB\QueryBuilder\IQueryBuilder;

/**
Expand All @@ -49,7 +50,8 @@ class DeleteOrphanedItems extends TimedJob {
/**
* sets the correct interval for this timed job
*/
public function __construct() {
public function __construct(ITimeFactory $time) {
parent::__construct($time);
$this->interval = $this->defaultIntervalMin * 60;
$this->connection = \OC::$server->getDatabaseConnection();
$this->logger = \OC::$server->getLogger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
*/
namespace OCA\Files_Sharing\BackgroundJob;

use OC\BackgroundJob\TimedJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\IDBConnection;
use OCP\OCS\IDiscoveryService;

Expand All @@ -36,8 +37,10 @@ class FederatedSharesDiscoverJob extends TimedJob {
/** @var IDiscoveryService */
private $discoveryService;

public function __construct(IDBConnection $connection,
public function __construct(ITimeFactory $time,
IDBConnection $connection,
IDiscoveryService $discoveryService) {
parent::__construct($time);
$this->connection = $connection;
$this->discoveryService = $discoveryService;

Expand Down
8 changes: 5 additions & 3 deletions apps/files_sharing/lib/DeleteOrphanedSharesJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
*/
namespace OCA\Files_Sharing;

use OC\BackgroundJob\TimedJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;

/**
* Delete all share entries that have no matching entries in the file cache table.
*/
class DeleteOrphanedSharesJob extends TimedJob {

/**
* Default interval in minutes
*
Expand All @@ -41,7 +41,9 @@ class DeleteOrphanedSharesJob extends TimedJob {
/**
* sets the correct interval for this timed job
*/
public function __construct() {
public function __construct(ITimeFactory $time) {
parent::__construct($time);

$this->interval = $this->defaultIntervalMin * 60;
}

Expand Down
7 changes: 5 additions & 2 deletions apps/updatenotification/lib/Notification/BackgroundJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
*/
namespace OCA\UpdateNotification\Notification;

use OC\BackgroundJob\TimedJob;
use OC\Installer;
use OC\Updater\VersionCheck;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IGroup;
Expand Down Expand Up @@ -60,12 +61,14 @@ class BackgroundJob extends TimedJob {
/** @var string[] */
protected $users;

public function __construct(IConfig $config,
public function __construct(ITimeFactory $timeFactory,
IConfig $config,
IManager $notificationManager,
IGroupManager $groupManager,
IAppManager $appManager,
IClientService $client,
Installer $installer) {
parent::__construct($timeFactory);
// Run once a day
$this->setInterval(60 * 60 * 24);

Expand Down
10 changes: 8 additions & 2 deletions apps/user_ldap/lib/Jobs/CleanUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
*/
namespace OCA\User_LDAP\Jobs;

use OC\BackgroundJob\TimedJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\DeletedUsersIndex;
Expand Down Expand Up @@ -64,7 +65,12 @@ class CleanUp extends TimedJob {
/** @var DeletedUsersIndex */
protected $dui;

public function __construct(User_Proxy $userBackend, DeletedUsersIndex $dui) {
public function __construct(
ITimeFactory $timeFactory,
User_Proxy $userBackend,
DeletedUsersIndex $dui
) {
parent::__construct($timeFactory);
$minutes = \OC::$server->getConfig()->getSystemValue(
'ldapUserCleanupInterval', (string)$this->defaultIntervalMin);
$this->setInterval((int)$minutes * 60);
Expand Down
6 changes: 4 additions & 2 deletions apps/workflowengine/lib/BackgroundJobs/Rotate.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
*/
namespace OCA\WorkflowEngine\BackgroundJobs;

use OC\BackgroundJob\TimedJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCA\WorkflowEngine\AppInfo\Application;
use OCP\Log\RotationTrait;

class Rotate extends TimedJob {
use RotationTrait;

public function __construct() {
public function __construct(ITimeFactory $time) {
parent::__construct($time);
$this->setInterval(60 * 60 * 3);
}

Expand Down
8 changes: 5 additions & 3 deletions lib/private/Preview/BackgroundCleanupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
*/
namespace OC\Preview;

use OC\BackgroundJob\TimedJob;
use OC\Preview\Storage\Root;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IDBConnection;

class BackgroundCleanupJob extends TimedJob {

/** @var IDBConnection */
private $connection;

Expand All @@ -47,10 +47,12 @@ class BackgroundCleanupJob extends TimedJob {
/** @var IMimeTypeLoader */
private $mimeTypeLoader;

public function __construct(IDBConnection $connection,
public function __construct(ITimeFactory $timeFactory,
IDBConnection $connection,
Root $previewFolder,
IMimeTypeLoader $mimeTypeLoader,
bool $isCLI) {
parent::__construct($timeFactory);
// Run at most once an hour
$this->setInterval(3600);

Expand Down

0 comments on commit a0f6a65

Please sign in to comment.