Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTP-3794 Make sure is_locked function return boolean result #9

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions classes/assess_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ public static function is_summative(int $cmid): bool {
*/
public static function is_locked(int $cmid): bool {
global $DB;
if ($r = $DB->get_record('local_assess_type', ['cmid' => $cmid])) {
return $r->locked;
}
return false;
$record = $DB->get_record('local_assess_type', ['cmid' => $cmid], 'locked');

return (bool) ($record->locked ?? false);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="local/assess_type/db" VERSION="20240902" COMMENT="XMLDB file for UCL"
<XMLDB PATH="local/assess_type/db" VERSION="20240913" COMMENT="XMLDB file for UCL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand All @@ -8,10 +8,10 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Foreign key of course id"/>
<FIELD NAME="cmid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Foreign key cm id"/>
<FIELD NAME="gradeitemid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="type" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="The value of this datum"/>
<FIELD NAME="locked" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Locked field"/>
<FIELD NAME="cmid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Foreign key cm id"/>
<FIELD NAME="gradeitemid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="type" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="The value of this datum"/>
<FIELD NAME="locked" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Locked field"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
67 changes: 67 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

/**
* Plugin upgrade steps are defined here.
*
* @package local_assess_type
* @category upgrade
* @copyright 2024 onwards University College London {@link https://www.ucl.ac.uk/}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Alex Yeung <[email protected]>
*/

/**
* Execute local_assess_type upgrade from the given old version.
*
* @param int $oldversion
* @return bool
*/
function xmldb_local_assess_type_upgrade($oldversion) {
global $DB;
$dbman = $DB->get_manager();

if ($oldversion < 2024091300) {
$table = new xmldb_table('local_assess_type');

$field = new xmldb_field('cmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'courseid');
// Launch change of nullability for field cmid.
$dbman->change_field_notnull($table, $field);
// Launch change of default for field cmid.
$dbman->change_field_default($table, $field);

$field = new xmldb_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'cmid');
// Launch change of nullability for field gradeitemid.
$dbman->change_field_notnull($table, $field);
// Launch change of default for field gradeitemid.
$dbman->change_field_default($table, $field);

$field = new xmldb_field('type', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, 'gradeitemid');
// Launch change of nullability for field type.
$dbman->change_field_notnull($table, $field);

$field = new xmldb_field('locked', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'type');
// Launch change of nullability for field locked.
$dbman->change_field_notnull($table, $field);
// Launch change of default for field locked.
$dbman->change_field_default($table, $field);

// Assess_type savepoint reached.
upgrade_plugin_savepoint(true, 2024091300, 'local', 'assess_type');
}

return true;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@

$plugin->component = 'local_assess_type';
$plugin->release = '1.0';
$plugin->version = 2024080600; // YYYYMMDD.
$plugin->version = 2024091300; // YYYYMMDD.
$plugin->requires = 2023100900;
$plugin->maturity = MATURITY_STABLE;