Skip to content

Commit

Permalink
Ad-hoc DB queries: Update to work with Moodle 4.0 #547714
Browse files Browse the repository at this point in the history
  • Loading branch information
AnupamaSarjoshi authored and timhunt committed Mar 18, 2022
1 parent 1a3b10c commit ef784d9
Show file tree
Hide file tree
Showing 18 changed files with 23 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
run: moodle-plugin-ci mustache

- name: grunt
if: ${{ always() }}
if: ${{ matrix.moodle-branch != 'master' }}
run: moodle-plugin-ci grunt

- name: phpunit
Expand Down
6 changes: 3 additions & 3 deletions categorydelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@

$category = $DB->get_record('report_customsql_categories', array('id' => $id));
if (!$category) {
print_error('invalidreportid', 'report_customsql', report_customsql_url('manage.php'), $id);
throw new moodle_exception('invalidreportid', 'report_customsql', report_customsql_url('manage.php'), $id);
}

if (optional_param('confirm', false, PARAM_BOOL)) {
require_sesskey();
if (!$queries = $DB->get_records('report_customsql_queries', array('categoryid' => $id))) {
$ok = $DB->delete_records('report_customsql_categories', array('id' => $id));
if (!$ok) {
print_error('errordeletingcategory', 'report_customsql', report_customsql_url('index.php'));
throw new moodle_exception('errordeletingcategory', 'report_customsql', report_customsql_url('index.php'));
}
report_customsql_log_delete($id);
} else {
print_error('errordeletingcategory', 'report_customsql', report_customsql_url('index.php'));
throw new moodle_exception('errordeletingcategory', 'report_customsql', report_customsql_url('index.php'));
}
redirect(report_customsql_url('manage.php'));
}
Expand Down
4 changes: 4 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log for the Ad-hoc database queries report

## Changes in 4.3

* This version works with Moodle 4.0.

## Changes in 4.2

* ...
Expand Down
1 change: 0 additions & 1 deletion classes/event/query_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

namespace report_customsql\event;
defined('MOODLE_INTERNAL') || die();

/**
* Event generated when a query is deleted.
Expand Down
1 change: 0 additions & 1 deletion classes/event/query_edited.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

namespace report_customsql\event;
defined('MOODLE_INTERNAL') || die();

/**
* Event generated when a query is edited.
Expand Down
1 change: 0 additions & 1 deletion classes/event/query_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

namespace report_customsql\event;
defined('MOODLE_INTERNAL') || die();

/**
* Event generated when a query is viewed.
Expand Down
2 changes: 0 additions & 2 deletions classes/task/run_reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*/

namespace report_customsql\task;
defined('MOODLE_INTERNAL') || die();


/**
* A scheduled task for Report Custom SQL, to run the scheduled reports.
Expand Down
3 changes: 0 additions & 3 deletions db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();


/**
* Install code for report_customsql.
*
Expand Down
5 changes: 1 addition & 4 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();


/**
* Upgrade code for report_customsql.
*
Expand Down Expand Up @@ -186,7 +183,7 @@ function xmldb_report_customsql_upgrade($oldversion) {
// Convert the contents of the emailto column from a list of usernames to a list of user ids.

// Transfer data from old columns into details.
// (There seem to be just a few thousand of these, so not too bad.)
// (There seem to be just a few thousand of these, so not too bad).
$queries = $DB->get_records_select('report_customsql_queries', 'emailto <> ?', [''], 'id', 'id, emailto');
$total = count($queries);

Expand Down
4 changes: 2 additions & 2 deletions delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

$report = $DB->get_record('report_customsql_queries', array('id' => $id));
if (!$report) {
print_error('invalidreportid', 'report_customsql', report_customsql_url('index.php'), $id);
throw new moodle_exception('invalidreportid', 'report_customsql', report_customsql_url('index.php'), $id);
}

if ($returnurl) {
Expand All @@ -48,7 +48,7 @@
if (optional_param('confirm', false, PARAM_BOOL)) {
$ok = $DB->delete_records('report_customsql_queries', array('id' => $id));
if (!$ok) {
print_error('errordeletingreport', 'report_customsql', report_customsql_url('index.php'));
throw new moodle_exception('errordeletingreport', 'report_customsql', report_customsql_url('index.php'));
}
report_customsql_log_delete($id);

Expand Down
6 changes: 3 additions & 3 deletions edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
if ($id) {
$report = $DB->get_record('report_customsql_queries', array('id' => $id));
if (!$report) {
print_error('invalidreportid', 'report_customsql', report_customsql_url('index.php'), $id);
throw new moodle_exception('invalidreportid', 'report_customsql', report_customsql_url('index.php'), $id);
}
$reportquerysql = $report->querysql;
$queryparams = !empty($report->queryparams) ? unserialize($report->queryparams) : array();
Expand Down Expand Up @@ -128,15 +128,15 @@
}
$ok = $DB->update_record('report_customsql_queries', $newreport);
if (!$ok) {
print_error('errorupdatingreport', 'report_customsql',
throw new moodle_exception('errorupdatingreport', 'report_customsql',
report_customsql_url('edit.php?id=' . $id));
}

} else {
$newreport->timecreated = $newreport->timemodified;
$id = $DB->insert_record('report_customsql_queries', $newreport);
if (!$id) {
print_error('errorinsertingreport', 'report_customsql',
throw new moodle_exception('errorinsertingreport', 'report_customsql',
report_customsql_url('edit.php'));
}
}
Expand Down
2 changes: 0 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Called by pluginfile, to download user generated reports via selected dataformat.
* Generated reports can also be downloaded via webservice/pluginfile.
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/report_customsql.feature
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Feature: Ad-hoc database queries report
| Query name | Test query |
| Query SQL | SELECT * FROM {config} WHERE name = 'version' |
And I press "Save changes"
And I follow "Ad-hoc database queries"
And I navigate to "Reports > Ad-hoc database queries" in site administration
And I follow "Special reports"
# Also test expand/collapse while we are here.
Then I should see "Test query"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @copyright 2020 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_users_testcase extends \externallib_advanced_testcase {
class external_get_users_test extends \externallib_advanced_testcase {

protected function setup_users(): array {
global $DB, $USER;
Expand Down
4 changes: 1 addition & 3 deletions tests/privacy_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

use \report_customsql\privacy\provider;
use core_privacy\local\request;

Expand All @@ -33,7 +31,7 @@
* @copyright 2021 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class report_customsql_privacy_testcase extends \core_privacy\tests\provider_testcase {
class privacy_test extends \core_privacy\tests\provider_testcase {

public function setUp(): void {
$this->resetAfterTest();
Expand Down
5 changes: 2 additions & 3 deletions tests/report_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

global $CFG;
Expand All @@ -33,7 +32,7 @@
* @copyright 2009 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class report_customsql_report_testcase extends advanced_testcase {
class report_test extends advanced_testcase {

/**
* Data provider for test_get_week_starts
Expand Down Expand Up @@ -186,7 +185,7 @@ public function test_report_customsql_get_ready_to_run_daily_reports() {
// Test entry 1.
// This report is supposed to run at the current hour (wehenver this test is run).
// The last run time recorded in the database is acutally tomorrow(!)
// relative to $timestamp. (Acutally timestamp is yesterday.)
// relative to $timestamp. (Acutally timestamp is yesterday).
$lastrun = $today;
$timestamp = $lastrun - ($today - $yesterday);
$id = $this->create_a_database_row('daily', $currenthour, $lastrun, null);
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2021111600;
$plugin->version = 2022031800;
$plugin->requires = 2020061500;
$plugin->component = 'report_customsql';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '4.2 for Moodle 3.9+';
$plugin->release = '4.3 for Moodle 3.9+';

$plugin->outestssufficient = true;
4 changes: 2 additions & 2 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
$urlparams = ['id' => $id];
$report = $DB->get_record('report_customsql_queries', array('id' => $id));
if (!$report) {
print_error('invalidreportid', 'report_customsql', report_customsql_url('index.php'), $id);
throw new moodle_exception('invalidreportid', 'report_customsql', report_customsql_url('index.php'), $id);
}

$category = $DB->get_record('report_customsql_categories', ['id' => $report->categoryid], '*', MUST_EXIST);
Expand Down Expand Up @@ -125,7 +125,7 @@
// Get the updated execution times.
$report = $DB->get_record('report_customsql_queries', array('id' => $id));
} catch (Exception $e) {
print_error('queryfailed', 'report_customsql', report_customsql_url('index.php'),
throw new moodle_exception('queryfailed', 'report_customsql', report_customsql_url('index.php'),
$e->getMessage());
}
} else {
Expand Down

0 comments on commit ef784d9

Please sign in to comment.