USP_CMSAPPLICATIONSTART

This is called when the CMS application is started to perform some configuration functions.

Definition

Copy


CREATE procedure [dbo].[USP_CMSAPPLICATIONSTART]
as
begin    

    declare @DATE date = GETDATE();
    declare @CHANGEAGENTID uniqueidentifier;
    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID out;

    -----------------------------------------------------------------------------------------------

    ----- Determine the backoffice (RE or Inf) from our settings and record value

    -----------------------------------------------------------------------------------------------

    declare @ISINFINITYBACKEND nvarchar(10) = 'False';
    select @ISINFINITYBACKEND = 'True' from dbo.Setting where ID = 33 and Value like '%BBNCSvc/MasterService.asmx%';

    declare @OLDBACKENDSETTING nvarchar(10) = null;
    select @OLDBACKENDSETTING = Value from dbo.Setting where ID = 113;

    if @OLDBACKENDSETTING is null
        insert into dbo.Setting(ID, Name, Value, CreateDate, UpdateDate)
        values (113, 'IsInfinityBackend', @ISINFINITYBACKEND, @DATE, @DATE)         
    else if @OLDBACKENDSETTING <> @ISINFINITYBACKEND
        update dbo.Setting set Value = @ISINFINITYBACKEND where ID = 113;
    -----------------------------------------------------------------------------------------------



    -----------------------------------------------------------------------------------------------

    ----- Configure email datasource information based on the back office

    -----------------------------------------------------------------------------------------------


    if @ISINFINITYBACKEND <> 'True'
    begin
        --- RE7

        update dbo.DataSources Set
        FIELDPROVIDER = null,
        LISTPROCESSOR = null,
        DATAPROCESSOR = null
        where DataSourceID = 1

        update dbo.DataSources set
        DATAPROCESSOR = null,
        LISTPROCESSOR = null
        where DataSourceID = 101;

        update dbo.DataSources Set
        FIELDPROVIDER = null,
        LISTPROCESSOR = null,
        DATAPROCESSOR = null
        where DataSourceID = 103;

    end
    else
    begin
        --- Infinity

        update dbo.DataSources Set
        FIELDPROVIDER = 'Blackbaud.Web.Content.Core.ExportDefinitionFieldProvider, Blackbaud.Web.Content.Core',
        LISTPROCESSOR = 'Blackbaud.AppFx.ContentManagement.Platform.Email.Catalog.ConstituentExportEmailListProcessor, Blackbaud.AppFx.ContentManagement.Platform.Email.Catalog',
        DATAPROCESSOR = 'Blackbaud.AppFx.ContentManagement.Platform.Email.Catalog.ConstituentExportDataProcessor, Blackbaud.AppFx.ContentManagement.Platform.Email.Catalog'
        where DataSourceID = 1

        update dbo.DataSources set
        DATAPROCESSOR = 'Blackbaud.AppFx.ContentManagement.Platform.Email.Catalog.BasicEmailDataProcessor, Blackbaud.AppFx.ContentManagement.Platform.Email.Catalog',
        LISTPROCESSOR = 'Blackbaud.AppFx.ContentManagement.Platform.Email.Catalog.UserListProcessor, Blackbaud.AppFx.ContentManagement.Platform.Email.Catalog'
        where DataSourceID = 101;

        update dbo.DataSources Set
        FIELDPROVIDER = 'Blackbaud.Web.Content.Core.ExportDefinitionFieldProvider, Blackbaud.Web.Content.Core',
        LISTPROCESSOR = 'Blackbaud.AppFx.ContentManagement.Platform.Email.Catalog.ConstituentExportEmailListProcessor, Blackbaud.AppFx.ContentManagement.Platform.Email.Catalog',
        DATAPROCESSOR = 'Blackbaud.AppFx.ContentManagement.Platform.Email.Catalog.ConstituentExportDataProcessor, Blackbaud.AppFx.ContentManagement.Platform.Email.Catalog'
        where DataSourceID = 103;

        update dbo.EmailTemplate
        set EXPORTDEFINITIONID = 'A6FA4983-5F8E-4623-AECD-540C4912150C'
        where DataSourceID in (1,103) and Deleted = 0 and EXPORTDEFINITIONID is null;

    end    
    -----------------------------------------------------------------------------------------------



    -----------------------------------------------------------------------------------------------

    ----- Create / migrate BBNC schedules.

    -----------------------------------------------------------------------------------------------

    begin try
        -- Create BBNC schedules

        exec dbo.USP_CREATECMSSCHEDULES;
    end try
    begin catch
        --don't blow up the app

    end catch

    if @ISINFINITYBACKEND <> 'True'
      begin
      -- ensure that Transaction Sync schedule is always enabled for BBNC.  As of 3.0, BBIS has this turned off by default and

      -- allows the client to enable/disable it through the UI.

      update dbo.SCHEDULE 
      set Enabled = 1
      where ID = 'F3DC1530-CDF2-4989-BF6F-FABF0E958277'
    end
    -----------------------------------------------------------------------------------------------



    -----------------------------------------------------------------------------------------------

    ----- Conditionally deprecate parts

    -----------------------------------------------------------------------------------------------

    -- for IsInfinityBackend but not Altru clients, we deprecate User Email Preferences Part (Q4/2011)

    if @ISINFINITYBACKEND = 'True' and
       (not exists (select ID from dbo.INSTALLEDPRODUCTLIST where ID = 'E5E0494B-BA0F-4E23-B8FB-A59112DBF3C8'))
        update dbo.ContentTypes set Deprecated = 1 where ID = 50
    else
        update dbo.ContentTypes set Deprecated = 0 where ID = 50

    --hide the Giving Search and legacy profile parts in BBIS

    if @ISINFINITYBACKEND = 'True'
    begin
        update dbo.ContentTypes set Deprecated = 1 where ID in (115,42)
    end
    else
    begin
        update dbo.ContentTypes set Deprecated = 0 where ID in (115,42)
    end


    -- for IsInfinityBackend the new Event Registration Form is not yet supported

    if @ISINFINITYBACKEND = 'True'
    begin
        update dbo.ContentTypes set Deprecated = 0, [Name] = 'Event Registration Form (Classic)' where ID = 47
        update dbo.ContentTypes set Hidden = 0, Deprecated = 0, [Name] = 'Event Registration Form' where ID = 154
    end
    else
    begin
        update dbo.ContentTypes set Deprecated = 0, [Name] = 'Event Registration Form (Classic)' where ID = 47
        update dbo.ContentTypes set Hidden = 0 where ID = 154
    end

    -- for eStore is not yet supported

    if @ISINFINITYBACKEND = 'True'
    begin
        update ct
            set ct.Deprecated  = 1,
                  ct.DesktopSrc  = 'admin/eStore/eStoreDisplay.ascx',
                ct.EditControl = 'admin/eStore/eStoreEditor.ascx'
            from [dbo].[ContentTypes] ct
            inner join [dbo].[ClientContentTypes] cct
            on cct.ContentTypesID = ct.ID 
            where ct.EditControl LIKE '%Store_Shared_Editor.ascx' 
            or    ct.EditControl LIKE '%Store_Master_Editor.ascx' 
    end
    -----------------------------------------------------------------------------------------------



    -----------------------------------------------------------------------------------------------

    ----- Configure Interests attribute by default for Infinity / ENTERPRISE??????????????????????????????????????????

    -----------------------------------------------------------------------------------------------

    if exists (select 1 from dbo.INSTALLEDPRODUCTLIST where ID = '3117D2C8-7F46-42F2-ABEB-B654F2F63046')
    begin
        if not exists (select 1 from dbo.ApplicationFields where AttribTypeID = 2)
            INSERT INTO ApplicationFields
                (FieldID,    ParentFieldID, FieldName, Sequence, HasMultiples, ApplicationsID, Searchable, PrivateShowByDefault, NeverPrivate, FieldType, FormField, HTMLEncode, AttribTypeID, DataType, CodeTableID, AttribRequired, AttribRecordType, ClientsID)
            values (101, 1, 'Interests', 150, 0, 1, 1, 0, 0, 1, 1, 1, 2, 9, 4999, 0, 1, 1)
        else
        begin
            update dbo.ApplicationFields set ParentFieldID = 1, Sequence = 150 where AttribTypeID = 2
            update dbo.SignOnControls set ParentFieldID = 1 where AttributeTypeID = 2
        end          
        update dbo.Clients set InterestsTypeID = 2 where ID = 1            
    end 
    -----------------------------------------------------------------------------------------------




   -----------------------------------------------------------------------------------------------------

    ----- Remove email type mapping for BBIS/Enterprise. BBIs will no longer use a specific type 

    ----- of email from BBEC. It will use whatever is primary on the constituent's record.

    ----- Only update clients that have the Enterprise flag but not the FAF flag.

    -----------------------------------------------------------------------------------------------------

    if exists (select 1 from dbo.INSTALLEDPRODUCTLIST where ID = '3117D2C8-7F46-42F2-ABEB-B654F2F63046')
    begin
          update dbo.Clients
          set EmailPhoneType = 0
    end
    -----------------------------------------------------------------------------------------------------




    -----------------------------------------------------------------------------------------------

    ----- Initial Configuration - logic in here will only run the very first time BBNC is set up.

    ----- If you want additional run-once features, add it in here for new clients and in a revision

    ----- conditioned by the opposite of this flag for existing clients.

    -----------------------------------------------------------------------------------------------

    declare @INITIALSTARTUPHASRUN bit = 0;
    select @INITIALSTARTUPHASRUN = 1 from dbo.Setting where ID = 116;
    if @INITIALSTARTUPHASRUN = 0
    begin
        begin transaction
        begin try

            -----------------------------------------------------------------------------------------------

            ----- Enable shared service email schedules the first time you use BBNC

            -----------------------------------------------------------------------------------------------

            update dbo.SCHEDULE set ENABLED = 1
            from dbo.SCHEDULE
            inner join dbo.BUSINESSPROCESSSCHEDULE BPS on BPS.SCHEDULEID = SCHEDULE.ID
            inner join dbo.GLOBALCHANGE GC on GC.ID = BPS.BUSINESSPROCESSPARAMETERSETID
            where BPS.BUSINESSPROCESSID = '3269A1D1-31CB-4D28-945C-B7623A3EFCCA'
            and GC.GLOBALCHANGECATALOGID in ('F79575E5-FE4F-47BD-954C-AB056EF109D9', '5066A489-6282-400C-96AF-1ECC1B7F281F', '8C3ECDB1-BE50-4898-AD1B-98ECB6D07812')
            -----------------------------------------------------------------------------------------------


            ---- Done with initial load, lets update the fact that we completed

            insert into dbo.Setting (ID, Name, Value, CreateDate, UpdateDate, ADDEDBYID, CHANGEDBYID)
            values (116, 'InitialStartHasRun', '1', @DATE, @DATE, @CHANGEAGENTID, @CHANGEAGENTID);
        commit transaction
        end try
        begin catch
            rollback transaction
        end catch
    end    
    -----------------------------------------------------------------------------------------------


end