what is the sql statment to add a content item?

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
User avatar
micheas
Joomla! Apprentice
Joomla! Apprentice
Posts: 29
Joined: Sat Sep 03, 2005 10:54 am
Location: San Francisco, CA
Contact:

what is the sql statment to add a content item?

Post by micheas » Sat Nov 03, 2007 10:40 pm

Feel free to move this question if it belongs someplace else, I couldn't find anyplace that looked completely correct.

I have 4200 pages to add and I am pretty sure that I can extract all the data I need out of the shtml and html files to fill in all the  fields.

I do not want to add them by hand for obvious reasons.

One of my main questions is what tables do I need to update. (jos_content only?) the second question is what do I need to do to replace images with {mosimage} tags?

I am just a little concerned of missing something and having 16,800 mistakes that require me to restore the old database and start again. (I probably will anyways but I would hate to miss something that is not obvious and find out after fifty updates have happened making a real painful data update to be figured out.

(Is there some documentation that I am just not finding?)

Thanks.

User avatar
bascherz
Joomla! Intern
Joomla! Intern
Posts: 86
Joined: Mon Jan 16, 2006 1:33 am
Location: Vienna, VA
Contact:

Re: what is the sql statment to add a content item?

Post by bascherz » Sun Nov 04, 2007 12:03 am

It really is pretty much that straightforward. However there are some things you need to take into consideration. For instance, each content item is either static or a member of a category and section. You'll need to make sure you get those IDs correct for every one of your articles. Regarding the {mosimage} tags, basically those are filled in with the files in order of occurrence in the image column of the jos_content table. By default, the images should appear in the /images/stories folder (that is the root). However, you can put them in a subfolder if you wish, which would prefix the image file name. The format of each image specification is as follows:

Code: Select all

food/bread.jpg|right|alt text|0|caption|top|center|100

which is the image name, alignment, alternate text, border thickness in pixels, caption, caption alignment, orientation, and width. Each image spec is terminated with a new line.

The best way to learn all this is to play around with an unpublished article in the site back end and see what your changes do by looking at the article record in the jos_content table using phpMyAdmin (or whatever tool you prefer). Since you have so many articles to deal with, you will want to become intimately familiar with all of the columns in this table and understand what they do. Otherwise you'll find yourself editing the attributes for 4200 articles in the site back end. Fortunately, you only have to deal with this one table once you have established the categories and sections into which your articles will be inserted.

You can also setup a test site to do all your experimenting until you get it working right, and then publish to your actual site. For that sort of thing you may want to entertain setting up a local site on one of your personal computers. You can read about how to setup a test environment in the Joomla! Beginning Developer Course. Look in the section about setting up an IDE and follow the instructions for installing XAMPP. Once you have XAMPP installed you can install as many test Joomla sites as you need on your local machine. You don't need the IDE if you aren't going to do any PHP coding.

Hope this helps.
Last edited by bascherz on Sun Nov 04, 2007 12:05 am, edited 1 time in total.
__________________
Bruce Scherzinger

User avatar
micheas
Joomla! Apprentice
Joomla! Apprentice
Posts: 29
Joined: Sat Sep 03, 2005 10:54 am
Location: San Francisco, CA
Contact:

Re: what is the sql statment to add a content item?

Post by micheas » Sun Nov 04, 2007 5:14 am

Thanks,

I was mostly concerned that I needed to add to the count field in jos_categories, or jos_sections.

I have three test sites to play with, but once I do the live update I don't want to find a small oops that requires reverse engineering the mistake and putting things the right way..

User avatar
bascherz
Joomla! Intern
Joomla! Intern
Posts: 86
Joined: Mon Jan 16, 2006 1:33 am
Location: Vienna, VA
Contact:

Re: what is the sql statment to add a content item?

Post by bascherz » Sun Nov 04, 2007 3:32 pm

I looked for correlations with those tables, but I couldn't see any. Not being a core developer, I am only able to glean information from doing what-if analyses. From all appearances, you should be fine just updating the jos_content table as described earlier. Having said that, I will reiterate that trying it on a test site first is the best way to go. Make sure the bulk update works first on a site you don't care about and can wipe clean and restart from scratch. You'll save yourself a lot of problems despite what might appear to be additional work.

Good luck!
__________________
Bruce Scherzinger

User avatar
Tonie
Joomla! Ace
Joomla! Ace
Posts: 1585
Joined: Thu Aug 18, 2005 7:13 am
Contact:

Re: what is the sql statment to add a content item?

Post by Tonie » Sun Nov 04, 2007 3:49 pm

Take a look at /installation/sql/sample.sql. This file is the default content that is installed in a default Joomla installation. If the sections and categories are in place, com_content is the only place that needs changing. The column names and types are available in /installation/sql/joomla.sql.

The easiest is to install create your categories and sections. Then create one content items as you want it. Export the content table with Phpmyadmin, you will have a 'template' for installing more content items.
Antonie de Wilde - Forum admin


Post Reply