File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,19 +70,17 @@ public function getModuleAttribute()
7070
7171 public function fixStato ()
7272 {
73- $ mails = $ this ->emails ;
74-
75- $ completed = true ;
76- foreach ($ mails as $ mail ) {
77- if (empty ($ mail ->sent_at )) {
78- $ completed = false ;
79- break ;
80- }
81- }
73+ // Verifica se esistono email associate a questa newsletter che non sono state ancora inviate.
74+ $ hasUnsentEmails = $ this ->emails ()->whereNull ('sent_at ' )->exists ();
75+
76+ // Se non ci sono email non inviate, la newsletter è completata.
77+ $ completed = !$ hasUnsentEmails ;
8278
83- $ this ->state = $ completed ? 'OK ' : $ this ->state ;
84- $ this ->completed_at = $ completed ? date ('Y-m-d H:i:s ' ) : $ this ->completed_at ;
85- $ this ->save ();
79+ if ($ completed && $ this ->state !== 'OK ' ) {
80+ $ this ->state = 'OK ' ;
81+ $ this ->completed_at = date ('Y-m-d H:i:s ' ); // Utilizza la funzione helper now() per ottenere la data e l'ora correnti
82+ $ this ->save ();
83+ }
8684 }
8785
8886 public function getNumeroDestinatariSenzaEmail ()
You can’t perform that action at this time.
0 commit comments