Example #1
0
 /**
  * Test conversion of semicolon separated custom parameters.
  */
 public function test_custom_parameter()
 {
     global $DB, $SITE, $USER;
     $custom1 = 'a=one;b=two;three=3';
     $custom2 = "a=one\nb=two\nthree=3";
     $this->resetAfterTest(true);
     $ltigenerator = $this->getDataGenerator()->get_plugin_generator('mod_lti');
     // Create 2 tools with custom parameters.
     $toolid1 = $DB->insert_record('lti_types', array('course' => $SITE->id, 'baseurl' => '', 'createdby' => $USER->id, 'timecreated' => time(), 'timemodified' => time()));
     $configid1 = $DB->insert_record('lti_types_config', array('typeid' => $toolid1, 'name' => 'customparameters', 'value' => $custom1));
     $toolid2 = $DB->insert_record('lti_types', array('course' => $SITE->id, 'baseurl' => '', 'createdby' => $USER->id, 'timecreated' => time(), 'timemodified' => time()));
     $configid2 = $DB->insert_record('lti_types_config', array('typeid' => $toolid2, 'name' => 'customparameters', 'value' => $custom2));
     // Create 2 instances with custom parameters.
     $activity1 = $ltigenerator->create_instance(array('course' => $SITE->id, 'name' => 'LTI activity 1', 'typeid' => $toolid1, 'toolurl' => '', 'instructorcustomparameters' => $custom1));
     $activity2 = $ltigenerator->create_instance(array('course' => $SITE->id, 'name' => 'LTI activity 2', 'typeid' => $toolid2, 'toolurl' => '', 'instructorcustomparameters' => $custom2));
     // Run upgrade script.
     mod_lti_upgrade_custom_separator();
     // Check semicolon-separated custom parameters have been updated but others have not.
     $config = $DB->get_record('lti_types_config', array('id' => $configid1));
     $this->assertEquals($config->value, $custom2);
     $config = $DB->get_record('lti_types_config', array('id' => $configid2));
     $this->assertEquals($config->value, $custom2);
     $config = $DB->get_record('lti', array('id' => $activity1->id));
     $this->assertEquals($config->instructorcustomparameters, $custom2);
     $config = $DB->get_record('lti', array('id' => $activity2->id));
     $this->assertEquals($config->instructorcustomparameters, $custom2);
 }
Example #2
0
/**
 * xmldb_lti_upgrade is the function that upgrades
 * the lti module database when is needed
 *
 * This function is automaticly called when version number in
 * version.php changes.
 *
 * @param int $oldversion New old version number.
 *
 * @return boolean
 */
function xmldb_lti_upgrade($oldversion)
{
    global $CFG, $DB;
    require_once __DIR__ . '/upgradelib.php';
    $dbman = $DB->get_manager();
    if ($oldversion < 2014060201) {
        // Changing type of field grade on table lti to int.
        $table = new xmldb_table('lti');
        $field = new xmldb_field('grade', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '100', 'instructorchoiceacceptgrades');
        // Launch change of type for field grade.
        $dbman->change_field_type($table, $field);
        // Lti savepoint reached.
        upgrade_mod_savepoint(true, 2014060201, 'lti');
    }
    if ($oldversion < 2014061200) {
        // Define table lti_tool_proxies to be created.
        $table = new xmldb_table('lti_tool_proxies');
        // Adding fields to table lti_tool_proxies.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'Tool Provider');
        $table->add_field('regurl', XMLDB_TYPE_TEXT, null, null, null, null, null);
        $table->add_field('state', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1');
        $table->add_field('guid', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table->add_field('secret', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table->add_field('vendorcode', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table->add_field('capabilityoffered', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
        $table->add_field('serviceoffered', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
        $table->add_field('toolproxy', XMLDB_TYPE_TEXT, null, null, null, null, null);
        $table->add_field('createdby', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        // Adding keys to table lti_tool_proxies.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Adding indexes to table lti_tool_proxies.
        $table->add_index('guid', XMLDB_INDEX_UNIQUE, array('guid'));
        // Conditionally launch create table for lti_tool_proxies.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Define table lti_tool_settings to be created.
        $table = new xmldb_table('lti_tool_settings');
        // Adding fields to table lti_tool_settings.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('toolproxyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        $table->add_field('course', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
        $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
        $table->add_field('settings', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        // Adding keys to table lti_tool_settings.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->add_key('toolproxy', XMLDB_KEY_FOREIGN, array('toolproxyid'), 'lti_tool_proxies', array('id'));
        $table->add_key('course', XMLDB_KEY_FOREIGN, array('course'), 'course', array('id'));
        $table->add_key('coursemodule', XMLDB_KEY_FOREIGN, array('coursemoduleid'), 'lti', array('id'));
        // Conditionally launch create table for lti_tool_settings.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Define table lti_types to be updated.
        $table = new xmldb_table('lti_types');
        // Adding fields to table lti_types.
        $field = new xmldb_field('toolproxyid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field('enabledcapability', XMLDB_TYPE_TEXT, null, null, null, null, null);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field('parameter', XMLDB_TYPE_TEXT, null, null, null, null, null);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field('icon', XMLDB_TYPE_TEXT, null, null, null, null, null);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field('secureicon', XMLDB_TYPE_TEXT, null, null, null, null, null);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Lti savepoint reached.
        upgrade_mod_savepoint(true, 2014061200, 'lti');
    }
    if ($oldversion < 2014100300) {
        mod_lti_upgrade_custom_separator();
        // Lti savepoint reached.
        upgrade_mod_savepoint(true, 2014100300, 'lti');
    }
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.9.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v3.0.0 release upgrade line.
    // Put any upgrade step following this.
    if ($oldversion < 2016041800) {
        // Define field description to be added to lti_types.
        $table = new xmldb_table('lti_types');
        $field = new xmldb_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null, 'timemodified');
        // Conditionally launch add field description.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Lti savepoint reached.
        upgrade_mod_savepoint(true, 2016041800, 'lti');
    }
    // Moodle v3.1.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v3.2.0 release upgrade line.
    // Put any upgrade step following this.
    if ($oldversion < 2016052301) {
        // Changing type of field value on table lti_types_config to text.
        $table = new xmldb_table('lti_types_config');
        $field = new xmldb_field('value', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'name');
        // Launch change of type for field value.
        $dbman->change_field_type($table, $field);
        // Lti savepoint reached.
        upgrade_mod_savepoint(true, 2016052301, 'lti');
    }
    return true;
}