public override void Migrate() { // Check if the package has already been installed. var pkgs = _packagingService.GetInstalledPackageByName(Constants.Internals.ProjectName); if (pkgs?.Any() == false) { // If not, then make a package definition and save it to the "installedPackages.config". _packagingService.SaveInstalledPackage(new PackageDefinition { Name = Constants.Internals.ProjectName, Url = Constants.Package.RepositoryUrl, Author = Constants.Package.Author, AuthorUrl = Constants.Package.AuthorUrl, IconUrl = Constants.Package.IconUrl, License = Constants.Package.License, LicenseUrl = Constants.Package.LicenseUrl, UmbracoVersion = Constants.Package.MinimumSupportedUmbracoVersion, Version = ContentmentVersion.Version.ToString(), Readme = "", }); } }
/// <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); }