Merge branch 'MDL-66222-antivirus-reporting' of https://github.com/Peterburnett/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Thu, 27 Aug 2020 01:34:37 +0000 (09:34 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Thu, 27 Aug 2020 01:34:37 +0000 (09:34 +0800)
1  2 
admin/settings/plugins.php
lib/db/install.xml
lib/db/upgrade.php
version.php

Simple merge
Simple merge
@@@ -2542,124 -2539,27 +2542,147 @@@ function xmldb_main_upgrade($oldversion
          upgrade_main_savepoint(true, 2020072300.01);
      }
  
 -    if ($oldversion < 2020081400.01) {
 +    if ($oldversion < 2021052500.01) {
 +
 +        // Define field timecreated to be added to task_adhoc.
 +        $table = new xmldb_table('task_adhoc');
 +        $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'blocking');
 +
 +        // Conditionally launch add field timecreated.
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +
 +        // Main savepoint reached.
 +        upgrade_main_savepoint(true, 2021052500.01);
 +    }
 +
 +    if ($oldversion < 2021052500.02) {
 +        // Delete all user evidence files from users that have been deleted.
 +        $sql = "SELECT DISTINCT f.*
 +                  FROM {files} f
 +             LEFT JOIN {context} c ON f.contextid = c.id
 +                 WHERE f.component = :component
 +                   AND f.filearea = :filearea
 +                   AND c.id IS NULL";
 +        $stalefiles = $DB->get_records_sql($sql, ['component' => 'core_competency', 'filearea' => 'userevidence']);
 +
 +        $fs = get_file_storage();
 +        foreach ($stalefiles as $stalefile) {
 +            $fs->get_file_instance($stalefile)->delete();
 +        }
 +
 +        upgrade_main_savepoint(true, 2021052500.02);
 +    }
 +
 +    if ($oldversion < 2021052500.04) {
 +        // Define field metadatasettings to be added to h5p_libraries.
 +        $table = new xmldb_table('h5p_libraries');
 +        $field = new xmldb_field('metadatasettings', XMLDB_TYPE_TEXT, null, null, null, null, null, 'coreminor');
 +
 +        // Conditionally launch add field metadatasettings.
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +
 +        // Get installed library files that have no metadata settings value.
 +        $params = [
 +            'component' => 'core_h5p',
 +            'filearea' => 'libraries',
 +            'filename' => 'library.json',
 +        ];
 +        $sql = "SELECT l.id, f.id as fileid
 +                  FROM {files} f
 +             LEFT JOIN {h5p_libraries} l ON f.itemid = l.id
 +                 WHERE f.component = :component
 +                       AND f.filearea = :filearea
 +                       AND f.filename = :filename";
 +        $libraries = $DB->get_records_sql($sql, $params);
 +
 +        // Update metadatasettings field when the attribute is present in the library.json file.
 +        $fs = get_file_storage();
 +        foreach ($libraries as $library) {
 +            $jsonfile = $fs->get_file_by_id($library->fileid);
 +            $jsoncontent = json_decode($jsonfile->get_content());
 +            if (isset($jsoncontent->metadataSettings)) {
 +                unset($library->fileid);
 +                $library->metadatasettings = json_encode($jsoncontent->metadataSettings);
 +                $DB->update_record('h5p_libraries', $library);
 +            }
 +        }
 +
 +        // Main savepoint reached.
 +        upgrade_main_savepoint(true, 2021052500.04);
 +    }
 +
 +    if ($oldversion < 2021052500.05) {
 +        // Define fields to be added to task_scheduled.
 +        $table = new xmldb_table('task_scheduled');
 +        $field = new xmldb_field('timestarted', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'disabled');
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +        $field = new xmldb_field('hostname', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'timestarted');
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +        $field = new xmldb_field('pid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'hostname');
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +
 +        // Define fields to be added to task_adhoc.
 +        $table = new xmldb_table('task_adhoc');
 +        $field = new xmldb_field('timestarted', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'blocking');
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +        $field = new xmldb_field('hostname', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'timestarted');
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +        $field = new xmldb_field('pid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'hostname');
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +
 +        // Define fields to be added to task_log.
 +        $table = new xmldb_table('task_log');
 +        $field = new xmldb_field('hostname', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'output');
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +        $field = new xmldb_field('pid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'hostname');
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +
 +        // Main savepoint reached.
 +        upgrade_main_savepoint(true, 2021052500.05);
 +    }
 +
++    if ($oldversion < 2021052500.06) {
+         // Define table to store virus infected details.
+         $table = new xmldb_table('infected_files');
+         // Adding fields to table infected_files.
+         $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+         $table->add_field('filename', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
+         $table->add_field('quarantinedfile', XMLDB_TYPE_TEXT, null, null, null, null, null);
+         $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+         $table->add_field('reason', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
+         $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
+         // Adding keys to table infected_files.
+         $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
+         $table->add_key('userid', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']);
+         // Conditionally launch create table for infected_files.
+         if (!$dbman->table_exists($table)) {
+             $dbman->create_table($table);
+         }
 -        upgrade_main_savepoint(true, 2020081400.01);
++        upgrade_main_savepoint(true, 2021052500.06);
+     }
++
      return true;
  }
diff --cc version.php
@@@ -29,9 -29,9 +29,9 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2021052500.05;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2020081400.01;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2021052500.06;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.
 -$release  = '4.0dev (Build: 20200814)'; // Human-friendly version name
 -$branch   = '40';                       // This version's branch.
 +$release  = '4.0dev (Build: 20200822)'; // Human-friendly version name
 +$branch   = '400';                      // This version's branch.
  $maturity = MATURITY_ALPHA;             // This version's maturity level.