Pragmatism in Code

Michael Percy AKA DeeEmm - Waxing lyrical about life the universe and everything software related...

Subscribe to feed Viewing entries tagged SQL

Jcomment to EasyBlog comment migration

Posted by DeeEmm
DeeEmm
DeeEmm AKA Michael Percy is an industrial software engineer specialising in lang
User is currently offline
on Friday, 20 January 2012
in Joomla 1.7 How To's

The recent migration from Joomla 1.5 to Joomla 1.7 left me without a comments system for the tutorials section of the site. Previously this was handled by Jcomment, a great component that allows you to easily add commenting to standard Joomla articles, its only drawback, is that the Joomla 1.7 version is still some way from release.

After having taken a look at various options, including several other commenting systems, I decided that the best solution would be to import the tutorial articles into EasyBlog, mostly as this would help keep some continuity on the site. The migration of the posts went flawlessly, as expected, but this still left me with the actual comments to migrate. I briefly considered a manual migration, but then discovered that there are actually quite a few comments on the site.

After a bit of digging around I discovered that EasyBlog creates a table that cross references the old article ID's to the new ID's. This is created during the migration process and the values are stored in the '#__easyblog_migrate_content' table. Perfect for migrating the missing comments across.

Using this table I was able to change the object_id in the original jcomments table to match the new post_id for EasyBlog. I simply ran the following SQL statement from within phpMyAdmin. (You will notice that I've made a copy of the original table into the table j17_oldjcomments, just in case.)

UPDATE j17_easyblog_migrate_content p, j17_oldjcomments pp
SET pp.object_id = p.post_id
WHERE pp.object_id = p.post_id

With the correct values assigned to the comments, I deleted all unnecessary fields (all fields except `userid`, `comment`, `date` and `object_id`) and then exported the table.

I then modified the SQL in a text editor as follows: I deleted the CREATE TABLE section and modified the INSERT statement as follows...

INSERT INTO `j17_oldjcomments` (`userid`, `comment`, `date`, `newid`) VALUES

Changed to

INSERT INTO `j17_easyblog_comment` (`created_by`, `comment`, `created`, `post_id`) VALUES

I then saved the file and using phpMyAdmin I imported the new comments into the database (again using phpMyAdmin).

Now all of the comments were under the correct posts but when viewing them I found that some of them had a left-margin set within an inline stye causing the comment to shift over to the right side of the page. After a  bit of digging, this transpired to be because there was some data missing from the database. For each entry there are two fields set which relate to the comments location within the comment stream, this is needed EasyBlog allows nested comments. My quick import simply assigned zero values to these fields confusing the script as to where the comments should sit within the comment stream.

The fields should function as follows - Assuming that all comments are sequential and not nested, on the first comment the values for the two fields lft and rgt will be 1 and 2, the next comment will be 3 and 4, and so on...

Rather than get technical and write a PHP script to do the job properly, I decided to manually add the values. I simply gave all comments the values 1 and 2 for the fields lft and rgt respectively (via phpMyAdmin). I then manually edited the posts where there were more then one comment so that the subsequent posts had the values, 3&4, 5&6, etc. I used the following SQL to find the duplicate entries:

SELECT `post_id` FROM `j17_easyblog_comment` GROUP BY  `post_id` HAVING  (COUNT(`post_id`) > 1)

Fortunately there were not too many posts with multiple comments.

/DM

Hits: 301 0 Comments Continue reading
Rate this blog entry

Exchange Mail And Linux Hosting + EMMA

Posted by DeeEmm
DeeEmm
DeeEmm AKA Michael Percy is an industrial software engineer specialising in lang
User is currently offline
on Wednesday, 30 July 2008
in General

Some of you may be aware that I've been setting up a new business - Indau Industrial Automation. Before setting up the new website and email servers I decided that I was going to look for exchange based email hosting packaged with a Linux web server. This would allow me to retain the Windows Mobile smart phone that I currently use and utilise it for push email and OWA Calendar and task synchronising. Having used Push based email for the past year it was high on the list of things to have - even though it meant retaining a tie to Micro$oft.

Unfortunately there are no comparible solutions available from the open source community yet, There are a few solutions that offer push email from the Linux platform but none that I wanted to risk trying, and none that are as feature rich as the Exchange + Windows mobile solution.

For the hosting package I looked no further than ComWebHosting my current service providers - although not advertised they were able to sort out a package that included Linux based web hosting with PHP and SQL along with exchange based Email. ComWebHosting come highly reccomended - I've used them for the past 8 or 9 years and have never had a problem - even now I'm based in Australia, using a UK based hosting company is not a problem - even for push email from my smart phone.

One new thing to sort out with the web hosting was the SQL database administration. Normally most web hosts provide phpMyAdmin to administer the database, some use other clients but there is normally a way in which you can upload a database backup or run an SQL query. As the sql database server was not the same as the webserver phpMyAdmin was not available so I needed to find a DB client that could be run remotely from the server - allowing me to install it on my local machine but access and administrate the database located on a different server.

A quick google managed to turn up nothing but a search in the ubuntu synaptics repository brough up EMMA - "extendable mysql managing assistant" (http://www.fastflo.de/projects/emma ) After installing the package I easily connected to the database with the info supplied by my web host and was then easily able to upload the database.

How to use EMMA is a bit beyond the scope of this article, but anyone familiar with databases, database structure or other database clients should easily be able to use EMMA. (Checkout the screenshot on the right or go to the fastflo website for a better idea of the interface) One feature I especially liked was that items shown in the query view (similar to phpMyAdmins 'browse') were shown in a table format that allowed direct editing of the values - no waiting for a browser to refresh!!

EMMA is based on "yamysqlfront" by the same author although it has been redesigned with extensibility in mind by utilising a plugin based architecture that allows contributors to provide additional features. Based on Python, EMMA is an open source project that is very easy to use and would easily be able to replace my need for phpMyAdmin for my day to day use.

With the site set up (it's based on DMCMS of course), all I now need to do is finalise the content and develop a new style template. You can view the progress at http://www.indau.com.au
Hits: 693 0 Comments Continue reading
Rate this blog entry
0 votes