diff --git a/cron.php b/cron.php index fd78c52ed..77aefd110 100644 --- a/cron.php +++ b/cron.php @@ -61,13 +61,13 @@ $handler->setFormatter($formatter); $logger->pushHandler($handler); // Lettura della cache -$ultima_esecuzione = Cache::pool('Ultima esecuzione del cron'); +$ultima_esecuzione = (new Cache())->getByName('Ultima esecuzione del cron'); $data = $ultima_esecuzione->content; -$in_esecuzione = Cache::pool('Cron in esecuzione'); -$cron_id = Cache::pool('ID del cron'); +$in_esecuzione = (new Cache())->getByName('Cron in esecuzione'); +$cron_id = (new Cache())->getByName('ID del cron'); -$disattiva = Cache::pool('Disabilita cron'); +$disattiva = (new Cache())->getByName('Disabilita cron'); if ($disattiva->content || (in_array($_SERVER['HTTP_HOST'], ['localhost', '127.0.0.1']) && !$forza_cron_localhost)) { return; } diff --git a/modules/aggiornamenti/actions.php b/modules/aggiornamenti/actions.php index f48d0c564..ef63dc41e 100755 --- a/modules/aggiornamenti/actions.php +++ b/modules/aggiornamenti/actions.php @@ -39,7 +39,7 @@ switch (filter('op')) { } // Salvataggio della versione nella cache - Cache::pool('Ultima versione di OpenSTAManager disponibile')->set($versione); + (new Cache())->getByName('Ultima versione di OpenSTAManager disponibile')->set($versione); echo $versione; diff --git a/modules/interventi/actions.php b/modules/interventi/actions.php index 094667de9..7675b70b2 100644 --- a/modules/interventi/actions.php +++ b/modules/interventi/actions.php @@ -93,7 +93,7 @@ switch (post('op')) { if (!in_array($tecnico_presente['id_tecnico'], $tecnici_assegnati)) { $tecnico = Anagrafica::find($tecnico_presente['id_tecnico']); if (!empty($tecnico['email'])) { - $template = Template::pool('Notifica rimozione intervento'); + $template = (new Template())->getByName('Notifica rimozione intervento'); if (!empty($template)) { $mail = Mail::build(auth()->getUser(), $template, $intervento->id); @@ -112,7 +112,7 @@ switch (post('op')) { $tecnico = Anagrafica::find($tecnico_assegnato); if (!empty($tecnico['email'])) { - $template = Template::pool('Notifica intervento'); + $template = (new Template())->getByName('Notifica intervento'); if (!empty($template)) { $mail = Mail::build(auth()->getUser(), $template, $intervento->id); @@ -294,7 +294,7 @@ switch (post('op')) { // Notifica al tecnico if (setting('Notifica al tecnico l\'assegnazione all\'attività')) { if (!empty($tecnico['email'])) { - $template = Template::pool('Notifica intervento'); + $template = (new Template())->getByName('Notifica intervento'); if (!empty($template)) { $mail = Mail::build(auth()->getUser(), $template, $intervento->id); @@ -917,7 +917,7 @@ switch (post('op')) { // Notifica rimozione dell' intervento al tecnico if (setting('Notifica al tecnico la rimozione della sessione dall\'attività')) { if (!empty($tecnico['email'])) { - $template = Template::pool('Notifica rimozione intervento'); + $template = (new Template())->getByName('Notifica rimozione intervento'); if (!empty($template)) { $mail = Mail::build(auth()->getUser(), $template, $id_record); diff --git a/modules/interventi/modutil.php b/modules/interventi/modutil.php index 6a186e172..8d480b8b3 100755 --- a/modules/interventi/modutil.php +++ b/modules/interventi/modutil.php @@ -107,7 +107,7 @@ if (!function_exists('add_tecnico')) { // Notifica nuovo intervento al tecnico if (setting('Notifica al tecnico l\'aggiunta della sessione nell\'attività')) { if (!empty($anagrafica['email'])) { - $template = Template::pool('Notifica intervento'); + $template = (new Template())->getByName('Notifica intervento'); if (!empty($template)) { $mail = Mail::build(auth()->getUser(), $template, $id_intervento); diff --git a/modules/scadenzario/bulk.php b/modules/scadenzario/bulk.php index c4a1ead09..f12d3c3c3 100755 --- a/modules/scadenzario/bulk.php +++ b/modules/scadenzario/bulk.php @@ -72,7 +72,7 @@ switch (post('op')) { break; case 'send-sollecito': - $template = Template::pool('Sollecito di pagamento raggruppato per anagrafica'); + $template = (new Template())->getByName('Sollecito di pagamento raggruppato per anagrafica'); $list = []; $anagrafiche = []; diff --git a/modules/stato_servizi/actions.php b/modules/stato_servizi/actions.php index 46c545c41..026ae9d44 100755 --- a/modules/stato_servizi/actions.php +++ b/modules/stato_servizi/actions.php @@ -372,7 +372,7 @@ switch (filter('op')) { break; case 'informazioni-fe': - $info = Cache::pool('Informazioni su spazio FE'); + $info = (new Cache())->getByName('Informazioni su spazio FE'); if (!$info->isValid()) { $response = Services::request('POST', 'informazioni_fe'); $response = Services::responseBody($response); diff --git a/plugins/importFE/src/Interaction.php b/plugins/importFE/src/Interaction.php index 6d6ee8109..7cb93c7bc 100755 --- a/plugins/importFE/src/Interaction.php +++ b/plugins/importFE/src/Interaction.php @@ -42,7 +42,7 @@ class Interaction extends Services $result = self::getFileList($list); // Aggiornamento cache hook - Cache::pool('Fatture Elettroniche')->set($result); + (new Cache())->getByName('Fatture Elettroniche')->set($result); return $result; } diff --git a/plugins/receiptFE/src/Interaction.php b/plugins/receiptFE/src/Interaction.php index 22a1a73af..430b87194 100755 --- a/plugins/receiptFE/src/Interaction.php +++ b/plugins/receiptFE/src/Interaction.php @@ -42,7 +42,7 @@ class Interaction extends Services $result = self::getFileList($list); // Aggiornamento cache hook - Cache::pool('Ricevute Elettroniche')->set($result); + (new Cache())->getByName('Ricevute Elettroniche')->set($result); return $result; } diff --git a/plugins/receiptFE/src/ReceiptHook.php b/plugins/receiptFE/src/ReceiptHook.php index aea5c4f4d..554048587 100755 --- a/plugins/receiptFE/src/ReceiptHook.php +++ b/plugins/receiptFE/src/ReceiptHook.php @@ -41,7 +41,7 @@ class ReceiptHook extends Manager } // Lettura cache - $todo_cache = Cache::pool('Ricevute Elettroniche'); + $todo_cache = (new Cache())->getByName('Ricevute Elettroniche'); return !$todo_cache->isValid() || !empty($todo_cache->content); } @@ -49,8 +49,8 @@ class ReceiptHook extends Manager public function execute() { // Lettura cache - $todo_cache = Cache::pool('Ricevute Elettroniche'); - $completed_cache = Cache::pool('Ricevute Elettroniche importate'); + $todo_cache = (new Cache())->getByName('Ricevute Elettroniche'); + $completed_cache = (new Cache())->getByName('Ricevute Elettroniche importate'); // Refresh cache if (!$todo_cache->isValid()) { @@ -94,8 +94,8 @@ class ReceiptHook extends Manager public function response() { // Lettura cache - $todo_cache = Cache::pool('Ricevute Elettroniche'); - $completed_cache = Cache::pool('Ricevute Elettroniche importate'); + $todo_cache = (new Cache())->getByName('Ricevute Elettroniche'); + $completed_cache = (new Cache())->getByName('Ricevute Elettroniche importate'); $completed_number = (is_array($completed_cache->content) ? count($completed_cache->content) : 0); $total_number = $completed_number + (is_array($todo_cache->content) ? count($todo_cache->content) : 0); diff --git a/reset.php b/reset.php index 378348d94..2aa1075d2 100755 --- a/reset.php +++ b/reset.php @@ -44,7 +44,7 @@ switch (post('op')) { $utente->reset_token = secure_random_string(); $utente->save(); - $template = Template::pool('Reset password'); + $template = (new Template())->getByName('Reset password'); $mail = Mail::build($utente, $template, $utente->id); $mail->addReceiver($utente->email); diff --git a/src/API/Common/Task.php b/src/API/Common/Task.php index ef33474c0..132f978e2 100644 --- a/src/API/Common/Task.php +++ b/src/API/Common/Task.php @@ -44,22 +44,22 @@ class Task extends Resource implements RetrieveInterface, CreateInterface $database = database(); // Rimozione della registrazione del cron attuale - $ultima_esecuzione = Cache::pool('Ultima esecuzione del cron'); + $ultima_esecuzione = (new Cache())->getByName('Ultima esecuzione del cron'); $ultima_esecuzione->set(null); // Segnalazione della chiusura al cron attuale - $cron_id = Cache::pool('ID del cron'); + $cron_id = (new Cache())->getByName('ID del cron'); $cron_id->set(null); // Rimozione dell'eventuale blocco sul cron - $disattiva = Cache::pool('Disabilita cron'); + $disattiva = (new Cache())->getByName('Disabilita cron'); $disattiva->set(null); // Salvataggio delle modifiche $database->commitTransaction(); // Attesa della conclusione per il cron precedente - $in_esecuzione = Cache::pool('Cron in esecuzione'); + $in_esecuzione = (new Cache())->getByName('Cron in esecuzione'); while ($in_esecuzione->content) { $timestamp = (new Carbon())->addMinutes(1)->getTimestamp(); time_sleep_until($timestamp); diff --git a/src/API/Services.php b/src/API/Services.php index 8f550421f..6802310dd 100755 --- a/src/API/Services.php +++ b/src/API/Services.php @@ -49,7 +49,7 @@ class Services */ public static function getInformazioni($force = false) { - $cache = Cache::pool('Informazioni su Services'); + $cache = (new Cache())->getByName('Informazioni su Services'); // Aggiornamento dei contenuti della cache if (!$cache->isValid() || $force) { diff --git a/src/Hooks/CachedManager.php b/src/Hooks/CachedManager.php index 286acfc8c..da61e2856 100755 --- a/src/Hooks/CachedManager.php +++ b/src/Hooks/CachedManager.php @@ -30,7 +30,7 @@ abstract class CachedManager extends Manager { parent::__construct($hook); - $this->cache = Cache::pool($this->getCacheName()); + $this->cache = (new Cache())->getByName($this->getCacheName()); } abstract public function cacheData(); diff --git a/src/Models/Cache.php b/src/Models/Cache.php index b7eaefc9b..e03542028 100755 --- a/src/Models/Cache.php +++ b/src/Models/Cache.php @@ -105,4 +105,34 @@ class Cache extends Model { return $query->where('expire_at', '<=', Carbon::now()); } + + /** + * Ritorna l'attributo name della cache. + * + * @return string + */ + public function getNameAttribute() + { + return database()->table($this->table.'_lang') + ->select('name') + ->where('id_record', '=', $this->id) + ->where('id_lang', '=', setting('Lingua')) + ->first()->name; + } + + /** + * Ritorna l'id della cache a partire dal nome. + * + * @param string $name il nome da ricercare + * + * @return \Illuminate\Support\Collection + */ + public function getByName($name) + { + return database()->table($this->table.'_lang') + ->select('id_record') + ->where('name', '=', $name) + ->where('id_lang', '=', setting('Lingua')) + ->first(); + } } diff --git a/src/Update.php b/src/Update.php index d8c6fde27..a1a7906f4 100755 --- a/src/Update.php +++ b/src/Update.php @@ -208,7 +208,7 @@ class Update self::normalizeDatabase($database->getDatabaseName()); if (class_exists('\Models\Cache')) { - Models\Cache::pool('Ultima versione di OpenSTAManager disponibile')->set(null); + (new Models\Cache())->getByName('Ultima versione di OpenSTAManager disponibile')->set(null); } // Correzione permessi per le cartelle backup e files diff --git a/update/2_4_55.sql b/update/2_4_55.sql index 62497da76..c378278af 100644 --- a/update/2_4_55.sql +++ b/update/2_4_55.sql @@ -1724,4 +1724,24 @@ ALTER TABLE `or_tipiordine` ALTER TABLE `or_tipiordine` CHANGE `id` `id` INT NOT NULL AUTO_INCREMENT; -ALTER TABLE `or_tipiordine_lang` ADD CONSTRAINT `or_tipiordine_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `or_tipiordine`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT; \ No newline at end of file +ALTER TABLE `or_tipiordine_lang` ADD CONSTRAINT `or_tipiordine_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `or_tipiordine`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT; + +-- Aggiunta tabella zz_cache_lang +CREATE TABLE IF NOT EXISTS `zz_cache_lang` ( + `id` int NOT NULL, + `id_lang` int NOT NULL, + `id_record` int NOT NULL, + `name` VARCHAR(255) NOT NULL +); +ALTER TABLE `zz_cache_lang` + ADD PRIMARY KEY (`id`); + +ALTER TABLE `zz_cache_lang` + MODIFY `id` int NOT NULL AUTO_INCREMENT; + +INSERT INTO `zz_cache_lang` (`id`, `id_lang`, `id_record`, `name`) SELECT NULL, (SELECT `id` FROM `zz_langs` WHERE `iso_code` = 'it'), `id`, `name` FROM `zz_cache`; + +ALTER TABLE `zz_cache` + DROP `name`; + +ALTER TABLE `zz_cache_lang` ADD CONSTRAINT `zz_cache_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `zz_cache`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT; \ No newline at end of file diff --git a/update/tables.php b/update/tables.php index 01cba11e5..49db4d104 100755 --- a/update/tables.php +++ b/update/tables.php @@ -154,6 +154,7 @@ return [ 'or_tipiordine_lang' 'zz_api_resources', 'zz_cache', + 'zz_cache_lang', 'zz_currencies', 'zz_checks', 'zz_check_user',