void InstalledPackage_BeforeDelete(InstalledPackage sender, EventArgs e)
 {
     if (sender.Data.Name == Constants.UmbracoPackageName)
     {
         Kraken.Uninstall();
     }
 }
Пример #2
0
        public static InstalledPackage GetByGuid(string packageGuid)
        {
            InstalledPackage pack = new InstalledPackage();

            pack.Data = data.Package(packageGuid, IOHelper.MapPath(Settings.InstalledPackagesSettings));
            return(pack);
        }
Пример #3
0
        public void InstallFiles(int packageId, string tempDir)
        {
            using (DisposableTimer.DebugDuration <Installer>(
                       () => "Installing package files for package id " + packageId + " into temp folder " + tempDir,
                       () => "Package file installation complete for package id " + packageId))
            {
                //retrieve the manifest to continue installation
                var insPack = InstalledPackage.GetById(packageId);

                //TODO: Depending on some files, some files should be installed differently.
                //i.e. if stylsheets should probably be installed via business logic, media items should probably use the media IFileSystem!

                // Move files
                //string virtualBasePath = System.Web.HttpContext.Current.Request.ApplicationPath;
                string basePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;

                foreach (XmlNode n in Config.DocumentElement.SelectNodes("//file"))
                {
                    //we enclose the whole file-moving to ensure that the entire installer doesn't crash
                    try
                    {
                        var destPath   = GetFileName(basePath, XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath")));
                        var sourceFile = GetFileName(tempDir, XmlHelper.GetNodeValue(n.SelectSingleNode("guid")));
                        var destFile   = GetFileName(destPath, XmlHelper.GetNodeValue(n.SelectSingleNode("orgName")));

                        // Create the destination directory if it doesn't exist
                        if (Directory.Exists(destPath) == false)
                        {
                            Directory.CreateDirectory(destPath);
                        }
                        //If a file with this name exists, delete it
                        else if (File.Exists(destFile))
                        {
                            File.Delete(destFile);
                        }

                        // Move the file
                        File.Move(sourceFile, destFile);

                        //PPH log file install
                        insPack.Data.Files.Add(XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath")) + "/" + XmlHelper.GetNodeValue(n.SelectSingleNode("orgName")));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error <Installer>("Package install error", ex);
                    }
                }

                // log that a user has install files
                if (_currentUserId > -1)
                {
                    Audit.Add(AuditTypes.PackagerInstall,
                              string.Format("Package '{0}' installed. Package guid: {1}", insPack.Data.Name, insPack.Data.PackageGuid),
                              _currentUserId, -1);
                }

                insPack.Save();
            }
        }
Пример #4
0
        public static InstalledPackage MakeNew(string name)
        {
            InstalledPackage pack = new InstalledPackage();

            pack.Data = data.MakeNew(name, IOHelper.MapPath(Settings.InstalledPackagesSettings));
            pack.OnNew(EventArgs.Empty);
            return(pack);
        }
 private void InstalledPackage_BeforeDelete(InstalledPackage sender, System.EventArgs e)
 {
     if (sender.Data.Name == "DTP App Pool Refresh")
     {
         InstallHelper installHelper = new InstallHelper();
         installHelper.RemoveSectionDashboard();
         installHelper.RemoveAppSetting();
     }
 }
Пример #6
0
        private static void OnPackageBusinessLogicInstalled(InstalledPackage e)
        {
            EventHandler <InstalledPackage> handler = PackageBusinessLogicInstalled;

            if (handler != null)
            {
                handler(null, e);
            }
        }
Пример #7
0
 /// <summary>
 /// Uninstall Package - Before Delete (Old style events, no V6/V7 equivelant)
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void InstalledPackage_BeforeDelete(InstalledPackage sender, System.EventArgs e)
 {
     //Check which package is being uninstalled
     if (sender.Data.Name == "Analytics")
     {
         //Start Uninstall - clean up process...
         Uninstall.RemoveSection();
         Uninstall.RemoveSectionLanguageKeys();
     }
 }
Пример #8
0
        /// <summary>
        /// Uninstall Package - Before Delete (Old style events, no V6/V7 equivelant)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void InstalledPackage_BeforeDelete(InstalledPackage sender, System.EventArgs e)
        {
            //Check which package is being uninstalled
            if (sender.Data.Name == "PieMan Analytics")
            {
                Translations.RemoveTranslations();

                var webConfig = WebConfigurationManager.OpenWebConfiguration("/");
                webConfig.AppSettings.Settings.Remove(AppSettingKey);
                webConfig.Save();
            }
        }
Пример #9
0
        public static List <InstalledPackage> GetAllInstalledPackages()
        {
            List <InstalledPackage> val = new List <InstalledPackage>();

            foreach (PackageInstance pack in data.GetAllPackages(IOHelper.MapPath(Settings.InstalledPackagesSettings)))
            {
                InstalledPackage insPackage = new InstalledPackage();
                insPackage.Data = pack;
                val.Add(insPackage);
            }

            return(val);
        }
Пример #10
0
        public static List<InstalledPackage> GetAllInstalledPackages() {

            List<InstalledPackage> val = new List<InstalledPackage>();

            foreach (PackageInstance pack in data.GetAllPackages(IOHelper.MapPath(Settings.InstalledPackagesSettings)))
            {
                InstalledPackage insPackage = new InstalledPackage();
                insPackage.Data = pack;
                val.Add(insPackage);
            }

            return val;
        }
Пример #11
0
        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
            var packName      = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/package/name"));
            var packAuthor    = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/author/name"));
            var packAuthorUrl = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/author/website"));
            var packVersion   = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/package/version"));
            var packReadme    = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/readme"));
            var packLicense   = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/package/license "));
            var packUrl       = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/package/url "));
            var iconUrl       = XmlHelper.GetNodeValue(Config.DocumentElement.SelectSingleNode("/umbPackage/info/package/iconUrl"));

            var enableSkins  = false;
            var skinRepoGuid = "";

            if (Config.DocumentElement.SelectSingleNode("/umbPackage/enableSkins") != null)
            {
                var skinNode = Config.DocumentElement.SelectSingleNode("/umbPackage/enableSkins");
                enableSkins = bool.Parse(XmlHelper.GetNodeValue(skinNode));
                if (skinNode.Attributes["repository"] != null && string.IsNullOrEmpty(skinNode.Attributes["repository"].Value) == false)
                {
                    skinRepoGuid = skinNode.Attributes["repository"].Value;
                }
            }

            //Create a new package instance to record all the installed package adds - this is the same format as the created packages has.
            //save the package meta data
            var insPack = InstalledPackage.MakeNew(packName);

            insPack.Data.Author    = packAuthor;
            insPack.Data.AuthorUrl = packAuthorUrl;
            insPack.Data.Version   = packVersion;
            insPack.Data.Readme    = packReadme;
            insPack.Data.License   = packLicense;
            insPack.Data.Url       = packUrl;
            insPack.Data.IconUrl   = iconUrl;

            //skinning
            insPack.Data.EnableSkins  = enableSkins;
            insPack.Data.SkinRepoGuid = string.IsNullOrEmpty(skinRepoGuid) ? Guid.Empty : new Guid(skinRepoGuid);

            insPack.Data.PackageGuid    = guid;     //the package unique key.
            insPack.Data.RepositoryGuid = repoGuid; //the repository unique key, if the package is a file install, the repository will not get logged.
            insPack.Save();

            return(insPack.Data.Id);
        }
Пример #12
0
        private void OnPackageInstalled(InstalledPackage insPack)
        {
            // getting an InstallationSummary for sending to the PackagingService.ImportedPackage event
            var fileService         = ApplicationContext.Current.Services.FileService;
            var macroService        = ApplicationContext.Current.Services.MacroService;
            var contentTypeService  = ApplicationContext.Current.Services.ContentTypeService;
            var dataTypeService     = ApplicationContext.Current.Services.DataTypeService;
            var localizationService = ApplicationContext.Current.Services.LocalizationService;

            var installationSummary = insPack.GetInstallationSummary(contentTypeService, dataTypeService, fileService, localizationService, macroService);

            installationSummary.PackageInstalled = true;

            var args = new ImportPackageEventArgs <InstallationSummary>(installationSummary, false);

            PackagingService.OnImportedPackage(args);
        }
Пример #13
0
        /// <summary>
        /// Uninstall Package - Before Delete (Old style events, no V6/V7 equivelant)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void InstalledPackage_BeforeDelete(InstalledPackage sender, System.EventArgs e)
        {
            //Check which package is being uninstalled
            if (sender.Data.Name == "Analytics")
            {
                var uninstall = new UninstallHelpers();

                //Start Uninstall - clean up process...
                uninstall.RemoveSection();
                uninstall.RemoveTranslations();
                uninstall.RemoveSectionDashboard();

                //Remove AppSetting key when all done
                ConfigurationManager.AppSettings.Remove(AppSettingKey);
            }
        }
Пример #14
0
 public static InstalledPackage MakeNew(string name) {
     InstalledPackage pack = new InstalledPackage();
     pack.Data = data.MakeNew(name, IOHelper.MapPath(Settings.InstalledPackagesSettings));
     pack.OnNew(EventArgs.Empty);
     return pack;
 }
Пример #15
0
 public static InstalledPackage GetByGuid(string packageGuid) {
     InstalledPackage pack = new InstalledPackage();
     pack.Data = data.Package(packageGuid, IOHelper.MapPath(Settings.InstalledPackagesSettings));
     return pack;
 }
Пример #16
0
        public void InstallFiles(int packageId, string tempDir)
        {
            using (DisposableTimer.DebugDuration <Installer>(
                       () => "Installing package files for package id " + packageId + " into temp folder " + tempDir,
                       () => "Package file installation complete for package id " + packageId))
            {
                //retrieve the manifest to continue installation
                var insPack = InstalledPackage.GetById(packageId);

                //TODO: Depending on some files, some files should be installed differently.
                //i.e. if stylsheets should probably be installed via business logic, media items should probably use the media IFileSystem!

                // Move files
                //string virtualBasePath = System.Web.HttpContext.Current.Request.ApplicationPath;
                string basePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;

                try
                {
                    foreach (XmlNode n in Config.DocumentElement.SelectNodes("//file"))
                    {
                        var destPath   = GetFileName(basePath, XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath")));
                        var sourceFile = GetFileName(tempDir, XmlHelper.GetNodeValue(n.SelectSingleNode("guid")));
                        var destFile   = GetFileName(destPath, XmlHelper.GetNodeValue(n.SelectSingleNode("orgName")));

                        // Create the destination directory if it doesn't exist
                        if (Directory.Exists(destPath) == false)
                        {
                            Directory.CreateDirectory(destPath);
                        }
                        //If a file with this name exists, delete it
                        else if (File.Exists(destFile))
                        {
                            File.Delete(destFile);
                        }

                        // Copy the file
                        // SJ: Note - this used to do a move but some packages included the same file to be
                        // copied to multiple locations like so:
                        //
                        // <file>
                        //   <guid>my-icon.png</guid>
                        //   <orgPath>/umbraco/Images/</orgPath>
                        //   <orgName>my-icon.png</orgName>
                        // </file>
                        // <file>
                        //   <guid>my-icon.png</guid>
                        //   <orgPath>/App_Plugins/MyPlugin/Images</orgPath>
                        //   <orgName>my-icon.png</orgName>
                        // </file>
                        //
                        // Since this file unzips as a flat list of files, moving the file the first time means
                        // that when you try to do that a second time, it would result in a FileNotFoundException
                        File.Copy(sourceFile, destFile);

                        //PPH log file install
                        insPack.Data.Files.Add(XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath")) + "/" + XmlHelper.GetNodeValue(n.SelectSingleNode("orgName")));
                    }

                    // Once we're done copying, remove all the files
                    foreach (XmlNode n in Config.DocumentElement.SelectNodes("//file"))
                    {
                        var sourceFile = GetFileName(tempDir, XmlHelper.GetNodeValue(n.SelectSingleNode("guid")));
                        if (File.Exists(sourceFile))
                        {
                            File.Delete(sourceFile);
                        }
                    }
                }
                catch (Exception exception)
                {
                    LogHelper.Error <Installer>("Package install error", exception);
                    throw;
                }

                // log that a user has install files
                if (_currentUserId > -1)
                {
                    Audit.Add(AuditTypes.PackagerInstall,
                              string.Format("Package '{0}' installed. Package guid: {1}", insPack.Data.Name, insPack.Data.PackageGuid),
                              _currentUserId, -1);
                }

                insPack.Save();
            }
        }
Пример #17
0
        public void InstallBusinessLogic(int packageId, string tempDir)
        {
            using (DisposableTimer.DebugDuration <Installer>(
                       () => "Installing business logic for package id " + packageId + " into temp folder " + tempDir,
                       () => "Package business logic installation complete for package id " + packageId))
            {
                InstalledPackage insPack;
                try
                {
                    //retrieve the manifest to continue installation
                    insPack = InstalledPackage.GetById(packageId);
                    //bool saveNeeded = false;

                    // Get current user, with a fallback
                    var currentUser = new User(0);

                    //if there's a context, try to resolve the user - this will return null if there is a context but no
                    // user found when there are old/invalid cookies lying around most likely during installation.
                    // in that case we'll keep using the admin user
                    if (string.IsNullOrEmpty(BasePages.UmbracoEnsuredPage.umbracoUserContextID) == false)
                    {
                        if (BasePages.UmbracoEnsuredPage.ValidateUserContextID(BasePages.UmbracoEnsuredPage.umbracoUserContextID))
                        {
                            var userById = User.GetCurrent();
                            if (userById != null)
                            {
                                currentUser = userById;
                            }
                        }
                    }


                    //Xml as XElement which is used with the new PackagingService
                    var rootElement      = Config.DocumentElement.GetXElement();
                    var packagingService = ApplicationContext.Current.Services.PackagingService;

                    //Perhaps it would have been a good idea to put the following into methods eh?!?

                    #region Stylesheets
                    foreach (XmlNode n in Config.DocumentElement.SelectNodes("Stylesheets/Stylesheet"))
                    {
                        StyleSheet s = StyleSheet.Import(n, currentUser);

                        insPack.Data.Stylesheets.Add(s.Id.ToString(CultureInfo.InvariantCulture));
                        //saveNeeded = true;
                    }

                    //if (saveNeeded) { insPack.Save(); saveNeeded = false; }
                    #endregion

                    #region Templates
                    var templateElement = rootElement.Descendants("Templates").FirstOrDefault();
                    if (templateElement != null)
                    {
                        var templates = packagingService.ImportTemplates(templateElement, currentUser.Id);
                        foreach (var template in templates)
                        {
                            insPack.Data.Templates.Add(template.Id.ToString(CultureInfo.InvariantCulture));
                        }
                    }
                    #endregion

                    #region Languages
                    var languageItemsElement = rootElement.Descendants("Languages").FirstOrDefault();
                    if (languageItemsElement != null)
                    {
                        var insertedLanguages = packagingService.ImportLanguages(languageItemsElement);
                        insPack.Data.Languages.AddRange(insertedLanguages.Select(l => l.Id.ToString(CultureInfo.InvariantCulture)));
                    }

                    #endregion

                    #region Dictionary items
                    var dictionaryItemsElement = rootElement.Descendants("DictionaryItems").FirstOrDefault();
                    if (dictionaryItemsElement != null)
                    {
                        var insertedDictionaryItems = packagingService.ImportDictionaryItems(dictionaryItemsElement);
                        insPack.Data.DictionaryItems.AddRange(insertedDictionaryItems.Select(d => d.Id.ToString(CultureInfo.InvariantCulture)));
                    }
                    #endregion

                    #region DataTypes
                    var dataTypeElement = rootElement.Descendants("DataTypes").FirstOrDefault();
                    if (dataTypeElement != null)
                    {
                        var dataTypeDefinitions = packagingService.ImportDataTypeDefinitions(dataTypeElement, currentUser.Id);
                        foreach (var dataTypeDefinition in dataTypeDefinitions)
                        {
                            insPack.Data.DataTypes.Add(dataTypeDefinition.Id.ToString(CultureInfo.InvariantCulture));
                        }
                    }
                    #endregion

                    #region Macros
                    var macroItemsElement = rootElement.Descendants("Macros").FirstOrDefault();
                    if (macroItemsElement != null)
                    {
                        var insertedMacros = packagingService.ImportMacros(macroItemsElement);
                        insPack.Data.Macros.AddRange(insertedMacros.Select(m => m.Id.ToString(CultureInfo.InvariantCulture)));
                    }
                    #endregion

                    #region DocumentTypes
                    //Check whether the root element is a doc type rather then a complete package
                    var docTypeElement = rootElement.Name.LocalName.Equals("DocumentType") ||
                                         rootElement.Name.LocalName.Equals("DocumentTypes")
                        ? rootElement
                        : rootElement.Descendants("DocumentTypes").FirstOrDefault();

                    if (docTypeElement != null)
                    {
                        var contentTypes = packagingService.ImportContentTypes(docTypeElement, currentUser.Id);
                        foreach (var contentType in contentTypes)
                        {
                            insPack.Data.Documenttypes.Add(contentType.Id.ToString(CultureInfo.InvariantCulture));
                            //saveNeeded = true;
                        }
                    }
                    #endregion

                    #region Documents
                    var documentElement = rootElement.Descendants("DocumentSet").FirstOrDefault();
                    if (documentElement != null)
                    {
                        var content          = packagingService.ImportContent(documentElement, -1, currentUser.Id);
                        var firstContentItem = content.First();
                        insPack.Data.ContentNodeId = firstContentItem.Id.ToString(CultureInfo.InvariantCulture);
                    }
                    #endregion

                    #region Package Actions
                    foreach (XmlNode n in Config.DocumentElement.SelectNodes("Actions/Action"))
                    {
                        if (n.Attributes["undo"] == null || n.Attributes["undo"].Value == "true")
                        {
                            insPack.Data.Actions += n.OuterXml;
                        }

                        //Run the actions tagged only for 'install'

                        if (n.Attributes["runat"] != null && n.Attributes["runat"].Value == "install")
                        {
                            var alias = n.Attributes["alias"] != null ? n.Attributes["alias"].Value : "";

                            if (alias.IsNullOrWhiteSpace() == false)
                            {
                                PackageAction.RunPackageAction(insPack.Data.Name, alias, n);
                            }
                        }
                    }
                    #endregion

                    // Trigger update of Apps / Trees config.
                    // (These are ApplicationStartupHandlers so just instantiating them will trigger them)
                    new ApplicationRegistrar();
                    new ApplicationTreeRegistrar();

                    insPack.Save();
                }
                catch (Exception exception)
                {
                    LogHelper.Error <Installer>("Error installing businesslogic", exception);
                    throw;
                }

                OnPackageBusinessLogicInstalled(insPack);
                OnPackageInstalled(insPack);
            }
        }