Skip to content

Commit 73381e8

Browse files
committed
Temp debug code
1 parent dc4c1ef commit 73381e8

File tree

6 files changed

+56
-4
lines changed

6 files changed

+56
-4
lines changed

actions/temptruncatelogs.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//TODO DEBUGGING ONLY DELETE THIS
18+
19+
require_once(dirname(__FILE__) . '/../../../config.php');
20+
if (!is_siteadmin()) {
21+
echo "not allowed";
22+
die();
23+
}
24+
25+
$DB->execute("TRUNCATE TABLE {coursework_temp_logs}");
26+
echo 'ok';

classes/framework/table_base.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,11 @@ public static function get_from_id(int $id, int $strictness = IGNORE_MISSING): ?
681681
* @param int $id
682682
* @return \stdClass|null
683683
*/
684-
private static function get_db_record_from_id(int $id, int $strictness): ?object {
684+
protected static function get_db_record_from_id(int $id, int $strictness): ?object {
685685
global $DB;
686+
self::temp_log_query(static::$tablename, $id, '');
687+
//todo also failing behat tests https://github.com/ucl-isd/moodle-mod_coursework/actions/runs/22192548221/job/64184141521
688+
// (Mostly in deadline_extension tests)
686689
return $DB->get_record(static::$tablename, ['id' => $id], '*', $strictness) ?: null;
687690
}
688691

@@ -705,4 +708,24 @@ public function clear_cache() {
705708
$cachetoclear->delete($this->submissionid);
706709
}
707710
}
711+
712+
public static function temp_log_query(string $tablename, int $id, string $notes) {
713+
//todo delete this.
714+
global $DB;
715+
if (optional_param('logdb', false, PARAM_BOOL) && is_siteadmin()) {
716+
717+
if (optional_param('display', false, PARAM_BOOL)) {
718+
\core\notification::info($tablename . ' ' . $id . ' ' . $notes);
719+
}
720+
$ex = new \Exception();
721+
$log = (object)[
722+
'classname' => $tablename,
723+
'requestedid' => $id,
724+
'notes' => $notes,
725+
'stacetrace' => $ex->getTraceAsString(),
726+
'timecreated' => time()
727+
];
728+
$DB->insert_record('coursework_temp_logs', $log);
729+
}
730+
}
708731
}

classes/models/user.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function __construct($data = false) {
8181
* @return \stdClass|null
8282
*/
8383
protected static function get_db_record_from_id(int $id, int $strictness): ?object {
84+
parent::temp_log_query('user', $id, '');
8485
// In the case of user we override this so we don't get all DB fields, to avoid caching unnecessary data incl user hashed password.
8586
$userfields = 'id,email,suspended' . implode(',', \core_user\fields::get_name_fields());
8687
$user = \core_user::get_user($id, $userfields);

classes/traits/table_with_allocatable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use core\exception\invalid_parameter_exception;
2121
use core_cache\cache;
2222
use mod_coursework\allocation\allocatable;
23+
use mod_coursework\framework\table_base;
2324
use mod_coursework\models\assessment_set_membership;
2425
use mod_coursework\models\deadline_extension;
2526
use mod_coursework\models\group;
@@ -98,6 +99,7 @@ public static function get_for_allocatable(int $courseworkid, int $allocatableid
9899
*/
99100
private static function get_db_ids_from_allocatable(int $courseworkid, int $allocatableid, string $allocatabletype): array {
100101
global $DB;
102+
table_base::temp_log_query(static::class::$tablename, $allocatableid, 'get_db_ids_from_allocatable');
101103
return $DB->get_fieldset(
102104
static::class::$tablename,
103105
'id',

db/upgrade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ function xmldb_coursework_upgrade($oldversion) {
366366
}
367367

368368
//todo debugging only - delete this
369-
if ($oldversion < 2026022301) {
369+
if ($oldversion < 2026022303) {
370370

371371
// Define table coursework_temp_logs to be created.
372372
$table = new xmldb_table('coursework_temp_logs');
@@ -387,7 +387,7 @@ function xmldb_coursework_upgrade($oldversion) {
387387
}
388388

389389
// Coursework savepoint reached.
390-
upgrade_mod_savepoint(true, 2026022301, 'coursework');
390+
upgrade_mod_savepoint(true, 2026022303, 'coursework');
391391
}
392392

393393
// Always needs to return true.

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
$plugin->component = 'mod_coursework';
2626

27-
$plugin->version = 2026022302;
27+
$plugin->version = 2026022303;
2828
$plugin->requires = 2024100700;
2929

3030
$plugin->cron = 300; // Period for cron to check this module (secs).

0 commit comments

Comments
 (0)