Page 1 of 1

HOWTO: migrate news + comments to cgblog

Posted: Tue Sep 21, 2010 8:07 pm
by Gregor
I've been using the combination news + comments as a sort of blog module. Because of the existance of CGBlog, I wanted to migrate my data to cgblog. In the following part I'll show / explain what I have done.

The basis is to keep the numbering of news articles equal to cgblog articles. This because it helps you to 'link' comments being made to the blog article.

0. Create a backup of the database and store it in a safe place!!!!
1. Install CGBlog
2. Install CGFeedback
3. Insert News-items into CGBlog. Replace 'Your Name' with the writer of the article. In this case all articles are written by me. If you have more writers, you have to add these names manually.

Code: Select all

insert into cms_module_cgblog
(`cgblog_id`, `cgblog_title`, `cgblog_data`, `cgblog_date`, `summary`, `start_time`, `end_time`, `status`, `create_date`, `modified_date`, `author`, `cgblog_extra`, `url`)
select
`news_id`, `news_title`, `news_data`, `news_date`, `summary`, `start_time`, `end_time`, `status`, `create_date`, `modified_date`, “Your Name”, `news_extra`, NULL
from cms_module_news
4. First delete all rows from the cgblog_category table, so you have an empty table. Manual action.
5. Insert the news categories into the cgblog categories:

Code: Select all

insert into cms_module_cgblog_categories
(`id`, `name`, `sort_order`)
select
`news_category_id`, `news_category_name`,  `hierarchy`
from cms_module_news_categories
6. Make sure that the sort_order column from  the 'Category' table has unique values (has to do with sub categories from News, those with a ‘|’ symbol). Manual correction.
7. Insert the relation between the blog categories and the news categories:

Code: Select all

insert into cms_module_cgblog_blog_categories
(`blog_id`, `category_id`)
select
`news_id`, `news_category_id`
from cms_module_news
8. If you have made any field definitions in News, insert these into field defs. from the cgblog module:

Code: Select all

insert into cms_module_cgblog_fielddefs 
(`id`, `name`, `type`, `max_length`, `create_date`, `modified_date`, `item_order`)
select
`id`, `name`, `type`, `max_length`, `create_date`, `modified_date`, `item_order`
from cms_module_news_fielddefs
9. Insert the field values, if any:

Code: Select all

insert into cms_module_cgblog_fieldvals 
(`cgblog_id`, `fielddef_id`, `value`, `create_date`, `modified_date`)
select
`news_id`, `fielddef_id`, `value`, `create_date`, `modified_date`
from cms_module_news_fieldvals
10. Make sure you add the correct sequent number:

Code: Select all

insert into cms_module_cgblog_seq
(`id`)
select
`id`
from cms_module_news_seq
Next you have to check the templates used in News. I copied the News templates into the according CGBlog templates and modify the variables. Safe the cgblog template in a separate text editor to verify what you are doing. Because both use the same names in most case, I had to make very limit changens.

If News articles have related comments, one can re-use these by replacing the word 'news' in the comments-table by the word 'CGBlog'. Because we keep the numbering the same, the comments will show up with the according blog article. This was a manual action. If you use CGFeedback, you can follow the same steps.

To 'connect' twitter to CGBlog, create a new UDT 'blog_twitter_update_status' containing the following code:

Code: Select all

/*********************************************************************************
 * about
*********************************************************************************/ 

/*

This UDT can be used to automatically post a Twitter message when a CGBlog article is added. 
The functionality is based on the Twitter and CGBlog module. 

- First you need to install and setup the CGBlog and Twitter module.
- After you need to create a UDT with this code, for example you can call it: 'blog_twitter_update_status'
- At last you need to connect this UDT to the 'CGBlogArticleAdded' event. 
   This can be done via Extensions -> Event Manager.

! Currently this UDT only works when pretty urls are enabled.
It seems that the bit.ly url shortner ($twitter->shortenUrls($link)) has some problems with unfriendly urls.
Querystring parameters &var=1 are converted to &=1 which will break the link.

*/

/*********************************************************************************
 * globals / objects
*********************************************************************************/ 

global $gCms;

$twitter    = $gCms->modules['Twitter']['object'];
$cgblog       = $gCms->modules['CGBlog']['object'];
$root_url   = $gCms->config['root_url'];
$debug      = '0';

/*********************************************************************************
 * variables
*********************************************************************************/ 

/* custom (string) */
$detailpage = '15';

/* blog article related  (string) */
$cgblog_id = $params['cgblog_id'];
$title = $params['title'];

/* added to link (array) */
$link['articleid']  = $params['cgblog_id'];

/*********************************************************************************
 * program
*********************************************************************************/ 

$aliased_title  = munge_string_to_url($title);
$prettyurl      = 'logboek/' . $cgblog_id.'/'.$detailpage."/$aliased_title";
$prettyfullurl  = $root_url . '/'. $prettyurl;

/* shorten URL does not work that well when pretty links are not enabled */

if ($debug) {
    $link = $cgblog->CreateLink($news_id, 'detail', $detailpage, '', $link,'', true, false, '', true, $prettyurl);
    $shortlink = $twitter->shortenUrls($link);
    //$message = $title.' '. $shortlink;
    print "<pre>link: $link / shortlink: $shortlink \n</pre>";
}

$message = $title. ' '. $prettyfullurl; 

if ($debug) {
    print "<pre>twitter: $message status: $params[status] \n</pre>";
} else {
    if ($params[status] == 'published') {
        $twitter->updateStatus($message, false);
    }
}
It was a puzzle, but it is working. :D

Gregor

Re: HOWTO: migrate news + comments to cgblog

Posted: Thu Sep 23, 2010 6:56 am
by nicmare
very nice, thank you!

Re: HOWTO: migrate news + comments to cgblog

Posted: Fri Sep 24, 2010 7:42 am
by Gregor
nicmare wrote: very nice, thank you!
Thanks for the compliement.