AppsAutoUpdater/lib/Cron/AppsAutoUpdateTask.php
2019-01-29 15:17:39 +01:00

56 lines
1.3 KiB
PHP

<?php
/**
* Created by IntelliJ IDEA.
* User: philippe-adrien
* Date: 2019-01-20
* Time: 15:18
*/
namespace OCA\AppsAutoUpdater\Cron;
use OC\BackgroundJob\TimedJob;
use OC\Installer;
use OCP\ILogger;
class AppsAutoUpdateTask extends TimedJob
{
private $installer;
private $log;
private $config;
/**
* AppsAutoUpdateTask constructor.
* @param ILogger|null $log
* @throws \OCP\AppFramework\QueryException
*/
public function __construct(ILogger $log = null)
{
$this->setInterval(15 * 60);
$this->log = $log;
$this->config =\OC::$server->getConfig();
$this->installer = \OC::$server->query(Installer::class);
}
protected function run($argument)
{
$ocApp = new \OC_App();
$apps = $ocApp->listAllApps();
foreach($apps as $app) {
if(!$app["active"]) continue;
$appId = $app["id"];
try {
if ($this->installer->isUpdateAvailable($appId)) {
$this->config->setSystemValue('maintenance', true);
$this->installer->updateAppstoreApp($appId);
$this->config->setSystemValue('maintenance', false);
}
} catch (\Exception $ex) {
$this->log->logException($ex, ['app' => 'appsautoupdate']);
$this->config->setSystemValue('maintenance', false);
}
}
}
}