More in this section

Forums / Developing with Sitefinity / Querying Database for content submissions

Querying Database for content submissions

4 posts, 0 answered
  1. Chris Dodge
    Chris Dodge avatar
    16 posts
    Registered:
    17 Dec 2009
    11 Jun 2010
    Link to this post
    Hello,

    We have a requirement for Administrators to be email notified when content has been submitted for approval.

    I've spend some time with the Sitefinity toolkit which looks like it has some of this capability, but it seems a bit limited for our need, so I wanted to write some of my own software to do this.

    One idea I had was to just simply query the Sitefinity database for content in a "Submitted for Approval" state. I'm looking at the DB and trying to see any way to do this relatively simply.

    Can you recommend any Tables/Fields to look at? Also, it'd be great if you could say what the various status codes for the workflow steps are.

    Thanks,

    Chris
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    14 Jun 2010
    Link to this post
    Hi Chris Dodge,

    We are doing all the querying through an ORM mapper, so we do not encourage you to look for these tables - there might be many dependencies. Alternatively, here is how you can get a list of items waiting for approval:

    Pages:

    //Get All Pages waiting to be approved
            CmsManager cmsManager = new CmsManager();
            IList allPages = cmsManager.GetPages();
            Response.Write("Pages for approval: <br/>");
            foreach (ICmsPage p in allPages)
            {
                WorkflowInstance workflow; 
                workflow = p.GetWorkflow();
                if (workflow != null)
                {
                    PageWorkflow activity = (PageWorkflow)workflow.Activity;
                    if (activity.ApprovalStatus == ApprovalStatus.ForApproval)
                         Response.Write("-> <b>" + p.Name + ".aspx</b><br/>");
                }
            }

    Generic Content Items:

    //Get All Generic Content Items
            ContentManager GenericCntManager = new ContentManager();
            IList AllItems = GenericCntManager.GetContent();
     
            Response.Write("Generic Content Items for approval: <br/>");
            foreach (IContent cnt in AllItems)
            {
                StagedContent stgCnt = GenericCntManager.GetStagedContent(cnt.ID) as StagedContent;
                if (stgCnt != null)
                {
                    WorkflowInstance workflow;
                    workflow = WorkflowRuntime.Instance.GetWorkflow(stgCnt.WorkflowInstanceId);
                    if (workflow != null)
                    {
                        ContentWorkflow activity = (ContentWorkflow)workflow.Activity;
                         if(activity.ApprovalStatus == ApprovalStatus.ForApproval)
                             Response.Write("-> <b>" +cnt.GetMetaData("Name").ToString()+"<b><br/>");
                    }
                }
            }

    I hope this helps. 

    Regards,
    Georgi
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Chris Dodge
    Chris Dodge avatar
    16 posts
    Registered:
    17 Dec 2009
    15 Jun 2010
    Link to this post
    Hi,

    Thank you very much for the code.

    However, after implementing I just happened to notice that I'm seeing "red locks" appearing in all the Generic Content (with an empty "Locked by..." field). I'm assuming that this code is somehow putting the content into an "edit mode" which is applying some flags to the data entities.

    If this is related, is there a way to open the objects "read-only" without any changes to the edit lock flags?

    Also, I'm assuming I can take the same "For Approval" approach with regards to News items as well, I'm doing:

    NewsManager newsManager = new NewsManager("News");
                    IList AllItems = newsManager.GetContent();

                    foreach (IContent cnt in AllItems)
                    {
                        StagedContent stgCnt = cm.GetStagedContent(cnt.ID) as StagedContent;

                        if (stgCnt != null)
                        {
                           
                            WorkflowInstance workflow;
                            workflow = WorkflowRuntime.Instance.GetWorkflow(stgCnt.WorkflowInstanceId);
                            if (workflow != null)
                            {
                               // see if we already alerted
                                if (!_alertId.ContainsKey(workflow.ID))
                                {
                                    ContentWorkflow activity = (ContentWorkflow)workflow.Activity;
                                    if (activity.ApprovalStatus == ApprovalStatus.ForApproval)
                                        changes += cnt.GetMetaData("Name").ToString() + "\r\n";
                                    _alertId.Add(workflow.ID, true);
                                }
                            }
                        }
                    }

    Thanks,

    Chris
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Jun 2010
    Link to this post
    Hello Chris Dodge,

    You can try adding these methods and then calling ExecuteActivity for activities like Publish:
    private EventActivity FindActivity(string name, IList<Activity> activities)
            {
                foreach (Activity act in activities)
                {
                    if ((act is EventActivity) && (((EventActivity)act).CommandName == name))
                        return (EventActivity)act;
                    EventActivity ea = FindActivity(name, act.Activities);
                    if (ea != null)
                        return ea;
                }
                return null;
            }
            private void ExecuteActivity(Guid id, string activityName)
            {
                WorkflowInstance instance = WorkflowRuntime.Instance.GetWorkflow(id);
                if (instance != null)
                {
                    ContentWorkflow workflow = (ContentWorkflow)instance.Activity;
                    EventActivity activity = FindActivity(activityName, workflow.Activities);
                    if (activity != null)
                    {
                        activity.Execute(WorkflowRuntime.Instance);
                    }
                }
            }

    ExecuteActivity(stgCnt.WorkflowInstanceId, "SendForApproval");

    for each activity that needs to be completed.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
4 posts, 0 answered