Wednesday, January 30, 2013

Use the moodle logs to troubleshoot a problem

I upgraded one of our moodle sites to 2.4 the other day and had a couple responses from users that they could not log in.  I browsed to the site, logged in as admin and checked the logs.

Use the moodle logs, sometimes they are real helpful.

Site Admin | Reports | Logs







Here is a sample from today, more students having login trouble...
 








I queued up the days activities and scrolled down to the bottom of the list and saw that a lot of users had failed to log in.  Turns out a lot of the students were smart enough to follow the login "fogot password" link and send a reset email to their email account.  I guess I heard from the couple who were not smart enough to do that.  To be fair, I did not realize their passwords would change.  I asked the teacher of one of the classes on the site if he had to reset his password, his response was that all the kids in his class had to change them.

I did great following the instructions on this official upgrading page, EXCEPT copying the config.php file.

Why passwords changed.

Upon further review of upgrading to 2.4 moodle docs, I noticed a step I did not perform, which was copying the existing config.php file from the old install into the new one, prior to starting the upgrade process.  By *creating a new config.php file, a new password salt was added to the file, rendering all existing passwords useless.  In hindsight this is clear.  The other detail specified in the config.php file are the database, the db connection info and the dataroot directory.  I had to specify those details again during the first steps of the install, since I DID NOT copy the old file into the new root directory.  I WILL DO THIS in my next upgrade projects to test this theory.

This is what the config.php file in the webroot looks like

unset($CFG);
global $CFG;
$CFG = new stdClass();

$CFG->dbtype    = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'dbname';
$CFG->dbuser    = 'user';
$CFG->dbpass    = 'password';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbsocket' => 0,
);

$CFG->wwwroot   = 'http://siteURL;
$CFG->dataroot  = 'F:\\pathtomoodledataFolder';
$CFG->admin     = 'admin';

$CFG->directorypermissions = 0777;
$CFG->passwordsaltmain = 'somelongstringofstrangecharacters';

require_once(dirname(__FILE__) . '/lib/setup.php');


It is that passwordsaltmain = 'somelongstringofstrangecharacters'; statement that is the problem IF i want to keep the same passwords.

Moral of the story?

You should rename the current (soon to be old) directory structure and create a new empty structure to hold your updated moodle code.  Then, before you start the install process.  COPY the config.php file from the old root dir. to the new root dir.  This will keep your passwords in tack and you will not have to specify DB, DB connections parameters or dataroot.
 

No comments:

Post a Comment