Exemple #1
0
        /// <summary>
        /// Operations to be performed during the upgrade process.
        /// </summary>
        public override void Up()
        {
            AddColumn("dbo.FinancialAccount", "ImageBinaryFileId", c => c.Int());
            AddColumn("dbo.FinancialAccount", "Url", c => c.String());
            CreateIndex("dbo.FinancialAccount", "ImageBinaryFileId");
            AddForeignKey("dbo.FinancialAccount", "ImageBinaryFileId", "dbo.BinaryFile", "Id");

            // update TransactionCode to be the CheckNumber for transactions that are a result of scanning checks from the Rock Check Scanner app
            try
            {
                var rockContext = new Rock.Data.RockContext();
                var financialTransactionService = new Rock.Model.FinancialTransactionService( rockContext );
                Guid currencyTypeCheckGuid = Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CHECK.AsGuid();
                var currencyTypeCheckId = Rock.Web.Cache.DefinedValueCache.Read( currencyTypeCheckGuid ).Id;
                var tran = rockContext.Database.BeginTransaction();
                try
                {
                    foreach ( var financialTransaction in financialTransactionService.Queryable().Where( a =>
                        ( a.CheckMicrEncrypted != null && a.CheckMicrEncrypted != string.Empty )
                        && ( a.TransactionCode == null || a.TransactionCode == string.Empty ) )
                        //&& a.CurrencyTypeValueId == currencyTypeCheckId )
                        .Select( a => new { a.Id, a.CheckMicrEncrypted } ).ToList() )
                    {
                        string checkMicrDecrypted = Rock.Security.Encryption.DecryptString( financialTransaction.CheckMicrEncrypted ) ?? string.Empty;
                        var parts = checkMicrDecrypted.Split( '_' );
                        if ( parts.Length == 3 )
                        {
                            string transactionCode = parts[2];

                            string sql = string.Format(
                                "update [FinancialTransaction] set [TransactionCode] = '{0}' where [Id] = {1}"
                                , transactionCode
                                , financialTransaction.Id );
                            rockContext.Database.ExecuteSqlCommand( sql );
                        }
                    }
                }
                finally
                {
                    tran.Commit();
                }
            }
            catch
            {
                // ignore if transaction TransactionCode can't be updated
            }
        }
        /// <summary>
        /// Operations to be performed during the upgrade process.
        /// </summary>
        public override void Up()
        {
            AddColumn("dbo.FinancialAccount", "ImageBinaryFileId", c => c.Int());
            AddColumn("dbo.FinancialAccount", "Url", c => c.String());
            CreateIndex("dbo.FinancialAccount", "ImageBinaryFileId");
            AddForeignKey("dbo.FinancialAccount", "ImageBinaryFileId", "dbo.BinaryFile", "Id");

            // update TransactionCode to be the CheckNumber for transactions that are a result of scanning checks from the Rock Check Scanner app
            try
            {
                var  rockContext = new Rock.Data.RockContext();
                var  financialTransactionService = new Rock.Model.FinancialTransactionService(rockContext);
                Guid currencyTypeCheckGuid       = Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CHECK.AsGuid();
                var  currencyTypeCheckId         = Rock.Web.Cache.DefinedValueCache.Read(currencyTypeCheckGuid).Id;
                var  tran = rockContext.Database.BeginTransaction();
                try
                {
                    foreach (var financialTransaction in financialTransactionService.Queryable().Where(a =>
                                                                                                       (a.CheckMicrEncrypted != null && a.CheckMicrEncrypted != string.Empty) &&
                                                                                                       (a.TransactionCode == null || a.TransactionCode == string.Empty))
                             //&& a.CurrencyTypeValueId == currencyTypeCheckId )
                             .Select(a => new { a.Id, a.CheckMicrEncrypted }).ToList())
                    {
                        string checkMicrDecrypted = Rock.Security.Encryption.DecryptString(financialTransaction.CheckMicrEncrypted) ?? string.Empty;
                        var    parts = checkMicrDecrypted.Split('_');
                        if (parts.Length == 3)
                        {
                            string transactionCode = parts[2];

                            string sql = string.Format(
                                "update [FinancialTransaction] set [TransactionCode] = '{0}' where [Id] = {1}"
                                , transactionCode
                                , financialTransaction.Id);
                            rockContext.Database.ExecuteSqlCommand(sql);
                        }
                    }
                }
                finally
                {
                    tran.Commit();
                }
            }
            catch
            {
                // ignore if transaction TransactionCode can't be updated
            }
        }
Exemple #3
0
        protected override void Seed(Rock.Data.RockContext context)
        {
            // Previous to Rock v4.0 the saved routing|account numbers in the PersonBankAccount table may have included
            // leading or trailing spaces for the routing number and/or account number. v4.0 trims these leading/trailing
            // spaces before looking for and saving the routing|account numbers. Because of this, any existing saved
            // values need to be updated so they don't include any spaces. This can probably be removed in a future update
            // after v4.0 -DT
            var txnService            = new Rock.Model.FinancialTransactionService(context);
            var personBankAcctService = new Rock.Model.FinancialPersonBankAccountService(context);

            foreach (string encryptedMicr in txnService
                     .Queryable()
                     .Where(t =>
                            t.CheckMicrParts != null &&
                            t.CheckMicrParts != "")
                     .Select(t => t.CheckMicrParts)
                     .Distinct())
            {
                if (!string.IsNullOrWhiteSpace(encryptedMicr))
                {
                    string clearMicr = Rock.Security.Encryption.DecryptString(encryptedMicr) ?? string.Empty;
                    var    parts     = clearMicr.Split('_');
                    if (parts.Length >= 2 && (parts[0] != parts[0].Trim() || parts[1] != parts[1].Trim()))
                    {
                        string oldHash = Rock.Security.Encryption.GetSHA1Hash(string.Format("{0}|{1}", parts[0], parts[1]));
                        string newHash = Rock.Security.Encryption.GetSHA1Hash(string.Format("{0}|{1}", parts[0].Trim(), parts[1].Trim()));

                        foreach (var match in personBankAcctService.Queryable().Where(a => a.AccountNumberSecured == oldHash))
                        {
                            match.AccountNumberSecured = newHash;
                        }

                        context.SaveChanges();
                    }
                }
            }

            // Previous to Rock v4.0 the PageViews didn't store Browser or OS info. This can probably be removed in a future update
            // after v4.0 -DT
            var pageViewRockContext      = new Rock.Data.RockContext();
            var pageViewUserAgentService = new Rock.Model.PageViewUserAgentService(pageViewRockContext);
            var qryPageViewUserAgent     = pageViewUserAgentService.Queryable().Where(a => a.Browser == null || a.OperatingSystem == null || a.ClientType == null);

            foreach (var pageViewUserAgent in qryPageViewUserAgent.Where(a => a.UserAgent != null))
            {
                try
                {
                    UAParser.Parser     uaParser = UAParser.Parser.GetDefault();
                    UAParser.ClientInfo client   = uaParser.Parse(pageViewUserAgent.UserAgent);
                    pageViewUserAgent.ClientType      = Rock.Model.PageViewUserAgent.GetClientType(pageViewUserAgent.UserAgent);
                    pageViewUserAgent.OperatingSystem = client.OS.ToString();
                    pageViewUserAgent.Browser         = client.UserAgent.ToString();
                }
                catch
                {
                    // shouldn't happen, but skip if unable to parse
                }
            }

            pageViewRockContext.SaveChanges(true);
        }