Skip to content

Commit

Permalink
Dev: Save date for next extension update check
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Oct 5, 2018
1 parent 00ff59a commit 268603c
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions application/core/plugins/UpdateCheck/UpdateCheck.php
Expand Up @@ -21,6 +21,13 @@
*/
class UpdateCheck extends PluginBase
{

/**
* Where to save plugin settings etc.
* @var string
*/
protected $storage = 'DbStorage';

/**
* @return void
*/
Expand All @@ -36,8 +43,14 @@ public function init()
public function afterSuccessfulLogin()
{
if (Permission::model()->hasGlobalPermission('superadmin')) {
// Set flag.
Yii::app()->session['do_extensions_update_check'] = true;
// NB: $nextCheck will be set to "now" if next_extension_update_check is empty.
// Hence it needs to be initialised *before* today.
$nextCheck = new DateTime($this->get('next_extension_update_check'));
$today = new DateTime("now");
if ($nextCheck <= $today) {
// Set flag.
Yii::app()->session['do_extensions_update_check'] = true;
}
}
}

Expand All @@ -47,13 +60,20 @@ public function afterSuccessfulLogin()
public function beforeControllerAction()
{
$controller = $this->getEvent()->get('controller');
$doUpdateCheck = Yii::app()->session['do_extensions_update_check'];
$doUpdateCheckFlag = Yii::app()->session['do_extensions_update_check'];

if ($controller == 'admin' && $doUpdateCheckFlag) {

if ($controller == 'admin' && $doUpdateCheck) {
// Render some JavaScript that will Ajax call update check.
$this->spitOutUrl();
$this->registerScript();

// Unset flag.
Yii::app()->session['do_extensions_update_check'] = false;

// Set date for next check.
$today = new DateTime("now");
$this->set('next_extension_update_check', $today->add(new DateInterval('P1D'))->format('Y-m-d H:i:s'));
}
}

Expand All @@ -68,7 +88,6 @@ public function checkAll()
$service = \Yii::app()->extensionUpdaterServiceLocator;

// Get one updater class for each extension type (PluginUpdater, ThemeUpdater, etc).
// Only static methods will be used for this updaters.
list($updaters, $errors) = $service->getAllUpdaters();

/** @var string[] */
Expand Down

0 comments on commit 268603c

Please sign in to comment.