From d7a67372cf862745fdcc764c11f5b0f70fe12b61 Mon Sep 17 00:00:00 2001 From: Tim Price Date: Tue, 13 Oct 2015 14:57:43 +1100 Subject: [PATCH 01/12] Add new custom directory option to store copy of report on filesystem --- db/install.xml | 5 +++-- db/upgrade.php | 15 +++++++++++++++ edit.php | 1 + edit_form.php | 10 ++++++++++ lang/en/report_customsql.php | 2 ++ locallib.php | 10 ++++++++++ version.php | 2 +- 7 files changed, 42 insertions(+), 3 deletions(-) mode change 100644 => 100755 db/install.xml diff --git a/db/install.xml b/db/install.xml old mode 100644 new mode 100755 index 456132c..08c71e3 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - @@ -22,6 +22,7 @@ + @@ -38,4 +39,4 @@ - + \ No newline at end of file diff --git a/db/upgrade.php b/db/upgrade.php index ee5e808..ea56f2c 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -160,5 +160,20 @@ function xmldb_report_customsql_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2015062900, 'report', 'customsql'); } + if ($oldversion < 2015101300) { + + // Define field customdir to be added to report_customsql_queries. + $table = new xmldb_table('report_customsql_queries'); + $field = new xmldb_field('customdir', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'categoryid'); + + // Conditionally launch add field customdir. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Customsql savepoint reached. + upgrade_plugin_savepoint(true, 2015101300, 'report', 'customsql'); + } + return true; } diff --git a/edit.php b/edit.php index 84c2fdb..d767e4b 100644 --- a/edit.php +++ b/edit.php @@ -74,6 +74,7 @@ $newreport->at = ''; $newreport->emailto = ''; $newreport->emailwhat = ''; + $newreport->customdir = ''; } if ($newreport->runable == 'manual' || empty($newreport->singlerow)) { $newreport->singlerow = 0; diff --git a/edit_form.php b/edit_form.php index 85e6721..ae01b9f 100644 --- a/edit_form.php +++ b/edit_form.php @@ -98,13 +98,16 @@ public function definition() { get_string('onerow', 'report_customsql')); $mform->addElement('text', 'emailto', get_string('emailto', 'report_customsql'), 'size = 70'); + $mform->addElement('text', 'customdir', get_string('customdir', 'report_customsql'), 'size = 70'); $mform->addElement('select', 'emailwhat', get_string('emailwhat', 'report_customsql'), report_customsql_email_options()); $mform->disabledIf('singlerow', 'runable', 'eq', 'manual'); $mform->disabledIf('at', 'runable', 'ne', 'daily'); $mform->disabledIf('emailto', 'runable', 'eq', 'manual'); + $mform->disabledIf('customdir', 'runable', 'eq', 'manual'); $mform->disabledIf('emailwhat', 'runable', 'eq', 'manual'); $mform->setType('emailto', PARAM_RAW); + $mform->setType('customdir', PARAM_RAW); // Add new category selection. $categoryoptions = report_customsql_category_options(); @@ -202,6 +205,13 @@ public function validation($data, $files) { $errors['querylimit'] = get_string('querylimitrange', 'report_customsql', REPORT_CUSTOMSQL_MAX_RECORDS); } + // Check that the custom directory is writable, if provided. + if (isset($data['customdir'])) { + if (!is_writable($data['customdir'])) { + $errors['customdir'] = get_string('directorynotwritable', 'report_customsql'); + } + } + return $errors; } diff --git a/lang/en/report_customsql.php b/lang/en/report_customsql.php index b9b4abc..4943e71 100644 --- a/lang/en/report_customsql.php +++ b/lang/en/report_customsql.php @@ -40,6 +40,7 @@ $string['categorynamex'] = 'Category name: {$a}'; $string['changetheparameters'] = 'Change the parameters'; $string['crontask'] = 'Ad-hoc database queries: run scheduled reports task'; +$string['customdir'] = 'Save file to directory'; $string['customsql:definequeries'] = 'Define custom queries'; $string['customsql:managecategories'] = 'Define custom categories'; $string['customsql:view'] = 'View custom queries report'; @@ -53,6 +54,7 @@ $string['deletethiscategory'] = 'Delete this category'; $string['deletethisreport'] = 'Delete this query'; $string['description'] = 'Description'; +$string['directorynotwritable'] = 'The directory you provided is not writable.'; $string['displayname'] = 'Query name'; $string['displaynamex'] = 'Query name: {$a}'; $string['displaynamerequired'] = 'You must enter a query name'; diff --git a/locallib.php b/locallib.php index 49b8067..7d881e2 100644 --- a/locallib.php +++ b/locallib.php @@ -112,6 +112,16 @@ function report_customsql_generate_csv($report, $timenow) { fclose($handle); } + // Copy the file to the custom directory. + if (!empty($report->customdir)) { + list($csvfilename, $csvtimestamp) = report_customsql_csv_filename($report, $timenow); + $filename = $report->id . '-' . basename($csvfilename); + // Make sure we always have a working path. + $filepath = rtrim($report->customdir, '/'); + $filepath = $filepath . '/' . $filename; + copy($csvfilename, $filepath); + } + // Update the execution time in the DB. $updaterecord = new stdClass; $updaterecord->id = $report->id; diff --git a/version.php b/version.php index d764470..97669a7 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2015071000; +$plugin->version = 2015101300; $plugin->requires = 2014041100; $plugin->component = 'report_customsql'; $plugin->maturity = MATURITY_STABLE; From 40e8fe791461a218006ca3d5502599ceef4c2ec0 Mon Sep 17 00:00:00 2001 From: Tim Price Date: Wed, 14 Oct 2015 10:26:00 +1100 Subject: [PATCH 02/12] Refactoring update to address Tim's feedback --- edit_form.php | 10 ++++++--- lang/en/report_customsql.php | 2 ++ locallib.php | 41 +++++++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/edit_form.php b/edit_form.php index ae01b9f..5856390 100644 --- a/edit_form.php +++ b/edit_form.php @@ -107,7 +107,8 @@ public function definition() { $mform->disabledIf('customdir', 'runable', 'eq', 'manual'); $mform->disabledIf('emailwhat', 'runable', 'eq', 'manual'); $mform->setType('emailto', PARAM_RAW); - $mform->setType('customdir', PARAM_RAW); + $mform->setType('customdir', PARAM_PATH); + $mform->addHelpButton('customdir', 'customdir', 'report_customsql'); // Add new category selection. $categoryoptions = report_customsql_category_options(); @@ -205,9 +206,12 @@ public function validation($data, $files) { $errors['querylimit'] = get_string('querylimitrange', 'report_customsql', REPORT_CUSTOMSQL_MAX_RECORDS); } - // Check that the custom directory is writable, if provided. + // Check that the custom directory is writable and a directory, if provided. if (isset($data['customdir'])) { - if (!is_writable($data['customdir'])) { + if (!is_dir($data['customdir'])) { + $errors['customdir'] = get_string('notadirectory', 'report_customsql'); + } + else if (!is_writable($data['customdir'])) { $errors['customdir'] = get_string('directorynotwritable', 'report_customsql'); } } diff --git a/lang/en/report_customsql.php b/lang/en/report_customsql.php index 4943e71..3b71200 100644 --- a/lang/en/report_customsql.php +++ b/lang/en/report_customsql.php @@ -41,6 +41,7 @@ $string['changetheparameters'] = 'Change the parameters'; $string['crontask'] = 'Ad-hoc database queries: run scheduled reports task'; $string['customdir'] = 'Save file to directory'; +$string['customdir_help'] = 'Files are saved in the CSV format. File names are of the format reportid-timecreated.csv'; $string['customsql:definequeries'] = 'Define custom queries'; $string['customsql:managecategories'] = 'Define custom categories'; $string['customsql:view'] = 'View custom queries report'; @@ -97,6 +98,7 @@ $string['norowsreturned'] = 'No rows were returned. This query should return one row.'; $string['noscheduleifplaceholders'] = 'Queries containing placeholders can only be run on-demand.'; $string['nosemicolon'] = 'You are not allowed a ; character in the SQL.'; +$string['notadirectory'] = 'The path provided is not a directory.'; $string['notallowedwords'] = 'You are not allowed to use the words {$a} in the SQL.'; $string['note'] = 'Notes'; $string['notrunyet'] = 'This query has not yet been run.'; diff --git a/locallib.php b/locallib.php index 7d881e2..5862e19 100644 --- a/locallib.php +++ b/locallib.php @@ -112,15 +112,6 @@ function report_customsql_generate_csv($report, $timenow) { fclose($handle); } - // Copy the file to the custom directory. - if (!empty($report->customdir)) { - list($csvfilename, $csvtimestamp) = report_customsql_csv_filename($report, $timenow); - $filename = $report->id . '-' . basename($csvfilename); - // Make sure we always have a working path. - $filepath = rtrim($report->customdir, '/'); - $filepath = $filepath . '/' . $filename; - copy($csvfilename, $filepath); - } // Update the execution time in the DB. $updaterecord = new stdClass; @@ -130,13 +121,19 @@ function report_customsql_generate_csv($report, $timenow) { $DB->update_record('report_customsql_queries', $updaterecord); // Report is runable daily, weekly or monthly. - if (($report->runable != 'manual') && !empty($report->emailto)) { + if ($report->runable != 'manual') { if ($csvfilenames) { foreach ($csvfilenames as $csvfilename) { - report_customsql_email_report($report, $csvfilename); + if (!empty($report->emailto)) { + report_customsql_email_report($report, $csvfilename); + } + report_customsql_copy_csv_to_customdir($report, $timenow, $csvfilename); } } else { // If there is no data. - report_customsql_email_report($report); + if (!empty($report->emailto)) { + report_customsql_email_report($report); + } + report_customsql_copy_csv_to_customdir($report, $timenow); } } return $csvtimestamp; @@ -651,3 +648,23 @@ function report_customsql_category_options() { global $DB; return $DB->get_records_menu('report_customsql_categories', null, 'name ASC', 'id, name'); } + +/** + * Copies a csv file to an optional custom directory. + * @param object $report + * @param integer $timenow + * @param string $csvfilename + */ +function report_customsql_copy_csv_to_customdir($report, $timenow, $csvfilename = null) { + // Copy the file to the custom directory. + if (!empty($report->customdir)) { + if (!$csvfilename) { + list($csvfilename, $csvtimestamp) = report_customsql_csv_filename($report, $timenow); + } + $filename = $report->id . '-' . basename($csvfilename); + // Make sure we always have a working path. + $filepath = rtrim($report->customdir, '/'); + $filepath = $filepath . '/' . $filename; + copy($csvfilename, $filepath); + } +} From af78630b6ddd63b4b6bf9c4965c656c5ca2b687b Mon Sep 17 00:00:00 2001 From: Tim Price Date: Thu, 15 Oct 2015 09:44:33 +1100 Subject: [PATCH 03/12] Allow no directory to be set --- edit_form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edit_form.php b/edit_form.php index 5856390..17b0644 100644 --- a/edit_form.php +++ b/edit_form.php @@ -207,7 +207,7 @@ public function validation($data, $files) { } // Check that the custom directory is writable and a directory, if provided. - if (isset($data['customdir'])) { + if (isset($data['customdir']) && !empty($data['customdir'])) { if (!is_dir($data['customdir'])) { $errors['customdir'] = get_string('notadirectory', 'report_customsql'); } From d98bbe5ab07fee83cb4a456f4300e2c73c88a62a Mon Sep 17 00:00:00 2001 From: Tim Price Date: Fri, 16 Oct 2015 10:37:28 +1100 Subject: [PATCH 04/12] Check file exists before attempting copy --- locallib.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/locallib.php b/locallib.php index 5862e19..a2b331a 100644 --- a/locallib.php +++ b/locallib.php @@ -665,6 +665,9 @@ function report_customsql_copy_csv_to_customdir($report, $timenow, $csvfilename // Make sure we always have a working path. $filepath = rtrim($report->customdir, '/'); $filepath = $filepath . '/' . $filename; - copy($csvfilename, $filepath); + // Check that the file we want to copy exists, if not do nothing. + if (file_exists($csvfilename)) { + copy($csvfilename, $filepath); + } } } From 1148946ada7bb4acfa438e49dc96887e858b544e Mon Sep 17 00:00:00 2001 From: Tim Price Date: Tue, 20 Oct 2015 10:58:57 +1100 Subject: [PATCH 05/12] Fixing file exists checks, allow to work if no records returned --- locallib.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/locallib.php b/locallib.php index 5862e19..e6cd75d 100644 --- a/locallib.php +++ b/locallib.php @@ -127,13 +127,14 @@ function report_customsql_generate_csv($report, $timenow) { if (!empty($report->emailto)) { report_customsql_email_report($report, $csvfilename); } - report_customsql_copy_csv_to_customdir($report, $timenow, $csvfilename); + if (!empty($report->customdir)) { + report_customsql_copy_csv_to_customdir($report, $timenow, $csvfilename); + } } } else { // If there is no data. if (!empty($report->emailto)) { report_customsql_email_report($report); } - report_customsql_copy_csv_to_customdir($report, $timenow); } } return $csvtimestamp; @@ -657,14 +658,12 @@ function report_customsql_category_options() { */ function report_customsql_copy_csv_to_customdir($report, $timenow, $csvfilename = null) { // Copy the file to the custom directory. - if (!empty($report->customdir)) { - if (!$csvfilename) { - list($csvfilename, $csvtimestamp) = report_customsql_csv_filename($report, $timenow); - } - $filename = $report->id . '-' . basename($csvfilename); - // Make sure we always have a working path. - $filepath = rtrim($report->customdir, '/'); - $filepath = $filepath . '/' . $filename; - copy($csvfilename, $filepath); - } + if (!$csvfilename) { + list($csvfilename, $csvtimestamp) = report_customsql_csv_filename($report, $timenow); + } + $filename = $report->id . '-' . basename($csvfilename); + // Make sure we always have a working path. + $filepath = rtrim($report->customdir, '/'); + $filepath = $filepath . '/' . $filename; + copy($csvfilename, $filepath); } From 83aeb3e3783319eaf66aa99a0a68975b6c47ba70 Mon Sep 17 00:00:00 2001 From: Tim Price Date: Tue, 20 Oct 2015 11:01:44 +1100 Subject: [PATCH 06/12] Revert "Check file exists before attempting copy" This reverts commit d98bbe5ab07fee83cb4a456f4300e2c73c88a62a. --- locallib.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/locallib.php b/locallib.php index a2b331a..5862e19 100644 --- a/locallib.php +++ b/locallib.php @@ -665,9 +665,6 @@ function report_customsql_copy_csv_to_customdir($report, $timenow, $csvfilename // Make sure we always have a working path. $filepath = rtrim($report->customdir, '/'); $filepath = $filepath . '/' . $filename; - // Check that the file we want to copy exists, if not do nothing. - if (file_exists($csvfilename)) { - copy($csvfilename, $filepath); - } + copy($csvfilename, $filepath); } } From cdc90326e0e2572dd91536d28eb67e48e4c654c3 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Mon, 5 Dec 2022 10:11:49 +1300 Subject: [PATCH 07/12] Fix #114 - return empty csv file (with headers) when no results. --- lib.php | 2 +- locallib.php | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib.php b/lib.php index 21013e6..8294dbf 100644 --- a/lib.php +++ b/lib.php @@ -89,7 +89,7 @@ function report_customsql_pluginfile($course, $cm, $context, $filearea, $args, $ if ($report->runable !== 'manual') { $runtime = $report->lastrun; } - $csvtimestamp = \report_customsql_generate_csv($report, $runtime); + $csvtimestamp = \report_customsql_generate_csv($report, $runtime, true); } list($csvfilename) = report_customsql_csv_filename($report, $csvtimestamp); diff --git a/locallib.php b/locallib.php index cd9fec4..6854140 100644 --- a/locallib.php +++ b/locallib.php @@ -96,7 +96,15 @@ function report_customsql_get_element_type($name) { return 'text'; } -function report_customsql_generate_csv($report, $timenow) { +/** + * Generate customsql csv file. + * + * @param stdclass $report - report record from customsql table. + * @param int $timetimenow - unix timestamp - usually "now()" + * @param bool $returnheaderwhenempty - if true will return a csv with the header row. + * @return void + */ +function report_customsql_generate_csv($report, $timenow, $returnheaderwhenempty = false) { global $DB; $starttime = microtime(true); @@ -104,6 +112,14 @@ function report_customsql_generate_csv($report, $timenow) { $queryparams = !empty($report->queryparams) ? unserialize($report->queryparams) : array(); $querylimit = $report->querylimit ?? get_config('report_customsql', 'querylimitdefault'); + if ($returnheaderwhenempty) { + // We want the export to always generate a CSV file so we modify the query slightly + // to generate an extra "null" values row, so we can get the column names, + // then we ignore rows that contain null records in every row when generating the csv. + $sql = "SELECT subq.* + FROM (SELECT 1) as ignoreme + LEFT JOIN ($sql) as subq on true"; + } // Query one extra row, so we can tell if we hit the limit. $rs = report_customsql_execute_query($sql, $queryparams, $querylimit + 1); @@ -124,6 +140,15 @@ function report_customsql_generate_csv($report, $timenow) { } $data = get_object_vars($row); + + if ($returnheaderwhenempty) { + // Ignore a row if it is full of null values. + $values = array_unique(array_values($data)); + if (empty($values) || (count($values) === 1 && $values[0] === null)) { + // This is a row with all null values - ignore it. + continue; + } + } foreach ($data as $name => $value) { if (report_customsql_get_element_type($name) == 'date_time_selector' && report_customsql_is_integer($value) && $value > 0) { From 485a8e75f637570c39f11664ed8349e79142a2f5 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Tue, 6 Dec 2022 09:06:45 +1300 Subject: [PATCH 08/12] Bump pg version in github action config. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2634621..d73dd5d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: services: postgres: - image: postgres:10 + image: postgres:12 env: POSTGRES_USER: 'postgres' POSTGRES_HOST_AUTH_METHOD: 'trust' From b2447ddc5c28429729fc7d0574e1a7c953322930 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Thu, 8 Dec 2022 12:50:23 +1300 Subject: [PATCH 09/12] Fix phpdocs and simplify check for empty row. --- locallib.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/locallib.php b/locallib.php index 6854140..44cd64f 100644 --- a/locallib.php +++ b/locallib.php @@ -99,10 +99,9 @@ function report_customsql_get_element_type($name) { /** * Generate customsql csv file. * - * @param stdclass $report - report record from customsql table. - * @param int $timetimenow - unix timestamp - usually "now()" - * @param bool $returnheaderwhenempty - if true will return a csv with the header row. - * @return void + * @param stdclass $report report record from customsql table. + * @param int $timetimenow unix timestamp - usually "now()" + * @param bool $returnheaderwhenempty if true, a CSV file with headers will always be generated, even if there are no results. */ function report_customsql_generate_csv($report, $timenow, $returnheaderwhenempty = false) { global $DB; @@ -141,13 +140,9 @@ function report_customsql_generate_csv($report, $timenow, $returnheaderwhenempty $data = get_object_vars($row); - if ($returnheaderwhenempty) { - // Ignore a row if it is full of null values. - $values = array_unique(array_values($data)); - if (empty($values) || (count($values) === 1 && $values[0] === null)) { - // This is a row with all null values - ignore it. - continue; - } + if ($returnheaderwhenempty && array_unique(array_values($data)) === [null]) { + // This is a row with all null values - ignore it. + continue; } foreach ($data as $name => $value) { if (report_customsql_get_element_type($name) == 'date_time_selector' && From 4862f67d4dc6a2ddb17fa366c980ede106ed9a4b Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Mon, 12 Dec 2022 15:35:06 +1300 Subject: [PATCH 10/12] Try a simple behat test --- tests/behat/behat_report_customsql.php | 22 ++++++++++++++++++++++ tests/behat/report_customsql.feature | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/tests/behat/behat_report_customsql.php b/tests/behat/behat_report_customsql.php index 70a09cc..e02c23e 100644 --- a/tests/behat/behat_report_customsql.php +++ b/tests/behat/behat_report_customsql.php @@ -238,6 +238,28 @@ public function adhoc_database_queries_thinks_the_time_is($time) { set_config('behat_fixed_time', $value, 'report_customsql'); } + /** + * Simulates downloading an empty report to ensure it shows table headers. + * + * For example: + * When downloading the empty custom sql report "Frog" it contains the headers "frogname,freddy" + * + * @Then /^downloading custom sql report "(?P[^"]*)" returns a file with headers "([^"]*)"$/ + * @param string $reportname the name of the report to go to. + * @param string $headers the headers that shuold be returned. + */ + public function downloading_custom_sql_report_x_returns_a_file_with_headers(string $reportname, string $headers) { + $report = $this->get_report_by_name($reportname); + $url = new \moodle_url('/pluginfile.php/1/'.'report_customsql'. '/'.'download'. '/'. $report->id, ['dataformat' => 'csv']); + + $session = $this->getSession()->getCookie('MoodleSession'); + $filecontent = trim(download_file_content($url, array('Cookie' => 'MoodleSession=' . $session))); + $filecontent = core_text::trim_utf8_bom($filecontent); + if ($filecontent != $headers) { + throw new \Behat\Mink\Exception\ExpectationException("File headers: $filecontent did not match expected: $headers", $this->getSession()); + } + } + /** * Find a report by name and get all the details. * diff --git a/tests/behat/report_customsql.feature b/tests/behat/report_customsql.feature index a831bd1..6c3e893 100644 --- a/tests/behat/report_customsql.feature +++ b/tests/behat/report_customsql.feature @@ -76,6 +76,13 @@ Feature: Ad-hoc database queries report And I view the "Test query" custom sql report Then I should see "This query did not return any data." + Scenario: Download an Ad-hoc database query that returns no data but includes headers + Given the following custom sql report exists: + | name | Test query | + | querysql | SELECT * FROM {config} WHERE name = '-1' | + When I log in as "admin" + Then downloading custom sql report "Test query" returns a file with headers "id,name,value" + Scenario: Create an Ad-hoc database queries category When I log in as "admin" And I navigate to "Reports > Ad-hoc database queries" in site administration From 882afea3e1d765de4722debc511fcb901d16a227 Mon Sep 17 00:00:00 2001 From: jnlar Date: Wed, 21 Dec 2022 14:30:17 +1100 Subject: [PATCH 11/12] Fix #123: Fix schema issues in report_customsql_categories --- db/upgrade.php | 16 ++++++++++++++++ tests/local/category_test.php | 2 +- version.php | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/db/upgrade.php b/db/upgrade.php index 2dc9304..7ee6350 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -269,5 +269,21 @@ function xmldb_report_customsql_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2021111600, 'report', 'customsql'); } + if ($oldversion < 2022031801) { + + // Changing nullability of field name on table report_customsql_categories to not null. + // Changing the default of field name on table report_customsql_categories to drop it. + $table = new xmldb_table('report_customsql_categories'); + $field = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'id'); + + // Launch change of nullability for field name. + $dbman->change_field_notnull($table, $field); + // Launch change of default for field name. + $dbman->change_field_default($table, $field); + + // Report savepoint reached. + upgrade_plugin_savepoint(true, 2022031801, 'report', 'customsql'); + } + return true; } diff --git a/tests/local/category_test.php b/tests/local/category_test.php index 51b0353..829a2bc 100644 --- a/tests/local/category_test.php +++ b/tests/local/category_test.php @@ -28,7 +28,7 @@ * @copyright 2021 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class _category_test extends \advanced_testcase { +class category_test extends \advanced_testcase { /** * Test create category. */ diff --git a/version.php b/version.php index fd29261..6e60617 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2022031800; +$plugin->version = 2022031801; $plugin->requires = 2020061500; $plugin->component = 'report_customsql'; $plugin->maturity = MATURITY_STABLE; From 40c30ec9e5f7d32f515299b372961bc740d46bb5 Mon Sep 17 00:00:00 2001 From: Jay Oswald Date: Wed, 13 Dec 2023 10:20:25 +1100 Subject: [PATCH 12/12] WR-416501 fix privacy test --- tests/privacy_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/privacy_test.php b/tests/privacy_test.php index 4f2cb6e..9e50e35 100644 --- a/tests/privacy_test.php +++ b/tests/privacy_test.php @@ -81,7 +81,7 @@ public function test_export_user_data(): void { $subcontext = [ get_string('privacy:metadata:reportcustomsqlqueries', 'report_customsql') ]; - $data = $writer->get_data($subcontext); + $data = (array)$writer->get_data($subcontext); $this->assertEquals('Report of user 1', reset($data)['displayname']); }