Change Course Code

Change Course Code

by uk nites -
Number of replies: 4

Hi:

   We have recently changed name of one of our programs

I have changed the category name but the course appearing under that category are with old names

There are about 50 different courses

for example its appearing as

ABC121

i want to change ABC to CIF121

How can i do it in one go?

if it would be via phpmyadmin then what would be the query? and under which table these titles are maintained

thanks

Average of ratings: -
In reply to uk nites

Re: Change Course Code

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi,

In the DB its the 'shortname' attribute of the 'course' table.  The same as 'Short name' when you edit the settings of a course.

Cheers,

Gareth

In reply to Gareth J Barnard

Re: Change Course Code

by uk nites -

thanks Gareth

but how can i change it all in one go

i can change it manually for some but not all

what would be the query to do that?

 

In reply to uk nites

Re: Change Course Code

by Oliver Jackson -

From your original post, it sounds like you have all your courses in one category. You'll need to find out the ID number of that category.

If you go to http://your.moodle.site/course on your site and then click on the category of interest you will see its ID number in the URL. It will contain /course/category.php?id=X where X is the category ID.

You should now be able to write a query to modify the shortname of courses directly under this category. If there are nested categorys it's going to be more complicated.

BACKUP YOUR DATABASE NOW in case you break anything. And make sure you know how to restore it if needed. In fact, do all this on a test server to prove that it works as I can't be held responsible for this breaking everything if it's in fact completely wrong wink

Seeing as you also mentioned phpmyadmin I'll assume you have a MySQL database.

Using phpmyadmin browse to your moodle database and find the course table (probably called mdl_course unless someone chose to use a non-default prefix in place of the standard mdl_).

So once your phpmyadmin shows you're at

  localhost -> moodle  -> mdl_course "Central course table"
 
click on the search tab and enter your category value X in the category search field (should be second row), press enter and you will be returned a list of all courses in that category. This is to make sure you're now looking at exactly the courses whose shortnames you wish to modify.
 
Now click the SQL tab and we'll write a query to modify your shortnames.
 
The following query will modify the shortname field of all courses directly in category X by replacing all instances of ABC to CIF within the shortname text. (tested on MySQL 5.5.28 running on Ubuntu Linux, Apache 2.2.22)
 
UPDATE `mdl_course` SET `shortname` = REPLACE(`shortname` , 'ABC' , 'CIF') WHERE `category` = X


To test it the first time add " LIMIT 1" without the double quotes to the end so that it will only modify the first record it finds as a test case. NOTE that the query contains both single quotes as well as backticks (backwards single quotes) and you'll need to get the right ones in the right place or MySQL will get confused and return an error. I'm not sure if these quote and backtick requirements are different for MySQL running on Windows or other platforms.

Of course if you wish to change the idnumber of the course rather than the shortname simply replace the two instances of shortname in the query with idnumber.

PLEASE: test first, backup first, have a perfect recovery plan when running queries directly on your database

Average of ratings: Useful (1)