@@ -29,18 +29,30 @@ namespace VirtoCommerce.Platform.Web.Controllers.Api
29
29
[ Authorize ]
30
30
public class ModulesController : Controller
31
31
{
32
+ private const string _managementIsDisabledMessage = "Module management is disabled." ;
33
+
32
34
private readonly IExternalModuleCatalog _externalModuleCatalog ;
33
35
private readonly IModuleInstaller _moduleInstaller ;
34
36
private readonly IPushNotificationManager _pushNotifier ;
35
37
private readonly IUserNameResolver _userNameResolver ;
36
38
private readonly ISettingsManager _settingsManager ;
37
39
private readonly PlatformOptions _platformOptions ;
38
40
private readonly ExternalModuleCatalogOptions _externalModuleCatalogOptions ;
41
+ private readonly LocalStorageModuleCatalogOptions _localStorageModuleCatalogOptions ;
39
42
private readonly IPlatformRestarter _platformRestarter ;
40
43
private static readonly object _lockObject = new object ( ) ;
41
44
private static readonly FormOptions _defaultFormOptions = new FormOptions ( ) ;
42
45
43
- public ModulesController ( IExternalModuleCatalog externalModuleCatalog , IModuleInstaller moduleInstaller , IPushNotificationManager pushNotifier , IUserNameResolver userNameResolver , ISettingsManager settingsManager , IOptions < PlatformOptions > platformOptions , IOptions < ExternalModuleCatalogOptions > externalModuleCatalogOptions , IPlatformRestarter platformRestarter )
46
+ public ModulesController (
47
+ IExternalModuleCatalog externalModuleCatalog ,
48
+ IModuleInstaller moduleInstaller ,
49
+ IPushNotificationManager pushNotifier ,
50
+ IUserNameResolver userNameResolver ,
51
+ ISettingsManager settingsManager ,
52
+ IOptions < PlatformOptions > platformOptions ,
53
+ IOptions < ExternalModuleCatalogOptions > externalModuleCatalogOptions ,
54
+ IOptions < LocalStorageModuleCatalogOptions > localStorageModuleCatalogOptions ,
55
+ IPlatformRestarter platformRestarter )
44
56
{
45
57
_externalModuleCatalog = externalModuleCatalog ;
46
58
_moduleInstaller = moduleInstaller ;
@@ -49,6 +61,7 @@ public ModulesController(IExternalModuleCatalog externalModuleCatalog, IModuleIn
49
61
_settingsManager = settingsManager ;
50
62
_platformOptions = platformOptions . Value ;
51
63
_externalModuleCatalogOptions = externalModuleCatalogOptions . Value ;
64
+ _localStorageModuleCatalogOptions = localStorageModuleCatalogOptions . Value ;
52
65
_platformRestarter = platformRestarter ;
53
66
}
54
67
@@ -143,22 +156,29 @@ public ActionResult<ModuleDescriptor[]> GetMissingDependencies([FromBody] Module
143
156
public async Task < ActionResult < ModuleDescriptor > > UploadModuleArchive ( )
144
157
{
145
158
EnsureModulesCatalogInitialized ( ) ;
146
- ModuleDescriptor result = null ;
159
+
160
+ if ( ! _localStorageModuleCatalogOptions . RefreshProbingFolderOnStart )
161
+ {
162
+ return BadRequest ( _managementIsDisabledMessage ) ;
163
+ }
164
+
147
165
if ( ! MultipartRequestHelper . IsMultipartContentType ( Request . ContentType ) )
148
166
{
149
167
return BadRequest ( $ "Expected a multipart request, but got { Request . ContentType } ") ;
150
168
}
169
+
151
170
var uploadPath = Path . GetFullPath ( _platformOptions . LocalUploadFolderPath ) ;
152
171
if ( ! Directory . Exists ( uploadPath ) )
153
172
{
154
173
Directory . CreateDirectory ( uploadPath ) ;
155
174
}
156
- string targetFilePath = null ;
157
175
176
+ ModuleDescriptor result = null ;
177
+ string targetFilePath = null ;
158
178
var boundary = MultipartRequestHelper . GetBoundary ( MediaTypeHeaderValue . Parse ( Request . ContentType ) , _defaultFormOptions . MultipartBoundaryLengthLimit ) ;
159
179
var reader = new MultipartReader ( boundary , HttpContext . Request . Body ) ;
160
-
161
180
var section = await reader . ReadNextSectionAsync ( ) ;
181
+
162
182
if ( section != null )
163
183
{
164
184
var hasContentDispositionHeader = ContentDispositionHeaderValue . TryParse ( section . ContentDisposition , out var contentDisposition ) ;
@@ -205,6 +225,7 @@ public async Task<ActionResult<ModuleDescriptor>> UploadModuleArchive()
205
225
}
206
226
}
207
227
}
228
+
208
229
return Ok ( result ) ;
209
230
}
210
231
@@ -394,27 +415,42 @@ public void ModuleBackgroundJob(ModuleBackgroundJobOptions options, ModulePushNo
394
415
try
395
416
{
396
417
notification . Started = DateTime . UtcNow ;
397
- var moduleInfos = _externalModuleCatalog . Modules . OfType < ManifestModuleInfo > ( )
398
- . Where ( x => options . Modules . Any ( y => y . Identity . Equals ( x . Identity ) ) )
399
- . ToArray ( ) ;
400
- var reportProgress = new Progress < ProgressMessage > ( m =>
418
+
419
+ if ( _localStorageModuleCatalogOptions . RefreshProbingFolderOnStart )
401
420
{
402
- lock ( _lockObject )
421
+ var moduleInfos = _externalModuleCatalog . Modules . OfType < ManifestModuleInfo > ( )
422
+ . Where ( x => options . Modules . Any ( y => y . Identity . Equals ( x . Identity ) ) )
423
+ . ToArray ( ) ;
424
+ var reportProgress = new Progress < ProgressMessage > ( m =>
403
425
{
404
- notification . Description = m . Message ;
405
- notification . ProgressLog . Add ( m ) ;
406
- _pushNotifier . Send ( notification ) ;
407
- }
408
- } ) ;
426
+ lock ( _lockObject )
427
+ {
428
+ notification . Description = m . Message ;
429
+ notification . ProgressLog . Add ( m ) ;
430
+ _pushNotifier . Send ( notification ) ;
431
+ }
432
+ } ) ;
409
433
410
- switch ( options . Action )
434
+ switch ( options . Action )
435
+ {
436
+ case ModuleAction . Install :
437
+ _moduleInstaller . Install ( moduleInfos , reportProgress ) ;
438
+ break ;
439
+ case ModuleAction . Uninstall :
440
+ _moduleInstaller . Uninstall ( moduleInfos , reportProgress ) ;
441
+ break ;
442
+ }
443
+ }
444
+ else
411
445
{
412
- case ModuleAction . Install :
413
- _moduleInstaller . Install ( moduleInfos , reportProgress ) ;
414
- break ;
415
- case ModuleAction . Uninstall :
416
- _moduleInstaller . Uninstall ( moduleInfos , reportProgress ) ;
417
- break ;
446
+ notification . Finished = DateTime . UtcNow ;
447
+ notification . Description = _managementIsDisabledMessage ;
448
+ notification . ProgressLog . Add ( new ProgressMessage
449
+ {
450
+ Level = ProgressMessageLevel . Error ,
451
+ Message = notification . Description ,
452
+ } ) ;
453
+ _pushNotifier . Send ( notification ) ;
418
454
}
419
455
}
420
456
catch ( Exception ex )
@@ -430,7 +466,7 @@ public void ModuleBackgroundJob(ModuleBackgroundJobOptions options, ModulePushNo
430
466
_settingsManager . SetValue ( PlatformConstants . Settings . Setup . ModulesAutoInstallState . Name , AutoInstallState . Completed ) ;
431
467
432
468
notification . Finished = DateTime . UtcNow ;
433
- notification . Description = "Installation finished." ;
469
+ notification . Description = options . Action == ModuleAction . Install ? "Installation finished." : "Uninstalling finished.";
434
470
notification . ProgressLog . Add ( new ProgressMessage
435
471
{
436
472
Level = ProgressMessageLevel . Info ,
0 commit comments