From bdfe393b456d2e54643b7a65adebf5b06bd19197 Mon Sep 17 00:00:00 2001 From: Roberto Guido Date: Mon, 18 Dec 2023 23:04:56 +0100 Subject: [PATCH 1/3] fix gestione indirizzi email invalidi --- code/app/Http/Controllers/MailController.php | 32 ++++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/code/app/Http/Controllers/MailController.php b/code/app/Http/Controllers/MailController.php index 5d886199..530fa9d4 100644 --- a/code/app/Http/Controllers/MailController.php +++ b/code/app/Http/Controllers/MailController.php @@ -15,7 +15,7 @@ class MailController extends Controller { - private function saveInstances($email, $message) + private function saveInstances($event, $email, $message) { $instances = get_instances(); $now = date('Y-m-d G:i:s'); @@ -26,9 +26,10 @@ private function saveInstances($email, $message) $db_emails = $db->select("SELECT COUNT(*) as count FROM contacts WHERE type = 'email' and value = '$email'"); if ($db_emails[0]->count != 0) { $db->insert("INSERT INTO inner_logs (level, type, message, created_at, updated_at) VALUES ('error', 'mail', '$message', '$now', '$now')"); - $db_failures = $db->select("SELECT COUNT(*) as count FROM inner_logs WHERE type = 'email' and message like '%$email%'"); - if ($db_failures[0]->count >= 3) { - $db->delete("DELETE FROM contacts WHERE type = 'email' and value = '$email'"); + $db_failures = $db->select("SELECT COUNT(*) as count FROM inner_logs WHERE type = 'mail' and message = '$message'"); + + if ($db_failures[0]->count >= 3 || $event == 'blocked') { + $db->delete("UPDATE contacts SET type = 'skip_email' WHERE type = 'email' and value = '$email'"); $message = _i('Rimosso indirizzo email ' . $email); $db->insert("INSERT INTO inner_logs (level, type, message, created_at, updated_at) VALUES ('error', 'mailsuppression', '$message', '$now', '$now')"); Log::info($message); @@ -41,13 +42,13 @@ private function saveInstances($email, $message) } } - private function registerBounce($email, $message) + private function registerBounce($event, $email, $message) { $message = sprintf(_i('Impossibile inoltrare mail a %s: %s', [$email, $message])); $message = addslashes($message); if (global_multi_installation()) { - $this->saveInstances($email, $message); + $this->saveInstances($event, $email, $message); } else { InnerLog::error('mail', $message); @@ -73,11 +74,13 @@ public function postStatusSES(Request $request) } else if ($message['Type'] === 'Notification') { $data = json_decode($message['Message']); - if ($data->notificationType == 'Bounce') { + $event = $data->notificationType; + + if ($event == 'Bounce') { try { $email = $data->bounce->bouncedRecipients[0]->emailAddress; $message = $data->bounce->bouncedRecipients[0]->diagnosticCode ?? '???'; - $this->registerBounce($email, $message); + $this->registerBounce($event, $email, $message); } catch(\Exception $e) { Log::error('Notifica SNS illeggibile: ' . $e->getMessage() . ' - ' . print_r($data, true)); @@ -107,18 +110,7 @@ public function postStatusSendinblue(Request $request) try { $email = $request->input('email'); $message = $request->input('reason', '???'); - $this->registerBounce($email, $message); - - /* - Se l'indirizzo mail è stato bloccato, è inutile - inoltrare altri messaggi: qui ne cambio il tipo per - evitare di generare altre mail a vuoto - */ - if ($event == 'blocked') { - Contact::where('type', 'email')->where('value', $email)->update([ - 'type' => 'skip_email', - ]); - } + $this->registerBounce($event, $email, $message); } catch(\Exception $e) { Log::error('Notifica SendInBlue illeggibile: ' . $e->getMessage() . ' - ' . print_r($request->all(), true)); From 6f4a9b4d2626337e581c0dacc98f9e8550a8657c Mon Sep 17 00:00:00 2001 From: Roberto Guido Date: Mon, 18 Dec 2023 23:25:32 +0100 Subject: [PATCH 2/3] fix su calcolo modificatori --- code/app/Services/DynamicBookingsService.php | 1 + code/app/Singletons/ModifierEngine.php | 85 ++++++++++++-------- 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/code/app/Services/DynamicBookingsService.php b/code/app/Services/DynamicBookingsService.php index af5e9059..6ad5ad4d 100644 --- a/code/app/Services/DynamicBookingsService.php +++ b/code/app/Services/DynamicBookingsService.php @@ -109,6 +109,7 @@ private function translateBooking($booking, $delivering) }, []), ]; + $booking->status = $delivering ? 'shipped' : 'pending'; $modified = $booking->applyModifiers(null, false); foreach($modified as $mod) { if (!isset($ret->modifiers[$mod->modifier_id])) { diff --git a/code/app/Singletons/ModifierEngine.php b/code/app/Singletons/ModifierEngine.php index 11eb2e4b..b9d7c0c5 100644 --- a/code/app/Singletons/ModifierEngine.php +++ b/code/app/Singletons/ModifierEngine.php @@ -2,9 +2,10 @@ namespace App\Singletons; -use App\ModifiedValue; +use Illuminate\Support\Facades\Log; -use Log; +use App\ModifiedValue; +use App\Product; class ModifierEngine { @@ -95,45 +96,68 @@ private function targetDefinition($modifier, $value) return null; } - private function handlingAttributes($booking, $modifier) + private function handlingAttributes($booking, $modifier, $attribute) { - /* - Fintantoché l'ordine non è marcato come "consegnato" uso le quantità - prenotate come riferimento per i calcoli (sulle soglie o per la - distribuzione dei costi sulle prenotazioni). - Se poi, alla fine, le quantità consegnate non corrispondono con - quelle prenotate, e dunque i calcoli devono essere revisionati per - ridistribuire in modo corretto il tutto, allora uso come riferimento - le quantità realmente consegnate: tale ricalcolo viene invocato da - OrdersController::postFixModifiers(), previa conferma dell'utente, - quando l'ordine è davvero in stato "consegnato" - */ - if (in_array($booking->status, ['saved', 'shipped'])) { - switch($modifier->applies_type) { - case 'none': + /* + Se l'ordine è chiuso (ma non consegnato e archiviato) attingo dai + valori relativi, che includono sia il consegnato che il prenotato ma + non ancora consegnato. Questo si applica in particolare in fase di + consegna + */ + if ($modifier->applies_target == 'order' || $booking->order->status == 'closed') { + switch($modifier->$attribute) { case 'quantity': - $attribute = 'delivered'; + $attribute = 'relative_quantity'; break; + case 'none': case 'price': - $attribute = 'price_delivered'; + $attribute = 'relative_price'; break; case 'weight': - $attribute = 'weight_delivered'; + $attribute = 'relative_weight'; break; default: $attribute = ''; break; } - $mod_attribute = 'price_delivered'; - } - else { - $attribute = $modifier->applies_type; + $mod_attribute = 'relative_price'; + } + + /* + Se sono qui, è perché sono in fase di prenotazione dunque mi baso + sui valori del prenotato + */ + else if ($booking->status == 'pending') { + $attribute = $modifier->$attribute; if ($attribute == 'none') { $attribute = 'price'; } $mod_attribute = 'price'; + } + + /* + In tutti gli altri casi, opero sui valori del consegnato + */ + else { + switch($modifier->$attribute) { + case 'none': + case 'quantity': + $attribute = 'delivered'; + break; + case 'price': + $attribute = 'price_delivered'; + break; + case 'weight': + $attribute = 'weight_delivered'; + break; + default: + $attribute = ''; + break; + } + + $mod_attribute = 'price_delivered'; } return [$attribute, $mod_attribute]; @@ -221,7 +245,7 @@ public function apply($modifier, $booking, $aggregate_data) $product_target_id = 0; - if ($modifier->target_type == 'App\Product') { + if ($modifier->target_type == Product::class) { $product_target_id = $modifier->target_id; switch($modifier->applies_target) { @@ -276,7 +300,7 @@ public function apply($modifier, $booking, $aggregate_data) return null; } - list($attribute, $mod_attribute) = $this->handlingAttributes($booking, $modifier); + list($attribute, $mod_attribute) = $this->handlingAttributes($booking, $modifier, 'applies_type'); $check_value = $check_target->$attribute ?? 0; $target_definition = null; $altered_amount = null; @@ -295,14 +319,9 @@ public function apply($modifier, $booking, $aggregate_data) singola prenotazione il suo valore relativo e proporzionale. */ if ($modifier->applies_target == 'order') { - $distribution_attribute = $modifier->distribution_type; - if ($distribution_attribute == 'none') { - $distribution_attribute = 'price'; - } - - $distribution_attribute = 'relative_' . $distribution_attribute; + list($distribution_attribute, $useless) = $this->handlingAttributes($booking, $modifier, 'distribution_type'); - if ($modifier->target_type == 'App\Product') { + if ($modifier->target_type == Product::class) { $booking_mod_target = $aggregate_data->orders[$booking->order_id]->bookings[$booking->id]->products[$product_target_id] ?? null; $reference = $mod_target->products[$product_target_id]->$distribution_attribute; } From f32b8193c05f55501f146017aedf3c6ab3c6d5a1 Mon Sep 17 00:00:00 2001 From: Roberto Guido Date: Mon, 18 Dec 2023 23:33:45 +0100 Subject: [PATCH 3/3] ordine non cancellabile se ci sono prenotazioni --- code/resources/views/order/edit.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/resources/views/order/edit.blade.php b/code/resources/views/order/edit.blade.php index 881f8b09..a2d0ad40 100644 --- a/code/resources/views/order/edit.blade.php +++ b/code/resources/views/order/edit.blade.php @@ -1,6 +1,6 @@ orders[$order->id] ?> - +