File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33namespace App \Command ;
44
55use App \Entity \ImportRun ;
6+ use App \Service \BaseImporter ;
67use Doctrine \ORM \EntityManagerInterface ;
78use Symfony \Component \Console \Command \Command ;
9+ use Symfony \Component \Console \Output \OutputInterface ;
810
911abstract class AbstractImportCommand extends Command
1012{
1113 protected $ entityManager ;
14+ protected $ importer ;
1215
13- public function __construct (EntityManagerInterface $ entityManager )
16+ public function __construct (BaseImporter $ importer , EntityManagerInterface $ entityManager )
1417 {
1518 parent ::__construct ();
1619
1720 $ this ->entityManager = $ entityManager ;
21+ $ this ->importer = $ importer ;
22+ }
23+
24+ /**
25+ * Run the importer.
26+ *
27+ * @param string $type
28+ * @param string $src
29+ * @param \Symfony\Component\Console\Output\OutputInterface $output
30+ * @throws \Exception
31+ */
32+ protected function import (string $ type , string $ src , OutputInterface $ output )
33+ {
34+ $ success = true ;
35+ $ errorMessage = null ;
36+
37+ try {
38+ $ this ->importer ->import ($ src );
39+ } catch (\Exception $ e ) {
40+ $ success = false ;
41+ $ errorMessage = $ e ->getMessage ();
42+ $ output ->writeln ($ errorMessage );
43+ }
44+
45+ $ this ->recordImportRun ($ type , $ success , $ errorMessage );
1846 }
1947
2048 /**
Original file line number Diff line number Diff line change 1111
1212class ReportImportCommand extends AbstractImportCommand
1313{
14- private $ reportImporter ;
15-
1614 public function __construct (ReportImporter $ reportImporter , EntityManagerInterface $ entityManager )
1715 {
18- parent ::__construct ($ entityManager );
19-
20- $ this ->reportImporter = $ reportImporter ;
21- $ this ->entityManager = $ entityManager ;
16+ parent ::__construct ($ reportImporter , $ entityManager );
2217 }
2318
2419 protected function configure ()
@@ -31,17 +26,6 @@ protected function configure()
3126
3227 protected function execute (InputInterface $ input , OutputInterface $ output )
3328 {
34- $ success = true ;
35- $ errorMessage = null ;
36-
37- try {
38- $ this ->reportImporter ->import ($ input ->getArgument ('src ' ));
39- } catch (\Exception $ e ) {
40- $ success = false ;
41- $ errorMessage = $ e ->getMessage ();
42- $ output ->writeln ($ errorMessage );
43- }
44-
45- $ this ->recordImportRun (Report::class, $ success , $ errorMessage );
29+ $ this ->import (Report::class, $ input ->getArgument ('src ' ), $ output );
4630 }
4731}
Original file line number Diff line number Diff line change 1111
1212class SystemImportCommand extends AbstractImportCommand
1313{
14- private $ systemImporter ;
15-
1614 public function __construct (SystemImporter $ systemImporter , EntityManagerInterface $ entityManager )
1715 {
18- parent ::__construct ($ entityManager );
19-
20- $ this ->systemImporter = $ systemImporter ;
16+ parent ::__construct ($ systemImporter , $ entityManager );
2117 }
2218
2319 protected function configure ()
@@ -30,17 +26,6 @@ protected function configure()
3026
3127 protected function execute (InputInterface $ input , OutputInterface $ output )
3228 {
33- $ success = true ;
34- $ errorMessage = null ;
35-
36- try {
37- $ this ->systemImporter ->import ($ input ->getArgument ('src ' ));
38- } catch (\Exception $ e ) {
39- $ success = false ;
40- $ errorMessage = $ e ->getMessage ();
41- $ output ->writeln ($ errorMessage );
42- }
43-
44- $ this ->recordImportRun (System::class, $ success , $ errorMessage );
29+ $ this ->import (System::class, $ input ->getArgument ('src ' ), $ output );
4530 }
4631}
You can’t perform that action at this time.
0 commit comments