. /** * Customcert module upgrade code. * * @package mod_customcert * @copyright 2016 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; /** * Customcert module upgrade code. * * @param int $oldversion the version we are upgrading from * @return bool always true */ function xmldb_customcert_upgrade($oldversion) { global $DB; $dbman = $DB->get_manager(); if ($oldversion < 2016052306) { $table = new xmldb_table('customcert_templates'); $field = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'id'); $dbman->change_field_precision($table, $field); // Savepoint reached. upgrade_mod_savepoint(true, 2016052306, 'customcert'); } if ($oldversion < 2016052308) { $table = new xmldb_table('customcert'); $field = new xmldb_field('emailstudents', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'requiredtime'); // Conditionally launch add field. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('emailteachers', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'emailstudents'); // Conditionally launch add field. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $field = new xmldb_field('emailothers', XMLDB_TYPE_TEXT, null, null, null, null, null, 'emailteachers'); // Conditionally launch add field. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $table = new xmldb_table('customcert_issues'); $field = new xmldb_field('emailed', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'code'); // Conditionally launch add field. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Savepoint reached. upgrade_mod_savepoint(true, 2016052308, 'customcert'); } if ($oldversion < 2016052310) { // Remove any duplicate rows from customcert issue table. // This SQL fetches the id of those records which have duplicate customcert issues. // This doesn't return the first issue. $fromclause = "FROM ( SELECT min(id) AS minid, userid, customcertid FROM {customcert_issues} GROUP BY userid, customcertid ) minid JOIN {customcert_issues} ci ON ci.userid = minid.userid AND ci.customcertid = minid.customcertid AND ci.id > minid.minid"; // Get the records themselves. $getduplicatessql = "SELECT ci.id $fromclause ORDER BY minid"; if ($records = $DB->get_records_sql($getduplicatessql)) { // Delete them. $ids = implode(',', array_keys($records)); $DB->delete_records_select('customcert_issues', "id IN ($ids)"); } // Savepoint reached. upgrade_mod_savepoint(true, 2016052310, 'customcert'); } if ($oldversion < 2016052311) { // Add column for new 'verifycertificateanyone' setting. $table = new xmldb_table('customcert'); $field = new xmldb_field('verifyany', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'requiredtime'); // Conditionally launch add field. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } // Savepoint reached. upgrade_mod_savepoint(true, 2016052311, 'customcert'); } if ($oldversion < 2016052314) { $table = new xmldb_table('customcert_elements'); $field = new xmldb_field('size'); // Rename column as it is a reserved word in Oracle. if ($dbman->field_exists($table, $field)) { $field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'font'); $dbman->rename_field($table, $field, 'fontsize'); } // Savepoint reached. upgrade_mod_savepoint(true, 2016052314, 'customcert'); } return true; }