2019-01-21 11:37:07 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by IntelliJ IDEA.
|
|
|
|
* User: philippe-adrien
|
|
|
|
* Date: 2019-01-20
|
|
|
|
* Time: 15:18
|
|
|
|
*/
|
|
|
|
|
2019-01-29 14:17:39 +00:00
|
|
|
namespace OCA\AppsAutoUpdater\Cron;
|
2019-01-21 11:37:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|