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

fix #3 rename table and change sql in upgrade for compatibility with … #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion classes/lifecycle/log_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct($filterdata = []) {
f.filename as filename, f.filesize as filesize, f.timecreated as createdat';
$from = '{files} f
JOIN {context} c ON c.id = f.contextid
LEFT JOIN {tool_lcbackupcourselogstep_metadata} md ON f.id = md.fileid';
LEFT JOIN {tool_lcbackupcourselogstep_m} md ON f.id = md.fileid';

$where = ["f.component = :component AND filename <> '.'"];
$params = ['component' => 'tool_lcbackupcourselogstep'];
Expand Down
2 changes: 1 addition & 1 deletion classes/lifecycle/step.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function process_course($processid, $instanceid, $course) {
// Write data to file.
$newfile = dataformat::write_data_to_filearea($filerecord, $fileformat, $columns, $logs);

$DB->insert_record('tool_lcbackupcourselogstep_metadata', [
$DB->insert_record('tool_lcbackupcourselogstep_m', [
'shortname' => $course->shortname,
'fullname' => $course->fullname,
'oldcourseid' => $course->id,
Expand Down
12 changes: 6 additions & 6 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="tool_lcbackupcourselogstep_metadata" COMMENT="Metadata for course logs.">
<TABLE NAME="tool_lcbackupcourselogstep_m" COMMENT="Metadata for course logs.">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="true"/>
<FIELD NAME="fullname" TYPE="char" LENGTH="255" NOTNULL="true"/>
<FIELD NAME="oldcourseid" TYPE="int" LENGTH="10" NOTNULL="true"/>
<FIELD NAME="fileid" TYPE="int" LENGTH="10" NOTNULL="true"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Timestamp when the log file was created"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="fullname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="oldcourseid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="fileid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" COMMENT="Timestamp when the log file was created" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
28 changes: 19 additions & 9 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
*/
function xmldb_tool_lcbackupcourselogstep_upgrade($oldversion) {
global $DB;
$dbman = $DB->get_manager();

if ($oldversion < 2024102000) {

$table = new xmldb_table('tool_lcbackupcourselogstep_metadata');
$table = new xmldb_table('tool_lcbackupcourselogstep_m');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused. Why do we need to change the table name in the past upgrade steps? Shouldn't we have tool_lcbackupcourselogstep_metadata table in that older version of the plugin?


$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
Expand All @@ -50,7 +51,7 @@ function xmldb_tool_lcbackupcourselogstep_upgrade($oldversion) {
}

$sql1 = "
INSERT INTO {tool_lcbackupcourselogstep_metadata} (shortname, fullname, oldcourseid, fileid, timecreated)
INSERT INTO {tool_lcbackupcourselogstep_m} (shortname, fullname, oldcourseid, fileid, timecreated)
SELECT crs.shortname,
crs.fullname,
crs.id AS oldcourseid,
Expand All @@ -74,13 +75,15 @@ function xmldb_tool_lcbackupcourselogstep_upgrade($oldversion) {
UPDATE {files}
SET contextid = :contextid
WHERE id IN (
SELECT f.id
FROM {files} f
JOIN {context} ctx ON ctx.id = f.contextid
WHERE ctx.contextlevel = :contextlevel
AND f.component = :component
AND f.filearea = :filearea
)
SELECT id FROM (
SELECT f.id
FROM {files} f
JOIN {context} ctx ON ctx.id = f.contextid
WHERE ctx.contextlevel = :contextlevel
AND f.component = :component
AND f.filearea = :filearea
) as fs
)
";
$DB->execute($sql2, [
'contextid' => \context_system::instance()->id,
Expand All @@ -91,6 +94,13 @@ function xmldb_tool_lcbackupcourselogstep_upgrade($oldversion) {

upgrade_plugin_savepoint(true, 2024102000, 'tool', 'lcbackupcourselogstep');
}
if ($oldversion < 2025022000) {
$table = new xmldb_table('tool_lcbackupcourselogstep_metadata');
if ($dbman->table_exists($table)) {
$dbman->rename_table($table, 'tool_lcbackupcourselogstep_m');
}
upgrade_plugin_savepoint(true, 2025022000, 'tool', 'lcbackupcourselogstep');
}

return true;
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

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

$plugin->version = 2024102000;
$plugin->requires = 2022041200;
$plugin->version = 2025022000;
$plugin->requires = 2022112800;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's behind this minimum Moodle version bump?

$plugin->component = 'tool_lcbackupcourselogstep';

$plugin->dependencies = [
Expand Down
Loading