From 2901cb10f815ffb39c0e731354411abde1bfabbd Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Wed, 17 Mar 2021 12:57:24 +0000 Subject: [PATCH] Remove last static event and implement canceable notification where users are able to cancel the import process --- .../Services/Implement/PackagingService.cs | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs b/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs index 75bd0b8ced..bf86d965b1 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs @@ -120,7 +120,12 @@ namespace Umbraco.Cms.Core.Services.Implement var compiledPackage = GetCompiledPackageInfo(packageFile); if (compiledPackage == null) throw new InvalidOperationException("Could not read the package file " + packageFile); - if (ImportingPackage.IsRaisedEventCancelled(new ImportPackageEventArgs(packageFile.Name, compiledPackage), this)) + // Trigger the Importing Package Notification + var notification = new ImportingPackageNotification(packageFile.Name, compiledPackage); + _eventAggregator.Publish(notification); + + // Stop execution if event/user is cancelling it + if (notification.Cancel) return new InstallationSummary { MetaData = compiledPackage }; var summary = _packageInstallation.InstallPackageData(packageDefinition, compiledPackage, userId); @@ -129,8 +134,8 @@ namespace Umbraco.Cms.Core.Services.Implement _auditService.Add(AuditType.PackagerInstall, userId, -1, "Package", $"Package data installed for package '{compiledPackage.Name}'."); - // trigger the ImportPackage event - _eventAggregator.Publish(new ImportPackageNotification(summary, compiledPackage)); + // trigger the ImportedPackage event + _eventAggregator.Publish(new ImportedPackageNotification(summary, compiledPackage)); return summary; } @@ -240,22 +245,5 @@ namespace Umbraco.Cms.Core.Services.Implement } #endregion - - #region Event Handlers - - /// - /// Occurs before Importing umbraco package - /// - public static event TypedEventHandler> ImportingPackage; - - /// - /// Occurs after a package is imported - /// - public static event TypedEventHandler> ImportedPackage; - - - #endregion - - } }