From 17eaf058243a3aa88c9019f171d2a08ab5895820 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Tue, 27 Aug 2019 15:42:13 +0200 Subject: [PATCH] Correzioni hooks --- actions.php | 2 +- ajax.php | 17 +-- assets/src/js/functions/hooks.js | 138 +++++++++++--------- config/namespaces.php | 1 + modules/aggiornamenti/src/UpdateHook.php | 4 +- modules/backups/src/BackupHook.php | 8 +- modules/emails/src/EmailHook.php | 79 +++++++++++ modules/interventi/actions.php | 33 +++-- modules/interventi/modutil.php | 13 +- plugins/exportFE/src/FatturaElettronica.php | 3 +- plugins/importFE/src/InvoiceHook.php | 4 +- plugins/receiptFE/src/ReceiptHook.php | 4 +- reset.php | 13 +- src/Backup.php | 2 + src/Database.php | 5 + src/Hooks/CachedManager.php | 34 ++--- src/Hooks/Manager.php | 19 ++- src/Models/Hook.php | 20 ++- src/Models/Mail.php | 41 ++++-- src/Notifications/EmailNotification.php | 13 +- update/2_4_11.sql | 7 +- 21 files changed, 312 insertions(+), 148 deletions(-) create mode 100644 modules/emails/src/EmailHook.php diff --git a/actions.php b/actions.php index 61352dbcf..4c2177111 100644 --- a/actions.php +++ b/actions.php @@ -208,7 +208,7 @@ elseif (filter('op') == 'sort_checks') { elseif (post('op') == 'send-email') { $template = MailTemplate::find(post('template')); - $mail = \Models\Mail::build($template, $id_record); + $mail = \Models\Mail::build($user, $template, $id_record); // Rimozione allegati predefiniti $mail->resetAttachments(); diff --git a/ajax.php b/ajax.php index 9f685051f..4256bd97c 100644 --- a/ajax.php +++ b/ajax.php @@ -108,17 +108,12 @@ switch (get('op')) { $hook_id = filter('id'); $hook = Hook::find($hook_id); - $response = $hook->execute(); - - echo json_encode($response); - - break; - - case 'prepare-hook': - $hook_id = filter('id'); - $hook = Hook::find($hook_id); - - $response = $hook->prepare(); + $init = filter('init'); + if (!empty($init)) { + $response = $hook->prepare(); + } else { + $response = $hook->execute(); + } echo json_encode($response); diff --git a/assets/src/js/functions/hooks.js b/assets/src/js/functions/hooks.js index b682afd73..1c8c6c4e2 100644 --- a/assets/src/js/functions/hooks.js +++ b/assets/src/js/functions/hooks.js @@ -8,7 +8,7 @@ function startHooks() { data: { op: "hooks", }, - success: function(data) { + success: function (data) { hooks = JSON.parse(data); $("#hooks-header").text(globals.translations.hooksExecuting); @@ -20,89 +20,66 @@ function startHooks() { $("#hooks-header").text(globals.translations.hookNone); } - hooks.forEach(function(item, index){ - startHook(item); + hooks.forEach(function (item, index) { + renderHook(item, { + show: true, + message: globals.translations.hookExecuting.replace('_NAME_', item.name) + }); + + executeHook(item, true); }); }, }); } -/** - * - * @param hook - */ -function startHook(hook){ - var element_id = "hook-" + hook.id; - $("#hooks").append('
  • ' + globals.translations.hookExecuting.replace('_NAME_', hook.name) + '
  • '); - - element_id = "#" + element_id; - - $.ajax({ - url: globals.rootdir + "/ajax.php", - type: "get", - data: { - op: "prepare-hook", - id: hook.id, - }, - success: function(data) { - var result = JSON.parse(data); - - addHookCount("#hooks-counter"); - - if (result){ - renderHook(element_id, result); - - if (result.execute){ - addHookCount("#hooks-notified"); - - executeHook(hook, element_id, true) - } else { - $(element_id).remove(); - } - } else { - executeHook(hook, element_id) - } - }, - }); -} - /** * * @param hook * @param element_id */ -function executeHook(hook, element_id, is_background){ +function executeHook(hook, init) { $.ajax({ url: globals.rootdir + "/ajax.php", type: "get", data: { op: "hook", id: hook.id, + init: init, }, - success: function(data) { + success: function (data) { var result = JSON.parse(data); - renderHook(element_id, result); + renderHook(hook, result); - if (!is_background) { - if (result.notify) { - addHookCount("#hooks-notified"); - } else { - $(element_id).remove(); - } + var timeout; + if (result.execute) { + timeout = 1; + } else { + timeout = 30; + } + + setTimeout(function () { + executeHook(hook); + }, timeout * 1000); + + if (init) { + hookCount("#hooks-counter"); } // Rimozione eventuale della rotella di caricamento var counter = $("#hooks-counter").text(); - var number = $("#hooks-notified").text(); - if(counter == $("#hooks-number").text()) { + var number = $("#hooks > li").length; + $("#hooks-notified").text(number); + + if (counter == $("#hooks-number").text()) { $("#hooks-loading").hide(); - if (number > 1){ + var hookMessage; + if (number > 1) { hookMessage = globals.translations.hookMultiple.replace('_NUM_', number); - }else if(number == 1){ + } else if (number == 1) { hookMessage = globals.translations.hookSingle; - }else { + } else { hookMessage = globals.translations.hookNone; } @@ -115,22 +92,57 @@ function executeHook(hook, element_id, is_background){ /** * Aggiunta dell'hook al numero totale. */ -function addHookCount(id) { - var hooks_number = $(id); - var number = parseInt(hooks_number.text()); +function hookCount(id, value) { + value = value ? value : 1; + + var element = $(id); + var number = parseInt(element.text()); number = isNaN(number) ? 0 : number; - number++; - hooks_number.text(number); + number += value; + element.text(number); return number; } /** + * Genera l'HTML per la visualizzazione degli hook. * * @param element_id * @param result */ -function renderHook(element_id, result) { - $(element_id).html(' ' + result.message + ''); +function renderHook(hook, result) { + if (result.length == 0) return; + + var element_id = "hook-" + hook.id; + + // Inizializzazione + var element = $("#" + element_id); + if (element.length == 0) { + $("#hooks").append('
  • '); + + element = $("#" + element_id); + } + + // Rimozione + if (!result.show) { + element.remove(); + + return; + } + + // Contenuto + var content = ' ' + result.message + ''; + + if (result.progress) { + var current = result.progress.current; + var total = result.progress.total; + var percentage = total == 0 ? current / total * 100 : 100; + + content += '
    ' + percentage + '% (' + current + '/' + total + ')
    '; + } + + content += '
    '; + + element.html(content); } diff --git a/config/namespaces.php b/config/namespaces.php index 328583a00..ac581e10f 100644 --- a/config/namespaces.php +++ b/config/namespaces.php @@ -5,6 +5,7 @@ return [ 'modules/aggiornamenti' => 'Modules\Aggiornamenti', 'modules/anagrafiche' => 'Modules\Anagrafiche', 'modules/backups' => 'Modules\Backups', + 'modules/emails' => 'Modules\Emails', 'modules/articoli' => 'Modules\Articoli', 'modules/checklists' => 'Modules\Checklists', 'modules/ritenute' => 'Modules\Ritenute', diff --git a/modules/aggiornamenti/src/UpdateHook.php b/modules/aggiornamenti/src/UpdateHook.php index dbdf8ec5d..db3ac2362 100644 --- a/modules/aggiornamenti/src/UpdateHook.php +++ b/modules/aggiornamenti/src/UpdateHook.php @@ -11,7 +11,7 @@ class UpdateHook extends CachedManager { protected static $client = null; - public function execute() + public function data() { $result = self::isAvailable(); @@ -31,7 +31,7 @@ class UpdateHook extends CachedManager 'icon' => 'fa fa-download text-info', 'link' => $link, 'message' => $message, - 'notify' => !empty($update), + 'show' => !empty($update), ]; } diff --git a/modules/backups/src/BackupHook.php b/modules/backups/src/BackupHook.php index d4971beee..aa97a2562 100644 --- a/modules/backups/src/BackupHook.php +++ b/modules/backups/src/BackupHook.php @@ -7,25 +7,25 @@ use Hooks\Manager; class BackupHook extends Manager { - public function manage() + public function execute() { $result = Backup::daily(); return $result; } - public function response($update) + public function response($data) { return [ 'icon' => 'fa fa-file-o text-info', 'message' => tr('Backup completato!'), - 'notify' => true, + 'show' => true, ]; } public function prepare() { - $result = setting('Backup automatico') && !Backup::isDailyComplete() && self::getHook()->processing == 0; + $result = setting('Backup automatico') && !Backup::isDailyComplete(); return [ 'icon' => 'fa fa-file-o text-danger', diff --git a/modules/emails/src/EmailHook.php b/modules/emails/src/EmailHook.php new file mode 100644 index 000000000..176ef1a52 --- /dev/null +++ b/modules/emails/src/EmailHook.php @@ -0,0 +1,79 @@ +where('id_account', $account->id) + ->whereNull('failed_at') + ->orWhereDate('failed_at', '<', $diff) + ->orderBy('created_at') + ->first(); + + if (!empty($mail)) { + $list[] = $mail; + } + } + + foreach ($list as $mail) { + $email = EmailNotification::build($mail); + + try { + // Invio mail + $email->send(); + } catch (PHPMailer\PHPMailer\Exception $e) { + } + } + + return count($list); + } + + public function response($data) + { + return $this->prepare(); + } + + public function prepare() + { + $yesterday = date('Y-m-d', strtotime('-1 days')); + $user = auth()->getUser(); + + $remaining = Mail::whereNull('sent_at') + ->where('created_by', $user->id) + ->count(); + $total = Mail::whereDate('sent_at', '>', $yesterday) + ->orWhereNull('sent_at') + ->where('created_by', $user->id) + ->count(); + $current = $total - $remaining; + + $total_remaining = Mail::whereNull('sent_at')->count(); + + $message = !empty($remaining) ? tr('Invio email in corso...') : tr('Invio email completato!'); + + return [ + 'icon' => 'fa fa-envelope text-info', + 'message' => $message, + 'execute' => !empty($total_remaining), + 'show' => true, + 'progress' => [ + 'current' => $current, + 'total' => $total, + ], + ]; + } +} diff --git a/modules/interventi/actions.php b/modules/interventi/actions.php index a6f1c8072..37ddca99d 100644 --- a/modules/interventi/actions.php +++ b/modules/interventi/actions.php @@ -2,6 +2,8 @@ include_once __DIR__.'/../../core.php'; +use Models\Mail; +use Models\MailTemplate; use Modules\Anagrafiche\Anagrafica; use Modules\Articoli\Articolo as ArticoloOriginale; use Modules\Interventi\Components\Articolo; @@ -11,6 +13,7 @@ use Modules\Interventi\Components\Sessione; use Modules\Interventi\Intervento; use Modules\Interventi\Stato; use Modules\TipiIntervento\Tipo as TipoSessione; +use Notifications\EmailNotification; switch (post('op')) { case 'update': @@ -49,12 +52,14 @@ switch (post('op')) { // Notifica chiusura intervento $stato = $dbo->selectOne('in_statiintervento', '*', ['idstatointervento' => post('idstatointervento')]); if (!empty($stato['notifica']) && !empty($stato['destinatari']) && $stato['idstatointervento'] != $record['idstatointervento']) { - $n = new Notifications\EmailNotification(); + $template = MailTemplate::find($stato['id_email']); - $n->setTemplate($stato['id_email'], $id_record); - $n->setReceivers($stato['destinatari']); + $mail = Mail::build(auth()->getUser(), $template, $id_record); + $mail->addReceiver($stato['destinatari']); + $mail->save(); - if ($n->send()) { + $email = EmailNotification::build($mail); + if ($email->send()) { flash()->info(tr('Notifica inviata')); } else { flash()->warning(tr("Errore nell'invio della notifica")); @@ -480,12 +485,14 @@ switch (post('op')) { $stato = $dbo->selectOne('in_statiintervento', '*', ['descrizione' => 'Completato']); // Notifica chiusura intervento if (!empty($stato['notifica']) && !empty($stato['destinatari'])) { - $n = new Notifications\EmailNotification(); + $template = MailTemplate::find($stato['id_email']); - $n->setTemplate($stato['id_email'], $id_record); - $n->setReceivers($stato['destinatari']); + $mail = Mail::build(auth()->getUser(), $template, $id_record); + $mail->addReceiver($stato['destinatari']); + $mail->save(); - if ($n->send()) { + $email = EmailNotification::build($mail); + if ($email->send()) { flash()->info(tr('Notifica inviata')); } else { flash()->warning(tr("Errore nell'invio della notifica")); @@ -529,12 +536,14 @@ switch (post('op')) { // Notifica rimozione dell' intervento al tecnico if (!empty($tecnico['email'])) { - $n = new Notifications\EmailNotification(); + $template = MailTemplate::get('Notifica rimozione intervento'); - $n->setTemplate('Notifica rimozione intervento', $id_record); - $n->setReceivers($tecnico['email']); + $mail = Mail::build(auth()->getUser(), $template, $id_record); + $mail->addReceiver($tecnico['email']); + $mail->save(); - if ($n->send()) { + $email = EmailNotification::build($mail); + if ($email->send()) { flash()->info(tr('Notifica inviata')); } else { flash()->warning(tr("Errore nell'invio della notifica")); diff --git a/modules/interventi/modutil.php b/modules/interventi/modutil.php index 3783eb51f..ae1efa30b 100644 --- a/modules/interventi/modutil.php +++ b/modules/interventi/modutil.php @@ -2,12 +2,15 @@ include_once __DIR__.'/../../core.php'; +use Models\Mail; +use Models\MailTemplate; use Modules\Anagrafiche\Anagrafica; use Modules\Fatture\Components\Descrizione; use Modules\Fatture\Components\Riga; use Modules\Fatture\Fattura; use Modules\Interventi\Components\Sessione; use Modules\Interventi\Intervento; +use Notifications\EmailNotification; /** * Recupera il totale delle ore spese per un intervento. @@ -61,12 +64,14 @@ function add_tecnico($idintervento, $idtecnico, $inizio, $fine, $idcontratto = n // Notifica nuovo intervento al tecnico if (!empty($tecnico['email'])) { - $n = new Notifications\EmailNotification(); + $template = MailTemplate::get('Notifica intervento'); - $n->setTemplate('Notifica intervento', $idintervento); - $n->setReceivers($anagrafica['email']); + $mail = Mail::build(auth()->getUser(), $template, $idintervento); + $mail->addReceiver($anagrafica['email']); + $mail->save(); - $n->send(); + $email = EmailNotification::build($mail); + $email->send(); } return true; diff --git a/plugins/exportFE/src/FatturaElettronica.php b/plugins/exportFE/src/FatturaElettronica.php index 523558bd0..abbbb0f9f 100644 --- a/plugins/exportFE/src/FatturaElettronica.php +++ b/plugins/exportFE/src/FatturaElettronica.php @@ -446,9 +446,8 @@ class FatturaElettronica // Codice fiscale if (!empty($anagrafica['codice_fiscale'])) { - $result['CodiceFiscale'] = preg_replace('/\s+/', '', $anagrafica['codice_fiscale']); - + //Rimuovo eventuali idicazioni relative alla nazione $result['CodiceFiscale'] = preg_replace($anagrafica->nazione->iso2, '', $result['CodiceFiscale'], 2); } diff --git a/plugins/importFE/src/InvoiceHook.php b/plugins/importFE/src/InvoiceHook.php index 278881517..a433eb810 100644 --- a/plugins/importFE/src/InvoiceHook.php +++ b/plugins/importFE/src/InvoiceHook.php @@ -7,7 +7,7 @@ use Modules; class InvoiceHook extends CachedManager { - public function execute() + public function data() { $list = Interaction::getInvoiceList(); @@ -40,7 +40,7 @@ class InvoiceHook extends CachedManager 'icon' => 'fa fa-file-text-o text-yellow', 'link' => $link, 'message' => $message, - 'notify' => $notify, + 'show' => $notify, ]; } } diff --git a/plugins/receiptFE/src/ReceiptHook.php b/plugins/receiptFE/src/ReceiptHook.php index 933ee5c1c..96cc89812 100644 --- a/plugins/receiptFE/src/ReceiptHook.php +++ b/plugins/receiptFE/src/ReceiptHook.php @@ -7,7 +7,7 @@ use Modules; class ReceiptHook extends CachedManager { - public function execute() + public function data() { $list = Interaction::getReceiptList(); @@ -40,7 +40,7 @@ class ReceiptHook extends CachedManager 'icon' => 'fa fa-ticket text-yellow', 'link' => $link, 'message' => $message, - 'notify' => $notify, + 'show' => $notify, ]; } } diff --git a/reset.php b/reset.php index 5bcb321d2..35ed2d6df 100644 --- a/reset.php +++ b/reset.php @@ -3,7 +3,10 @@ $skip_permissions = true; include_once __DIR__.'/core.php'; +use Models\Mail; +use Models\MailTemplate; use Models\User; +use Notifications\EmailNotification; $token = get('reset_token'); @@ -23,12 +26,14 @@ switch (post('op')) { $utente->reset_token = secure_random_string(); $utente->save(); - $n = new Notifications\EmailNotification(); + $template = MailTemplate::get('Reset password'); - $n->setTemplate('Reset password', $utente->id); - $n->setReceivers($utente->email); + $mail = Mail::build($user, $template, $utente->id); + $mail->addReceiver($utente->email); + $mail->save(); - $n->send(); + $email = EmailNotification::build($mail); + $email->send(); } //$message_email = substr($email, 0, 2).str_repeat('*', strlen($email)-8).substr($email, -6); diff --git a/src/Backup.php b/src/Backup.php index e61cf9ed1..638163488 100644 --- a/src/Backup.php +++ b/src/Backup.php @@ -114,6 +114,8 @@ class Backup if (!self::isDailyComplete()) { return self::create(); } + + return false; } /** diff --git a/src/Database.php b/src/Database.php index 6a87a73a9..cd78cd6d5 100644 --- a/src/Database.php +++ b/src/Database.php @@ -632,6 +632,11 @@ class Database extends Util\Singleton Capsule::commit(); } + public function rollbackTransaction() + { + Capsule::rollBack(); + } + /** * Esegue le query interne ad un file ".sql". * diff --git a/src/Hooks/CachedManager.php b/src/Hooks/CachedManager.php index 938487913..a2b1762c4 100644 --- a/src/Hooks/CachedManager.php +++ b/src/Hooks/CachedManager.php @@ -10,7 +10,23 @@ abstract class CachedManager extends Manager protected static $cache = null; protected static $is_cached = null; - abstract public function execute(); + abstract public function data(); + + public function execute() + { + if (self::isCached()) { + $results = self::getCache()['results']; + + // Interpretazione della cache + $results = json_decode($results, true); + } else { + $results = $this->data(); + + self::update($results); + } + + return $results; + } public static function getCache() { @@ -68,20 +84,4 @@ abstract class CachedManager extends Manager return self::$is_cached; } - - public function manage() - { - if (self::isCached()) { - $results = self::getCache()['results']; - - // Interpretazione della cache - $results = json_decode($results, true); - } else { - $results = $this->execute(); - - self::update($results); - } - - return $results; - } } diff --git a/src/Hooks/Manager.php b/src/Hooks/Manager.php index c9e05f7f1..635cc3451 100644 --- a/src/Hooks/Manager.php +++ b/src/Hooks/Manager.php @@ -11,7 +11,7 @@ abstract class Manager * * @return mixed */ - abstract public function manage(); + abstract public function execute(); /** * Restituisce le informazioni per la visualizzazione dell'hook. @@ -29,7 +29,22 @@ abstract class Manager */ public function prepare() { - return null; + return [ + 'execute' => true, + ]; + } + + public function manage() + { + $prepare = $this->prepare(); + if (empty($prepare['execute'])) { + return []; + } + + $data = $this->execute(); + $results = $this->response($data); + + return $results; } /** diff --git a/src/Models/Hook.php b/src/Models/Hook.php index fcd9fe58d..07ee7aee7 100644 --- a/src/Models/Hook.php +++ b/src/Models/Hook.php @@ -3,6 +3,7 @@ namespace Models; use Common\Model; +use Hooks\Manager; use Illuminate\Database\Eloquent\Builder; use Traits\StoreTrait; @@ -31,16 +32,13 @@ class Hook extends Model $class = $this->class; $hook = new $class(); - $this->processing = true; - $this->save(); + if (!$hook instanceof Manager) { + return [ + 'show' => false, + ]; + } - $data = $hook->manage(); - $results = $hook->response($data); - - $this->processing = false; - $this->save(); - - return $results; + return $hook->manage(); } public function prepare() @@ -48,9 +46,7 @@ class Hook extends Model $class = $this->class; $hook = new $class(); - $results = $hook->prepare(); - - return $results; + return $hook->prepare(); } /* Relazioni Eloquent */ diff --git a/src/Models/Mail.php b/src/Models/Mail.php index e32ac25df..75903895c 100644 --- a/src/Models/Mail.php +++ b/src/Models/Mail.php @@ -10,15 +10,17 @@ class Mail extends Model protected $receivers = []; - protected $attachments = []; - protected $prints = []; + protected $attachments = null; + protected $prints = null; - protected $options = []; + protected $options = null; - public static function build($template = null, $id_record = null, $account = null) + public static function build(User $user, $template = null, $id_record = null, $account = null) { $model = parent::build(); + $model->created_by = $user->id; + $model->id_template = $template->id; $model->id_record = $id_record; @@ -42,6 +44,10 @@ class Mail extends Model */ public function addAttachment($file_id) { + if (!isset($this->attachments)) { + $this->attachments = []; + } + $this->attachments[] = $file_id; } @@ -58,6 +64,10 @@ class Mail extends Model */ public function addPrint($print_id, $name = null) { + if (!isset($this->prints)) { + $this->prints = []; + } + $print = PrintTemplate::find($print_id); if (empty($name)) { @@ -87,6 +97,10 @@ class Mail extends Model return; } + if (!isset($this->receivers)) { + $this->receivers = []; + } + $list = explode(';', $value); foreach ($list as $element) { $this->receivers[] = [ @@ -98,10 +112,21 @@ class Mail extends Model public function save(array $options = []) { - $this->setReceiversAttribute($this->receivers); - $this->setAttachmentsAttribute($this->attachments); - $this->setPrintsAttribute($this->prints); - $this->setOptionsAttribute($this->options); + if (isset($this->receivers)) { + $this->setReceiversAttribute($this->receivers); + } + + if (isset($this->attachments)) { + $this->setAttachmentsAttribute($this->attachments); + } + + if (isset($this->prints)) { + $this->setPrintsAttribute($this->prints); + } + + if (isset($this->options)) { + $this->setOptionsAttribute($this->options); + } return parent::save($options); } diff --git a/src/Notifications/EmailNotification.php b/src/Notifications/EmailNotification.php index 2bf0eeb83..1ebb16152 100644 --- a/src/Notifications/EmailNotification.php +++ b/src/Notifications/EmailNotification.php @@ -71,7 +71,7 @@ class EmailNotification extends PHPMailer implements NotificationInterface $this->WordWrap = 78; } - public static function build(\Models\Mail $mail, $exceptions = true) + public static function build(\Models\Mail $mail, $exceptions = null) { $result = new self($mail->account->id, $exceptions); @@ -145,6 +145,17 @@ class EmailNotification extends PHPMailer implements NotificationInterface $exception = $e; } + // Registazione invio + if (!empty($this->mail)) { + if ($result) { + $this->mail->sent_at = date('Y-m-d H:i:s'); + } else { + $this->mail->failed_at = date('Y-m-d H:i:s'); + } + + $this->mail->save(); + } + $this->SmtpClose(); // Pulizia file generati diff --git a/update/2_4_11.sql b/update/2_4_11.sql index 11315baef..8f4c55c13 100644 --- a/update/2_4_11.sql +++ b/update/2_4_11.sql @@ -357,10 +357,13 @@ CREATE TABLE IF NOT EXISTS `em_emails` ( `prints` TEXT, `options` TEXT, `sent_at` TIMESTAMP NULL DEFAULT NULL, + `failed_at` TIMESTAMP NULL DEFAULT NULL, + `created_by` int(11) NOT NULL, PRIMARY KEY (`id`), FOREIGN KEY (`id_account`) REFERENCES `em_accounts`(`id`) ON DELETE CASCADE, FOREIGN KEY (`id_template`) REFERENCES `em_templates`(`id`) ON DELETE CASCADE, - FOREIGN KEY (`id_campaign`) REFERENCES `em_campaigns`(`id`) ON DELETE CASCADE + FOREIGN KEY (`id_campaign`) REFERENCES `em_campaigns`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`created_by`) REFERENCES `zz_users`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS `em_campaign_anagrafica` ( @@ -371,3 +374,5 @@ CREATE TABLE IF NOT EXISTS `em_campaign_anagrafica` ( FOREIGN KEY (`id_anagrafica`) REFERENCES `an_anagrafiche`(`idanagrafica`) ON DELETE CASCADE, FOREIGN KEY (`id_email`) REFERENCES `em_emails`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB; + +INSERT INTO `zz_hooks` (`id`, `name`, `class`, `frequency`, `id_module`) VALUES (NULL, 'Email', 'Modules\\Emails\\EmailHook', '1 minute', (SELECT `id` FROM `zz_modules` WHERE `name` = 'Account email'));