44
55use Closure ;
66use Symfony \Component \Console \Command \Command ;
7- use Symfony \Component \Console \Helper \ProcessHelper ;
87use Symfony \Component \Console \Helper \QuestionHelper ;
8+ use Symfony \Component \Console \Input \ArrayInput ;
99use Symfony \Component \Console \Input \InputArgument ;
1010use Symfony \Component \Console \Input \InputInterface ;
1111use Symfony \Component \Console \Input \InputOption ;
1212use Symfony \Component \Console \Output \OutputInterface ;
1313use Symfony \Component \Console \Question \Question ;
14- use Symfony \Component \Process \Exception \ProcessFailedException ;
15- use Symfony \Component \Process \PhpExecutableFinder ;
16- use Symfony \Component \Process \Process ;
17- use Symfony \Component \Process \ProcessBuilder ;
1814use XF \Cli \Command \AddOnActionTrait ;
1915use XF \Cli \Command \Development \RequiresDevModeTrait ;
2016use XF \Util \File ;
@@ -45,7 +41,7 @@ protected function configure() : void
4541 'table to inspect '
4642 )
4743 ->addArgument (
48- 'RelationName ' ,
44+ 'name ' ,
4945 InputArgument::REQUIRED ,
5046 'The entity \'s name '
5147 )
@@ -58,10 +54,12 @@ protected function configure() : void
5854 }
5955
6056 /**
61- * @param InputInterface $input
57+ * @param InputInterface $input
6258 * @param OutputInterface $output
6359 *
6460 * @return int
61+ *
62+ * @throws \Exception
6563 */
6664 protected function execute (InputInterface $ input , OutputInterface $ output ) : int
6765 {
@@ -94,7 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
9492 $ output ->writeln ('' );
9593 }
9694
97- $ name = $ input ->getArgument ('RelationName ' );
95+ $ name = $ input ->getArgument ('name ' );
9896 if (!$ name )
9997 {
10098 $ question = new Question ('<question>Enter the relationship name for the entity:</question> ' );
@@ -252,20 +250,20 @@ public static function getStructure(Structure \$structure)
252250TEMPLATE ;
253251 $ entityName = "{$ namespace }: {$ name }" ;
254252 $ entityName = str_replace ('/ ' , '\\' , $ entityName );
253+ File::writeFile ($ filename , $ template , false );
255254
256255 $ output ->writeln ("Writing entity for {$ entityName }" );
257- echo $ template . "\n\n" ;
258- File::writeFile ($ filename , $ template , false );
256+ $ output ->writeln ($ template );
259257
260- $ this ->runSubAction ( $ output , [
261- ' xf-dev:entity-class-properties ' ,
262- $ entityName
263- ] );
258+ $ command = $ this ->getApplication ()-> find ( ' xf-dev:entity-class-properties ' );
259+ $ childInput = new ArrayInput ([ ' addon-or-entity ' => $ entityName ]);
260+ $ command -> run ( $ childInput , $ output );
261+ $ output -> writeln ( '' );
264262
265- $ this ->runSubAction ( $ output , [
266- ' tdt-addon:generate-schema-entity ' ,
267- $ entityName
268- ] );
263+ $ command = $ this ->getApplication ()-> find ( ' tck-dt:generate-schema-entity ' );
264+ $ childInput = new ArrayInput ([ ' id ' => $ entityName ]);
265+ $ command -> run ( $ childInput , $ output );
266+ $ output -> writeln ( '' );
269267
270268 return 0 ;
271269 }
@@ -397,56 +395,6 @@ protected function parseSqlType(string $sqlType) : array
397395 return [$ type , $ len , $ allowedValues ];
398396 }
399397
400- /**
401- * @param OutputInterface $output
402- * @param array $args
403- */
404- public function runSubAction (OutputInterface $ output , array $ args = []) : void
405- {
406- $ execFinder = new PhpExecutableFinder ();
407-
408- $ builderOptions = [
409- $ execFinder ->find (false ),
410- \XF ::getRootDirectory () . DIRECTORY_SEPARATOR . 'cmd.php ' ,
411- '-n '
412- ];
413- $ builderOptions = \array_merge ($ builderOptions , $ args );
414-
415- if ($ verbosityOption = $ this ->getVerbosityOption ($ output ->getVerbosity ()))
416- {
417- $ builderOptions [] = $ verbosityOption ;
418- }
419-
420- $ process = new Process ($ builderOptions );
421- $ process ->setTimeout (null );
422-
423- /** @var ProcessHelper $processHelper */
424- $ processHelper = $ this ->getHelper ('process ' );
425-
426- try
427- {
428- $ processHelper ->mustRun ($ output , $ process , null , function ($ type , $ data ) use ($ output )
429- {
430- if ($ type === Process::OUT )
431- {
432- $ output ->write ($ data );
433- }
434- // Note that progress bar output is in Process::ERR/stderr, but they get streamed to this callback
435- // interleaved, so displaying both is difficult. Thus, we need to only display stuff sent stdout.
436- });
437- }
438- catch (ProcessFailedException $ e )
439- {
440- $ process = $ e ->getProcess ();
441- if ($ process ->getExitCode () === 222 )
442- {
443- // This indicates that the sub-process threw an exception. It will have been printed and logged
444- // so don't trigger the normal exception handling. However, we can't continue so exit.
445- exit (1 );
446- }
447- }
448- }
449-
450398 /**
451399 * @param $key
452400 *
0 commit comments