Exemplo n.º 1
0
        public InstallationSummary InstallCompiledPackageData(XDocument?packageXml, int userId = Constants.Security.SuperUserId)
        {
            CompiledPackage compiledPackage = GetCompiledPackageInfo(packageXml);

            if (compiledPackage == null)
            {
                throw new InvalidOperationException("Could not read the package file " + packageXml);
            }

            // Trigger the Importing Package Notification and stop execution if event/user is cancelling it
            var importingPackageNotification = new ImportingPackageNotification(compiledPackage.Name);

            if (_eventAggregator.PublishCancelable(importingPackageNotification))
            {
                return(new InstallationSummary(compiledPackage.Name));
            }

            var summary = _packageInstallation.InstallPackageData(compiledPackage, userId, out _);

            _auditService.Add(AuditType.PackagerInstall, userId, -1, "Package", $"Package data installed for package '{compiledPackage.Name}'.");

            // trigger the ImportedPackage event
            _eventAggregator.Publish(new ImportedPackageNotification(summary).WithStateFrom(importingPackageNotification));

            return(summary);
        }
Exemplo n.º 2
0
        public InstallationSummary InstallCompiledPackageData(PackageDefinition packageDefinition, FileInfo packageFile, int userId = Constants.Security.SuperUserId)
        {
            if (packageDefinition == null)
            {
                throw new ArgumentNullException(nameof(packageDefinition));
            }
            if (packageDefinition.Id == default)
            {
                throw new ArgumentException("The package definition has not been persisted");
            }
            if (packageDefinition.Name == default)
            {
                throw new ArgumentException("The package definition has incomplete information");
            }

            var compiledPackage = GetCompiledPackageInfo(packageFile);

            if (compiledPackage == null)
            {
                throw new InvalidOperationException("Could not read the package file " + packageFile);
            }

            if (ImportingPackage.IsRaisedEventCancelled(new ImportPackageEventArgs <string>(packageFile.Name, compiledPackage), this))
            {
                return new InstallationSummary {
                           MetaData = compiledPackage
                }
            }
            ;

            var summary = _packageInstallation.InstallPackageData(packageDefinition, compiledPackage, userId);

            SaveInstalledPackage(packageDefinition);

            _auditService.Add(AuditType.PackagerInstall, userId, -1, "Package", $"Package data installed for package '{compiledPackage.Name}'.");

            ImportedPackage.RaiseEvent(new ImportPackageEventArgs <InstallationSummary>(summary, compiledPackage, false), this);

            return(summary);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This will install the Articulate package based on the actual articulate package manifest file which is embedded
        /// into this assembly.
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        /// <remarks>
        /// This would be like installing the package in the back office to install all schema, etc... but we do this
        /// without the full package file, just to install the schema and content and to add the package to the package repo.
        /// </remarks>
        private bool InstallPackage(int userId)
        {
            //TODO: We need to reflect here because this isn't public and we're resolving the internal type from DI
            var parserType = _contentService.GetType().Assembly.GetType("Umbraco.Core.Packaging.CompiledPackageXmlParser");

            if (parserType == null)
            {
                throw new InvalidOperationException("Could not get type Umbraco.Core.Packaging.CompiledPackageXmlParser");
            }
            var parser = Current.Factory.GetInstance(parserType);

            //these are the parameters required, the fake FileInfo doesn't really do anything in this context
            var fakePackageFile = new FileInfo(Path.Combine(IOHelper.MapPath("~/App_Data/TEMP/Articulate"), Guid.NewGuid().ToString(), "fake-package.zip"));
            var xdoc            = XDocument.Parse(ArticulateResources.packageManifest); //read in the xdocument package xml
            var appRoot         = GetRootDirectorySafe();                               //the root folder (based on what is passed in the Core)

            //reflect, call ToCompiledPackage to get the CompiledPackage reference
            CompiledPackage compiledPackage = (CompiledPackage)parser.CallMethod("ToCompiledPackage", xdoc, fakePackageFile, appRoot);

            //TODO: Need to reflect again to get the package definition
            PackageDefinition packageDefinition = (PackageDefinition)typeof(PackageDefinition).CallStaticMethod("FromCompiledPackage", compiledPackage);

            //if it's not installed or it's not the same version, then we need to run the installer
            if (!IsPackageVersionAlreadyInstalled(packageDefinition.Name, packageDefinition.Version, out var sameVersion, out var packageId) || !sameVersion)
            {
                //clear out the files, we don't want to save this package manifest with files since we don't want to delete them on package
                //uninstallation done in the back office since this will generally only be the case when we are installing via Nuget
                packageDefinition.Files = new List <string>();
                var summary = _packageInstallation.InstallPackageData(packageDefinition, compiledPackage, userId);
                //persist this to the package repo, it will now show up as installed packages in the back office
                _packagingService.SaveInstalledPackage(packageDefinition);
                return(true);
            }

            return(false);
        }