2
2
3
3
namespace App \Services ;
4
4
5
+ use Exception ;
6
+ use RecursiveIteratorIterator ;
7
+ use RecursiveDirectoryIterator ;
5
8
use App \Models \Plugin ;
6
9
use Illuminate \Support \Facades \File ;
7
10
use Illuminate \Support \Facades \Artisan ;
@@ -52,12 +55,12 @@ public function installPlugin($pluginData)
52
55
$ existingPlugin = Plugin::where ('slug ' , $ pluginData ['slug ' ])->first ();
53
56
54
57
if ($ existingPlugin ) {
55
- throw new \ Exception ("Plugin ' {$ pluginData ['slug ' ]}' already exists. " );
58
+ throw new Exception ("Plugin ' {$ pluginData ['slug ' ]}' already exists. " );
56
59
}
57
60
58
61
// Validate compatibility
59
62
if (!$ this ->checkCompatibility ($ pluginData )) {
60
- throw new \ Exception ("Plugin ' {$ pluginData ['slug ' ]}' is not compatible with current system. " );
63
+ throw new Exception ("Plugin ' {$ pluginData ['slug ' ]}' is not compatible with current system. " );
61
64
}
62
65
63
66
// Create plugin record
@@ -89,7 +92,7 @@ public function installPlugin($pluginData)
89
92
90
93
return $ plugin ;
91
94
92
- } catch (\ Exception $ e ) {
95
+ } catch (Exception $ e ) {
93
96
Log::error ("Failed to install plugin: " . $ e ->getMessage ());
94
97
throw $ e ;
95
98
}
@@ -107,26 +110,26 @@ public function uploadAndInstallPlugin($zipFile)
107
110
$ zip ->extractTo ($ tempDir );
108
111
$ zip ->close ();
109
112
} else {
110
- throw new \ Exception ('Failed to extract plugin ZIP file. ' );
113
+ throw new Exception ('Failed to extract plugin ZIP file. ' );
111
114
}
112
115
113
116
// Find plugin manifest
114
117
$ manifestPath = $ this ->findPluginManifest ($ tempDir );
115
118
if (!$ manifestPath ) {
116
- throw new \ Exception ('Plugin manifest (plugin.json) not found. ' );
119
+ throw new Exception ('Plugin manifest (plugin.json) not found. ' );
117
120
}
118
121
119
122
$ manifest = json_decode (File::get ($ manifestPath ), true );
120
123
if (!$ manifest || !$ this ->validateManifest ($ manifest )) {
121
- throw new \ Exception ('Invalid plugin manifest. ' );
124
+ throw new Exception ('Invalid plugin manifest. ' );
122
125
}
123
126
124
127
// Move plugin to plugins directory
125
128
$ pluginSlug = $ manifest ['slug ' ];
126
129
$ pluginPath = $ this ->pluginsPath . '/ ' . $ pluginSlug ;
127
130
128
131
if (File::exists ($ pluginPath )) {
129
- throw new \ Exception ("Plugin directory ' {$ pluginSlug }' already exists. " );
132
+ throw new Exception ("Plugin directory ' {$ pluginSlug }' already exists. " );
130
133
}
131
134
132
135
File::moveDirectory (dirname ($ manifestPath ), $ pluginPath );
@@ -144,7 +147,7 @@ public function uploadAndInstallPlugin($zipFile)
144
147
145
148
return $ plugin ;
146
149
147
- } catch (\ Exception $ e ) {
150
+ } catch (Exception $ e ) {
148
151
// Cleanup on failure
149
152
if (isset ($ tempDir ) && File::exists ($ tempDir )) {
150
153
File::deleteDirectory ($ tempDir );
@@ -180,7 +183,7 @@ public function uninstallPlugin($pluginSlug)
180
183
181
184
return true ;
182
185
183
- } catch (\ Exception $ e ) {
186
+ } catch (Exception $ e ) {
184
187
Log::error ("Failed to uninstall plugin: " . $ e ->getMessage ());
185
188
throw $ e ;
186
189
}
@@ -193,17 +196,17 @@ public function activatePlugin($pluginSlug)
193
196
194
197
// Check dependencies
195
198
if (!$ plugin ->validateDependencies ()) {
196
- throw new \ Exception ("Plugin dependencies not met. " );
199
+ throw new Exception ("Plugin dependencies not met. " );
197
200
}
198
201
199
202
// Check compatibility
200
203
if (!$ plugin ->checkCompatibility ()) {
201
- throw new \ Exception ("Plugin not compatible with current system. " );
204
+ throw new Exception ("Plugin not compatible with current system. " );
202
205
}
203
206
204
207
// Load plugin
205
208
if (!$ plugin ->loadPlugin ()) {
206
- throw new \ Exception ("Failed to load plugin main file. " );
209
+ throw new Exception ("Failed to load plugin main file. " );
207
210
}
208
211
209
212
// Activate plugin
@@ -213,7 +216,7 @@ public function activatePlugin($pluginSlug)
213
216
214
217
return $ plugin ;
215
218
216
- } catch (\ Exception $ e ) {
219
+ } catch (Exception $ e ) {
217
220
Log::error ("Failed to activate plugin: " . $ e ->getMessage ());
218
221
throw $ e ;
219
222
}
@@ -229,7 +232,7 @@ public function deactivatePlugin($pluginSlug)
229
232
230
233
return $ plugin ;
231
234
232
- } catch (\ Exception $ e ) {
235
+ } catch (Exception $ e ) {
233
236
Log::error ("Failed to deactivate plugin: " . $ e ->getMessage ());
234
237
throw $ e ;
235
238
}
@@ -242,7 +245,7 @@ public function loadActivePlugins()
242
245
foreach ($ activePlugins as $ plugin ) {
243
246
try {
244
247
$ plugin ->loadPlugin ();
245
- } catch (\ Exception $ e ) {
248
+ } catch (Exception $ e ) {
246
249
Log::error ("Failed to load plugin ' {$ plugin ->slug }': " . $ e ->getMessage ());
247
250
}
248
251
}
@@ -283,8 +286,8 @@ protected function checkCompatibility($pluginData)
283
286
284
287
protected function findPluginManifest ($ directory )
285
288
{
286
- $ iterator = new \ RecursiveIteratorIterator (
287
- new \ RecursiveDirectoryIterator ($ directory )
289
+ $ iterator = new RecursiveIteratorIterator (
290
+ new RecursiveDirectoryIterator ($ directory )
288
291
);
289
292
290
293
foreach ($ iterator as $ file ) {
@@ -314,7 +317,7 @@ protected function runPluginMigrations($plugin, $action = 'install')
314
317
'--force ' => true
315
318
]);
316
319
}
317
- } catch (\ Exception $ e ) {
320
+ } catch (Exception $ e ) {
318
321
Log::warning ("Plugin migration failed for ' {$ plugin ->slug }': " . $ e ->getMessage ());
319
322
}
320
323
}
0 commit comments