Bulk User Actions in 1.9 beta 4

Bulk User Actions in 1.9 beta 4

by e klopfer -
Number of replies: 9
I recently read about the bulk user actions in 1.9 so I thought I'd give the latest stable build of 1.9 a whirl.

Things seem to work fine, but the bulk user actions never return any users. Even with no filter present it says that 0/0 users are selected. Browsing users normally shows me all of the users as one would expect.

I turned up the debugging output to see what was going on, and this is what I have. I know this is beta, so it is a work in progress. But I thought I'd ask for suggestions.

Notice: Trying to get property of non-object in /var/www/html/moodle/admin/user/lib.php on line 30

Notice: Trying to get property of non-object in /var/www/html/moodle/admin/user/lib.php on line 32
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND deleted 1' at line 1

SELECT COUNT(*) FROM mdl_user WHERE id<> AND deleted <> 1
  • line 686 of lib/dmllib.php: call to debugging()
  • line 379 of lib/dmllib.php: call to get_recordset_sql()
  • line 362 of lib/dmllib.php: call to count_records_sql()
  • line 32 of admin/user/lib.php: call to count_records_select()
  • line 30 of admin/user/user_bulk.php: call to get_selection_data()
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND deleted 1' at line 1

SELECT COUNT(*) FROM mdl_user WHERE id<> AND deleted <> 1
  • line 686 of lib/dmllib.php: call to debugging()
  • line 379 of lib/dmllib.php: call to get_recordset_sql()
  • line 362 of lib/dmllib.php: call to count_records_sql()
  • line 33 of admin/user/lib.php: call to count_records_select()
  • line 30 of admin/user/user_bulk.php: call to get_selection_data()
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND deleted 1 ORDER BY fullname LIMIT 2000' at line 1

SELECT id,CONCAT(firstname,' ',lastname) AS fullname FROM mdl_user WHERE id<> AND deleted <> 1 ORDER BY fullname
  • line 686 of lib/dmllib.php: call to debugging()
  • line 609 of lib/dmllib.php: call to get_recordset_sql()
  • line 1040 of lib/dmllib.php: call to get_recordset_select()
  • line 37 of admin/user/lib.php: call to get_records_select_menu()
  • line 30 of admin/user/user_bulk.php: call to get_selection_data()

Average of ratings: -
In reply to e klopfer

Re: Bulk User Actions in 1.9 beta 4

by e klopfer -
I have done a bit of debugging and it seems to be coming from these lines (30 and 32 mentioned above)

$sqlwhere = $ufiltering->get_sql_filter("id<>{$guest->id} AND deleted <> 1");

$total = count_records_select('user', "id<>{$guest->id} AND deleted <> 1");

Specifically, it is coming from the id<>{$guest->id} part of the query.

I'm guessing that this is because I don't have guest users enabled on my system. But this should probably be checked. Taking that part of the query out fixes the problem, but I don't know how to provide a more permanent fix.
In reply to e klopfer

Re: Bulk User Actions in 1.9 beta 4

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Even if you dont' have guest access on your system, Moodle always has a guest user (or it should). So there should be a guest user account in your mdl_user table. If there isn't, then that's part of the problem (there could be other unrelated reasons).

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: Bulk User Actions in 1.9 beta 4

by e klopfer -
I checked out my tables and there is indeed a guest user record in there. It looks ok (it is not marked as "deleted").

I do have "force users to login" and "force users to login for profiles" both checked under security, though I don't know if either of them has an impact in this case.

Anything else that might cause this variable to be undefined or poorly defined?
In reply to e klopfer

Re: Bulk User Actions in 1.9 beta 4

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That seems like a bug in the code or a problem with your database, as it has nothing to do with the settings you mention.

$guest should be populated on line 29 of admin/user/lib.php, including $guest->id. So it seems its failing to get the guest user details. get_guest() just calls get_complete_user_data() with the username set as guest, so the problem has to be there (or at the database).

Make sure your guest user record has a mnethostid value equal to $CFG->mnet_localhost_id (you can get this value from mdl_config; search for the record with a 'name' of 'mnet_localhost_id').

If it does, then enable your database server logs, and have a look at the error logs you might get when you repeat the operation (so the error triggers again).

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: Bulk User Actions in 1.9 beta 4

by e klopfer -
Thanks for the help.

A search on mnet_localhost_id turned up empty on the name field in mdl_config table. I also don't see an mnethostid field in my mdl_user table.

Did my tables not get updated correctly during some upgrade? Is there a way to repair them?

Note, this is the only unusual behavior I've seen. Everything else seems fine.
In reply to e klopfer

Re: Bulk User Actions in 1.9 beta 4

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Did my tables not get updated correctly during some upgrade?

Was this a fresh install or an upgrade? If it was an upgrade, from which version? And did you have any warnings/errors during the upgrade?

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: Bulk User Actions in 1.9 beta 4

by e klopfer -
It is a system that has been upgraded quite a number of times (and has been actively used with classes). I think I started around Moodle 1.6 and gone through each .1 upgrade. I've never received warnings/errors on upgrades.
In reply to e klopfer

Re: Bulk User Actions in 1.9 beta 4

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hummm, then something has failed during the upgrade to 1.8.x, where Moodle Network was introduced. You should have the additional mnethostid column in mdl_user, and a few other mnet related tables and values in various tables.

Not knowing the state of your database with respect to Moodle Network tables and values, the only thing I can safely recommend is:

1.- Make a full database backup (and check that you can restore it in another database server, just in case), as we are going to modify the database and something could go wrong.

2.- Alter the mdl_user table to add the missing column (mnethostid) with something like this (the following syntax assumes you are using MySQL, other DBs might use a different syntax):

ALTER TABLE mdl_user ADD COLUMN mnethostid bigint(10) NOT NULL DEFAULT(0) AFTER deleted; DROP INDEX username ON mdl_user; CREATE UNIQUE INDEX mdl_user_mneuse_uix ON mdl_user(mnethostid, username);

3.- Assign a valid mnethostid value for all of your users (this assumes that your site will have mnet_localhost_id value of '1', which is what 99'999% Moodle systems out there have):

INSERT INTO mdl_config (name, value) VALUES ('mnet_localhost_id', '1'); UPDATE mdl_user SET mnethostid=1 WHERE mnethostid=0;

This should fix the problem you are experiencing, but this is really a temporary hack. You should really inspect your database tables to see what mnet_* tables are missing, and what Moodle Network-related functionality is missing to.

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: Bulk User Actions in 1.9 beta 4

by e klopfer -
SOLVED. As I started exploring my databases, I figured something must be wrong. It turned out I was looking at an older backed up database before the 1.8 upgrade (sorry blush). I looked at the latest database and sure enough there are mnet tables and fields in there. And also sure enough the "guest" id was tagged as deleted. I changed that field from a 1 to a 0 and all is well again.

Thanks so much for helping to troubleshoot and sorry for the red herring.