HXH
HXH
Apr 30, 2012
  2826
(0 votes)

EPiServer Workflow Replacement : Step 4–Rejecting Pages Programmatically

This is the fourth in a series of posts about how my company built a replacement workflow platform for EPiServer. Why we chose to do this is explained here: http://world.episerver.com/Blogs/Hans/Dates/2012/4/EPiServer-Workflow-Replacement--Step-1Explanation-and-Disabling-Edit-Tab/

I’ll go on record here and say that I don’t love that this is done through the database. This is why SDK’s are made..and this entire process should be able to be done by using the PageProviderBase.SetPageStatus method as described here : http://sdk.episerver.com/library/cms5/html/M_EPiServer_Core_PageProviderBase_SetPageStatus.htm

….. but, as I mentioned already, it doesn’t work – so we have to go right into the database. Any time you do this, make sure you know what you’re doing – there’s a good chance you’re mucking with something that isn’t meant to be touched. I take no responsibility for you using this, you’ve been warned*!

(*that being said, we’ve been using this in EPiServer CMS 5 for three years and EPiServer CMS 6 for several months, across different environments, and haven’t had any problems)

Here’s our RejectPage method. Basically, tblWorkPage seems to have all of the page status information – and all it really  needs is the WorkPageID (pkID) and the PageLinkID (fkPageID) values, and all we do is set ReadyToPublish back to 0, which in EPiServer terms basically means that the page is “Not Ready”.

 

        protected void RejectPage(PageData pageToReject)
        {
            SqlConnection SQLConnection = new SqlConnection();
            string UpdateString = "UPDATE tblWorkPage " +
                                "SET ReadyToPublish = 0 " +
                                "WHERE (pkID = " + pageToReject.WorkPageID + " ) " +
                                "AND (fkPageID = " + pageToReject.PageLink.ID + " )";

            String strConnString = ConfigurationManager.ConnectionStrings["EPiServerDB"].ConnectionString;
            try
            {
                SQLConnection.ConnectionString = strConnString;
                SQLConnection.Open();
                SqlCommand mySqlCommand = SQLConnection.CreateCommand();
                mySqlCommand.CommandText = UpdateString;

                mySqlCommand.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                if (SQLConnection != null)
                    SQLConnection.Dispose();
                ErrorHandler.HandleError(ex);
            }
            finally
            {
                SQLConnection.Close();
            }

        }
 

We, of course, are an Oracle shop, so most of our instances are actually using the following variant instead:

      protected void RejectPageOracle(PageData pageToReject)
        {
            OracleConnection ORCLConnection = new OracleConnection(strConnString);

            string UpdateString = "UPDATE tblWorkPage SET " +
                            "ReadyToPublish = 0 " +
                            "WHERE pkID = " + pageToReject.WorkPageID +
                            "AND fkPageID = " + pageToReject.PageLink.ID;
            try
            {
                ORCLConnection.Open();
                OracleCommand oracleCommand = ORCLConnection.CreateCommand();
                oracleCommand.CommandText = UpdateString;
                oracleCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ORCLConnection.Close();
                ErrorHandler.HandleError(ex);
            }
            finally
            {
                ORCLConnection.Close();
            }
        }
 

…but you get the idea. In the next post I will discuss how we get around those pesky “Save and Publish” buttons which let people circumvent our new Workflow implementation.

Apr 30, 2012

Comments

sca sc
sca sc May 30, 2018 05:26 AM

http://www.wholesalereclinersfurniture.com/ 

Our superior recliner chairs come in various styles to complement any room.From traditional reclining chairs to power and wall hugger recliners, La-Z-Boy has one to fit every room and every style.

Please login to comment.
Latest blogs
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024