tags:

views:

452

answers:

2

How can you edit Joomla's articles in terminal?

Problem: to know the location where Joomla stores its articles

I tried to find articles unsuccessfully by

locate Masi | xargs -0 grep great
+1  A: 

Joomla stores articles in a MySQL database. If you want to read/modify/delete articles you'll have to use SQL queries.

If you're determined to do this from a terminal, you could always start the mysql client from the command line and execute your queries from there.

Stuart Childs
How can I start a MySQL client in terminal? I am using Ubuntu.
Masi
+3  A: 

The articles are stored in the database in a table called jos_content. If you wanted to do a find and replace across them all, open a connection to the database (or use something like phpMyAdmin) and run something like this:

 UPDATE `jos_content`
 SET    `introtext` = REPLACE(`introtext`, 'great', 'awesome'),
        `fulltext`  = REPLACE(`fulltext`, 'great', 'awesome')

Edit to help you debug the problem:
You won't be able to find "jos_content" in your codebase, because of a feature of Joomla which allows you to specify different table prefixes: "jos" is the default prefix. In the code, it's always written like this: #__content, and the DBO object converts that to "jos_content" behind the scenes.

However, you don't need to be looking in your code at all, just the database. You should be able to connect to the database - all the details you need will be in your configuration.php file.

  • If you're using Joomla 1.5, the variables you need are called $host, $user, $password and $db.
  • In Joomla 1.0, the variables are named $mosConfig_host, $mosConfig_user, $mosConfig_password and $mosConfig_db

There are a number of ways that you can connect to the database (check with your hosting company if you have phpMyAdmin available: it's quite easy to use), but to do it from the terminal (substitute in your own variables from above):

$ mysql -h $host -u $user -p$password -D $db

note that there's no space between the -p and the password. From there you should be able to run your own SQL, but I would highly recommend making a backup before you do any manual changes.

nickf
I tried to find the string jos_content in my server unsuccessfully by $ find jos_content | xargs grep -L jos .
Masi
It seems that find cannot see inside the database.
Masi