init
This commit is contained in:
16
lib/Controller/AppsAutoUpdateController.php
Normal file
16
lib/Controller/AppsAutoUpdateController.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace OCA\ApplicationsAutoUpdater\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Controller;
|
||||
|
||||
class AppsAutoUpdateController extends Controller {
|
||||
|
||||
|
||||
public function __construct($AppName, IRequest $request){
|
||||
parent::__construct($AppName, $request);
|
||||
|
||||
}
|
||||
}
|
55
lib/Cron/AppsAutoUpdateTask.php
Normal file
55
lib/Cron/AppsAutoUpdateTask.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: philippe-adrien
|
||||
* Date: 2019-01-20
|
||||
* Time: 15:18
|
||||
*/
|
||||
|
||||
namespace OCA\ApplicationsAutoUpdater\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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user