Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Upgrade code for the feedback_editpdf module.
  19   *
  20   * @package   assignfeedback_editpdf
  21   * @copyright 2013 Jerome Mouneyrac
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * EditPDF upgrade code
  29   * @param int $oldversion
  30   * @return bool
  31   */
  32  function xmldb_assignfeedback_editpdf_upgrade($oldversion) {
  33      global $CFG, $DB;
  34  
  35      $dbman = $DB->get_manager();
  36  
  37      // Automatically generated Moodle v3.5.0 release upgrade line.
  38      // Put any upgrade step following this.
  39  
  40      if ($oldversion < 2018051401) {
  41          $table = new xmldb_table('assignfeedback_editpdf_queue');
  42          $field = new xmldb_field('attemptedconversions', XMLDB_TYPE_INTEGER, '10', null,
  43              XMLDB_NOTNULL, null, 0, 'submissionattempt');
  44  
  45          if (!$dbman->field_exists($table, $field)) {
  46              $dbman->add_field($table, $field);
  47          }
  48  
  49          // Attempts are removed from the queue after being processed, a duplicate row won't achieve anything productive.
  50          // So look for any duplicates and remove them so we can add a unique key.
  51          $sql = "SELECT MIN(id) as minid, submissionid, submissionattempt
  52                  FROM {assignfeedback_editpdf_queue}
  53                  GROUP BY submissionid, submissionattempt
  54                  HAVING COUNT(id) > 1";
  55  
  56          if ($duplicatedrows = $DB->get_recordset_sql($sql)) {
  57              foreach ($duplicatedrows as $row) {
  58                  $DB->delete_records_select('assignfeedback_editpdf_queue',
  59                      'submissionid = :submissionid AND submissionattempt = :submissionattempt AND id <> :minid', (array)$row);
  60              }
  61          }
  62          $duplicatedrows->close();
  63  
  64          // Define key submissionid-submissionattempt to be added to assignfeedback_editpdf_queue.
  65          $table = new xmldb_table('assignfeedback_editpdf_queue');
  66          $key = new xmldb_key('submissionid-submissionattempt', XMLDB_KEY_UNIQUE, ['submissionid', 'submissionattempt']);
  67  
  68          $dbman->add_key($table, $key);
  69  
  70          upgrade_plugin_savepoint(true, 2018051401, 'assignfeedback', 'editpdf');
  71      }
  72  
  73      // Automatically generated Moodle v3.6.0 release upgrade line.
  74      // Put any upgrade step following this.
  75  
  76      if ($oldversion < 2019010800) {
  77          // Define table assignfeedback_editpdf_rot to be created.
  78          $table = new xmldb_table('assignfeedback_editpdf_rot');
  79  
  80          // Adding fields to table assignfeedback_editpdf_rot.
  81          $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
  82          $table->add_field('gradeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
  83          $table->add_field('pageno', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
  84          $table->add_field('pathnamehash', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
  85          $table->add_field('isrotated', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
  86          $table->add_field('degree', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
  87  
  88          // Adding keys to table assignfeedback_editpdf_rot.
  89          $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
  90          $table->add_key('gradeid', XMLDB_KEY_FOREIGN, ['gradeid'], 'assign_grades', ['id']);
  91  
  92          // Adding indexes to table assignfeedback_editpdf_rot.
  93          $table->add_index('gradeid_pageno', XMLDB_INDEX_UNIQUE, ['gradeid', 'pageno']);
  94  
  95          // Conditionally launch create table for assignfeedback_editpdf_rot.
  96          if (!$dbman->table_exists($table)) {
  97              $dbman->create_table($table);
  98          }
  99  
 100          // Editpdf savepoint reached.
 101          upgrade_plugin_savepoint(true, 2019010800, 'assignfeedback', 'editpdf');
 102      }
 103  
 104      // Automatically generated Moodle v3.7.0 release upgrade line.
 105      // Put any upgrade step following this.
 106  
 107      // Automatically generated Moodle v3.8.0 release upgrade line.
 108      // Put any upgrade step following this.
 109  
 110      // Automatically generated Moodle v3.9.0 release upgrade line.
 111      // Put any upgrade step following this.
 112  
 113      // Automatically generated Moodle v3.10.0 release upgrade line.
 114      // Put any upgrade step following this.
 115  
 116      if ($oldversion < 2020110901) {
 117          // Remove submissions from the processing queue that have been processed.
 118          $sql = 'DELETE
 119                    FROM {assignfeedback_editpdf_queue}
 120                   WHERE EXISTS (SELECT 1
 121                                   FROM {assign_submission} s,
 122                                        {assign_grades} g
 123                                  WHERE s.id = submissionid
 124                                    AND s.assignment = g.assignment
 125                                    AND s.userid = g.userid
 126                                    AND s.attemptnumber = g.attemptnumber)';
 127  
 128          $DB->execute($sql);
 129  
 130          // Editpdf savepoint reached.
 131          upgrade_plugin_savepoint(true, 2020110901, 'assignfeedback', 'editpdf');
 132      }
 133  
 134      return true;
 135  }