Attempting to Change Courses' Shortname via Upload Courses with CSV

Attempting to Change Courses' Shortname via Upload Courses with CSV

by Melanie Hoag -
Number of replies: 3

Greetings!

I am attempting to change the shortname of existing courses via the Upload Courses interface with a CSV file. The importance to us is the script on our registration system to generate the CSV file for our adds and drops uses shortname to match. Unfortunately, when we created the courses via a CSV file, the CSV file generated by our registration system added an extra space in the shortname field.

So thus we need to change, for example:

BIO5012101-fall -19 to BIO5012101-fall-19

it may be hard to see but there is an extra space between fall and -19 in 

BIO5012101-fall -19

The CSV file reads:

shortname
rename
BIO5012101-fall -19
BIO5012101-fall-19


with:


I receive a green checkmark and Course renamed in the status field but the shortname has not been changed. Viewing the shortname field in mdl_course shows no change.

I have searched for similar posts and found an old one with the same query but no replies. I've also tried various combinations of fields and quotes around the shortname in the upload CSV file, but alas, no success.

We are running locally Moodle 3.5.1, CentOS, MariaDB 5.5.60, php 7.2.21 

I appreciate any assistance and guidance - thank you!

Average of ratings: -
In reply to Melanie Hoag

Re: Attempting to Change Courses' Shortname via Upload Courses with CSV

by Ken Task -
Picture of Particularly helpful Moodlers

Double check the csv file with NotePad or TextEdit to make sure there isn't a space after the changed "BIO5012101-fall-19'  or the original shortname or other character 'imperfection'.

What does the help button display on the setting for 'Allow resets'?

You might do a mysql export to text of mdl_course for just the current id,fullname,shortname to see what that looks like for all courses currently in the table:

mysql -u $mddbuser -p$mddbpass -e "use $mddbname;select id,fullname,shortname from mdl_course;" > courses.txt;cat courses.txt

'SoS', Ken

In reply to Ken Task

Re: Attempting to Change Courses' Shortname via Upload Courses with CSV

by Melanie Hoag -
Dear Ken,

Thank you for your reply and your time!

The view in TextWrangler of the CSV file with the option to display Invisibles • there is no trailing space on the second line [wasn't able to catch that in the screen grab]


The help for Allow resets displays:


and for Allow renames shows:



BTW - I've tried with and without Allow resets and with and without Allow deletes using all the possible combinations.

After doing an Upload course with the CSV file:

And viewing the course's record in phpMyAdmin:



I've also tried adding the idnumber field after the rename field, before the rename field and as the first field before shortname.

Hope this sheds some light!
In reply to Melanie Hoag

Re: Attempting to Change Courses' Shortname via Upload Courses with CSV

by Ken Task -
Picture of Particularly helpful Moodlers

Hmmm .... csv routine not working.  Wonder if code restricts?

I see the idnumber is what you want in shortname.

Couldn't that be done via MySQL client?

| shortname         | varchar(255) | NO   | MUL
| idnumber          | varchar(100) | NO   | MUL

UPDATE mdl_course SET idnumber=shortname where shortname='X';

where X above is a shortname.

Try that with just one row ... then see change via mysql client:

select fullname,shortname,idnumber from mdl_course where idnumber='m341';

Query above had

Moodle Sharing                                          | MSHARE       | MSHARE

Originally ... I then changed idnumber to m341 on test system.

and check via Moodle interface.

You could tinker with mysql client commands with a copy of your production DB re-imported to another DB name on same DB server.

Then find a way to loop through the shortnames and set idnumber to same.

'SoS', Ken