77namespace Ho \Import \Model ;
88
99use Ho \Import \Api \ImportProfileInterface ;
10+ use Ho \Import \Logger \Log ;
1011use Magento \Framework \Phrase ;
1112use Magento \Framework \ObjectManagerInterface ;
12-
13-
14- use Magento \Framework \App \ObjectManager \ConfigLoader ;
1513use Magento \Framework \App \ObjectManagerFactory ;
16- use Magento \Framework \App \State as AppState ;
1714use Symfony \Component \Console \Output \ConsoleOutput ;
1815use Symfony \Component \Stopwatch \Stopwatch ;
1916
@@ -40,22 +37,27 @@ abstract class ImportProfile implements ImportProfileInterface
4037 */
4138 private $ objectManagerFactory ;
4239
40+ /**
41+ * @var Log
42+ */
43+ protected $ log ;
4344
4445 /**
45- * ImportProfile constructor.
46- *
47- * @param ObjectManagerFactory $objectManagerFactory
48- * @param Stopwatch $stopwatch
49- * @param ConsoleOutput $consoleOutput
46+ * @param ObjectManagerFactory $objectManagerFactory
47+ * @param Stopwatch $stopwatch
48+ * @param ConsoleOutput $consoleOutput
49+ * @param Log $log
5050 */
5151 public function __construct (
5252 ObjectManagerFactory $ objectManagerFactory ,
5353 Stopwatch $ stopwatch ,
54- ConsoleOutput $ consoleOutput
54+ ConsoleOutput $ consoleOutput ,
55+ Log $ log
5556 ) {
5657 $ this ->objectManagerFactory = $ objectManagerFactory ;
5758 $ this ->stopwatch = $ stopwatch ;
5859 $ this ->consoleOutput = $ consoleOutput ;
60+ $ this ->log = $ log ;
5961 }
6062
6163
@@ -78,19 +80,24 @@ public function run()
7880 $ errors = $ importer ->processImport ($ items );
7981 $ stopwatchEvent = $ this ->stopwatch ->stop ('importinstance ' );
8082
81- $ this -> consoleOutput -> writeln ( (string ) new Phrase (
83+ $ output = (string ) new Phrase (
8284 '%1 items imported in %2 sec, <info>%3 items / sec</info> (%4mb used) ' , [
8385 count ($ items ),
8486 round ($ stopwatchEvent ->getDuration () / 1000 , 1 ),
8587 round (count ($ items ) / ($ stopwatchEvent ->getDuration () / 1000 ), 1 ),
8688 round ($ stopwatchEvent ->getMemory () / 1024 / 1024 , 1 )
87- ]));
89+ ]);
90+
91+ $ this ->consoleOutput ->writeln ($ output );
92+ $ this ->log ->addInfo ($ output );
8893
8994 $ this ->consoleOutput ->writeln ("<error> $ errors</error> " );
95+ $ this ->log ->addError ($ errors );
9096
9197 return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
9298 } catch (\Exception $ e ) {
9399 $ this ->consoleOutput ->writeln ($ e ->getMessage ());
100+ $ this ->log ->addCritical ($ e ->getMessage ());
94101
95102 return \Magento \Framework \Console \Cli::RETURN_FAILURE ;
96103 }
@@ -99,26 +106,31 @@ public function run()
99106 /**
100107 * Get all items that need to be imported
101108 *
102- * @return \[]
109+ * @return array
103110 */
104111 private function getItemsMeasured ()
105112 {
106113 $ this ->stopwatch ->start ('profileinstance ' );
107114 $ this ->consoleOutput ->writeln ('Getting item data ' );
115+ $ this ->log ->addInfo ('Getting item data ' );
108116 $ items = $ this ->getItems ();
109117 $ stopwatchEvent = $ this ->stopwatch ->stop ('profileinstance ' );
110118
111119 if (! $ stopwatchEvent ->getDuration ()) {
112120 return $ items ;
113121 }
114122
115- $ this -> consoleOutput -> writeln (( string )new Phrase ('%1 items processed in %2 sec, <info>%3 items / sec</info> (%4mb used) ' ,
123+ $ output = ( string ) new Phrase ('%1 items processed in %2 sec, <info>%3 items / sec</info> (%4mb used) ' ,
116124 [
117125 count ($ items ),
118126 round ($ stopwatchEvent ->getDuration () / 1000 , 1 ),
119127 round (count ($ items ) / ($ stopwatchEvent ->getDuration () / 1000 ), 1 ),
120128 round ($ stopwatchEvent ->getMemory () / 1024 / 1024 , 1 )
121- ]));
129+ ]);
130+
131+ $ this ->consoleOutput ->writeln ($ output );
132+ $ this ->log ->addInfo ($ output );
133+
122134 return $ items ;
123135 }
124136
0 commit comments