init
This commit is contained in:
		
							
								
								
									
										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