Skip to content

Commit

Permalink
Dev: Update check after super admin login works
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Oct 4, 2018
1 parent d367983 commit 7c073b4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
52 changes: 50 additions & 2 deletions application/core/plugins/UpdateCheck/UpdateCheck.php
Expand Up @@ -27,13 +27,34 @@ class UpdateCheck extends PluginBase
public function init()
{
$this->subscribe('afterSuccessfulLogin');
$this->subscribe('beforeControllerAction');
}

/**
* @return void
*/
public function afterSuccessfulLogin()
{
if (Permission::model()->hasGlobalPermission('superadmin')) {
// Set flag.
Yii::app()->session['do_update_check'] = true;
}
}

/**
* @return void
*/
public function beforeControllerAction()
{
$controller = $this->getEvent()->get('controller');
$doUpdateCheck = Yii::app()->session['do_update_check'];

if ($controller == 'admin' && $doUpdateCheck) {
$this->spitOutUrl();
$this->registerScript();
// Unset flag.
Yii::app()->session['do_update_check'] = false;
}
}

/**
Expand Down Expand Up @@ -64,7 +85,7 @@ public function checkAll()
implode(', ', $availableVersions)
);
}
} catch (\Exception $ex) {
} catch (\Throwable $ex) {
$errors[] = $ex->getMessage();
}
}
Expand All @@ -74,10 +95,37 @@ public function checkAll()
UniqueNotification::broadcast(
[
'title' => gT('Updates available'),
'message' => implode('<br/>', $messages)
'message' => implode('<br/>', $messages) . '<br/>' . implode('<br/>', $errors)
],
$superadmins
);
}
}

/**
* @return void
*/
protected function spitOutUrl()
{
$data = [
'url' => Yii::app()->createUrl(
'admin/pluginhelper',
array(
'sa' => 'ajax',
'plugin' => 'updateCheck',
'method' => 'checkAll'
)
)
];
echo $this->api->renderTwig(__DIR__ . '/views/index.twig', $data);
}

/**
* @return void
*/
protected function registerScript()
{
$assetsUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets/js');
Yii::app()->clientScript->registerScriptFile($assetsUrl . '/updateCheck.js');
}
}
15 changes: 15 additions & 0 deletions application/core/plugins/UpdateCheck/assets/js/updateCheck.js
@@ -0,0 +1,15 @@
$(document).ready(function() {
var url = LS.plugin.updateCheck.url;
$.ajax({
url: url,
data: {},
method: 'GET',
success: function(response) {
console.ls.log(response);
//LS.updateNotificationWidget();
},
error : function(arguments) {
console.ls.log(arguments);
}
});
});

0 comments on commit 7c073b4

Please sign in to comment.