Пример #1
0
        /// <summary>
        /// Determines the version of the currently installed database.
        /// </summary>
        /// <returns>
        /// A <see cref="Version"/> with Major and Minor values for
        /// non-empty database, otherwise "0.0.0" for empty databases.
        /// </returns>
        public new Version DetermineInstalledVersion()
        {
            //If (ValidTables.Count == 0) database is empty and we return -> new Version(0, 0, 0);
            if (ValidTables.Count == 0)
            {
                return(new Version(0, 0, 0));
            }

            //If Errors is empty or if TableDefinitions tables + columns correspond to valid tables + columns then we're at current version
            if (!Errors.Any() ||
                (TableDefinitions.All(x => ValidTables.Contains(x.Name)) &&
                 TableDefinitions.SelectMany(definition => definition.Columns).All(x => ValidColumns.Contains(x.Name))))
            {
                return(MerchelloVersion.Current);
            }


            return(MerchelloVersion.Current);
        }
Пример #2
0
        /// <summary>
        /// Determines the version of the currently installed database.
        /// </summary>
        /// <returns>
        /// A <see cref="Version"/> with Major and Minor values for
        /// non-empty database, otherwise "0.0.0" for empty databases.
        /// </returns>
        public Version DetermineInstalledVersion()
        {
            //If (ValidTables.Count == 0) database is empty and we return -> new Version(0, 0, 0);
            if (ValidTables.Count == 0)
            {
                return(new Version(0, 0, 0));
            }

            //If Errors is empty or if TableDefinitions tables + columns correspond to valid tables + columns then we're at current version
            if (!Errors.Any() ||
                (TableDefinitions.All(x => ValidTables.Contains(x.Name)) &&
                 TableDefinitions.SelectMany(definition => definition.Columns).All(x => ValidColumns.Contains(x.Name))))
            {
                return(UmbracoVersion.Current);
            }

            //If Errors contains umbracoApp or umbracoAppTree its pre-6.0.0 -> new Version(4, 10, 0);
            if (Errors.Any(x => x.Item1.Equals("Table") && (x.Item2.Equals("umbracoApp") || x.Item2.Equals("umbracoAppTree"))))
            {
                //If Errors contains umbracoUser2app or umbracoAppTree foreignkey to umbracoApp exists its pre-4.8.0 -> new Version(4, 7, 0);
                if (Errors.Any(x =>
                               x.Item1.Equals("Constraint") &&
                               (x.Item2.Contains("umbracoUser2app_umbracoApp") ||
                                x.Item2.Contains("umbracoAppTree_umbracoApp"))))
                {
                    return(new Version(4, 7, 0));
                }

                return(new Version(4, 9, 0));
            }

            //if the error is for umbracoServer
            if (Errors.Any(x => x.Item1.Equals("Table") && (x.Item2.Equals("umbracoServer"))))
            {
                return(new Version(6, 0, 0));
            }

            return(UmbracoVersion.Current);
        }
        /// <summary>
        /// Determines the version of the currently installed database by detecting the current database structure
        /// </summary>
        /// <returns>
        /// A <see cref="Version"/> with Major and Minor values for
        /// non-empty database, otherwise "0.0.0" for empty databases.
        /// </returns>
        public Version DetermineInstalledVersion()
        {
            //If (ValidTables.Count == 0) database is empty and we return -> new Version(0, 0, 0);
            if (ValidTables.Count == 0)
            {
                return(new Version(0, 0, 0));
            }

            //If Errors is empty or if TableDefinitions tables + columns correspond to valid tables + columns then we're at current version
            if (Errors.Any() == false ||
                (TableDefinitions.All(x => ValidTables.Contains(x.Name)) &&
                 TableDefinitions.SelectMany(definition => definition.Columns).All(x => ValidColumns.Contains(x.Name))))
            {
                return(UmbracoVersion.Current);
            }

            //If Errors contains umbracoApp or umbracoAppTree its pre-6.0.0 -> new Version(4, 10, 0);
            if (Errors.Any(x => x.Item1.Equals("Table") && (x.Item2.InvariantEquals("umbracoApp") || x.Item2.InvariantEquals("umbracoAppTree"))))
            {
                //If Errors contains umbracoUser2app or umbracoAppTree foreignkey to umbracoApp exists its pre-4.8.0 -> new Version(4, 7, 0);
                if (Errors.Any(x =>
                               x.Item1.Equals("Constraint") &&
                               (x.Item2.InvariantContains("umbracoUser2app_umbracoApp") ||
                                x.Item2.InvariantContains("umbracoAppTree_umbracoApp"))))
                {
                    return(new Version(4, 7, 0));
                }

                return(new Version(4, 8, 0));
            }

            //if the error is for umbracoServer
            if (Errors.Any(x => x.Item1.Equals("Table") && (x.Item2.InvariantEquals("umbracoServer"))))
            {
                return(new Version(6, 0, 0));
            }

            //if the error indicates a problem with the column cmsMacroProperty.macroPropertyType then it is not version 7
            // since these columns get removed in v7
            if (Errors.Any(x => x.Item1.Equals("Column") && (x.Item2.InvariantEquals("cmsMacroProperty,macroPropertyType"))))
            {
                //if the error is for this IX_umbracoNodeTrashed which is added in 6.2 AND in 7.1 but we do not have the above columns
                // then it must mean that we aren't on 6.2 so must be 6.1
                if (Errors.Any(x => x.Item1.Equals("Index") && (x.Item2.InvariantEquals("IX_umbracoNodeTrashed"))))
                {
                    return(new Version(6, 1, 0));
                }
                else
                {
                    //if there are no errors for that index, then the person must have 6.2 installed
                    return(new Version(6, 2, 0));
                }
            }

            //if the error indicates a problem with the constraint FK_cmsContent_cmsContentType_nodeId then it is not version 7.2
            // since this gets added in 7.2.0 so it must be the previous version
            if (Errors.Any(x => x.Item1.Equals("Constraint") && (x.Item2.InvariantEquals("FK_cmsContent_cmsContentType_nodeId"))))
            {
                return(new Version(7, 0, 0));
            }

            //if the error is for umbracoAccess it must be the previous version to 7.3 since that is when it is added
            if (Errors.Any(x => x.Item1.Equals("Table") && (x.Item2.InvariantEquals("umbracoAccess"))))
            {
                return(new Version(7, 2, 0));
            }

            //if the error is for umbracoDeployChecksum it must be the previous version to 7.4 since that is when it is added
            if (Errors.Any(x => x.Item1.Equals("Table") && (x.Item2.InvariantEquals("umbracoDeployChecksum"))))
            {
                return(new Version(7, 3, 0));
            }

            //if the error is for umbracoRedirectUrl it must be the previous version to 7.5 since that is when it is added
            if (Errors.Any(x => x.Item1.Equals("Table") && (x.Item2.InvariantEquals("umbracoRedirectUrl"))))
            {
                return(new Version(7, 4, 0));
            }

            //if the error indicates a problem with the column cmsMacroProperty.uniquePropertyId then it is not version 7.6 since that is when it is added
            if (Errors.Any(x => x.Item1.Equals("Column") && (x.Item2.InvariantEquals("cmsMacroProperty,uniquePropertyId"))))
            {
                return(new Version(7, 5, 0));
            }

            //if the error is for umbracoUserGroup it must be the previous version to 7.7 since that is when it is added
            if (Errors.Any(x => x.Item1.Equals("Table") && (x.Item2.InvariantEquals("umbracoUserStartNode"))))
            {
                return(new Version(7, 6, 0));
            }

            return(UmbracoVersion.Current);
        }