本文整理汇总了PHP中upgrade_set_timeout函数的典型用法代码示例。如果您正苦于以下问题:PHP upgrade_set_timeout函数的具体用法?PHP upgrade_set_timeout怎么用?PHP upgrade_set_timeout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了upgrade_set_timeout函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: xmldb_assignment_upgrade
function xmldb_assignment_upgrade($oldversion) {
global $CFG, $DB, $OUTPUT;
$dbman = $DB->get_manager();
// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this
// Moodle v2.3.0 release upgrade line
// Put any upgrade step following this
if ($oldversion < 2012061701) {
// Fixed/updated numfiles field in assignment_submissions table to count the actual
// number of files has been uploaded when sendformarking is disabled
upgrade_set_timeout(600); // increase excution time for in large sites
$fs = get_file_storage();
// Fetch the moduleid for use in the course_modules table
$moduleid = $DB->get_field('modules', 'id', array('name' => 'assignment'), MUST_EXIST);
$selectcount = 'SELECT COUNT(s.id) ';
$select = 'SELECT s.id, cm.id AS cmid ';
$query = 'FROM {assignment_submissions} s
JOIN {assignment} a ON a.id = s.assignment
JOIN {course_modules} cm ON a.id = cm.instance AND cm.module = :moduleid
WHERE assignmenttype = :assignmenttype';
$params = array('moduleid' => $moduleid, 'assignmenttype' => 'upload');
$countsubmissions = $DB->count_records_sql($selectcount.$query, $params);
$submissions = $DB->get_recordset_sql($select.$query, $params);
$pbar = new progress_bar('assignmentupgradenumfiles', 500, true);
$i = 0;
foreach ($submissions as $sub) {
$i++;
if ($context = context_module::instance($sub->cmid)) {
$sub->numfiles = count($fs->get_area_files($context->id, 'mod_assignment', 'submission', $sub->id, 'sortorder', false));
$DB->update_record('assignment_submissions', $sub);
}
$pbar->update($i, $countsubmissions, "Counting files of submissions ($i/$countsubmissions)");
}
$submissions->close();
// assignment savepoint reached
upgrade_mod_savepoint(true, 2012061701, 'assignment');
}
// Moodle v2.4.0 release upgrade line
// Put any upgrade step following this
// Moodle v2.5.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
开发者ID:verbazend,项目名称:AWFA,代码行数:60,代码来源:upgrade.php
示例2: xmldb_pcast_upgrade
/**
* xmldb_pcast_upgrade
*
* @param int $oldversion
* @return bool
*/
function xmldb_pcast_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of "/lib/ddllib.php" function calls
/// }
/// RatingArea Upgrade
if ($oldversion < 2011080700) {
// rating.component and rating.ratingarea have now been added as mandatory fields.
// Presently you can only rate data entries so component = 'mod_pcast' and ratingarea = 'episode'
// for all ratings with a pcast context.
// We want to update all ratings that belong to a glossary context and don't already have a
// component set.
// This could take a while reset upgrade timeout to 5 min
upgrade_set_timeout(60 * 20);
$sql = "UPDATE {rating}\n SET component = 'mod_pcast', ratingarea = 'episode'\n WHERE contextid IN (\n SELECT ctx.id\n FROM {context} ctx\n JOIN {course_modules} cm ON cm.id = ctx.instanceid\n JOIN {modules} m ON m.id = cm.module\n WHERE ctx.contextlevel = 70 AND\n m.name = 'pcast'\n ) AND component = 'unknown'";
$DB->execute($sql);
upgrade_mod_savepoint(true, 2011080700, 'pcast');
}
/// Final return of upgrade result (true/false) to Moodle. Must be
/// always the last line in the script
return true;
}
开发者ID:rtsfc,项目名称:moodle-mod_pcast,代码行数:34,代码来源:upgrade.php
示例3: xmldb_survey_upgrade
function xmldb_survey_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
//===== 1.9.0 upgrade line ======//
if ($oldversion < 2009042002) {
/// Define field introformat to be added to survey
$table = new xmldb_table('survey');
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
/// Conditionally launch add field introformat
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// conditionally migrate to html format in intro
if ($CFG->texteditors !== 'textarea') {
$rs = $DB->get_recordset('survey', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat');
foreach ($rs as $s) {
$s->intro = text_to_html($s->intro, false, false, true);
$s->introformat = FORMAT_HTML;
$DB->update_record('survey', $s);
upgrade_set_timeout();
}
$rs->close();
}
/// survey savepoint reached
upgrade_mod_savepoint(true, 2009042002, 'survey');
}
return true;
}
开发者ID:vuchannguyen,项目名称:web,代码行数:29,代码来源:upgrade.php
示例4: page_20_migrate_candidate
function page_20_migrate_candidate($candidate, $fs, $format)
{
global $CFG, $DB;
upgrade_set_timeout();
$page = new object();
$page->course = $candidate->course;
$page->name = $candidate->name;
$page->intro = $candidate->intro;
$page->introformat = $candidate->introformat;
$page->content = $candidate->alltext;
$page->contentformat = $format;
$page->revision = 1;
$page->timemodified = time();
// convert links to old course files - let the automigration do the actual job
$usedfiles = array("{$CFG->wwwroot}/file.php/{$page->course}/", "{$CFG->wwwroot}/file.php?file=/{$page->course}/");
$page->content = str_ireplace($usedfiles, '@@PLUGINFILE@@/', $page->content);
if (strpos($page->content, '@@PLUGINFILE@@/') === false) {
$page->legacyfiles = RESOURCELIB_LEGACYFILES_NO;
} else {
$page->legacyfiles = RESOURCELIB_LEGACYFILES_ACTIVE;
}
$options = array('printheading' => 0, 'printintro' => 0);
if ($candidate->popup) {
$page->display = RESOURCELIB_DISPLAY_POPUP;
if ($candidate->popup) {
$rawoptions = explode(',', $candidate->popup);
foreach ($rawoptions as $rawoption) {
list($name, $value) = explode('=', trim($rawoption), 2);
if ($value > 0 and ($name == 'width' or $name == 'height')) {
$options['popup' . $name] = $value;
continue;
}
}
}
} else {
$page->display = RESOURCELIB_DISPLAY_OPEN;
}
$page->displayoptions = serialize($options);
$page = resource_migrate_to_module('page', $candidate, $page);
// now try to migrate files from site files
// noite: this can not work for html pages or files with other relatively linked files :-(
$siteid = get_site()->id;
if (preg_match_all("|{$CFG->wwwroot}/file.php(\\?file=)?/{$siteid}(/[^\\s'\"&\\?#]+)|", $page->content, $matches)) {
$context = get_context_instance(CONTEXT_MODULE, $candidate->cmid);
$sitecontext = get_context_instance(CONTEXT_COURSE, $siteid);
$file_record = array('contextid' => $context->id, 'filearea' => 'page_content', 'itemid' => 0);
$fs = get_file_storage();
foreach ($matches[2] as $i => $sitefile) {
if (!($file = $fs->get_file_by_hash(sha1($sitecontext->id . 'course_content0' . $sitefile)))) {
continue;
}
try {
$fs->create_file_from_storedfile($file_record, $file);
$page->content = str_replace($matches[0][$i], '@@PLUGINFILE@@' . $sitefile, $page->content);
} catch (Exception $x) {
}
}
$DB->update_record('page', $page);
}
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:60,代码来源:upgradelib.php
示例5: xmldb_logstore_standard_upgrade
function xmldb_logstore_standard_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
// 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 < 2016041200) {
// This could take a long time. Unfortunately, no way to know how long, and no way to do progress, so setting for 1 hour.
upgrade_set_timeout(3600);
// Define key contextid (foreign) to be added to logstore_standard_log.
$table = new xmldb_table('logstore_standard_log');
$key = new xmldb_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
// Launch add key contextid.
$dbman->add_key($table, $key);
// Standard savepoint reached.
upgrade_plugin_savepoint(true, 2016041200, 'logstore', 'standard');
}
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
开发者ID:Chocolate-lightning,项目名称:moodle,代码行数:27,代码来源:upgrade.php
示例6: folder_20_migrate
/**
* Migrate folder module data from 1.9 resource_old table to new older table
* @return void
*/
function folder_20_migrate()
{
global $CFG, $DB;
require_once "{$CFG->libdir}/filelib.php";
require_once "{$CFG->dirroot}/course/lib.php";
if (!file_exists("{$CFG->dirroot}/mod/resource/db/upgradelib.php")) {
// bad luck, somebody deleted resource module
return;
}
require_once "{$CFG->dirroot}/mod/resource/db/upgradelib.php";
// create resource_old table and copy resource table there if needed
if (!resource_20_prepare_migration()) {
// no modules or fresh install
return;
}
if (!($candidates = $DB->get_recordset('resource_old', array('type' => 'directory', 'migrated' => 0)))) {
return;
}
$fs = get_file_storage();
foreach ($candidates as $candidate) {
upgrade_set_timeout();
$directory = '/' . trim($candidate->reference, '/') . '/';
$directory = str_replace('//', '/', $directory);
$folder = new object();
$folder->course = $candidate->course;
$folder->name = $candidate->name;
$folder->intro = $candidate->intro;
$folder->introformat = $candidate->introformat;
$folder->revision = 1;
$folder->timemodified = time();
if (!($folder = resource_migrate_to_module('folder', $candidate, $folder))) {
continue;
}
// copy files in given directory, skip moddata and backups!
$context = get_context_instance(CONTEXT_MODULE, $candidate->cmid);
$coursecontext = get_context_instance(CONTEXT_COURSE, $candidate->course);
$files = $fs->get_directory_files($coursecontext->id, 'course_content', 0, $directory, true, true);
$file_record = array('contextid' => $context->id, 'filearea' => 'folder_content', 'itemid' => 0);
foreach ($files as $file) {
$path = $file->get_filepath();
if (stripos($path, '/backupdata/') === 0 or stripos($path, '/moddata/') === 0) {
// do not publish protected data!
continue;
}
$relpath = substr($path, strlen($directory) - 1);
// keep only subfolder paths
$file_record['filepath'] = $relpath;
$fs->create_file_from_storedfile($file_record, $file);
}
}
$candidates->close();
// clear all course modinfo caches
rebuild_course_cache(0, true);
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:58,代码来源:upgradelib.php
示例7: xmldb_qtype_essay_upgrade
/**
* Upgrade code for the essay question type.
* @param int $oldversion the version we are upgrading from.
*/
function xmldb_qtype_essay_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this
if ($oldversion < 2011102701) {
$sql = "\n FROM {question} q\n JOIN {question_answers} qa ON qa.question = q.id\n\n WHERE q.qtype = 'essay'\n AND " . $DB->sql_isnotempty('question_answers', 'feedback', false, true);
// In Moodle <= 2.0 essay had both question.generalfeedback and question_answers.feedback.
// This was silly, and in Moodel >= 2.1 only question.generalfeedback. To avoid
// dataloss, we concatenate question_answers.feedback onto the end of question.generalfeedback.
$count = $DB->count_records_sql("\n SELECT COUNT(1) {$sql}");
if ($count) {
$progressbar = new progress_bar('essay23', 500, true);
$done = 0;
$toupdate = $DB->get_recordset_sql("\n SELECT q.id,\n q.generalfeedback,\n q.generalfeedbackformat,\n qa.feedback,\n qa.feedbackformat\n {$sql}");
foreach ($toupdate as $data) {
$progressbar->update($done, $count, "Updating essay feedback ({$done}/{$count}).");
upgrade_set_timeout(60);
if ($data->generalfeedbackformat == $data->feedbackformat) {
$DB->set_field('question', 'generalfeedback', $data->generalfeedback . $data->feedback, array('id' => $data->id));
} else {
$newdata = new stdClass();
$newdata->id = $data->id;
$newdata->generalfeedback = qtype_essay_convert_to_html($data->generalfeedback, $data->generalfeedbackformat) . qtype_essay_convert_to_html($data->feedback, $data->feedbackformat);
$newdata->generalfeedbackformat = FORMAT_HTML;
$DB->update_record('question', $newdata);
}
}
$progressbar->update($count, $count, "Updating essay feedback complete!");
$toupdate->close();
}
// Essay savepoint reached.
upgrade_plugin_savepoint(true, 2011102701, 'qtype', 'essay');
}
if ($oldversion < 2011102702) {
// Then we delete the old question_answers rows for essay questions.
$DB->delete_records_select('question_answers', "question IN (SELECT id FROM {question} WHERE qtype = 'essay')");
// Essay savepoint reached.
upgrade_plugin_savepoint(true, 2011102702, 'qtype', 'essay');
}
// Moodle v2.3.0 release upgrade line
// Put any upgrade step following this
// Moodle v2.4.0 release upgrade line
// Put any upgrade step following this
return true;
}
开发者ID:vinoth4891,项目名称:clinique,代码行数:51,代码来源:upgrade.php
示例8: xmldb_adobeconnect_upgrade
/**
* @package mod
* @subpackage adobeconnect
* @author Akinsaya Delamarre ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function xmldb_adobeconnect_upgrade($oldversion = 0)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
//===== 1.9.0 upgrade line ======//
if ($oldversion < 2010120800) {
/// Define field introformat to be added to survey
$table = new xmldb_table('adobeconnect');
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
/// Conditionally launch add field introformat
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// conditionally migrate to html format in intro
if ($CFG->texteditors !== 'textarea') {
$rs = $DB->get_recordset('adobeconnect', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat');
foreach ($rs as $s) {
$s->intro = text_to_html($s->intro, false, false, true);
$s->introformat = FORMAT_HTML;
$DB->update_record('adobeconnect', $s);
upgrade_set_timeout();
}
$rs->close();
}
/// adobeconnect savepoint reached
upgrade_mod_savepoint(true, 2010120800, 'adobeconnect');
}
if ($oldversion < 2011041400) {
// Changing precision of field meeturl on table adobeconnect to (60)
$table = new xmldb_table('adobeconnect');
$field = new xmldb_field('meeturl', XMLDB_TYPE_CHAR, '60', null, null, null, null, 'templatescoid');
// Launch change of precision for field meeturl
$dbman->change_field_precision($table, $field);
// adobeconnect savepoint reached
upgrade_mod_savepoint(true, 2011041400, 'adobeconnect');
}
return true;
}
开发者ID:number33,项目名称:moodle-mod_adobeconnect,代码行数:44,代码来源:upgrade.php
示例9: geogebra_migrate_files
/**
* Migrate geogebra package to new area if found
*
* @return
*/
function geogebra_migrate_files()
{
global $CFG, $DB;
$fs = get_file_storage();
$sqlfrom = "FROM {geogebra} j\n JOIN {modules} m ON m.name = 'geogebra'\n JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = j.id)";
$count = $DB->count_records_sql("SELECT COUNT('x') {$sqlfrom}");
$rs = $DB->get_recordset_sql("SELECT j.id, j.url, j.course, cm.id AS cmid {$sqlfrom} ORDER BY j.course, j.id");
if ($rs->valid()) {
$pbar = new progress_bar('migrategeogebrafiles', 500, true);
$i = 0;
foreach ($rs as $geogebra) {
$i++;
upgrade_set_timeout(180);
// set up timeout, may also abort execution
$pbar->update($i, $count, "Migrating geogebra files - {$i}/{$count}.");
$context = context_module::instance($geogebra->cmid);
$coursecontext = context_course::instance($geogebra->course);
if (!geogebra_is_valid_external_url($geogebra->url)) {
// first copy local files if found - do not delete in case they are shared ;-)
$geogebrafile = clean_param($geogebra->url, PARAM_PATH);
$pathnamehash = sha1("/{$coursecontext->id}/course/legacy/0/{$geogebrafile}");
if ($file = $fs->get_file_by_hash($pathnamehash)) {
$file_record = array('contextid' => $context->id, 'component' => 'mod_geogebra', 'filearea' => 'content', 'itemid' => 0, 'filepath' => '/');
try {
$fs->create_file_from_storedfile($file_record, $file);
} catch (Exception $x) {
// ignore any errors, we can not do much anyway
}
$geogebra->url = $pathnamehash;
} else {
$geogebra->url = '';
}
$DB->update_record('geogebra', $geogebra);
}
}
}
$rs->close();
}
开发者ID:ninelanterns,项目名称:moodle-mod_geogebra,代码行数:43,代码来源:upgradelib.php
示例10: forum_upgrade_grades
/**
* Update all grades in gradebook.
* @global object
*/
function forum_upgrade_grades() {
global $DB;
$sql = "SELECT COUNT('x')
FROM {forum} f, {course_modules} cm, {modules} m
WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
$count = $DB->count_records_sql($sql);
$sql = "SELECT f.*, cm.idnumber AS cmidnumber, f.course AS courseid
FROM {forum} f, {course_modules} cm, {modules} m
WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
$rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
$pbar = new progress_bar('forumupgradegrades', 500, true);
$i=0;
foreach ($rs as $forum) {
$i++;
upgrade_set_timeout(60*5); // set up timeout, may also abort execution
forum_update_grades($forum, 0, false);
$pbar->update($i, $count, "Updating Forum grades ($i/$count).");
}
}
$rs->close();
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:28,代码来源:lib.php
示例11: mod_giportfolio_migrate_all_areas
/**
* Migrate legacy files in intro and chapters
* @return void
*/
function mod_giportfolio_migrate_all_areas()
{
global $DB;
$rsgiportfolios = $DB->get_recordset('giportfolio');
foreach ($rsgiportfolios as $giportfolio) {
upgrade_set_timeout(360);
// Set up timeout, may also abort execution.
$cm = get_coursemodule_from_instance('giportfolio', $giportfolio->id);
$context = context_module::instance($cm->id);
mod_giportfolio_migrate_area($giportfolio, 'intro', 'giportfolio', $giportfolio->course, $context, 'mod_giportfolio', 'intro', 0);
$rschapters = $DB->get_recordset('giportfolio_chapters', array('giportfolioid' => $giportfolio->id));
foreach ($rschapters as $chapter) {
mod_giportfolio_migrate_area($chapter, 'content', 'giportfolio_chapters', $giportfolio->course, $context, 'mod_giportfolio', 'chapter', $chapter->id);
}
$rschapters->close();
}
$rsgiportfolios->close();
}
开发者ID:andrewhancox,项目名称:moodle-mod_giportfolio,代码行数:22,代码来源:upgradelib.php
示例12: assignment_upgrade_grades
/**
* Update all grades in gradebook.
*/
function assignment_upgrade_grades() {
global $DB;
$sql = "SELECT COUNT('x')
FROM {assignment} a, {course_modules} cm, {modules} m
WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
$count = $DB->count_records_sql($sql);
$sql = "SELECT a.*, cm.idnumber AS cmidnumber, a.course AS courseid
FROM {assignment} a, {course_modules} cm, {modules} m
WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
$rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
// too much debug output
$pbar = new progress_bar('assignmentupgradegrades', 500, true);
$i=0;
foreach ($rs as $assignment) {
$i++;
upgrade_set_timeout(60*5); // set up timeout, may also abort execution
assignment_update_grades($assignment);
$pbar->update($i, $count, "Updating Assignment grades ($i/$count).");
}
upgrade_set_timeout(); // reset to default timeout
}
$rs->close();
}
开发者ID:nuckey,项目名称:moodle,代码行数:29,代码来源:lib.php
示例13: data_upgrade_grades
/**
* Update all grades in gradebook.
*
* @global object
*/
function data_upgrade_grades() {
global $DB;
$sql = "SELECT COUNT('x')
FROM {data} d, {course_modules} cm, {modules} m
WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
$count = $DB->count_records_sql($sql);
$sql = "SELECT d.*, cm.idnumber AS cmidnumber, d.course AS courseid
FROM {data} d, {course_modules} cm, {modules} m
WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
$rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
// too much debug output
$pbar = new progress_bar('dataupgradegrades', 500, true);
$i=0;
foreach ($rs as $data) {
$i++;
upgrade_set_timeout(60*5); // set up timeout, may also abort execution
data_update_grades($data, 0, false);
$pbar->update($i, $count, "Updating Database grades ($i/$count).");
}
}
$rs->close();
}
开发者ID:nottmoo,项目名称:moodle,代码行数:30,代码来源:lib.php
示例14: xmldb_main_upgrade
/**
* Main upgrade tasks to be executed on Moodle version bump
*
* This function is automatically executed after one bump in the Moodle core
* version is detected. It's in charge of performing the required tasks
* to raise core from the previous version to the next one.
*
* It's a collection of ordered blocks of code, named "upgrade steps",
* each one performing one isolated (from the rest of steps) task. Usually
* tasks involve creating new DB objects or performing manipulation of the
* information for cleanup/fixup purposes.
*
* Each upgrade step has a fixed structure, that can be summarised as follows:
*
* if ($oldversion < XXXXXXXXXX.XX) {
* // Explanation of the update step, linking to issue in the Tracker if necessary
* upgrade_set_timeout(XX); // Optional for big tasks
* // Code to execute goes here, usually the XMLDB Editor will
* // help you here. See {@link http://docs.moodle.org/dev/XMLDB_editor}.
* upgrade_main_savepoint(true, XXXXXXXXXX.XX);
* }
*
* All plugins within Moodle (modules, blocks, reports...) support the existence of
* their own upgrade.php file, using the "Frankenstyle" component name as
* defined at {@link http://docs.moodle.org/dev/Frankenstyle}, for example:
* - {@link xmldb_page_upgrade($oldversion)}. (modules don't require the plugintype ("mod_") to be used.
* - {@link xmldb_auth_manual_upgrade($oldversion)}.
* - {@link xmldb_workshopform_accumulative_upgrade($oldversion)}.
* - ....
*
* In order to keep the contents of this file reduced, it's allowed to create some helper
* functions to be used here in the {@link upgradelib.php} file at the same directory. Note
* that such a file must be manually included from upgrade.php, and there are some restrictions
* about what can be used within it.
*
* For more information, take a look to the documentation available:
* - Data definition API: {@link http://docs.moodle.org/dev/Data_definition_API}
* - Upgrade API: {@link http://docs.moodle.org/dev/Upgrade_API}
*
* @param int $oldversion
* @return bool always true
*/
function xmldb_main_upgrade($oldversion)
{
global $CFG, $USER, $DB, $OUTPUT, $SITE;
require_once $CFG->libdir . '/db/upgradelib.php';
// Core Upgrade-related functions
$dbman = $DB->get_manager();
// loads ddl manager and xmldb classes
if ($oldversion < 2011120500) {
// just in case somebody hacks upgrade scripts or env, we really can not continue
echo "You need to upgrade to 2.2.x first!\n";
exit(1);
// Note this savepoint is 100% unreachable, but needed to pass the upgrade checks
upgrade_main_savepoint(true, 2011120500);
}
// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this
if ($oldversion < 2011120500.02) {
upgrade_set_timeout(60 * 20);
// This may take a while
// MDL-28180. Some missing restrictions in certain backup & restore operations
// were causing incorrect duplicates in the course_completion_aggr_methd table.
// This upgrade step takes rid of them.
$sql = 'SELECT course, criteriatype, MIN(id) AS minid
FROM {course_completion_aggr_methd}
GROUP BY course, criteriatype
HAVING COUNT(*) > 1';
$duprs = $DB->get_recordset_sql($sql);
foreach ($duprs as $duprec) {
// We need to handle NULLs in criteriatype diferently
if (is_null($duprec->criteriatype)) {
$where = 'course = ? AND criteriatype IS NULL AND id > ?';
$params = array($duprec->course, $duprec->minid);
} else {
$where = 'course = ? AND criteriatype = ? AND id > ?';
$params = array($duprec->course, $duprec->criteriatype, $duprec->minid);
}
$DB->delete_records_select('course_completion_aggr_methd', $where, $params);
}
$duprs->close();
// Main savepoint reached
upgrade_main_savepoint(true, 2011120500.02);
}
if ($oldversion < 2011120500.03) {
// Changing precision of field value on table user_preferences to (1333)
$table = new xmldb_table('user_preferences');
$field = new xmldb_field('value', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'name');
// Launch change of precision for field value
$dbman->change_field_precision($table, $field);
// Main savepoint reached
upgrade_main_savepoint(true, 2011120500.03);
}
if ($oldversion < 2012020200.03) {
// Define index rolecontext (not unique) to be added to role_assignments
$table = new xmldb_table('role_assignments');
$index = new xmldb_index('rolecontext', XMLDB_INDEX_NOTUNIQUE, array('roleid', 'contextid'));
// Conditionally launch add index rolecontext
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
//.........这里部分代码省略.........
开发者ID:nigeli,项目名称:moodle,代码行数:101,代码来源:upgrade.php
示例15: xmldb_forum_upgrade
/**
* This file keeps track of upgrades to
* the forum module
*
* Sometimes, changes between versions involve
* alterations to database structures and other
* major things that may break installations.
*
* The upgrade function in this file will attempt
* to perform all the necessary actions to upgrade
* your older installation to the current version.
*
* If there's something it cannot do itself, it
* will tell you what you need to do.
*
* The commands in here will all be database-neutral,
* using the methods of database_manager class
*
* Please do not forget to use upgrade_set_timeout()
* before any action that may take longer time to finish.
*
* @package mod-forum
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function xmldb_forum_upgrade($oldversion)
{
global $CFG, $DB, $OUTPUT;
$dbman = $DB->get_manager();
// loads ddl manager and xmldb classes
//===== 1.9.0 upgrade line ======//
if ($oldversion < 2007101511) {
//MDL-13866 - send forum ratins to gradebook again
require_once $CFG->dirroot . '/mod/forum/lib.php';
forum_upgrade_grades();
upgrade_mod_savepoint(true, 2007101511, 'forum');
}
if ($oldversion < 2008072800) {
/// Define field completiondiscussions to be added to forum
$table = new xmldb_table('forum');
$field = new xmldb_field('completiondiscussions');
$field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'blockperiod');
/// Launch add field completiondiscussions
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('completionreplies');
$field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completiondiscussions');
/// Launch add field completionreplies
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define field completionposts to be added to forum
$field = new xmldb_field('completionposts');
$field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionreplies');
/// Launch add field completionposts
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_mod_savepoint(true, 2008072800, 'forum');
}
if ($oldversion < 2008081900) {
/////////////////////////////////////
/// new file storage upgrade code ///
/////////////////////////////////////
$fs = get_file_storage();
$empty = $DB->sql_empty();
// silly oracle empty string handling workaround
$sqlfrom = "FROM {forum_posts} p\n JOIN {forum_discussions} d ON d.id = p.discussion\n JOIN {forum} f ON f.id = d.forum\n JOIN {modules} m ON m.name = 'forum'\n JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = f.id)\n WHERE p.attachment <> '{$empty}' AND p.attachment <> '1'";
$count = $DB->count_records_sql("SELECT COUNT('x') {$sqlfrom}");
$rs = $DB->get_recordset_sql("SELECT p.id, p.attachment, p.userid, d.forum, f.course, cm.id AS cmid {$sqlfrom} ORDER BY f.course, f.id, d.id");
if ($rs->valid()) {
$pbar = new progress_bar('migrateforumfiles', 500, true);
$i = 0;
foreach ($rs as $post) {
$i++;
upgrade_set_timeout(60);
// set up timeout, may also abort execution
$pbar->update($i, $count, "Migrating forum posts - {$i}/{$count}.");
$filepath = "{$CFG->dataroot}/{$post->course}/{$CFG->moddata}/forum/{$post->forum}/{$post->id}/{$post->attachment}";
if (!is_readable($filepath)) {
//file missing??
echo $OUTPUT->notification("File not readable, skipping: " . $filepath);
$post->attachment = '';
$DB->update_record('forum_posts', $post);
continue;
}
$context = get_context_instance(CONTEXT_MODULE, $post->cmid);
$filearea = 'attachment';
$filename = clean_param($post->attachment, PARAM_FILE);
if ($filename === '') {
echo $OUTPUT->notification("Unsupported post filename, skipping: " . $filepath);
$post->attachment = '';
$DB->update_record('forum_posts', $post);
continue;
}
if (!$fs->file_exists($context->id, 'mod_forum', $filearea, $post->id, '/', $filename)) {
$file_record = array('contextid' => $context->id, 'component' => 'mod_forum', 'filearea' => $filearea, 'itemid' => $post->id, 'filepath' => '/', 'filename' => $filename, 'userid' => $post->userid);
if ($fs->create_file_from_pathname($file_record, $filepath)) {
$post->attachment = '1';
//.........这里部分代码省略.........
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:101,代码来源:upgrade.php
示例16: xmldb_chat_upgrade
function xmldb_chat_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
//===== 1.9.0 upgrade line ======//
if ($oldversion < 2010050100) {
/// Changing precision of field ip on table chat_users to (45)
$table = new xmldb_table('chat_users');
$field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'version');
/// Launch change of precision for field ip
$dbman->change_field_precision($table, $field);
/// chat savepoint reached
upgrade_mod_savepoint(true, 2010050100, 'chat');
}
if ($oldversion < 2010050101) {
/// Define field introformat to be added to chat
$table = new xmldb_table('chat');
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
/// Launch add field introformat
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// conditionally migrate to html format in intro
if ($CFG->texteditors !== 'textarea') {
$rs = $DB->get_recordset('chat', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat');
foreach ($rs as $ch) {
$ch->intro = text_to_html($ch->intro, false, false, true);
$ch->introformat = FORMAT_HTML;
$DB->update_record('chat', $ch);
upgrade_set_timeout();
}
$rs->close();
}
/// chat savepoint reached
upgrade_mod_savepoint(true, 2010050101, 'chat');
}
/// Creating chat_messages_current to hold latest chat messages
if ($oldversion < 2010050102) {
/// Define table chat_messages_current to be created
$table = new xmldb_table('chat_messages_current');
/// Adding fields to table chat_messages_current
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('chatid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('system', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('message', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
$table->add_field('timestamp', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
/// Adding keys to table chat_messages_current
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('chatid', XMLDB_KEY_FOREIGN, array('chatid'), 'chat', array('id'));
/// Adding indexes to table chat_messages_current
$table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
$table->add_index('groupid', XMLDB_INDEX_NOTUNIQUE, array('groupid'));
$table->add_index('timestamp-chatid', XMLDB_INDEX_NOTUNIQUE, array('timestamp', 'chatid'));
/// create table for chat_messages_current
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// chat savepoint reached
upgrade_mod_savepoint(true, 2010050102, 'chat');
}
// Moodle v2.1.0 release upgrade line
// Put any upgrade step following this
return true;
}
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:66,代码来源:upgrade.php
示例17: xmldb_main_upgrade
/**
* Main upgrade tasks to be executed on Moodle version bump
*
* This function is automatically executed after one bump in the Moodle core
* version is detected. It's in charge of performing the required tasks
* to raise core from the previous version to the next one.
*
* It's a collection of ordered blocks of code, named "upgrade steps",
* each one performing one isolated (from the rest of steps) task. Usually
* tasks involve creating new DB objects or performing manipulation of the
* information for cleanup/fixup purposes.
*
* Each upgrade step has a fixed structure, that can be summarised as follows:
*
* if ($oldversion < XXXXXXXXXX.XX) {
* // Explanation of the update step, linking to issue in the Tracker if necessary
* upgrade_set_timeout(XX); // Optional for big tasks
* // Code to execute goes here, usually the XMLDB Editor will
* // help you here. See {@link http://docs.moodle.org/dev/XMLDB_editor}.
* upgrade_main_savepoint(true, XXXXXXXXXX.XX);
* }
*
* All plugins within Moodle (modules, blocks, reports...) support the existence of
* their own upgrade.php file, using the "Frankenstyle" component name as
* defined at {@link http://docs.moodle.org/dev/Frankenstyle}, for example:
* - {@link xmldb_page_upgrade($oldversion)}. (modules don't require the plugintype ("mod_") to be used.
* - {@link xmldb_auth_manual_upgrade($oldversion)}.
* - {@link xmldb_workshopform_accumulative_upgrade($oldversion)}.
* - ....
*
* In order to keep the contents of this file reduced, it's allowed to create some helper
* functions to be used here in the {@link upgradelib.php} file at the same directory. Note
* that such a file must be manually included from upgrade.php, and there are some restrictions
* about what can be used within it.
*
* For more information, take a look to the documentation available:
* - Data definition API: {@link http://docs.moodle.org/dev/Data_definition_API}
* - Upgrade API: {@link http://docs.moodle.org/dev/Upgrade_API}
*
* @param int $oldversion
* @return bool always true
*/
function xmldb_main_upgrade($oldversion)
{
global $CFG, $USER, $DB, $OUTPUT, $SITE, $COURSE;
require_once $CFG->libdir . '/db/upgradelib.php';
// Core Upgrade-related functions
$dbman = $DB->get_manager();
// loads ddl manager and xmldb classes
if ($oldversion < 2011120500) {
// just in case somebody hacks upgrade scripts or env, we really can not continue
echo "You need to upgrade to 2.2.x first!\n";
exit(1);
// Note this savepoint is 100% unreachable, but nee
|
请发表评论