2222
2323use Common \SimpleModelTrait ;
2424use Illuminate \Database \Eloquent \Model ;
25+ use Models \Module ;
2526use Models \PrintTemplate ;
2627use Models \Upload ;
2728use Models \User ;
2829use Modules \Newsletter \Newsletter ;
30+ use Monolog \Logger ;
2931
3032class Mail extends Model
3133{
@@ -78,7 +80,7 @@ public function addUpload($file_id, $name = null)
7880
7981 // duplica il file
8082 $ upload = $ file ->copia ([
81- 'id_module ' => \ Models \ Module::where ('name ' , 'Stato email ' )->first ()->id ,
83+ 'id_module ' => Module::where ('name ' , 'Stato email ' )->first ()->id ,
8284 'id_record ' => $ this ->id ,
8385 ]);
8486
@@ -109,8 +111,20 @@ public function addPrint($print_id, $name = null)
109111 // Genera la stampa come PDF
110112 $ print = \Prints::render ($ print_id , $ this ->id_record , null , true );
111113
114+ // Verifica che la stampa sia stata generata correttamente
115+ if (!$ print || !isset ($ print ['pdf ' ])) {
116+ $ logger = \logger_osm ();
117+ $ logger ->addRecord (Logger::ERROR , 'Impossibile generare il PDF per la stampa: ' .$ print_id , [
118+ 'id_email ' => $ this ->id ,
119+ 'id_record ' => $ this ->id_record ,
120+ 'print_id ' => $ print_id ,
121+ ]);
122+
123+ return ;
124+ }
125+
112126 // Ottieni il modulo "Coda d'invio"
113- $ id_module = \ Models \ Module::where ('name ' , 'Stato email ' )->first ()->id ;
127+ $ id_module = Module::where ('name ' , 'Stato email ' )->first ()->id ;
114128
115129 $ name = $ name ?: $ print ['name ' ];
116130
@@ -123,6 +137,19 @@ public function addPrint($print_id, $name = null)
123137 'id_record ' => $ this ->id ,
124138 ]);
125139
140+ // Verifica che l'upload sia stato eseguito correttamente
141+ if (!$ upload ) {
142+ $ logger = \logger_osm ();
143+ $ logger ->addRecord (Logger::ERROR , 'Impossibile salvare l \'allegato PDF per la email ' , [
144+ 'id_email ' => $ this ->id ,
145+ 'id_record ' => $ this ->id_record ,
146+ 'print_id ' => $ print_id ,
147+ 'filename ' => $ name ,
148+ ]);
149+
150+ return ;
151+ }
152+
126153 // Collega il file alla tabella em_email_attachment
127154 $ this ->attachments ()->attach ($ upload ->id , ['id_email ' => $ this ->id , 'name ' => $ name , 'type ' => 'print ' ]);
128155 }
0 commit comments