spModifySiteStyleSheets
Parameters
| Parameter | Parameter Type | Mode | Description | 
|---|---|---|---|
| @nameLike | nvarchar(100) | IN | |
| @className | nvarchar(250) | IN | |
| @style | nvarchar(max) | IN | |
| @markToFlushBrowserCache | bit | IN | 
Definition
 Copy 
                                    
-- To remove a class: exec spModifySiteStyleSheets 'faf theme%', '.existingclass', null
-- To add a class: exec spModifySiteStyleSheets 'faf theme%', '.newclass', 'somestyle;'
-- To modify a class: exec spModifySiteStyleSheets 'faf theme%', '.existingclass', 'somestyle;'      --  equivalent to remove+add
CREATE procedure dbo.spModifySiteStyleSheets(
    @nameLike nvarchar(100),
    @className nvarchar(250) = null,
    @style nvarchar(max) = null,
    @markToFlushBrowserCache bit = 0
) as
begin
    if Len(@nameLike) = 0
        raiserror('@nameLike are required.', 13, 1);
    if Len(@className) > 0
    begin    
        set @className = @className + ' {'
        while exists(select 1 from dbo.SiteStyleSheets
                     where charindex(@className, cast(customcss as nvarchar(max))) > 0 and Name like @nameLike)
        begin
            -- Search for @className, then remove the substring from @classNameToDel to the next "}", effectively removing 'class { some_styles; }' from the chunk.
            update dbo.SiteStyleSheets
            set CustomCSS = SUBSTRING(cast(customcss as nvarchar(max)), 1, charindex(@className,cast(customcss as nvarchar(max)))-1)
                            + SUBSTRING(cast(customcss as nvarchar(max)),
                                CHARINDEX('}', cast(customcss as nvarchar(max)), charindex(@className, cast(customcss as nvarchar(max)))) + 1,
                                LEN(cast(customcss as nvarchar(max))) - CHARINDEX('}', cast(customcss as nvarchar(max)), charindex(@className,cast(customcss as nvarchar(max)))))
            where charindex(@className,cast(customcss as nvarchar(max))) > 0 and Name like @nameLike
        end
        -- append new style
        if len(@style) > 0
        begin
            update dbo.SiteStyleSheets set customcss = cast(customcss as nvarchar(max)) + ' ' + @className + ' ' + @style + ' }'
            where Name like @nameLike
        end
    end
    if @markToFlushBrowserCache = 1
    begin
        -- "touch"(spAuditThis) these records so that stylesheet handler will clear cache and load new stuff
        declare item_cursor cursor for  
            select Guid from dbo.SiteStyleSheets where Name like @nameLike
        declare @guid uniqueidentifier
        open item_cursor   
        fetch next from item_cursor into @guid
        while @@fetch_status = 0   
        begin
            exec spAuditThis -1, 2, @guid, 30
            fetch next from item_cursor into @guid
        end   
        close item_cursor   
        deallocate item_cursor
    end
end