Skip to content

Commit

Permalink
Additional details
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Nguyen committed Oct 25, 2024
1 parent bf0e71e commit 29bbf56
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions classes/s3/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion 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="admin/tool/lcbackupcoursestep/db" VERSION="20241023" COMMENT="XMLDB file for Moodle admin/tool/lcbackupcoursestep"
<XMLDB PATH="admin/tool/lcbackupcoursestep/db" VERSION="20241025" COMMENT="XMLDB file for Moodle admin/tool/lcbackupcoursestep"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
Expand All @@ -12,6 +12,8 @@
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Course ID"/>
<FIELD NAME="filename" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Name of the uploaded file"/>
<FIELD NAME="contenthash" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" COMMENT="Content hash of the uploaded file"/>
<FIELD NAME="bucketname" TYPE="char" LENGTH="512" NOTNULL="false" SEQUENCE="false" COMMENT="Name of the s3 bucket"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
27 changes: 25 additions & 2 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
}
1 change: 1 addition & 0 deletions tests/step_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

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

$plugin->version = 2023100401;
$plugin->version = 2023100402;
$plugin->requires = 2020061500;
$plugin->component = 'tool_lcbackupcoursestep';

Expand Down

0 comments on commit 29bbf56

Please sign in to comment.