Forums

 
  Support Forum  Modules  Engage: Publish  Automated Article Creation Module
Previous Previous
 
Next Next
New Post 7/10/2008 1:52 PM
Unresolved
  Derek Trauger
65 posts
http:\\www.derektrauger.com
6th Level Poster


Automated Article Creation Module 

This is somewhat of a continuation of a prior post but because I had the import working correctly and the issue that I am now having is different I felt that it should be a new post.  I have built a module that automates the creation of articles and although it is far from complete in respect to my project it is fully functional now with the exception that the article does not post automatically to the page upon insert instead you must go into the Engage Publish GUI and select the article to be placed on the page.  With that said the article seems to be created properly in terms of the Article, its Settings and its Relationships.  Any help in regards to how to get the article to populate a particular page on insert is appreciated.  I will include my code for anyone out there to use as a jump start for there own migration project as well as possible help in troubleshooting why my articles are not publishing to the page specified automatically.

Thanks again.

Derek

Code:

using System;
using System.Web.UI;
using System.Text;
using System.Collections.Generic;
using System.Reflection;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Engage.Dnn.Publish;
using Engage.Dnn.Publish.ArticleControls;
using Engage.Dnn.Publish.Admin;
using Engage.Dnn.Publish.CategoryControls;
using Engage.Dnn.Publish.Controls;
using Engage.Dnn.Publish.Data;
using Engage.Dnn.Publish.Forum;
using Engage.Dnn.Publish.Portability;
using Engage.Dnn.Publish.Search;
using Engage.Dnn.Publish.Security;
using Engage.Dnn.Publish.Services;
using Engage.Dnn.Publish.Tags;
using Engage.Dnn.Publish.Util;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Exceptions;

public partial class DesktopModules_ImportTool_ImportTool : DotNetNuke.Entities.Modules.PortalModuleBase
{
    protected void Page_Load(object sender, System.EventArgs e) {
        //if (!Page.IsPostBack)
        //{
        //    CreatePosting();
        //}
    }
    public const string PublishCacheKeys = "PublishCacheKeys";

    private static void ClearPublishCache(int portalId)
    {
        string cacheKey = PublishCacheKeys + portalId.ToString();
        ArrayList al;
        al = DataCache.GetCache(cacheKey) as ArrayList;
        if (al != null)
        {
            foreach (string s in al)
            {
                DataCache.RemoveCache(s);

            }
        }
        DataCache.RemoveCache(cacheKey);
    }

    private void CreatePosting()
        {
            try
            {
                string name = "Migration Test Article Name";
                string htmlEncoded = "<p>Migration Test Article<p>";
                string description = "Migration Test Article Description";
                int pageid = 60; //current page to place article
                int portalid = 0; //current portal to import into

                Article art = Article.Create(0);
                art.ApprovalComments = "Auto Imported by Migration Process";
                art.ApprovalStatusId = ApprovalStatus.Approved.GetId();
                art.ApprovalUserId = 1;
                art.ArticleText = HttpUtility.HtmlDecode(htmlEncoded);
                art.AuthorUserId = 1;
                art.CreatedDate = DateTime.Now.ToString();
                art.LastUpdated = DateTime.Now.ToString();
                art.Description = description;
                art.DisplayTabId = pageid;
                art.ItemTypeId = ItemType.Article.GetId();
                art.LanguageId = 1;
                art.Name = name;
                art.StartDate = DateTime.Now.ToString();
                art.PortalId = portalid;
                art.Save(1);


            }
            catch (Exception ex)
            {
                TextBox1.Text = ex.InnerException.Message;
            }
            finally
            {
                TextBox1.Text += Environment.NewLine;
                TextBox1.Text += "Article Imported";
                TextBox1.Text += Environment.NewLine;
            }
        }

    private void CreateRelationship(int lastItemId, int lastItemVersionId)
    {
        int parentItemId = 11; //mapped to the correct parent, which happens to be category
        int childItemId = lastItemId; //GetLastItemId();
        int childItemVersionId = lastItemVersionId; //GetLastItemVersionId();
        TextBox1.Text += Convert.ToString(childItemId);
        TextBox1.Text += Environment.NewLine;
        TextBox1.Text += Convert.ToString(childItemVersionId);
        ItemRelationship ir = new ItemRelationship();
        ir.RelationshipTypeId = RelationshipType.ItemToParentCategory.GetId();
        ir.StartDate = DateTime.Now.ToString();
        ir.EndDate = null;
        ir.SortOrder = 0;
        ItemRelationship.AddItemRelationship(childItemId, childItemVersionId, parentItemId, ir.RelationshipTypeId, ir.StartDate, ir.EndDate, ir.SortOrder);
        TextBox1.Text += Environment.NewLine;
        TextBox1.Text += "Relationship Imported";
    }

    private static int GetArticleDisplayTabId(string pagename) //not currently being used
    {
        int tabid = 60; //need to add code for this, possibly from a translation table of some sort
        return tabid;
    }

    private static int GetLastItemVersionId()
    {
        int itemVersionId;
        StringBuilder mySqlString = new StringBuilder();
        mySqlString.Append("SELECT max(ItemVersionId) ");
        mySqlString.Append("FROM {databaseOwner}{objectQualifier}Publish_ItemVersion ");
        System.Data.IDataReader dr = ((IDataReader)(DotNetNuke.Data.DataProvider.Instance().ExecuteSQL(mySqlString.ToString())));
        dr.Read();
        itemVersionId = Convert.ToInt32(dr[0]);
        return itemVersionId;
    }

    private static int GetLastItemId(int lastItemVersionId)
    {
        int itemVersionId = lastItemVersionId;//GetLastItemVersionId();
        int itemId;
        StringBuilder mySqlString = new StringBuilder();
        mySqlString.Append("SELECT ItemId ");
        mySqlString.Append("FROM {databaseOwner}{objectQualifier}Publish_ItemVersion ");
        mySqlString.Append("WHERE ItemVersionId = " + Convert.ToString(itemVersionId));
        System.Data.IDataReader dr1 = ((IDataReader)(DotNetNuke.Data.DataProvider.Instance().ExecuteSQL(mySqlString.ToString())));
        dr1.Read();
        itemId = Convert.ToInt32(dr1[0]);
        return itemId;
    }

    public void PopulateItemVersionSettingsTable(int lastItemVersionID)
    {
        // Create Item Version Settings
        ItemVersionSetting ivs1 = new ItemVersionSetting();
        ivs1.ItemVersionId = lastItemVersionID; //Convert.ToInt16(TextBox4.Text);//Grab Greatest ItemVersionId from ItemVersion table
        ivs1.ControlName = "chkUseApprovals";
        ivs1.PropertyName = "Checked";
        ivs1.PropertyValue = "True";
        ivs1.Save();

        ItemVersionSetting ivs2 = new ItemVersionSetting();
        ivs2.ItemVersionId = lastItemVersionID; //Convert.ToInt16(TextBox4.Text);//Grab Greatest ItemVersionId from ItemVersion table
        ivs2.ControlName = "ArticleSettings";
        ivs2.PropertyName = "DisplayOnCurrentPage";
        ivs2.PropertyValue = "True";
        ivs2.Save();

        ItemVersionSetting ivs3 = new ItemVersionSetting();
        ivs3.ItemVersionId = lastItemVersionID; //Convert.ToInt16(TextBox4.Text);//Grab Greatest ItemVersionId from ItemVersion table
        ivs3.ControlName = "ArticleSettings";
        ivs3.PropertyName = "ForceDisplayOnPage";
        ivs3.PropertyValue = "False";
        ivs3.Save();

        ItemVersionSetting ivs4 = new ItemVersionSetting();
        ivs4.ItemVersionId = lastItemVersionID; //Convert.ToInt16(TextBox4.Text);//Grab Greatest ItemVersionId from ItemVersion table
        ivs4.ControlName = "pnlPrinterFriendly";
        ivs4.PropertyName = "Visible";
        ivs4.PropertyValue = "True";
        ivs4.Save();

        ItemVersionSetting ivs5 = new ItemVersionSetting();
        ivs5.ItemVersionId = lastItemVersionID; //Convert.ToInt16(TextBox4.Text);//Grab Greatest ItemVersionId from ItemVersion table
        ivs5.ControlName = "ArticleSettings";
        ivs5.PropertyName = "IncludeParentCategoryArticles";
        ivs5.PropertyValue = "False";
        ivs5.Save();

        ItemVersionSetting ivs6 = new ItemVersionSetting();
        ivs6.ItemVersionId = lastItemVersionID; //Convert.ToInt16(TextBox4.Text);//Grab Greatest ItemVersionId from ItemVersion table
        ivs6.ControlName = "ArticleSettings";
        ivs6.PropertyName = "DisplayReturnToList";
        ivs6.PropertyValue = "False";
        ivs6.Save();

        ItemVersionSetting ivs7 = new ItemVersionSetting();
        ivs7.ItemVersionId = lastItemVersionID; //Convert.ToInt16(TextBox4.Text);//Grab Greatest ItemVersionId from ItemVersion table
        ivs7.ControlName = "pnlEmailAFriend";
        ivs7.PropertyName = "Visible";
        ivs7.PropertyValue = "True";
        ivs7.Save();

        TextBox1.Text += Environment.NewLine;
        TextBox1.Text += "Settings Imported";
    }

    public void Import()
    {
        CreatePosting();
        int itemVersionID = GetLastItemVersionId();
        int itemID = GetLastItemId(GetLastItemVersionId());
        CreateRelationship(itemID, itemVersionID);
        PopulateItemVersionSettingsTable(itemVersionID);
        ClearPublishCache(0);


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Import();
    }
}

 
New Post 7/10/2008 2:05 PM
  Chris Hammond
1117 posts
1st Level Poster


Re: Automated Article Creation Module 

Publish's implementation of IPortable within DNN doesn't take into account "module settings", the project that the IPortable functionality was simply to get all of categories and articles imported. Publish is setup to allow for multiple pages, or a single page, for content to be displayed on, getting all of the settings for potentially hundreds of modules in an import/export scenario isn't really feasible.

Essentially what you're trying to do is setup a new DNN page for each article? Or are you going more broad with your page functionality than that?

 


Directory of Training Programs, DotNetNuke Corporation
 
New Post 7/10/2008 2:15 PM
  Derek Trauger
65 posts
http:\\www.derektrauger.com
6th Level Poster


Re: Automated Article Creation Module 

Yes, I am trying to setup a new page for every article, so that on import when an article is imported it is automatically published on a particular page.  What is the purpose of specifying the DisplayTabId?

In order for me to auto create the articles I would essentially need to create a script to create the pages, place the module on it and then specify which article is placed on any given page.  What setting controls which particular article is placed within a particular instance of Engage:Publish?

Thanks.

Derek

 
New Post 7/10/2008 2:17 PM
  Chris Hammond
1117 posts
1st Level Poster


Re: Automated Article Creation Module 

The DisplayTabId allows you to point multiple articles to the same page. Through the use of Category lists users can navigate to that page passing in a querystring parameter for a specific article, Publish then loads that article from the parameter (this is the notion of overrideable in the module settings)

I would approach your import in such a manner that you minimize the number of pages that you're creating within DNN and try to utilize the Overrideable functionality to dynamically load the articles.


Directory of Training Programs, DotNetNuke Corporation
 
New Post 7/10/2008 3:13 PM
  Derek Trauger
65 posts
http:\\www.derektrauger.com
6th Level Poster


Re: Automated Article Creation Module 

While this may work in some instances where we display a list of linked pages, I do not see how this would work where the pages are viewed in the current system as individual/separate pages.  We are trying to mimic the look and feel of our current site in the migration of DNN so users do not notice a significant difference.

In many cases we would need physical pages in order to place other modules on them.

Is the TabModuleSettings table where the settings would be located to automate the creation of an article on a page once the engage module is created there?  From looking at the table it appears the SettingName Column using the adArticleId parameter with the SettingValue of the Item ID in question.

Is my logic corrent in thinking this way?

Thanks.

Derek

 
New Post 7/10/2008 3:15 PM
  Chris Hammond
1117 posts
1st Level Poster


Re: Automated Article Creation Module 

That would be correct. You'll have to put modules on the pages and them configure them appropriately. The settings are stored in TabModuleSettings,

adArticleId is short for Article Display Article ID, which is the setting used when you choose the Display Type of Article Display.

If you copy the settings for a module, you could duplicate those settings elsewhere on the site through SQL, or a number of other ways.


Directory of Training Programs, DotNetNuke Corporation
 
Previous Previous
 
Next Next
  Support Forum  Modules  Engage: Publish  Automated Article Creation Module

Purchase

Please click here to buy now.
Payment will be processed via credit card or PayPal.

Please click here to buy now.
Payment will be processed via credit card or PayPal.

Test Drive!

Want to find out how it works? Visit our demo site to see the modules in actions!

Want to find out how it works? Visit our demo site to see the modules in actions!

Subscribe

Sign up for our newsletter and get the latest product updates!

Sign up for our newsletter and get the latest product updates!

Online Support

Powered by DotNetNuke