@@ -42,15 +42,28 @@ protected function execute(InputInterface $input, OutputInterface $output) {
4242 ->setInput ($ input )
4343 ->writeBlockCommand ($ this ->getName ());
4444
45+ // Refresh modules to discover any manually copied modules
46+ \ProcessWire \wire ('modules ' )->refresh ();
47+
4548 $ modules = $ this ->tools ->ask ($ input ->getArgument ('modules ' ), 'Modules ' , null , false , null , 'required ' );
4649 if (!is_array ($ modules )) $ modules = explode (', ' , $ modules );
4750
4851 foreach ($ modules as $ module ) {
52+ $ module = trim ($ module );
53+
4954 // if module doesn't exist, download the module
5055 if (!$ this ->checkIfModuleExists ($ module )) {
5156 $ this ->tools ->writeComment ("Cannot find ' {$ module }' locally, trying to download... " );
5257 $ this ->tools ->nl ();
53- $ this ->passOnToModuleDownloadCommand ($ module , $ output , $ input );
58+
59+ try {
60+ $ this ->passOnToModuleDownloadCommand ($ module , $ output , $ input );
61+ // Refresh modules after download to make sure the newly downloaded module is discoverable
62+ \ProcessWire \wire ('modules ' )->refresh ();
63+ } catch (\Exception $ e ) {
64+ $ this ->tools ->writeError ("Failed to download module ' {$ module }': " . $ e ->getMessage ());
65+ continue ;
66+ }
5467 }
5568
5669 // check whether module is already installed
@@ -59,35 +72,31 @@ protected function execute(InputInterface $input, OutputInterface $output) {
5972 continue ;
6073 }
6174
62- // install module
75+ // install module with proper CLI options
6376 $ options = array (
6477 'noPermissionCheck ' => true ,
6578 'noInit ' => true
6679 );
6780
68- if (\ProcessWire \wire ('modules ' )->getInstall ($ module , $ options )) {
69- $ this ->tools ->writeSuccess (" Module ` {$ module }` installed successfully. " );
70- } else {
71- $ this ->tools ->writeError (" Module ` {$ module }` does not exist. " );
81+ try {
82+ if (\ProcessWire \wire ('modules ' )->getInstall ($ module , $ options )) {
83+ $ this ->tools ->writeSuccess (" Module ` {$ module }` installed successfully. " );
84+ } else {
85+ $ this ->tools ->writeError (" Module ` {$ module }` installation failed. " );
86+ }
87+ } catch (\Exception $ e ) {
88+ $ this ->tools ->writeError (" Module ` {$ module }` does not exist or installation failed: " . $ e ->getMessage ());
7289 }
7390 }
7491
7592 return static ::SUCCESS ;
7693 }
7794
78- private function checkIfModuleExistsLocally ($ module , $ output , $ input ) {
79- if (!$ this ->checkIfModuleExists ($ module )) {
80- $ output ->writeln ("<comment>Cannot find ' {$ module }' locally, trying to download...</comment> " );
81- $ this ->passOnToModuleDownloadCommand ($ module , $ output , $ input );
82- }
83-
84- }
85-
8695 private function passOnToModuleDownloadCommand ($ module , $ output , $ input ) {
87- $ command = $ this ->getApplication ()->find ('mod :download ' );
96+ $ command = $ this ->getApplication ()->find ('module :download ' );
8897
8998 $ arguments = array (
90- 'command ' => 'mod :download ' ,
99+ 'command ' => 'module :download ' ,
91100 'modules ' => $ module ,
92101 '--github ' => $ input ->getOption ('github ' ),
93102 '--branch ' => $ input ->getOption ('branch ' )
0 commit comments