report_customsql
Maintained by Tim Hunt, Mahmoud Kassaei
This report plugin allows Administrators to set up arbitrary database queries to act as ad-hoc reports. Reports can be of two types, either run on demand, or scheduled to run automatically. Other users with the right capability can go in and see a list of queries that they have access to. Results can be viewed on-screen or downloaded as CSV.
3294 sites
130 fans

This report, created by The Open University, lets Administrators set up arbitrary SQL select queries that anyone with the appropriate permissions can then run. Reports can be set to be runnable on-demand, or automatically run weekly or monthly.

The results are displayed as a fairly plain HTML table, and can also be downloaded as CSV.

The idea is that this lets you quicly set up ad-hoc reports, without having to create a whole new admin report plugin.

### Contributors

Mahmoud Kassaei: Developer

• Mon, Sep 7, 2020, 11:16 PM
Hi Tim,

From /var/log/apache2/error.log:

[Mon Sep 07 06:25:02.736876 2020] [mpm_prefork:notice] [pid 16451] AH00163: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g configured -- resuming normal operations
[Mon Sep 07 06:25:02.736915 2020] [core:notice] [pid 16451] AH00094: Command line: '/usr/sbin/apache2'
[Mon Sep 07 11:04:50.717559 2020] [php7:notice] [pid 4677] [client 192.168.1.70:47036] PHP Notice: Invalid get_string() identifier: 'fontsans' or component 'mod_certificate'. Perhaps you are missing $string['fontsans'] = ''; in mod/ce$
[Mon Sep 07 11:04:50.717617 2020] [php7:notice] [pid 4677] [client 192.168.1.70:47036] PHP Notice: Invalid get_string() identifier: 'fontsans_desc' or component 'mod_certificate'. Perhaps you are missing $string['fontsans_desc'] = '';$
[Mon Sep 07 11:04:50.717646 2020] [php7:notice] [pid 4677] [client 192.168.1.70:47036] PHP Notice: Invalid get_string() identifier: 'fontserif' or component 'mod_certificate'. Perhaps you are missing $string['fontserif'] = ''; in mod/$
[Mon Sep 07 11:04:50.717668 2020] [php7:notice] [pid 4677] [client 192.168.1.70:47036] PHP Notice: Invalid get_string() identifier: 'fontserif_desc' or component 'mod_certificate'. Perhaps you are missing $string['fontserif_desc'] = '$
[Mon Sep 07 11:05:21.130167 2020] [php7:warn] [pid 4673] [client 192.168.1.70:47102] PHP Warning: fopen(/var/moodledata/admin_report_customsql/temp/114/20200907-110508.csv): failed to open stream: No such file or directory in /var/www$[Mon Sep 07 11:05:21.130575 2020] [php7:notice] [pid 4673] [client 192.168.1.70:47102] Default exception handler: Unknown download file. Debug: \nError code: unknowndownloadfile\n* line 482 of /lib/setuplib.php: moodle_exception thrown$
[Mon Sep 07 11:09:24.954536 2020] [php7:notice] [pid 4672] [client 192.168.1.70:47418] PHP Notice: Invalid get_string() identifier: 'fontsans' or component 'mod_certificate'. Perhaps you are missing $string['fontsans'] = ''; in mod/ce$
[Mon Sep 07 11:09:24.954615 2020] [php7:notice] [pid 4672] [client 192.168.1.70:47418] PHP Notice: Invalid get_string() identifier: 'fontsans_desc' or component 'mod_certificate'. Perhaps you are missing $string['fontsans_desc'] = '';$
[Mon Sep 07 11:09:24.954645 2020] [php7:notice] [pid 4672] [client 192.168.1.70:47418] PHP Notice: Invalid get_string() identifier: 'fontserif' or component 'mod_certificate'. Perhaps you are missing $string['fontserif'] = ''; in mod/$
[Mon Sep 07 11:09:24.954666 2020] [php7:notice] [pid 4672] [client 192.168.1.70:47418] PHP Notice: Invalid get_string() identifier: 'fontserif_desc' or component 'mod_certificate'. Perhaps you are missing $string['fontserif_desc'] = '$
[Mon Sep 07 11:09:31.032453 2020] [php7:notice] [pid 4677] [client 192.168.1.70:47426] PHP Notice: Invalid get_string() identifier: 'fontsans' or component 'mod_certificate'. Perhaps you are missing $string['fontsans'] = ''; in mod/ce$
[Mon Sep 07 11:09:31.032507 2020] [php7:notice] [pid 4677] [client 192.168.1.70:47426] PHP Notice: Invalid get_string() identifier: 'fontsans_desc' or component 'mod_certificate'. Perhaps you are missing $string['fontsans_desc'] = '';$
[Mon Sep 07 11:09:31.032536 2020] [php7:notice] [pid 4677] [client 192.168.1.70:47426] PHP Notice: Invalid get_string() identifier: 'fontserif' or component 'mod_certificate'. Perhaps you are missing $string['fontserif'] = ''; in mod/$
[Mon Sep 07 11:09:31.032557 2020] [php7:notice] [pid 4677] [client 192.168.1.70:47426] PHP Notice: Invalid get_string() identifier: 'fontserif_desc' or component 'mod_certificate'. Perhaps you are missing $string['fontserif_desc'] = '$
[Mon Sep 07 11:09:56.152745 2020] [php7:warn] [pid 4674] [client 192.168.1.70:47480] PHP Warning: fopen(/var/moodledata/admin_report_customsql/temp/114/20200907-110951.csv): failed to open stream: No such file or directory in /var/www$[Mon Sep 07 11:09:56.153032 2020] [php7:notice] [pid 4674] [client 192.168.1.70:47480] Default exception handler: Unknown download file. Debug: \nError code: unknowndownloadfile\n* line 482 of /lib/setuplib.php: moodle_exception thrown$

Paul
• Tue, Sep 8, 2020, 12:02 AM
So, the error is coming from here: https://github.com/moodleou/moodle-report_customsql/blob/v3.9/download.php#L49. So, it is failing to find the CSV data for the report on disc. How is your Moodle site set up? What sort of storage is used for the moodledata folder?
• Tue, Sep 8, 2020, 12:17 AM
Hi Tim,
The moodle site is setup on a Ubuntu 16.04 LTS server. There is ample free space on the server with over 100GB provided of which we are using only about 19GB at the moment.
The Moodledata folder is in the path /var/moodledata. The permissions are set at 777 for the parent and subfolders.
When I examined the path referenced in the line [Mon Sep 07 11:09:56.152745 2020] [php7:warn] [pid 4674] [client 192.168.1.70:47480] PHP Warning: fopen(/var/moodledata/admin_report_customsql/temp/114/20200907-110951.csv): failed to open stream: No such file or directory in /var/www$, I was able to confirm that the path /var/moodledata/admin_report_customsql/temp and the file 20200807-110951.csv do exist. However, I am not sure where /var/www$ is coming from....

Thank you for your assistance on this issue!

Paul
• Tue, Sep 8, 2020, 12:19 AM
The \$ may just be Apache (unhelpfully) truncating the lines in the error log to a fixed lenght.
• Tue, Sep 8, 2020, 1:23 AM
Hi Tim,
Do you require any additional logs or server details?

Paul
• Tue, Sep 8, 2020, 7:53 PM
I don't need that. You need to work out why files are disappearing from your server's moodledata folder.
• Wed, Sep 9, 2020, 5:05 AM
Hi Paul, the download links for the reports work fine for me, even on Ubuntu 16.04. I am pretty sure it is a server configuration issue (most likely PHP), not a plugin issue.

Best regards,

Michael
• Wed, Sep 9, 2020, 5:08 AM
Could also be Apache mime types.
• Wed, Sep 9, 2020, 7:38 PM
Hello Tim and Michael,

We have been working to debug the issue on our moodle site, during which we have observed the following:
* The timestamp is being turned into a filename in a function called report_customsql_temp_cvs_name in locallib.php, which is called from both the view.php and download.php files.
* view.php is the report view, where you have the option to download the various types of reports.
* download.php is the PHP script that is supposed to return the file or display the error message.

The timestamp is the exact same when the function is called from view.php and download.php, but the filename that is created based on the timestamp is 5 hours different in the view.php instance than the download.php instance, even though it is the same function.

We suspect the download function fails because of the difference in the timestamp.

Any ideas? Your feedback is most welcome.

Paul
• Wed, Sep 9, 2020, 7:41 PM
Well down for working that out.

Sounds like a time-zone bug in the code. Please re-open the github issue I closed (or create a new one) with the details.

I am busy, so I don't know when I will be able to work on fixing this myself. Pull requests welcome.
• Wed, Oct 28, 2020, 9:35 AM
I'm using Moodle 3.9.2+ Build 20201028 and Ad-Hoc Database queries 3.9 for Moodle 3.5+ 2020062800. I have everything setup and can generate reports on demand. I can not, however, get reports to send email. Where can I go debug why it isn't happening? I've done all the regular debugging stuff, php error_log has nothing in it, I've turned PHP logging all the way up and still get nothing. What is the "thing" that sends the email? The cron job? If so, it never complains about anything. Any ideas where to go look? Thanks
• Wed, Oct 28, 2020, 11:33 AM
Hello Patrick,

What worked for us was to uninstall the plugin and re-install it.

There's a table in the Moodle database called 'mdl_message_providers', and for a plugin to be able to send out a message it needs to have an entry in that table. The site that was not sending scheduled reports had no entry for the report_customsql plugin. We backed up our custom reports, uninstalled the plugin, reinstalled and restored the backed up reports.
When we checked the database that message provider got added to the correct table in the database during the installation process and our daily scheduled reports started getting emailed right on time!

Hope this helps!

In the spirit of sharing,
Sarah
• Wed, Oct 28, 2020, 6:03 PM
Can other parts of Moodle send email? (E.g. forum subscription emails.) That is nother thing to text.
• Thu, Oct 29, 2020, 9:28 AM
@Sarah Ashley - I checked the DB and that value was indeed in the message_providers table. But just to be sure all was good, I uninstalled the plugin and reinstalled it, restored my sql and set it to run automatically, daily at 20:00. At 20:02, still nothing. @Tim Hunt yes. I tested this out and I received an email. I checked the task log and it is indeed running according to the log, but nothing is being sent. Anyone have any ideas or where I can go to troubleshoot?
• Thu, Oct 29, 2020, 5:51 PM
This is getting very puzzling. You could check under Site administration > Messaging > Notification settings, and Your profile -> Preferences -> Notification preferences. However, it would be surprising if that was wrong, particularly if you have just reinstalled.

And, might be worth setting Debugging to Developer level, to see if that makes a difference.

But, this is just standard Moodle messaging API. It should work. It does normally.