Databases: How to insert more than 2 characters in the country field

Databases: How to insert more than 2 characters in the country field

by Adrian Sarmas -
Number of replies: 2
Picture of Plugin developers

Hi! I'm working on a Joomla 2.5.6 site that is connected with a Moodle 2.2.3 installation through Joomdle 0.81 so that users that register through Joomla are automatically created in Moodle. I've done some field mappings between Joomla and Moodle. 

I have some problems with the country field from Moodle database (table user). No matter what I do I cannot insert more than two characters in that field, using the Joomla register form (I can insert more than 2 characters manually from phpmyadmin). I need to insert more than 2 characters because I changed the countries.php file and I've replaced the countries list with a list of local regions.

I changed the country field type from varchar(2) to varchar(50) and changed the country limit from /lib/moodlelib.php to 50, but it's not working.

(starting at line 3725 in my installation)

function truncate_userinfo($info) {
// define the limits
$limit = array(
'username' => 100,
'idnumber' => 255,
'firstname' => 100,
'lastname' => 100,
'email' => 100,
'icq' => 15,
'phone1' => 20,
'phone2' => 20,
'institution' => 40,
'department' => 30,
'address' => 70,
'city' => 120,
'country' => 50,
'url' => 255,
);

$textlib = textlib_get_instance();
// apply where needed
foreach (array_keys($info) as $key) {
if (!empty($limit[$key])) {
$info[$key] = trim($textlib->substr($info[$key],0, $limit[$key]));
}
}

return $info;
}

I believe that Moodle is somewhere limiting the amount of information that can be inserted in the database through external authentication but I don't know where. Any ideas on how to insert more than 2 characters in the country field are appreciated. 

Average of ratings: -
In reply to Adrian Sarmas

Re: Databases: How to insert more than 2 characters in the country field

by Adrian Sarmas -
Picture of Plugin developers

I found the solution. The auth.php file in /auth/joomdle trimmed the country name.

In reply to Adrian Sarmas

Re: Databases: How to insert more than 2 characters in the country field

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

There is no point in storing more than 2 characters in that field because of how Moodle uses that data. user.country is a 2-charater country-code (http://www.theodora.com/country_digraphs.html). Those are the only values that should be stored in that column.