Skip to content

Commit

Permalink
Fixed issue: No update notification for comfort update users
Browse files Browse the repository at this point in the history
  • Loading branch information
eddylackmann committed Oct 14, 2020
1 parent c2bd269 commit 7804ea5
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 3 deletions.
4 changes: 2 additions & 2 deletions application/config/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
*/

$config['versionnumber'] = '4.3.20';
$config['dbversionnumber'] = 429;
$config['dbversionnumber'] = 430;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['templateapiversion'] = 3;
$config['assetsversionnumber'] = '30164';
$config['assetsversionnumber'] = '30165';
return $config;
126 changes: 126 additions & 0 deletions application/core/plugins/ComfortUpdateChecker/ComfortUpdateChecker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

/*
* Update Checker for Comfort Update users
* Copyright (C) LimeSurvey GmbH
* License: GNU/GPL License v2 http://www.gnu.org/licenses/gpl-2.0.html
* A plugin of LimeSurvey, a free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/

define('ROOT_FOLDER', __DIR__ . '/');

//loads libraries
require_once(ROOT_FOLDER . 'helpers/CUCMenuClass.php');


class ComfortUpdateChecker extends PluginBase
{

protected $storage = 'DbStorage';

static protected $description = 'Update Checker for Comfort Update users';

static protected $name = 'ComfortUpdateChecker';

protected $settings = [

'only_security_update' => array(
'type' => 'checkbox',
'label' => 'Notification only for security updates',
'default' => false,
),

'animate_icon' => array(
'type' => 'checkbox',
'label' => 'Animate update icon',
'default' => false,
),

];


public function init()
{

$this->subscribe('beforeAdminMenuRender');
}

/**
* Append new menu item to the admin topbar
*
* @return void
*/
public function beforeAdminMenuRender()
{
$oEvent = $this->getEvent();

//Register css and js script
$this->registerAssets();

$update = (array)$this->getUpdate();

if ($update['result']) {

//Default icon class
$iconClass = "";
$NotificationText = gT("Update available");

if ($update[key($update)]->security_update) {
$NotificationText = gT("Security update available");
}
//Append cu-checker class to icon when animate option is true in plugin settings
if ($this->get('animate_icon', null, null, false)) {
$iconClass = "cu-checker";
}

//Display update notification only for superadmin user
if (Permission::model()->hasGlobalPermission('superadmin')) {
$aMenuItemAdminOptions = [
'isDivider' => false,
'isSmallText' => false,
'label' => '<strong class="text-warning">' . $NotificationText . '</strong>',
'href' => $this->api->createUrl('admin/update', []),
'iconClass' => 'icon-shield text-warning ' . $iconClass,
];

$aMenuItems[] = (new \LimeSurvey\Menu\MenuItem($aMenuItemAdminOptions));

$oNewMenu = new CUCMenuClass($aMenuItemAdminOptions);

//Check if display only for security update is true in plugin settings and display it otherwhise display all
if ($this->get('only_security_update', null, null, false) && $update[key($update)]->security_update) {
$oEvent->append('extraMenus', [$oNewMenu]);
} elseif (!$this->get('only_security_update', null, null, false)) {
$oEvent->append('extraMenus', [$oNewMenu]);
}
}
}
}

/**
* This function check if update is available from the comfort update server
*
* @return void
*/
private function getUpdate()
{
$buttons = 1;
$updateModel = new UpdateForm();
$serverAnswer = $updateModel->getUpdateInfo($buttons);
return $serverAnswer;
}

/**
* Register css and js file
* @return void
*/
protected function registerAssets()
{
$assetsUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets');
Yii::app()->clientScript->registerScriptFile($assetsUrl . '/script.js');
Yii::app()->clientScript->registerCssFile($assetsUrl . '/style.css');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$(document).ready(function () {

});
30 changes: 30 additions & 0 deletions application/core/plugins/ComfortUpdateChecker/assets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.cu-checker {
animation: shake 1.25s cubic-bezier(.36, .07, .19, .97) both infinite;
transform: translate3d(0, 0, 0);
backface-visibility: hidden;
perspective: 1000px;
}

@keyframes shake {

10%,
90% {
transform: translate3d(-1px, 0, 0);
}

20%,
80% {
transform: translate3d(1px, 0, 0);
}

30%,
50%,
70% {
transform: translate3d(-4px, 0, 0);
}

40%,
60% {
transform: translate3d(4px, 0, 0);
}
}
23 changes: 23 additions & 0 deletions application/core/plugins/ComfortUpdateChecker/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<config>
<metadata>
<name>ComfortUpdateChecker</name>
<type>plugin</type>
<creationDate>2020-10-12</creationDate>
<lastUpdate>2020-10-12</lastUpdate>
<author>Eddy Lackmann | LimeSurvey Team</author>
<authorUrl>https://limesurvey.org</authorUrl>
<email>support@limesurvey.org</email>
<version>1.0.0</version>
<license>GNU General Public License version 2 or later</license>
<description><![CDATA[Checks if new update is available for comfort update users]]></description>
<supportUrl>https://www.limesurvey.org</supportUrl>
</metadata>
<compatibility>
<version>4.0</version>
<version>3.0</version>
</compatibility>
<updaters disabled="disabled">

</updaters>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

/**
* Extending the basic menu class with an icon in front of the label
*/
class CUCMenuClass extends \LimeSurvey\Menu\Menu
{
public function getLabel()
{
return "<i class='" . $this->iconClass . "'></i>&nbsp;" . $this->label;
}
}
16 changes: 15 additions & 1 deletion application/helpers/update/updatedb_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3205,8 +3205,22 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
extendDatafields429($oDB); // Do it again for people already using 4.x before this was introduced
$oDB->createCommand()->update('{{settings_global}}', ['stg_value'=>429], "stg_name='DBVersion'");
$oTransaction->commit();
}
}

if ($iOldDBVersion < 430) {
$oTransaction = $oDB->beginTransaction();
$oDB->createCommand()->insert("{{plugins}}", [
'name' => 'ComfortUpdateChecker',
'plugin_type' => 'core',
'active' => 1,
'version' => '1.0.0',
'load_error' => 0,
'load_error_message' => null
]);

$oDB->createCommand()->update('{{settings_global}}', array('stg_value' => 430), "stg_name='DBVersion'");
$oTransaction->commit();
}

} catch (Exception $e) {
Yii::app()->setConfig('Updating', false);
Expand Down

0 comments on commit 7804ea5

Please sign in to comment.