diff --git a/classes/s3/helper.php b/classes/s3/helper.php index 9ddc8ab..4afe112 100644 --- a/classes/s3/helper.php +++ b/classes/s3/helper.php @@ -152,6 +152,8 @@ public static function upload_file(int $processid, int $instanceid, int $coursei $filedetails->courseid = $courseid; $filedetails->filename = $file->get_filename(); $filedetails->contenthash = $file->get_contenthash(); + $filedetails->bucketname = $settings['s3_bucket']; + $filedetails->timecreated = time(); $DB->insert_record('tool_lcbackupcoursestep_s3', $filedetails); } diff --git a/db/install.xml b/db/install.xml index 9dd452f..67ddad8 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - @@ -12,6 +12,8 @@ + + diff --git a/db/upgrade.php b/db/upgrade.php index 23a03ae..7a635b6 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -36,6 +36,8 @@ function xmldb_tool_lcbackupcoursestep_upgrade($oldversion) { global $DB; + $dbman = $DB->get_manager(); + if ($oldversion < 2023100401) { // New table to be created. $table = new xmldb_table('tool_lcbackupcoursestep_s3'); @@ -50,12 +52,33 @@ function xmldb_tool_lcbackupcoursestep_upgrade($oldversion) { $table->add_index('processid_idx', XMLDB_INDEX_NOTUNIQUE, ['processid']); $table->add_index('courseid_idx', XMLDB_INDEX_NOTUNIQUE, ['courseid']); - if (!$DB->get_manager()->table_exists($table)) { - $DB->get_manager()->create_table($table); + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); } upgrade_plugin_savepoint(true, 2023100401, 'tool', 'lcbackupcoursestep'); } + if ($oldversion < 2023100402) { + + // Define field bucketname to be added to tool_lcbackupcoursestep_s3. + $table = new xmldb_table('tool_lcbackupcoursestep_s3'); + + // Conditionally launch add field bucketname. + $field = new xmldb_field('bucketname', XMLDB_TYPE_CHAR, '512', null, null, null, null, 'contenthash'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Conditionally launch add field timecreated. + $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'bucketname'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Lcbackupcoursestep savepoint reached. + upgrade_plugin_savepoint(true, 2023100402, 'tool', 'lcbackupcoursestep'); + } + return true; } diff --git a/tests/step_test.php b/tests/step_test.php index 4aa2408..b08d87e 100644 --- a/tests/step_test.php +++ b/tests/step_test.php @@ -261,5 +261,6 @@ public function test_backup_course_step_s3() { $filedetails = $DB->get_record('tool_lcbackupcoursestep_s3', ['processid' => $process->id]); $this->assertEquals($filedetails->courseid, $this->course->id); $this->assertEquals($filedetails->filename, $file->filename); + $this->assertEquals('testbucket', $filedetails->testbucket); } } diff --git a/version.php b/version.php index 99d20cd..5a828c3 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023100401; +$plugin->version = 2023100402; $plugin->requires = 2020061500; $plugin->component = 'tool_lcbackupcoursestep';