mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-16 11:30:55 +01:00
Aggiunto hook per aggiornamenti
This commit is contained in:
parent
271346f6aa
commit
7cc0620226
@ -2,6 +2,7 @@
|
||||
|
||||
return [
|
||||
'include' => 'Common',
|
||||
'modules/aggiornamenti' => 'Modules\Aggiornamenti',
|
||||
'modules/anagrafiche' => 'Modules\Anagrafiche',
|
||||
'modules/articoli' => 'Modules\Articoli',
|
||||
'modules/ritenute' => 'Modules\Ritenute',
|
||||
|
@ -63,11 +63,13 @@ if (Auth::check()) {
|
||||
},
|
||||
success: function(data) {
|
||||
hooks = JSON.parse(data);
|
||||
|
||||
|
||||
$("#hooks-header").text(globals.translations.hooksExecuting);
|
||||
|
||||
if (hooks.length == 0) {
|
||||
$("#hooks-loading").hide();
|
||||
$("#hooks-number").text(0);
|
||||
$("#hooks-header").append(\'<span class="small">\' + globals.translations.hookNone + \'</small>\');
|
||||
$("#hooks-header").text(globals.translations.hookNone);
|
||||
}
|
||||
|
||||
hooks.forEach(function(item, index){
|
||||
|
@ -84,6 +84,7 @@ if (Auth::check()) {
|
||||
'details' => tr('Dettagli'),
|
||||
'waiting' => tr('Impossibile procedere'),
|
||||
'waiting_msg' => tr('Prima di proseguire devi selezionare alcuni elementi!'),
|
||||
'hooksExecuting' => tr('Hooks in esecuzione'),
|
||||
'hookExecuting' => tr('Hook "_NAME_" in esecuzione'),
|
||||
'hookMultiple' => tr('Hai _NUM_ notifiche'),
|
||||
'hookSingle' => tr('Hai 1 notifica'),
|
||||
@ -243,7 +244,7 @@ if (Auth::check()) {
|
||||
</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li class="header" id="hooks-header" ></li>
|
||||
<li class="header"><span class="small" id="hooks-header"></span></li>
|
||||
<li><ul class="menu" id="hooks">
|
||||
|
||||
</ul></li>
|
||||
|
@ -1570,7 +1570,7 @@ function executeHook(hook, length){
|
||||
hookMessage = globals.translations.hookNone;
|
||||
}
|
||||
|
||||
$("#hooks-header").append('<span class="small">' + hookMessage + '</small>');
|
||||
$("#hooks-header").text(hookMessage);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
86
modules/aggiornamenti/src/UpdateHook.php
Normal file
86
modules/aggiornamenti/src/UpdateHook.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Aggiornamenti;
|
||||
|
||||
use Common\HookManager;
|
||||
use GuzzleHttp\Client;
|
||||
use Modules;
|
||||
use Update;
|
||||
|
||||
class UpdateHook extends HookManager
|
||||
{
|
||||
protected static $client = null;
|
||||
|
||||
public function manage()
|
||||
{
|
||||
$result = self::isAvailable();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function response($update)
|
||||
{
|
||||
$module = Modules::get('Aggiornamenti');
|
||||
$link = ROOTDIR.'/controller.php?id_module='.$module->id;
|
||||
|
||||
$message = tr("E' disponibile la versione _VERSION_ del gestionale", [
|
||||
'_VERSION_' => $update,
|
||||
]);
|
||||
|
||||
return [
|
||||
'icon' => 'fa fa-download text-info',
|
||||
'link' => $link,
|
||||
'message' => $message,
|
||||
'notify' => !empty($update),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Controlla se è disponibile un aggiornamento nella repository GitHub.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function isAvailable()
|
||||
{
|
||||
$api = self::getAPI();
|
||||
|
||||
$version = ltrim($api['tag_name'], 'v');
|
||||
$current = Update::getVersion();
|
||||
|
||||
if (version_compare($current, $version) < 0) {
|
||||
return $version;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'oggetto per la connessione all'API del progetto.
|
||||
*
|
||||
* @return Client
|
||||
*/
|
||||
protected static function getClient()
|
||||
{
|
||||
if (!isset(self::$client)) {
|
||||
self::$client = new Client([
|
||||
'base_uri' => 'https://api.github.com/repos/devcode-it/openstamanager/',
|
||||
'verify' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
return self::$client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce i contenuti JSON dell'API del progetto.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getAPI()
|
||||
{
|
||||
$response = self::getClient()->request('GET', 'releases');
|
||||
$body = $response->getBody();
|
||||
|
||||
return json_decode($body, true)[0];
|
||||
}
|
||||
}
|
@ -47,7 +47,7 @@ class API extends \Util\Singleton
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (!self::isAPIRequest() || (!Auth::check() && self::getRequest()['resource'] != 'login')) {
|
||||
if (!Auth::check() && self::getRequest()['resource'] != 'login') {
|
||||
throw new InvalidArgumentException();
|
||||
}
|
||||
}
|
||||
|
@ -23,3 +23,6 @@ ALTER TABLE `zz_hooks` ADD `enabled` boolean NOT NULL DEFAULT 1, ADD `id_module`
|
||||
UPDATE `zz_hooks` SET `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Fatture di vendita') WHERE `name` = 'Ricevute';
|
||||
UPDATE `zz_hooks` SET `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Fatture di acquisto') WHERE `name` = 'Fatture';
|
||||
ALTER TABLE `zz_hooks` ADD FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE;
|
||||
|
||||
INSERT INTO `zz_hooks` (`id`, `name`, `class`, `frequency`, `id_module`) VALUES
|
||||
(NULL, 'Ricevute', 'Modules\\Aggiornamenti\\UpdateHook', '7 day', (SELECT `id` FROM `zz_modules` WHERE `name` = 'Aggiornamenti'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user