function ouwiki_update_instance($ouwiki)
{
    global $CFG;
    $ok = true;
    $ouwiki->id = $ouwiki->instance;
    // Set up null values
    $nullvalues = array('editbegin', 'editend', 'timeout');
    foreach ($nullvalues as $nullvalue) {
        if (empty($ouwiki->{$nullvalue})) {
            unset($ouwiki->{$nullvalue});
            $ok &= execute_sql("UPDATE {$CFG->prefix}ouwiki SET {$nullvalue}=NULL WHERE id={$ouwiki->id}", false);
        }
    }
    if (strlen(preg_replace('/(<.*?>)|(&.*?;)|\\s/', '', $ouwiki->summary)) == 0) {
        unset($ouwiki->summary);
        $ok &= execute_sql("UPDATE {$CFG->prefix}ouwiki SET summary=NULL WHERE id={$ouwiki->id}", false);
    }
    ouwiki_check_groups($ouwiki);
    // insitu editing
    if (class_exists('ouflags') && has_capability('local/course:revisioneditor', get_context_instance(CONTEXT_COURSE, $ouwiki->course), null, false)) {
        include_once $CFG->dirroot . '/local/insitu/lib.php';
        return oci_mod_make_backup_and_save_instance($ouwiki);
    }
    // Update main record
    $ok &= update_record("ouwiki", $ouwiki);
    return $ok;
}
Beispiel #2
0
function xmldb_artefact_calendar_upgrade($oldversion = 0)
{
    if ($oldversion < 2013062404) {
        $table = new XMLDBTable('artefact_calendar_reminder');
        drop_table($table);
        $table->addFieldInfo('user', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addFieldInfo('reminder_type', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL);
        $table->addFieldInfo('reminder_date', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '-1', null);
        $table->addKeyInfo('reminder_pk', XMLDB_KEY_PRIMARY, array('user'));
        if (!create_table($table)) {
            throw new SQLException($table . " could not be created, check log for errors.");
        }
        execute_sql('ALTER TABLE {artefact_calendar_calendar} DROP COLUMN {reminder_status}');
    }
    if ($oldversion < 2013062501) {
        execute_sql('ALTER TABLE {artefact_calendar_calendar} change {reminder_date} {reminder_date} int(4) NOT NULL;');
    }
    if ($oldversion < 2013063001) {
        $table = new XMLDBTable('artefact_calendar_event');
        $table->addFieldInfo('eventid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addFieldInfo('begin', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addFieldInfo('end', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addFieldInfo('whole_day', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL);
        $table->addFieldInfo('repeat_type', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL);
        $table->addFieldInfo('repeats_every', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL);
        $table->addFieldInfo('end_date', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addFieldInfo('ends_after', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL);
        $table->addKeyInfo('event_pk', XMLDB_KEY_PRIMARY, array('eventid'));
        if (!create_table($table)) {
            throw new SQLException($table . " could not be created, check log for errors.");
        }
    }
    return true;
}
Beispiel #3
0
function xmldb_artefact_comment_upgrade($oldversion = 0)
{
    $success = true;
    if ($oldversion < 2011011201) {
        $table = new XMLDBTable('artefact_comment_comment');
        $field = new XMLDBField('rating');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED);
        $success = $success && add_field($table, $field);
    }
    if ($oldversion < 2013072400) {
        $table = new XMLDBTable('artefact_comment_comment');
        $field = new XMLDBField('lastcontentupdate');
        $field->setAttributes(XMLDB_TYPE_DATETIME);
        $success = $success && add_field($table, $field);
        $success = $success && execute_sql('update {artefact_comment_comment} acc
            set lastcontentupdate = (
                select a.mtime
                from {artefact} a
                where a.id = acc.artefact
            )');
    }
    if ($oldversion < 2015081000) {
        // Set default maxindent for threaded comments
        set_config_plugin('artefact', 'comment', 'maxindent', 5);
    }
    return $success;
}
function xmldb_assignment_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2007091900) {
        /// MDL-11268
        /// Changing nullability of field data1 on table assignment_submissions to null
        $table = new XMLDBTable('assignment_submissions');
        $field = new XMLDBField('data1');
        $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'numfiles');
        /// Launch change of nullability for field data1
        $result = $result && change_field_notnull($table, $field);
        /// Changing nullability of field data2 on table assignment_submissions to null
        $field = new XMLDBField('data2');
        $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'data1');
        /// Launch change of nullability for field data2
        $result = $result && change_field_notnull($table, $field);
    }
    if ($result && $oldversion < 2007091902) {
        // add draft tracking default to existing upload assignments
        $sql = "UPDATE {$CFG->prefix}assignment SET var4=1 WHERE assignmenttype='upload'";
        $result = execute_sql($sql);
    }
    //===== 1.9.0 upgrade line ======//
    if ($result && $oldversion < 2007101511) {
        notify('Processing assignment grades, this may take a while if there are many assignments...', 'notifysuccess');
        // change grade typo to text if no grades MDL-13920
        require_once $CFG->dirroot . '/mod/assignment/lib.php';
        // too much debug output
        $db->debug = false;
        assignment_update_grades();
        $db->debug = true;
    }
    return $result;
}
function xmldb_artefact_resume_upgrade($oldversion = 0)
{
    $status = true;
    if ($oldversion < 2009122100) {
        $table = new XMLDBTable('artefact_resume_employmenthistory');
        $field = new XMLDBField('employeraddress');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        add_field($table, $field);
        $table = new XMLDBTable('artefact_resume_educationhistory');
        $field = new XMLDBField('institutionaddress');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        add_field($table, $field);
    }
    if ($oldversion < 2010020300) {
        $table = new XMLDBTable('artefact_resume_educationhistory');
        $field = new XMLDBField('qualtype');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        change_field_notnull($table, $field);
        $table = new XMLDBTable('artefact_resume_educationhistory');
        $field = new XMLDBField('qualname');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        change_field_notnull($table, $field);
    }
    if ($oldversion < 2013071300) {
        $table = new XMLDBTable('artefact_resume_book');
        $field = new XMLDBField('url');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        add_field($table, $field);
    }
    if ($oldversion < 2013072900) {
        execute_sql("UPDATE {blocktype_installed_category} SET category = 'internal' WHERE category = 'resume'");
    }
    return $status;
}
Beispiel #6
0
function log($log)
{
    //Insert new log to the database
    $date = new date(DATE_ATOM);
    $sql = "INSERT INTO  mdl_deva_log (description, date) VALUES ('" . $log . "','" . $date . "');";
    execute_sql($sql);
}
function backup_upgrade($oldversion = 0)
{
    global $CFG;
    $result = true;
    if ($oldversion < 2006011600 and $result) {
        $result = execute_sql("DROP TABLE {$CFG->prefix}backup_files");
        if ($result) {
            $result = execute_sql("CREATE TABLE {$CFG->prefix}backup_files (\n                          id SERIAL PRIMARY KEY,\n                          backup_code integer NOT NULL default '0',\n                          file_type varchar(10) NOT NULL default '',\n                          path varchar(255) NOT NULL default '',\n                          old_id integer default NULL,\n                          new_id integer default NULL,\n                          CONSTRAINT {$CFG->prefix}backup_files_uk UNIQUE (backup_code, file_type, path))");
        }
        if ($result) {
            $result = execute_sql("DROP TABLE {$CFG->prefix}backup_ids");
        }
        if ($result) {
            $result = execute_sql("CREATE TABLE {$CFG->prefix}backup_ids (\n                          id SERIAL PRIMARY KEY,\n                          backup_code integer NOT NULL default '0',\n                          table_name varchar(30) NOT NULL default '',\n                          old_id integer NOT NULL default '0',\n                          new_id integer default NULL,\n                          info text,\n                          CONSTRAINT {$CFG->prefix}backup_ids_uk UNIQUE (backup_code, table_name, old_id))");
        }
    }
    if ($oldversion < 2006042801) {
        table_column('backup_log', 'time', 'time', 'integer', '', '', '0');
        table_column('backup_log', 'laststarttime', 'laststarttime', 'integer', '', '', '0');
        table_column('backup_log', 'courseid', 'courseid', 'integer', '', '', '0');
        table_column('backup_courses', 'lastendtime', 'lastendtime', 'integer', '', '', '0');
        table_column('backup_courses', 'laststarttime', 'laststarttime', 'integer', '', '', '0');
        table_column('backup_courses', 'courseid', 'courseid', 'integer', '', '', '0');
        table_column('backup_courses', 'nextstarttime', 'nextstarttime', 'integer', '', '', '0');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    //Finally, return result
    return $result;
}
function game_insert_glossaries_ids($course, $backup_unique_code, $instances = null)
{
    global $CFG;
    // Insert categories used by games
    $status = execute_sql("INSERT INTO {$CFG->prefix}backup_ids\n                                   (backup_code, table_name, old_id, info)\n                               SELECT DISTINCT {$backup_unique_code}, 'glossary', g.glossaryid, ''\n                               FROM {$CFG->prefix}game g\n                               WHERE g.course={$course}", false);
    return $status;
}
function certificate_upgrade($oldversion)
{
    global $CFG;
    if ($oldversion < 2006081700) {
        execute_sql(" ALTER TABLE `{$CFG->prefix}certificate_issues` CHANGE `classname` `classname` VARCHAR( 254 )");
    }
    return true;
}
Beispiel #10
0
function log($log)
{
    //Insert new log to the database
    //$date = new date(DATE_ATOM);
    $date = new date("yyyy-mm-dd HH:ii:ss");
    $sql = "INSERT INTO  mdl_shoppingcart_log (description, date) VALUES ('" . $log . "','" . $date . "');";
    execute_sql($sql);
}
function email_upgrade($oldversion = 0)
{
    global $CFG;
    $result = true;
    if ($oldversion < 2005012800 && $result) {
        execute_sql(" create table " . $CFG->prefix . "block_quickmail_log\n                    ( id int(10) unsigned not null auto_increment,\n                      courseid int(10) unsigned not null,\n                      userid int(10) unsigned not null,\n                      mailto text not null,\n                      subject varchar(255) not null,\n                      message text not null,\n                      attachment varchar(255) not null,\n                      format tinyint(3) unsigned not null default 1,\n                      timesent int(10) unsigned not null,\n                      PRIMARY KEY  (`id`)\n                    )");
    }
    return $result;
}
Beispiel #12
0
function db_setUserTimeZone($userId, $timeZoneId)
{
    try {
        $sql = "UPDATE mdl_user_info_data SET data ='" . $timeZoneId . "' WHERE userid = " . $userId . " and fieldid = 4";
        execute_sql($sql, false);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}
Beispiel #13
0
function hotpot_upgrade($oldversion)
{
    global $CFG;
    $ok = true;
    // set path to update functions
    $update_to_v2 = "{$CFG->dirroot}/mod/hotpot/db/update_to_v2.php";
    // if the version number indicates this could be an early HotPot v2.1 (Moodle 1.6),
    // check this is not actually HotPot v1 or v2.0 (Moodle 1.5) with an overly advanced version number
    if ($oldversion > 2005031400 && $oldversion <= 2006082899) {
        require_once $update_to_v2;
        if (hotpot_db_table_exists('hotpot_attempts')) {
            if (hotpot_db_field_exists('hotpot_attempts', 'details')) {
                // HotPot v2.0 (Moodle 1.5)
                $oldversion = 2005031400;
            }
        } else {
            // HotPot v1
            $oldversion = 2004122000;
        }
    }
    if ($oldversion < 2004021400) {
        execute_sql(" ALTER TABLE `{$CFG->prefix}hotpot_events` ADD `starttime` INT(10) unsigned NOT NULL DEFAULT '0' AFTER `time`");
        execute_sql(" ALTER TABLE `{$CFG->prefix}hotpot_events` ADD `endtime` INT(10) unsigned NOT NULL DEFAULT '0' AFTER `time`");
    }
    // update from HotPot v1 to HotPot v2
    if ($oldversion < 2005031400) {
        require_once $update_to_v2;
        $ok = $ok && hotpot_update_to_v2_from_v1();
    }
    if ($oldversion < 2005090700) {
        require_once $update_to_v2;
        $ok = $ok && hotpot_update_to_v2_1();
    }
    if ($oldversion > 2005031419 && $oldversion < 2005090702) {
        // update to from HotPot v2.1.0 or v2.1.1
        require_once $update_to_v2;
        $ok = $ok && hotpot_update_to_v2_1_2();
    }
    if ($oldversion < 2006042103) {
        require_once $update_to_v2;
        $ok = $ok && hotpot_update_to_v2_1_16();
    }
    if ($oldversion < 2006042601) {
        require_once $update_to_v2;
        $ok = $ok && hotpot_update_to_v2_1_17();
    }
    if ($oldversion < 2006042803) {
        require_once $update_to_v2;
        $ok = $ok && hotpot_update_to_v2_1_18();
    }
    if ($oldversion < 2006083101) {
        require_once $update_to_v2;
        $ok = $ok && hotpot_update_to_v2_2();
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return $ok;
}
function resource_upgrade($oldversion)
{
    // This function does anything necessary to upgrade
    // older versions to match current functionality
    global $CFG;
    if ($oldversion < 2004013101) {
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('resource', 'update', 'resource', 'name');");
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('resource', 'add', 'resource', 'name');");
    }
    if ($oldversion < 2004071000) {
        table_column("resource", "", "popup", "text", "", "", "", "", "alltext");
        if ($resources = get_records_select("resource", "type='3' OR type='5'", "", "id, alltext")) {
            foreach ($resources as $resource) {
                $resource->popup = addslashes($resource->alltext);
                $resource->alltext = "";
                if (!update_record("resource", $resource)) {
                    notify("Error updating popup field for resource id = {$resource->id}");
                }
            }
        }
        require_once "{$CFG->dirroot}/course/lib.php";
        rebuild_course_cache();
    }
    if ($oldversion < 2004071300) {
        table_column("resource", "", "options", "varchar", "255", "", "", "", "popup");
    }
    if ($oldversion < 2004071303) {
        table_column("resource", "type", "type", "varchar", "30", "", "", "", "");
        modify_database("", "UPDATE prefix_resource SET type='reference' WHERE type='1';");
        modify_database("", "UPDATE prefix_resource SET type='file', options='frame' WHERE type='2';");
        modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='3';");
        modify_database("", "UPDATE prefix_resource SET type='text', options='0' WHERE type='4';");
        modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='5';");
        modify_database("", "UPDATE prefix_resource SET type='html' WHERE type='6';");
        modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='7';");
        modify_database("", "UPDATE prefix_resource SET type='text', options='3' WHERE type='8';");
        modify_database("", "UPDATE prefix_resource SET type='directory' WHERE type='9';");
    }
    if ($oldversion < 2004080801) {
        modify_database("", "UPDATE prefix_resource SET alltext=reference,type='html' WHERE type='reference';");
        rebuild_course_cache();
    }
    if ($oldversion < 2004111200) {
        //drop first to avoid conflicts when upgrading
        execute_sql("DROP INDEX {$CFG->prefix}resource_course_idx;", false);
        modify_database('', 'CREATE INDEX prefix_resource_course_idx ON prefix_resource (course);');
    }
    if ($oldversion < 2005041100) {
        // replace wiki-like with markdown
        include_once "{$CFG->dirroot}/lib/wiki_to_markdown.php";
        $wtm = new WikiToMarkdown();
        $wtm->update('resource', 'alltext', 'options');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
Beispiel #15
0
function xmldb_assignment_type_poodllonline_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    if ($oldversion < 2010030312) {
        // add field to store media comments (audio or video) filename to students submissions
        $sql = "ALTER TABLE {$CFG->prefix}assignment_submissions ADD poodllfeedback TEXT";
        $result = execute_sql($sql);
    }
    return $result;
}
function questionnaire_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    global $CFG;
    if ($oldversion < 2004021300) {
        # Do something ...
    }
    if ($oldversion < 2004081300) {
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire` ADD `respondenttype` ENUM( \'fullname\', \'anonymous\' ) DEFAULT \'fullname\' NOT NULL AFTER `qtype`');
    }
    if ($oldversion < 2004090700) {
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire` ADD `resp_eligible` ENUM( \'all\', \'students\', \'teachers\' ) DEFAULT \'all\' NOT NULL AFTER `respondenttype`');
    }
    if ($oldversion < 2004090900) {
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire` ADD `opendate` INT( 10 ) NOT NULL AFTER `resp_eligible` , ' . 'ADD `closedate` INT( 10 ) NOT NULL AFTER `opendate`');
    }
    if ($oldversion < 2005021100) {
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire` ADD INDEX ( `sid` )');
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire_survey` ADD INDEX ( `owner` )');
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire_survey` DROP INDEX `name` , ' . 'ADD INDEX `name` ( `name` )');
        questionnaire_upgrade_2005021100();
    }
    if ($oldversion < 2005030100) {
        execute_sql('ALTER TABLE `' . $CFG->prefix . 'questionnaire_attempts` ADD `rid` INT( 10 ) UNSIGNED ' . 'DEFAULT \'0\' NOT NULL AFTER `userid`');
    }
    if ($oldversion < 2005062700) {
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_bool` DROP PRIMARY KEY ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_bool` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_bool` ADD INDEX `response_question` ( `response_id` , `question_id` ) ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_single` DROP PRIMARY KEY ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_single` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_single` ADD INDEX `response_question` ( `response_id` , `question_id` ) ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_rank` DROP PRIMARY KEY ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_rank` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_rank` ADD INDEX `response_question_choice` ( `response_id` , `question_id`, `choice_id` ) ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_text` DROP PRIMARY KEY ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_text` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_text` ADD INDEX `response_question` ( `response_id` , `question_id` ) ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_other` DROP PRIMARY KEY ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_other` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_other` ADD INDEX `response_question_choice` ( `response_id` , `question_id`, `choice_id` ) ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_date` DROP PRIMARY KEY ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_date` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;');
        modify_database('', 'ALTER TABLE `prefix_questionnaire_response_date` ADD INDEX `response_question` ( `response_id` , `question_id` ) ;');
    }
    if ($oldversion < 2006012700) {
        questionnaire_upgrade_2006012700();
    }
    if ($oldversion < 2006031702) {
        questionnaire_upgrade_2006031700();
    }
    return true;
}
function generateProducts($file, $con)
{
    global $products;
    $products = checkProductsGlobalVariable($con);
    $multiplier = 0.15;
    $n_node = retrieveNodesCount($file, $con);
    for ($i = 0; $i < ceil($n_node * $multiplier); $i++) {
        execute_sql('<create_initial_products.php>', $con, "INSERT INTO products (name, base_cost, max_cost, global_quantity) VALUES ('P" . $i . "', '" . 0 . "', '" . frand() . "', '" . 0 . "')");
    }
    $products = fetch_nodes_toArray($con);
}
Beispiel #18
0
/**
* Function called when plugin first installed into the database
* Utility function must be prefixed with the plugin name
* followed by an underscore.
* 
* Format: pluginname_install
* 
*/
function sms_to_email_install()
{
    $CI =& get_instance();
    // check if table already exist
    if (!$CI->db->table_exists('plugin_sms_to_email')) {
        $db_driver = $CI->db->platform();
        $db_prop = get_database_property($db_driver);
        execute_sql(APPPATH . "plugins/sms_to_email/media/" . $db_prop['file'] . "_sms_to_email.sql");
    }
    return true;
}
Beispiel #19
0
/**
* Function called when plugin first installed into the database
* Utility function must be prefixed with the plugin name
* followed by an underscore.
* 
* Format: pluginname_install
* 
*/
function blacklist_number_install()
{
    $CI =& get_instance();
    // check if table already exist
    if (!$CI->db->table_exists('plugin_blacklist_number')) {
        $db_driver = $CI->db->platform();
        $db_prop = get_database_property($db_driver);
        execute_sql(APPPATH . "plugins/blacklist_number/media/" . $db_prop['file'] . "_blacklist_number.sql");
    }
    return true;
}
Beispiel #20
0
/**
* Function called when plugin first installed into the database
* Utility function must be prefixed with the plugin name
* followed by an underscore.
* 
* Format: pluginname_install
* 
*/
function soap_install()
{
    $CI =& get_instance();
    $CI->load->helper('kalkun');
    // check if table already exist
    if (!$CI->db->table_exists('plugin_remote_access')) {
        $db_driver = $CI->db->platform();
        $db_prop = get_database_property($db_driver);
        execute_sql(APPPATH . "plugins/soap/media/" . $db_prop['file'] . "_remote_access.sql");
    }
    return true;
}
Beispiel #21
0
function insert_category_ids($course, $backup_unique_code, $instances = null)
{
    global $CFG;
    include_once "{$CFG->dirroot}/mod/quiz/lib.php";
    //Create missing categories and reasign orphaned questions.
    fix_orphaned_questions($course);
    // First, all categories from this course.
    $status = execute_sql("INSERT INTO {$CFG->prefix}backup_ids\n                                   (backup_code, table_name, old_id, info)\n                               SELECT '{$backup_unique_code}', 'question_categories', qc.id, ''\n                               FROM {$CFG->prefix}question_categories qc\n                               WHERE qc.course = {$course}", false);
    // Then published categories from other courses used by the quizzes we are backing up.
    $from = "{$CFG->prefix}quiz quiz,";
    $where = "AND quiz.course = '{$course}'\n                     AND qqi.quiz = quiz.id";
    if (!empty($instances) && is_array($instances) && count($instances)) {
        $from = '';
        $where = 'AND qqi.quiz IN (' . implode(',', array_keys($instances)) . ')';
    }
    $categories = get_records_sql("\n                SELECT id, parent, 0 AS childrendone\n                FROM {$CFG->prefix}question_categories\n                WHERE course <> {$course}\n                  AND id IN (\n                    SELECT DISTINCT question.category \n                    FROM {$CFG->prefix}question question,\n                         {$from}\n                         {$CFG->prefix}quiz_question_instances qqi\n                    WHERE qqi.question = question.id\n                      {$where}\n                )", false);
    if (!$categories) {
        $categories = array();
    }
    // Add the parent categories, of these categories up to the top of the category tree.
    foreach ($categories as $category) {
        while ($category->parent != 0) {
            if (array_key_exists($category->parent, $categories)) {
                // Parent category already on the list.
                break;
            }
            $currentid = $category->id;
            $category = get_record('question_categories', 'id', $category->parent, '', '', '', '', 'id, parent, 0 AS childrendone');
            if ($category) {
                $categories[$category->id] = $category;
            } else {
                // Parent not found: this indicates an error, but just fix it.
                set_field('question_categories', 'parent', 0, 'id', $currentid);
                break;
            }
        }
    }
    // Now we look for categories from other courses containing random questions
    // in our quiz that select from the category and its subcategories. That implies
    // those subcategories also need to be backed up. (The categories themselves
    // and their parents will already have been included.)
    $categorieswithrandom = get_records_sql("\n                SELECT DISTINCT question.category AS id\n                FROM {$CFG->prefix}quiz_question_instances qqi,\n                     {$from}\n                     {$CFG->prefix}question question\n                WHERE question.id = qqi.question\n                  AND question.qtype = '" . RANDOM . "'\n                  AND question.questiontext = '1'\n                  {$where}\n                ");
    if ($categorieswithrandom) {
        foreach ($categorieswithrandom as $category) {
            $status = quiz_backup_add_sub_categories($categories, $category->id);
        }
    }
    // Finally, add all these extra categories to the backup_ids table.
    foreach ($categories as $category) {
        $status = $status && backup_putid($backup_unique_code, 'question_categories', $category->id, 0);
    }
    return $status;
}
function xmldb_artefact_internal_upgrade($oldversion = 0)
{
    $status = true;
    if ($oldversion < 2014022700) {
        // Remove the unnecessary Contact information block and change all current instances to Profile information
        execute_sql("UPDATE {block_instance} SET blocktype='profileinfo' WHERE blocktype='contactinfo'");
        execute_sql("DELETE FROM {blocktype_installed_viewtype} WHERE blocktype='contactinfo'");
        execute_sql("DELETE FROM {blocktype_installed_category} WHERE blocktype='contactinfo'");
        execute_sql("DELETE FROM {blocktype_installed} WHERE name='contactinfo'");
    }
    return $status;
}
function xmldb_blocktype_textbox_upgrade($oldversion = 0)
{
    if ($oldversion < 2011082200) {
        // Convert all textbox html content to artefacts
        $tbcount = count_records('block_instance', 'blocktype', 'textbox');
        $sql = '
            SELECT b.id, b.title, b.configdata, b.view,
                v.owner, v.group, v.institution, v.ctime, v.mtime, v.atime
            FROM {block_instance} b JOIN {view} v ON b.view = v.id
            WHERE b.id > ? AND b.blocktype = ?
            ORDER BY b.id';
        $done = 0;
        $lastid = 0;
        if (is_mysql()) {
            $mp = mysql_get_variable('max_allowed_packet');
            $limit = $mp && is_numeric($mp) && $mp > 1048576 ? $mp / 8192 : 100;
        } else {
            $limit = 5000;
        }
        while ($records = get_records_sql_array($sql, array($lastid, 'textbox'), 0, $limit)) {
            // Create the new artefacts
            $values = array();
            foreach ($records as $r) {
                $configdata = unserialize($r->configdata);
                array_push($values, 'html', $r->ctime, $r->mtime, $r->atime, $r->title, isset($configdata['text']) ? $configdata['text'] : '', $r->owner, $r->group, $r->institution, $r->owner > 0 ? $r->owner : null, $r->owner > 0 ? null : '?', $r->id);
                // Dumping the block id in the note column makes it easier to update block_instance later
            }
            $insertsql = "\n                INSERT INTO {artefact}\n                    (artefacttype, ctime, mtime, atime, title, description, owner, \"group\", institution, author, authorname, note)\n                VALUES ";
            $insertsql .= join(',', array_fill(0, count($records), '(?,?,?,?,?,?,?,?,?,?,?,?)'));
            execute_sql($insertsql, $values);
            // Update block_instance configdata to point at the new artefacts
            if (is_postgres()) {
                execute_sql("\n                    UPDATE {block_instance}\n                    SET configdata = 'a:1:{s:10:\"artefactid\";i:' || a.id::text || ';}'\n                    FROM (\n                        SELECT id, note FROM {artefact} WHERE artefacttype = 'html' AND note IS NOT NULL\n                    ) a\n                    WHERE blocktype = 'textbox' AND {block_instance}.id::text = a.note");
                // Update view_artefact table
                execute_sql("\n                    INSERT INTO {view_artefact} (view, block, artefact)\n                    SELECT b.view, b.id, a.id\n                    FROM {block_instance} b, {artefact} a\n                    WHERE b.blocktype = 'textbox' AND a.artefacttype = 'html' AND a.note IS NOT NULL AND CAST(b.id AS TEXT) = a.note", array());
            } else {
                if (is_mysql()) {
                    execute_sql("\n                    UPDATE {block_instance}, {artefact}\n                    SET {block_instance}.configdata = CONCAT('a:1:{s:10:\"artefactid\";i:', {artefact}.id, ';}')\n                    WHERE\n                        {artefact}.artefacttype = 'html'\n                        AND {artefact}.note IS NOT NULL\n                        AND {block_instance}.blocktype = 'textbox'\n                        AND {block_instance}.id = {artefact}.note");
                    // Update view_artefact table
                    execute_sql("\n                    INSERT INTO {view_artefact} (view, block, artefact)\n                    SELECT b.view, b.id, a.id\n                    FROM {block_instance} b, {artefact} a\n                    WHERE b.blocktype = 'textbox' AND a.artefacttype = 'html' AND a.note IS NOT NULL AND b.id = a.note", array());
                }
            }
            // Remove the dodgy block id in the note column
            execute_sql("UPDATE {artefact} SET note = NULL WHERE artefacttype = 'html' AND note IS NOT NULL");
            $done += count($records);
            log_debug("Upgrading textbox blocks: {$done}/{$tbcount}");
            $last = end($records);
            $lastid = $last->id;
        }
    }
    return true;
}
Beispiel #24
0
 function cron()
 {
     global $CFG;
     // Delete annotations whose users no longer exist
     // this removes the need to touch admin/user.php
     // Other code should therefore be careful not to join on non-existent users
     $query = "DELETE FROM {$CFG->prefix}marginalia WHERE userid NOT IN (SELECT id FROM {$CFG->prefix}user)";
     execute_sql($query, false);
     // This will catch all read records for non-existent users and annotations, though the latter should
     // already have been deleted with the annotation.
     $query = "DELETE FROM {$CFG->prefix}marginalia_read WHERE annotationid NOT IN (SELECT id FROM {$CFG->prefix}marginalia)";
     execute_sql($query, false);
 }
function delete_tag_submit(Pieform $form, $values)
{
    global $SESSION, $USER, $tag;
    if (!($userid = $USER->get('id'))) {
        redirect(get_config('wwwroot') . 'edittags.php?tag=' . urlencode($tag));
    }
    db_begin();
    execute_sql("DELETE FROM {view_tag} WHERE tag = ? AND view IN (SELECT id FROM {view} WHERE \"owner\" = ?)", array($tag, $userid));
    execute_sql("DELETE FROM {artefact_tag} WHERE tag = ? AND artefact IN (SELECT id FROM {artefact} WHERE \"owner\" = ?)", array($tag, $userid));
    db_commit();
    $SESSION->add_ok_msg(get_string('tagdeletedsuccessfully'));
    redirect(get_config('wwwroot') . 'tags.php');
}
Beispiel #26
0
 public static function deleteuser($event, $user)
 {
     db_begin();
     // Before deleting the user's notifications, remove parent pointers to the
     // messages we're about to delete. The temporary table in this query is
     // required by MySQL
     execute_sql("\n            UPDATE {notification_internal_activity}\n            SET parent = NULL\n            WHERE parent IN (\n                SELECT id FROM (\n                   SELECT id FROM {notification_internal_activity} WHERE usr = ?\n                ) AS temp\n            )", array($user['id']));
     delete_records('notification_internal_activity', 'usr', $user['id']);
     // Delete system messages from this user where the url points to their
     // missing profile.  They're mostly friend requests, which are now useless.
     delete_records_select('notification_internal_activity', '"from" = ? AND type = (SELECT id FROM {activity_type} WHERE name = ?) AND url = ?', array($user['id'], 'maharamessage', get_config('wwwroot') . 'user/view.php?id=' . $user['id']));
     db_commit();
 }
Beispiel #27
0
function exercise_upgrade($oldversion)
{
    // This function does anything necessary to upgrade
    // older versions to match current functionality
    global $CFG;
    if ($oldversion < 2003111400) {
        execute_sql(" ALTER TABLE `{$CFG->prefix}exercise_submissions` ADD INDEX (`userid`)");
        execute_sql(" ALTER TABLE `{$CFG->prefix}exercise_submissions` DROP INDEX `title`");
        execute_sql(" ALTER TABLE `{$CFG->prefix}exercise_assessments` ADD INDEX (`submissionid`)");
        execute_sql(" ALTER TABLE `{$CFG->prefix}exercise_assessments` ADD INDEX (`userid`)");
        execute_sql(" ALTER TABLE `{$CFG->prefix}exercise_grades` ADD INDEX (`assessmentid`)");
    }
    if ($oldversion < 2003121000) {
        execute_sql(" ALTER TABLE `{$CFG->prefix}exercise_submissions` ADD `late` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0'");
    }
    if ($oldversion < 2004062300) {
        table_column("exercise", "", "gradinggrade", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade");
        table_column("exercise", "", "assessmentcomps", "INTEGER", "4", "UNSIGNED", "2", "NOT NULL", "usemaximum");
        execute_sql("ALTER TABLE `{$CFG->prefix}exercise` DROP COLUMN `teacherweight`");
        execute_sql("ALTER TABLE `{$CFG->prefix}exercise` DROP COLUMN `gradingweight`");
    }
    if ($oldversion < 2004090200) {
        table_column("exercise", "", "usepassword", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL");
        table_column("exercise", "", "password", "VARCHAR", "32", "", "", "NOT NULL");
    }
    if ($oldversion < 2004091000) {
        table_column("exercise_assessments", "generalcomment", "generalcomment", "text", "", "", "", "NOT NULL");
        table_column("exercise_assessments", "teachercomment", "teachercomment", "text", "", "", "", "NOT NULL");
    }
    if ($oldversion < 2004100800) {
        include_once "{$CFG->dirroot}/mod/exercise/lib.php";
        exercise_refresh_events();
    }
    if ($oldversion < 2004111200) {
        execute_sql("ALTER TABLE {$CFG->prefix}exercise DROP INDEX course;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}exercise_submissions DROP INDEX exerciseid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}exercise_assessments DROP INDEX exerciseid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}exercise_elements DROP INDEX exerciseid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}exercise_rubrics DROP INDEX exerciseid;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}exercise_grades DROP INDEX exerciseid;", false);
        modify_database('', 'ALTER TABLE prefix_exercise ADD INDEX course (course);');
        modify_database('', 'ALTER TABLE prefix_exercise_submissions ADD INDEX exerciseid (exerciseid);');
        modify_database('', 'ALTER TABLE prefix_exercise_assessments ADD INDEX exerciseid (exerciseid);');
        modify_database('', 'ALTER TABLE prefix_exercise_elements ADD INDEX exerciseid (exerciseid);');
        modify_database('', 'ALTER TABLE prefix_exercise_rubrics ADD INDEX exerciseid (exerciseid);');
        modify_database('', 'ALTER TABLE prefix_exercise_grades ADD INDEX exerciseid (exerciseid);');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
Beispiel #28
0
function nanogong_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    global $CFG;
    if ($oldversion < 2008081100) {
        execute_sql(" ALTER TABLE `{$CFG->prefix}nanogong` ADD `maxmessages` int(4) NOT NULL default '0' AFTER `message` ");
        execute_sql(" ALTER TABLE `{$CFG->prefix}nanogong` ADD `color` varchar(7) AFTER `message` ");
        execute_sql(" ALTER TABLE `{$CFG->prefix}nanogong_message` ADD `title` varchar(255) NOT NULL default '' AFTER `groupid` ");
        execute_sql(" ALTER TABLE `{$CFG->prefix}nanogong_message` ADD `commentedby` int(10) unsigned AFTER `comments` ");
        execute_sql(" ALTER TABLE `{$CFG->prefix}nanogong_message` ADD `timeedited` int(10) unsigned AFTER `timestamp` ");
    }
    return true;
}
Beispiel #29
0
function chat_upgrade($oldversion)
{
    // This function does anything necessary to upgrade
    // older versions to match current functionality
    global $CFG;
    if ($oldversion < 2003072100) {
        modify_database("", " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('chat', 'report', 'chat', 'name'); ");
    }
    if ($oldversion < 2003072101) {
        table_column("chat", "messages", "keepdays", "integer", "10", "unsigned", "0", "not null");
    }
    if ($oldversion < 2003072102) {
        table_column("chat", "", "studentlogs", "integer", "4", "unsigned", "0", "not null", "keepdays");
    }
    if ($oldversion < 2003072500) {
        table_column("chat", "", "chattime", "integer", "10", "unsigned", "0", "not null", "studentlogs");
        table_column("chat", "", "schedule", "integer", "4", "", "0", "not null", "studentlogs");
    }
    if ($oldversion < 2004022300) {
        table_column("chat_messages", "", "groupid", "integer", "10", "unsigned", "0", "not null", "userid");
        table_column("chat_users", "", "groupid", "integer", "10", "unsigned", "0", "not null", "userid");
    }
    if ($oldversion < 2004042500) {
        include_once "{$CFG->dirroot}/mod/chat/lib.php";
        chat_refresh_events();
    }
    if ($oldversion < 2004043000) {
        modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('chat', 'talk', 'chat', 'name');");
    }
    if ($oldversion < 2004111200) {
        execute_sql("ALTER TABLE {$CFG->prefix}chat DROP INDEX `course`;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}chat_messages DROP INDEX  `chatid`;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}chat_messages DROP INDEX `userid`;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}chat_messages DROP INDEX `groupid`;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}chat_users DROP INDEX  `chatid`;", false);
        execute_sql("ALTER TABLE {$CFG->prefix}chat_users DROP INDEX  `groupid`;", false);
        modify_database('', 'ALTER TABLE prefix_chat ADD INDEX `course` (`course`);');
        modify_database('', 'ALTER TABLE prefix_chat_messages ADD INDEX  `chatid` (`chatid`);');
        modify_database('', 'ALTER TABLE prefix_chat_messages ADD INDEX `userid` (`userid`);');
        modify_database('', 'ALTER TABLE prefix_chat_messages ADD INDEX `groupid` (`groupid`);');
        modify_database('', 'ALTER TABLE prefix_chat_users ADD INDEX  `chatid` (`chatid`);');
        modify_database('', 'ALTER TABLE prefix_chat_users ADD INDEX  `groupid` (`groupid`);');
    }
    if ($oldversion < 2005020300) {
        table_column('chat_users', '', 'course', 'integer', '10', 'unsigned', '0', 'not null', '');
        table_column('chat_users', '', 'lang', 'varchar', '10', '', '', 'not null', '');
    }
    //////  DO NOT ADD NEW THINGS HERE!!  USE upgrade.php and the lib/ddllib.php functions.
    return true;
}
function xmldb_artefact_internal_upgrade($oldversion = 0)
{
    $status = true;
    if ($oldversion < 2007042500) {
        // migrate everything we had to change to  make mysql happy
        execute_sql("ALTER TABLE {artefact_internal_profile_email} ALTER COLUMN email TYPE varchar(255)");
        execute_sql("ALTER TABLE {artefact_internal_profile_icon} ALTER COLUMN filename TYPE varchar(255)");
    }
    if ($oldversion < 2008101300) {
        execute_sql("DROP TABLE {artefact_internal_profile_icon}");
    }
    // everything up to here we pre mysql support.
    return $status;
}