1919use Ivy \Template \Presentation \View \View ;
2020use Ivy \User \Domain \Exception \AuthorizationException ;
2121use ReflectionException ;
22+ use Symfony \Component \Process \Process ;
2223
2324class PluginController extends Controller
2425{
@@ -61,7 +62,7 @@ public function index(?string $id = null): void
6162 $ this ->plugin ->authorize ('index ' );
6263
6364 $ installedPlugins = collect (Plugin::all ())->map (function ($ plugin ) use (&$ installedUrls ) {
64- if ($ plugin ->status !== PluginStatus::PENDING ) {
65+ if ($ plugin ->status !== PluginStatus::PENDING ) {
6566 $ loader = new PluginInfoLoader ;
6667 $ factory = new PluginInfoFactory ;
6768
@@ -77,7 +78,7 @@ public function index(?string $id = null): void
7778
7879 $ uninstalledPlugins = [];
7980
80- if (! $ id ) {
81+ if (!$ id ) {
8182 $ pluginsPath = Path::get ('PLUGINS_PATH ' );
8283
8384 if (is_dir ($ pluginsPath )) {
@@ -90,9 +91,9 @@ public function index(?string $id = null): void
9091 continue ;
9192 }
9293
93- $ infoPath = $ pluginsPath. $ plugin. '/info.json ' ;
94+ $ infoPath = $ pluginsPath . $ plugin . '/info.json ' ;
9495
95- if (! is_file ($ infoPath )) {
96+ if (!is_file ($ infoPath )) {
9697 continue ;
9798 }
9899
@@ -124,7 +125,7 @@ public function index(?string $id = null): void
124125 }
125126
126127 /**
127- * @param array<string, mixed> $data
128+ * @param array<string, mixed> $data
128129 *
129130 * @throws Exception
130131 */
@@ -164,7 +165,7 @@ public function update(Plugin|int $plugin, mixed $data): void
164165
165166 $ plugin ->fill ($ data );
166167
167- if (! $ plugin ->isDirty ()) {
168+ if (!$ plugin ->isDirty ()) {
168169 return ;
169170 }
170171
@@ -174,7 +175,7 @@ public function update(Plugin|int $plugin, mixed $data): void
174175
175176 $ this ->flashBag ->add (
176177 'success ' ,
177- 'Plugin ' . $ plugin ->name . ' updated successfully. '
178+ 'Plugin ' . $ plugin ->name . ' updated successfully. '
178179 );
179180 }
180181
@@ -239,4 +240,35 @@ public function sync(): void
239240
240241 $ this ->redirect ('admin/plugin ' );
241242 }
243+
244+ public function download (): void
245+ {
246+ $ this ->plugin ->authorize ('install ' );
247+
248+ $ package = $ this ->request ->request ->get ('package ' );
249+
250+ try {
251+ $ process = new Process (
252+ [
253+ Path::get ('PROJECT_PATH ' ) . '/vendor/bin/require ' ,
254+ $ package ,
255+ ],
256+ Path::get ('PROJECT_PATH ' ),
257+ );
258+
259+ $ process ->start ();
260+
261+ $ this ->flashBag ->add (
262+ 'success ' ,
263+ 'Plugin download started. '
264+ );
265+ } catch (\Throwable $ e ) {
266+ $ this ->flashBag ->add (
267+ 'error ' ,
268+ 'Failed to start plugin download: ' . $ e ->getMessage ()
269+ );
270+ }
271+
272+ $ this ->redirect ('admin/plugin ' );
273+ }
242274}
0 commit comments