33namespace App \Http \Controllers ;
44
55use Illuminate \Http \Request ;
6+ use Illuminate \Support \Facades \DB ;
7+ use Illuminate \Support \Facades \Log ;
8+ use Illuminate \Support \Facades \App ;
69
7- use DB ;
8- use Log ;
9- use App ;
10-
11- use ezcArchive ;
1210use App \Exceptions \MissingFieldException ;
1311use App \Importers \CSV \CSVImporter ;
1412use App \Importers \GDXP \Suppliers ;
@@ -33,45 +31,45 @@ public function postCsv(Request $request)
3331 return $ this ->errorResponse (__ ('texts.generic.unauthorized ' ));
3432 }
3533
34+ $ return = null ;
35+
3636 try {
3737 switch ($ step ) {
3838 case 'guess ' :
3939 $ parameters = $ importer ->guess ($ request );
40-
41- return view ( ' import.csvsortcolumns ' , $ parameters ) ;
40+ $ return = view ( ' import.csvsortcolumns ' , $ parameters );
41+ break ;
4242
4343 case 'select ' :
4444 try {
4545 $ parameters = $ importer ->select ($ request );
46-
47- return $ importer ->formatSelect ($ parameters );
46+ $ return = $ importer ->formatSelect ($ parameters );
4847 }
4948 catch (MissingFieldException $ e ) {
50- return view ('import.csvimportfinal ' , [
49+ $ return = view ('import.csvimportfinal ' , [
5150 'title ' => __ ('texts.imports.help.failure_notice ' ),
5251 'objects ' => [],
5352 'errors ' => [$ e ->getMessage ()],
5453 ]);
5554 }
5655
56+ break ;
57+
5758 case 'run ' :
5859 $ parameters = $ importer ->run ($ request );
59-
60- return view ( $ importer -> finalTemplate (), $ parameters ) ;
60+ $ return = view ( $ importer -> finalTemplate (), $ parameters );
61+ break ;
6162
6263 default :
6364 throw new \InvalidArgumentException ('Passaggio non previsto in fase di importazione: ' . $ step );
6465 break ;
6566 }
6667 }
6768 catch (\Exception $ e ) {
68- return $ this ->errorResponse ($ e ->getMessage ());
69+ $ return = $ this ->errorResponse ($ e ->getMessage ());
6970 }
7071
71- return $ this ->errorResponse (__ ('texts.imports.help.invalid_command ' , [
72- 'type ' => $ type ,
73- 'step ' => $ step ,
74- ]));
72+ return $ return ;
7573 }
7674
7775 public function getGdxp (Request $ request )
@@ -81,70 +79,24 @@ public function getGdxp(Request $request)
8179 $ obj = $ classname ::findOrFail ($ id );
8280
8381 $ working_dir = sys_get_temp_dir ();
84-
85- switch ($ request ->input ('format ' , 'json ' )) {
86- case 'xml ' :
87- $ xml = $ obj ->exportXML ();
88-
89- chdir ($ working_dir );
90- $ filename = md5 ($ xml );
91- file_put_contents ($ filename , $ xml );
92-
93- $ downloadable = sprintf ('%s/%s.gdxp ' , $ working_dir , str_replace ('/ ' , '_ ' , $ obj ->printableName ()));
94- $ archive = ezcArchive::open ('compress.zlib:// ' . $ downloadable , ezcArchive::TAR_USTAR );
95- $ archive ->append ([$ filename ], '' );
96- unlink ($ filename );
97- break ;
98-
99- case 'json ' :
100- default :
101- $ json = $ obj ->exportJSON ();
102- $ downloadable = sprintf ('%s/%s.json ' , $ working_dir , str_replace ('/ ' , '_ ' , $ obj ->printableName ()));
103- file_put_contents ($ downloadable , $ json );
104- break ;
105- }
82+ $ json = $ obj ->exportJSON ();
83+ $ downloadable = sprintf ('%s/%s.json ' , $ working_dir , str_replace ('/ ' , '_ ' , $ obj ->printableName ()));
84+ file_put_contents ($ downloadable , $ json );
10685
10786 return response ()->download ($ downloadable )->deleteFileAfterSend (true );
10887 }
10988
11089 private function readGdxpFile ($ path , $ execute , $ supplier_replace )
11190 {
112- $ working_dir = sys_get_temp_dir ();
113-
11491 $ data = [];
115- $ type = mime_content_type ($ path );
116-
117- if (in_array ($ type , ['text/plain ' , 'application/json ' ])) {
118- $ info = json_decode (file_get_contents ($ path ));
119- foreach ($ info ->blocks as $ c ) {
120- if ($ execute ) {
121- $ data [] = Suppliers::importJSON ($ info , $ c ->supplier , $ supplier_replace );
122- }
123- else {
124- $ data [] = Suppliers::readJSON ($ c ->supplier );
125- }
126- }
127- }
128- else {
129- $ archive = ezcArchive::open ('compress.zlib:// ' . $ path );
130- while ($ archive ->valid ()) {
131- $ entry = $ archive ->current ();
132- $ archive ->extractCurrent ($ working_dir );
133- $ filepath = sprintf ('%s/%s ' , $ working_dir , $ entry ->getPath ());
134- $ contents = file_get_contents ($ filepath );
135- $ contents = simplexml_load_string ($ contents );
136-
137- foreach ($ contents ->children () as $ c ) {
138- if ($ execute ) {
139- $ data [] = Suppliers::importXML ($ c , $ supplier_replace );
140- }
141- else {
142- $ data [] = Suppliers::readXML ($ c );
143- }
144- }
14592
146- unlink ($ filepath );
147- $ archive ->next ();
93+ $ info = json_decode (file_get_contents ($ path ));
94+ foreach ($ info ->blocks as $ c ) {
95+ if ($ execute ) {
96+ $ data [] = Suppliers::importJSON ($ info , $ c ->supplier , $ supplier_replace );
97+ }
98+ else {
99+ $ data [] = Suppliers::readJSON ($ c ->supplier );
148100 }
149101 }
150102
0 commit comments