本文整理汇总了PHP中upgrade_grade_item_fix_sortorder函数的典型用法代码示例。如果您正苦于以下问题:PHP upgrade_grade_item_fix_sortorder函数的具体用法?PHP upgrade_grade_item_fix_sortorder怎么用?PHP upgrade_grade_item_fix_sortorder使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了upgrade_grade_item_fix_sortorder函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_upgrade_grade_item_fix_sortorder
/**
* Test the {@link upgrade_grade_item_fix_sortorder() function with
* faked duplicate sortorder data.
*/
public function test_upgrade_grade_item_fix_sortorder()
{
global $DB;
$this->resetAfterTest(true);
// The purpose of this test is to make sure that after upgrade script
// there is no duplicates in the field grade_items.sortorder (for each course)
// and the result of query "SELECT id FROM grade_items WHERE courseid=? ORDER BY sortorder, id" does not change.
$sequencesql = 'SELECT id FROM {grade_items} WHERE courseid=? ORDER BY sortorder, id';
// Each set is used for filling the db with fake data and will be representing the result of query:
// "SELECT sortorder from {grade_items} WHERE courseid=? ORDER BY id".
$testsets = array(array(1, 2, 3), array(5, 6, 7), array(7, 6, 1, 3, 2, 5), array(1, 2, 2, 3, 3, 4, 5), array(1, 1), array(3, 3), array(3, 3, 7, 5, 6, 6, 9, 10, 8, 3), array(7, 7, 3), array(3, 4, 5, 3, 5, 4, 7, 1));
$origsequences = array();
// Generate the data and remember the initial sequence or items.
foreach ($testsets as $testset) {
$course = $this->getDataGenerator()->create_course();
foreach ($testset as $sortorder) {
$this->insert_fake_grade_item_sortorder($course->id, $sortorder);
}
$DB->get_records('grade_items');
$origsequences[$course->id] = $DB->get_fieldset_sql($sequencesql, array($course->id));
}
$duplicatedetectionsql = "SELECT courseid, sortorder\n FROM {grade_items}\n GROUP BY courseid, sortorder\n HAVING COUNT(id) > 1";
// Verify there are duplicates before we start the fix.
$dupes = $DB->record_exists_sql($duplicatedetectionsql);
$this->assertTrue($dupes);
// Do the work.
upgrade_grade_item_fix_sortorder();
// Verify that no duplicates are left in the database.
$dupes = $DB->record_exists_sql($duplicatedetectionsql);
$this->assertFalse($dupes);
// Verify that sequences are exactly the same as they were before upgrade script.
$idx = 0;
foreach ($origsequences as $courseid => $origsequence) {
if (count($testsets[$idx]) == count(array_unique($testsets[$idx]))) {
// If there were no duplicates for this course verify that sortorders are not modified.
$newsortorders = $DB->get_fieldset_sql("SELECT sortorder from {grade_items} WHERE courseid=? ORDER BY id", array($courseid));
$this->assertEquals($testsets[$idx], $newsortorders);
}
$newsequence = $DB->get_fieldset_sql($sequencesql, array($courseid));
$this->assertEquals($origsequence, $newsequence, "Sequences do not match for test set {$idx} : " . join(',', $testsets[$idx]));
$idx++;
}
}
示例2: xmldb_main_upgrade
//.........这里部分代码省略.........
$sqlcompareoldvalue = $DB->sql_compare_text('oldvalue');
if ($plugin === 'core') {
$sql = "UPDATE {config_log}\n SET value = :value\n WHERE name = :name AND plugin IS NULL AND {$sqlcomparevalue} <> :empty";
$params = array('value' => '********', 'name' => $name, 'empty' => '');
$DB->execute($sql, $params);
$sql = "UPDATE {config_log}\n SET oldvalue = :value\n WHERE name = :name AND plugin IS NULL AND {$sqlcompareoldvalue} <> :empty";
$params = array('value' => '********', 'name' => $name, 'empty' => '');
$DB->execute($sql, $params);
} else {
$sql = "UPDATE {config_log}\n SET value = :value\n WHERE name = :name AND plugin = :plugin AND {$sqlcomparevalue} <> :empty";
$params = array('value' => '********', 'name' => $name, 'plugin' => $plugin, 'empty' => '');
$DB->execute($sql, $params);
$sql = "UPDATE {config_log}\n SET oldvalue = :value\n WHERE name = :name AND plugin = :plugin AND {$sqlcompareoldvalue} <> :empty";
$params = array('value' => '********', 'name' => $name, 'plugin' => $plugin, 'empty' => '');
$DB->execute($sql, $params);
}
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2013122400.01);
}
if ($oldversion < 2014011000.01) {
// Define table cache_text to be dropped.
$table = new xmldb_table('cache_text');
// Conditionally launch drop table for cache_text.
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
unset_config('cachetext');
// Main savepoint reached.
upgrade_main_savepoint(true, 2014011000.01);
}
if ($oldversion < 2014011701.0) {
// Fix gradebook sortorder duplicates.
upgrade_grade_item_fix_sortorder();
// Main savepoint reached.
upgrade_main_savepoint(true, 2014011701.0);
}
if ($oldversion < 2014012300.01) {
// Remove deleted users home pages.
$sql = "DELETE FROM {my_pages}\n WHERE EXISTS (SELECT {user}.id\n FROM {user}\n WHERE {user}.id = {my_pages}.userid\n AND {user}.deleted = 1)\n AND {my_pages}.private = 1";
$DB->execute($sql);
// Reached main savepoint.
upgrade_main_savepoint(true, 2014012300.01);
}
if ($oldversion < 2014012400.0) {
// Define table lock_db to be created.
$table = new xmldb_table('lock_db');
// Adding fields to table lock_db.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('resourcekey', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('expires', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
$table->add_field('owner', XMLDB_TYPE_CHAR, '36', null, null, null, null);
// Adding keys to table lock_db.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
// Adding indexes to table lock_db.
$table->add_index('resourcekey_uniq', XMLDB_INDEX_UNIQUE, array('resourcekey'));
$table->add_index('expires_idx', XMLDB_INDEX_NOTUNIQUE, array('expires'));
$table->add_index('owner_idx', XMLDB_INDEX_NOTUNIQUE, array('owner'));
// Conditionally launch create table for lock_db.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014012400.0);
}
if ($oldversion < 2014021300.01) {
示例3: xmldb_main_upgrade
//.........这里部分代码省略.........
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2013051402.1);
}
if ($oldversion < 2013051402.12) {
// MDL-38228. Corrected course_modules upgrade script instead of 2013021801.01.
// This upgrade script fixes the mismatches between DB fields course_modules.section
// and course_sections.sequence. It makes sure that each module is included
// in the sequence of only one section and that course_modules.section points back to it.
// This script in included in each major version upgrade process so make sure we don't run it twice.
if (empty($CFG->movingmoduleupgradescriptwasrun)) {
upgrade_course_modules_sequences();
// To skip running the same script on the upgrade to the next major release.
set_config('movingmoduleupgradescriptwasrun', 1);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2013051402.12);
}
if ($oldversion < 2013051403.02) {
// Delete notes of deleted courses.
$sql = "DELETE FROM {post}\n WHERE NOT EXISTS (SELECT {course}.id FROM {course}\n WHERE {course}.id = {post}.courseid)\n AND {post}.module = ?";
$DB->execute($sql, array('notes'));
// Main savepoint reached.
upgrade_main_savepoint(true, 2013051403.02);
}
if ($oldversion < 2013051403.09) {
// Purge stored passwords from config_log table, ideally this should be in each plugin
// but that would complicate backporting...
$items = array('core/cronremotepassword', 'core/proxypassword', 'core/smtppass', 'core/jabberpassword', 'enrol_database/dbpass', 'enrol_ldap/bind_pw', 'url/secretphrase');
foreach ($items as $item) {
list($plugin, $name) = explode('/', $item);
$sqlcomparevalue = $DB->sql_compare_text('value');
$sqlcompareoldvalue = $DB->sql_compare_text('oldvalue');
if ($plugin === 'core') {
$sql = "UPDATE {config_log}\n SET value = :value\n WHERE name = :name AND plugin IS NULL AND {$sqlcomparevalue} <> :empty";
$params = array('value' => '********', 'name' => $name, 'empty' => '');
$DB->execute($sql, $params);
$sql = "UPDATE {config_log}\n SET oldvalue = :value\n WHERE name = :name AND plugin IS NULL AND {$sqlcompareoldvalue} <> :empty";
$params = array('value' => '********', 'name' => $name, 'empty' => '');
$DB->execute($sql, $params);
} else {
$sql = "UPDATE {config_log}\n SET value = :value\n WHERE name = :name AND plugin = :plugin AND {$sqlcomparevalue} <> :empty";
$params = array('value' => '********', 'name' => $name, 'plugin' => $plugin, 'empty' => '');
$DB->execute($sql, $params);
$sql = "UPDATE {config_log}\n SET oldvalue = :value\n WHERE name = :name AND plugin = :plugin AND {$sqlcompareoldvalue} <> :empty";
$params = array('value' => '********', 'name' => $name, 'plugin' => $plugin, 'empty' => '');
$DB->execute($sql, $params);
}
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2013051403.09);
}
if ($oldversion < 2013051404.02) {
// Fix gradebook sortorder duplicates.
upgrade_grade_item_fix_sortorder();
// Main savepoint reached.
upgrade_main_savepoint(true, 2013051404.02);
}
if ($oldversion < 2013051404.04) {
// Remove deleted users home pages.
$sql = "DELETE FROM {my_pages}\n WHERE EXISTS (SELECT {user}.id\n FROM {user}\n WHERE {user}.id = {my_pages}.userid\n AND {user}.deleted = 1)\n AND {my_pages}.private = 1";
$DB->execute($sql);
// Reached main savepoint.
upgrade_main_savepoint(true, 2013051404.04);
}
if ($oldversion < 2013051405.1) {
// Fixing possible wrong MIME type for DigiDoc files.
$extensions = array('%.bdoc', '%.cdoc', '%.ddoc');
$select = $DB->sql_like('filename', '?', false);
foreach ($extensions as $extension) {
$DB->set_field_select('files', 'mimetype', 'application/x-digidoc', $select, array($extension));
}
upgrade_main_savepoint(true, 2013051405.1);
}
// MDL-32543 Make sure that the log table has correct length for action and url fields.
if ($oldversion < 2013051406.01) {
$table = new xmldb_table('log');
$columns = $DB->get_columns('log');
if ($columns['action']->max_length < 40) {
$index1 = new xmldb_index('course-module-action', XMLDB_INDEX_NOTUNIQUE, array('course', 'module', 'action'));
if ($dbman->index_exists($table, $index1)) {
$dbman->drop_index($table, $index1);
}
$index2 = new xmldb_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
if ($dbman->index_exists($table, $index2)) {
$dbman->drop_index($table, $index2);
}
$field = new xmldb_field('action', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'cmid');
$dbman->change_field_precision($table, $field);
$dbman->add_index($table, $index1);
$dbman->add_index($table, $index2);
}
if ($columns['url']->max_length < 100) {
$field = new xmldb_field('url', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'action');
$dbman->change_field_precision($table, $field);
}
upgrade_main_savepoint(true, 2013051406.01);
}
return true;
}