From d61d6008da2ecef2bbc83e002ee9c0d74fd1e0ba Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 17 Nov 2014 18:00:51 +1100 Subject: [PATCH] Adds internal event for when a package is installed which gives access to the InstalledPackage instance which contains a PackageInstance reference that contains all of the files installed in the package --- .../businesslogic/Packager/Installer.cs | 70 +++++++++++-------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/src/umbraco.cms/businesslogic/Packager/Installer.cs b/src/umbraco.cms/businesslogic/Packager/Installer.cs index 49541df9b3..dfb76d1f7c 100644 --- a/src/umbraco.cms/businesslogic/Packager/Installer.cs +++ b/src/umbraco.cms/businesslogic/Packager/Installer.cs @@ -76,7 +76,7 @@ namespace umbraco.cms.businesslogic.packager /// Indicates that the package contains legacy property editors /// public bool ContainsLegacyPropertyEditors { get; private set; } - + public bool ContainsStyleSheeConflicts { get; private set; } public IDictionary ConflictingStyleSheetNames { get { return _conflictingStyleSheetNames; } } @@ -138,7 +138,7 @@ namespace umbraco.cms.businesslogic.packager } #region Public Methods - + /// /// Imports the specified package /// @@ -175,7 +175,7 @@ namespace umbraco.cms.businesslogic.packager return tempDir; } } - + public int CreateManifest(string tempDir, string guid, string repoGuid) { //This is the new improved install rutine, which chops up the process into 3 steps, creating the manifest, moving files, and finally handling umb objects @@ -256,14 +256,16 @@ namespace umbraco.cms.businesslogic.packager } catch (Exception ex) { - LogHelper.Error("Package install error", ex); + LogHelper.Error("Package install error", ex); } } insPack.Save(); + + } } - + public void InstallBusinessLogic(int packageId, string tempDir) { using (DisposableTimer.DebugDuration( @@ -292,7 +294,7 @@ namespace umbraco.cms.businesslogic.packager #region DataTypes var dataTypeElement = rootElement.Descendants("DataTypes").FirstOrDefault(); - if(dataTypeElement != null) + if (dataTypeElement != null) { var dataTypeDefinitions = packagingService.ImportDataTypeDefinitions(dataTypeElement, currentUser.Id); foreach (var dataTypeDefinition in dataTypeDefinitions) @@ -309,7 +311,7 @@ namespace umbraco.cms.businesslogic.packager var insertedLanguages = packagingService.ImportLanguages(languageItemsElement); insPack.Data.Languages.AddRange(insertedLanguages.Select(l => l.Id.ToString())); } - + #endregion #region Dictionary items @@ -335,7 +337,7 @@ namespace umbraco.cms.businesslogic.packager //if (saveNeeded) { insPack.Save(); saveNeeded = false; } #endregion - + #region Templates var templateElement = rootElement.Descendants("Templates").FirstOrDefault(); if (templateElement != null) @@ -404,7 +406,7 @@ namespace umbraco.cms.businesslogic.packager if (alias.IsNullOrWhiteSpace() == false) { - PackageAction.RunPackageAction(insPack.Data.Name, alias, n); + PackageAction.RunPackageAction(insPack.Data.Name, alias, n); } } } @@ -416,22 +418,24 @@ namespace umbraco.cms.businesslogic.packager new ApplicationTreeRegistrar(); insPack.Save(); + + OnPackageBusinessLogicInstalled(insPack); } } - /// - /// Remove the temp installation folder - /// - /// - /// + /// + /// Remove the temp installation folder + /// + /// + /// public void InstallCleanUp(int packageId, string tempDir) { - if (Directory.Exists(tempDir)) - { - Directory.Delete(tempDir, true); - } + if (Directory.Exists(tempDir)) + { + Directory.Delete(tempDir, true); + } } - + /// /// Reads the configuration of the package from the configuration xmldocument /// @@ -466,10 +470,10 @@ namespace umbraco.cms.businesslogic.packager { badFile = true; } - + if (destPath.ToLower().Contains(IOHelper.DirSepChar + "bin")) { - badFile = true; + badFile = true; } if (destFile.ToLower().EndsWith(".dll")) @@ -514,9 +518,9 @@ namespace umbraco.cms.businesslogic.packager ContainsMacroConflict = true; if (_conflictingMacroAliases.ContainsKey(m.Name) == false) { - _conflictingMacroAliases.Add(m.Name, alias); + _conflictingMacroAliases.Add(m.Name, alias); } - } + } } } @@ -548,8 +552,8 @@ namespace umbraco.cms.businesslogic.packager ContainsStyleSheeConflicts = true; if (_conflictingStyleSheetNames.ContainsKey(s.Text) == false) { - _conflictingStyleSheetNames.Add(s.Text, alias); - } + _conflictingStyleSheetNames.Add(s.Text, alias); + } } } } @@ -566,7 +570,7 @@ namespace umbraco.cms.businesslogic.packager } catch { } } - + /// /// This uses the old method of fetching and only supports the packages.umbraco.org repository. /// @@ -586,9 +590,9 @@ namespace umbraco.cms.businesslogic.packager return "packages\\" + Package + ".umb"; } - + #endregion - + #region Private Methods /// @@ -655,7 +659,7 @@ namespace umbraco.cms.businesslogic.packager string tempDir = IOHelper.MapPath(SystemDirectories.Data) + Path.DirectorySeparatorChar + packageId.ToString(); //clear the directory if it exists if (Directory.Exists(tempDir)) Directory.Delete(tempDir, true); - Directory.CreateDirectory(tempDir); + Directory.CreateDirectory(tempDir); var s = new ZipInputStream(File.OpenRead(zipName)); @@ -697,5 +701,13 @@ namespace umbraco.cms.businesslogic.packager } #endregion + + internal static event EventHandler PackageBusinessLogicInstalled; + + private static void OnPackageBusinessLogicInstalled(InstalledPackage e) + { + EventHandler handler = PackageBusinessLogicInstalled; + if (handler != null) handler(null, e); + } } }