@@ -24,11 +24,6 @@ class ExportCommand
24
24
*/
25
25
private $ config ;
26
26
27
- /**
28
- * @var string
29
- */
30
- private $ eShopSourcePath ;
31
-
32
27
/**
33
28
* @var Exporter
34
29
*/
@@ -37,12 +32,10 @@ class ExportCommand
37
32
/**
38
33
* @param array $cliArguments
39
34
* @param Factory $factory
40
- * @param string $eShopSourcePath
41
35
*/
42
- public function __construct ($ cliArguments , $ factory, string $ eShopSourcePath )
36
+ public function __construct ($ cliArguments , $ factory )
43
37
{
44
38
Registry::getConfig ()->setAdminMode (true );
45
- $ this ->eShopSourcePath = $ eShopSourcePath ;
46
39
$ this ->config = $ this ->getConfigurationParameters ($ cliArguments );
47
40
Registry::getConfig ()->setShopId ($ this ->config ['shopId ' ]);
48
41
@@ -77,44 +70,35 @@ public function export()
77
70
0
78
71
);
79
72
} catch (ExporterException $ exception ) {
80
- exit ($ exception ->getMessage ());
73
+ throw new \ Exception ($ exception ->getMessage ());
81
74
}
82
75
83
- print ("Export completed. \n" );
84
- exit (0 );
76
+ return "Export completed. \n" ;
85
77
}
86
78
87
79
/**
88
- * @param array $cliArguments
80
+ * @param string $cliArguments
89
81
*
90
82
* @return string
91
83
*/
92
84
private function getConfigFile ($ cliArguments )
93
85
{
94
- $ configFile = Path::join ($ this ->eShopSourcePath , 'modules/oe/personalization/config/default_params.php ' );
95
- array_shift ($ cliArguments );
96
- if (isset ($ cliArguments [0 ])) {
97
- if ($ cliArguments [0 ] === '--config ' ) {
98
- $ configFile = (isset ($ cliArguments [1 ])) ? $ cliArguments [1 ] : '' ;
99
- if (!file_exists ($ configFile )) {
100
- exit ('File does not exist: ' . $ configFile . "\n" );
101
- }
102
- } else {
103
- $ message = 'Unknown command: ' . $ cliArguments [0 ] .
104
- '. If you want to override the configuration file for the export, please, use the "--config" command ' .
105
- "\n" ;
106
- exit ($ message );
86
+ $ configFile = Path::join (__DIR__ , '../../../config/default_params.php ' );
87
+ if (isset ($ cliArguments )) {
88
+ $ configFile = $ cliArguments ;
89
+ if (!file_exists ($ configFile )) {
90
+ throw new \Exception ('File does not exist: ' . $ configFile . "\n" );
107
91
}
108
92
}
109
93
110
94
if (!file_exists ($ configFile )) {
111
- exit ('Config file is missing: ' . $ configFile . "\n" );
95
+ throw new \ Exception ('Config file is missing: ' . $ configFile . "\n" );
112
96
}
113
97
return $ configFile ;
114
98
}
115
99
116
100
/**
117
- * @param array $argv
101
+ * @param string $argv
118
102
*
119
103
* @return array
120
104
*/
@@ -125,7 +109,7 @@ private function getConfigurationParameters($argv)
125
109
$ config = include $ configFile ;
126
110
127
111
if (!is_array ($ config )) {
128
- exit ('Config file has wrong format. ' ."\n" );
112
+ throw new \ Exception ('Config file has wrong format. ' ."\n" );
129
113
}
130
114
131
115
return $ config ;
0 commit comments