Пример #1
0
        /// <summary>
        /// Upgrades the database schema and data by running migrations.
        /// </summary>
        /// <remarks>
        /// <para>This assumes that the database exists and the connection string is
        /// configured and it is possible to connect to the database.</para>
        /// <para>Runs whichever migrations need to run.</para>
        /// </remarks>
        public Result UpgradeSchemaAndData(UmbracoPlan plan)
        {
            try
            {
                var readyForInstall = CheckReadyForInstall();
                if (readyForInstall.Success == false)
                {
                    return(readyForInstall.Result);
                }

                _logger.LogInformation("Database upgrade started");

                // upgrade
                var upgrader = new Upgrader(plan);
                upgrader.Execute(_migrationPlanExecutor, _scopeProvider, _keyValueService);

                var message = "<p>Upgrade completed!</p>";

                //now that everything is done, we need to determine the version of SQL server that is executing

                _logger.LogInformation("Database configuration status: {DbConfigStatus}", message);

                return(new Result {
                    Message = message, Success = true, Percentage = "100"
                });
            }
            catch (Exception ex)
            {
                return(HandleInstallException(ex));
            }
        }
        public override Task <InstallSetupResult> ExecuteAsync(object model)
        {
            var installSteps = InstallStatusTracker.GetStatus().ToArray();
            var previousStep = installSteps.Single(x => x.Name == "DatabaseInstall");
            var upgrade      = previousStep.AdditionalData.ContainsKey("upgrade");

            if (upgrade)
            {
                _logger.Info <DatabaseUpgradeStep>("Running 'Upgrade' service");

                var plan = new UmbracoPlan();
                plan.AddPostMigration <ClearCsrfCookies>(); // needed when running installer (back-office)

                var result = _databaseBuilder.UpgradeSchemaAndData(plan);

                if (result.Success == false)
                {
                    throw new InstallException("The database failed to upgrade. ERROR: " + result.Message);
                }

                DatabaseInstallStep.HandleConnectionStrings(_logger);
            }

            return(Task.FromResult <InstallSetupResult>(null));
        }
        public void Initialize()
        {
            // double check - is this on in config
            // are we in upgrade mode (we should be - we only register in upgrade)
            if (!SilentUpgradeOn || runtimeState.Level != RuntimeLevel.Upgrade)
            {
                return;
            }

            // Do we need to lock? the upgrade so it only happens once?
            logger.Debug <SilentUpgradeComponent>("Silently upgrading the Site");

            // The 'current' steps for upgrading Umbraco

            try
            {
                //
                // If these steps change in the core then this will be wrong.
                //
                // We don't run the file permission step, we assume you have that sorted already.
                // and besides its internal and we can't get to the tests
                //      FilePermissionHelper.RunFilePermissionTestSuite(out result);

                // Step: 'DatabaseInstallStep'
                var result = databaseBuilder.CreateSchemaAndData();
                if (!result.Success)
                {
                    // failed.
                    throw new Exception("Upgrade Failed - Create Schema");
                }

                // Step: 'DatabaseUpgradeStep'
                var plan = new UmbracoPlan();
                logger.Debug <SilentUpgradeComponent>("Running Migrations {initialState} to {finalState}", plan.InitialState, plan.FinalState);

                var upgrade = databaseBuilder.UpgradeSchemaAndData(plan);
                if (!upgrade.Success)
                {
                    throw new Exception("Upgrade Failed - Upgrade Schema");
                }

                // Step: 'SetUmbracoVersionStep'

                // Update the version number inside the web.config
                logger.Debug <SilentUpgradeComponent>("Updating version in the web.config {version}", UmbracoVersion.SemanticVersion.ToSemanticString());
                // Doing this essentially restats the site.
                globalSettings.ConfigurationStatus = UmbracoVersion.SemanticVersion.ToSemanticString();

                // put something in the log.
                logger.Info <SilentUpgradeComponent>("Silent Upgrade Completed {version}", UmbracoVersion.SemanticVersion.ToSemanticString());

                Upgraded = true;
            }
            catch (Exception ex)
            {
                logger.Warn <SilentUpgradeComponent>(ex, "Silent Upgrade Failed");
                Upgraded = false; // if this is false, we should fall through to the 'standard' upgrade path.
            }
        }
Пример #4
0
        public void ValidateUmbracoPlan()
        {
            var plan = new UmbracoPlan();

            plan.Validate();
            Console.WriteLine(plan.FinalState);
            Assert.IsFalse(plan.FinalState.IsNullOrWhiteSpace());
        }
Пример #5
0
        public Task HandleAsync(RuntimeUnattendedUpgradeNotification notification, CancellationToken cancellationToken)
        {
            if (_runtimeState.RunUnattendedBootLogic())
            {
                switch (_runtimeState.Reason)
                {
                case RuntimeLevelReason.UpgradeMigrations:
                {
                    var plan = new UmbracoPlan(_umbracoVersion);
                    using (_profilingLogger.TraceDuration <UnattendedUpgrader>(
                               "Starting unattended upgrade.",
                               "Unattended upgrade completed."))
                    {
                        DatabaseBuilder.Result result = _databaseBuilder.UpgradeSchemaAndData(plan);
                        if (result.Success == false)
                        {
                            var innerException = new UnattendedInstallException("An error occurred while running the unattended upgrade.\n" + result.Message);
                            _runtimeState.Configure(Core.RuntimeLevel.BootFailed, Core.RuntimeLevelReason.BootFailedOnException, innerException);
                        }

                        notification.UnattendedUpgradeResult = RuntimeUnattendedUpgradeNotification.UpgradeResult.CoreUpgradeComplete;
                    }
                }
                break;

                case RuntimeLevelReason.UpgradePackageMigrations:
                {
                    if (!_runtimeState.StartupState.TryGetValue(RuntimeState.PendingPacakgeMigrationsStateKey, out var pm) ||
                        pm is not IReadOnlyList <string> pendingMigrations)
                    {
                        throw new InvalidOperationException($"The required key {RuntimeState.PendingPacakgeMigrationsStateKey} does not exist in startup state");
                    }

                    if (pendingMigrations.Count == 0)
                    {
                        throw new InvalidOperationException("No pending migrations found but the runtime level reason is " + Core.RuntimeLevelReason.UpgradePackageMigrations);
                    }

                    try
                    {
                        IEnumerable <ExecutedMigrationPlan> result = _packageMigrationRunner.RunPackagePlans(pendingMigrations);
                        notification.UnattendedUpgradeResult = RuntimeUnattendedUpgradeNotification.UpgradeResult.PackageMigrationComplete;
                    }
                    catch (Exception ex)
                    {
                        SetRuntimeError(ex);
                        notification.UnattendedUpgradeResult = RuntimeUnattendedUpgradeNotification.UpgradeResult.HasErrors;
                    }
                }
                break;

                default:
                    throw new InvalidOperationException("Invalid reason " + _runtimeState.Reason);
                }
            }

            return(Task.CompletedTask);
        }
Пример #6
0
        private void DoUnattendedUpgrade(DatabaseBuilder databaseBuilder)
        {
            var plan = new UmbracoPlan();

            using (ProfilingLogger.TraceDuration <CoreRuntime>("Starting unattended upgrade.", "Unattended upgrade completed."))
            {
                var result = databaseBuilder.UpgradeSchemaAndData(plan);
                if (result.Success == false)
                {
                    throw new UnattendedInstallException("An error occurred while running the unattended upgrade.\n" + result.Message);
                }
            }
        }
Пример #7
0
        public override Task <InstallSetupResult?> ExecuteAsync(object model)
        {
            InstallTrackingItem[] installSteps = InstallStatusTracker.GetStatus().ToArray();
            InstallTrackingItem   previousStep = installSteps.Single(x => x.Name == "DatabaseInstall");
            var upgrade = previousStep.AdditionalData.ContainsKey("upgrade");

            if (upgrade)
            {
                _logger.LogInformation("Running 'Upgrade' service");

                var plan = new UmbracoPlan(_umbracoVersion);
                plan.AddPostMigration <ClearCsrfCookies>(); // needed when running installer (back-office)

                DatabaseBuilder.Result?result = _databaseBuilder.UpgradeSchemaAndData(plan);

                if (result?.Success == false)
                {
                    throw new InstallException("The database failed to upgrade. ERROR: " + result.Message);
                }
            }

            return(Task.FromResult((InstallSetupResult?)null));
        }