Skip to content

Commit

Permalink
MDL-14679 ok, here is the big patch with new dmllib and ddlib API, so…
Browse files Browse the repository at this point in the history
…me code is already converted, XML db editor works; see tracker for details of regressions and TODOs
  • Loading branch information
skodak committed May 15, 2008
1 parent 469dcbc commit f33e1ed
Show file tree
Hide file tree
Showing 112 changed files with 8,187 additions and 6,558 deletions.
12 changes: 6 additions & 6 deletions admin/cliupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,16 +860,16 @@
/// Both old .sql files and new install.xml are supported
/// But we prioritise install.xml (XMLDB) if present

change_db_encoding(); // first try to change db encoding to utf8

if (!setup_is_unicodedb()) {
// If could not convert successfully, throw error, and prevent installation
console_write(STDERR,'unicoderequired', 'admin');
if (!$DB->setup_is_unicodedb()) {
if (!$DB->change_db_encoding()) {
// If could not convert successfully, throw error, and prevent installation
console_write(STDERR,'unicoderequired', 'admin');
}
}

$status = false;
if (file_exists("$CFG->libdir/db/install.xml")) {
$status = install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
$status = $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
} else {
console_write(STDERR,"Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle or install.xml is not present. See the lib/db directory.",'',false);
}
Expand Down
2 changes: 1 addition & 1 deletion admin/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

/// Extra debugging (set in config.php)
if (!empty($CFG->showcronsql)) {
$db->debug = true;
$DB->set_debug(true);
}
if (!empty($CFG->showcrondebugging)) {
$CFG->debug = DEBUG_DEVELOPER;
Expand Down
42 changes: 17 additions & 25 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@
print_error('phpvaron', 'debug', '', array('file_uploads', $documentationlink));
}

if (empty($CFG->prefix) && $CFG->dbfamily != 'mysql') { //Enforce prefixes for everybody but mysql
print_error('prefixcannotbeempty', 'debug', '', array($CFG->prefix, $CFG->dbtype));
}

if ($CFG->dbfamily == 'oracle' && strlen($CFG->prefix) > 2) { //Max prefix length for Oracle is 2cc
print_error('prefixlimit', 'debug', '', $CFG->prefix);
}

/// Check that config.php has been edited

if ($CFG->wwwroot == "http://example.com/moodle") {
Expand Down Expand Up @@ -103,8 +95,7 @@
}

/// Check if the main tables have been installed yet or not.

if (! $tables = $db->Metatables() ) { // No tables yet at all.
if (!$tables = $DB->get_tables() ) { // No tables yet at all.
$maintables = false;

} else { // Check for missing main tables
Expand All @@ -113,7 +104,7 @@
"course_sections", "log", "log_display", "modules",
"user");
foreach ($mtables as $mtable) {
if (!in_array($CFG->prefix.$mtable, $tables)) {
if (!in_array($mtable, $tables)) {
$maintables = false;
break;
}
Expand Down Expand Up @@ -164,20 +155,21 @@
$CFG->debug = $origdebug;
error_reporting($CFG->debug);
upgrade_log_start();
$db->debug = true;
$DB->set_debug(true);

/// Both old .sql files and new install.xml are supported
/// But we prioritise install.xml (XMLDB) if present

change_db_encoding(); // first try to change db encoding to utf8
if (!setup_is_unicodedb()) {
// If could not convert successfully, throw error, and prevent installation
print_error('unicoderequired', 'admin');
if (!$DB->setup_is_unicodedb()) {
if (!$DB->change_db_encoding()) {
// If could not convert successfully, throw error, and prevent installation
print_error('unicoderequired', 'admin');
}
}

$status = false;
if (file_exists("$CFG->libdir/db/install.xml")) {
$status = install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
$status = $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
} else {
print_error('dbnotsupport', 'debug', '', $CFG->dbtype);
}
Expand All @@ -186,7 +178,7 @@
set_config('unicodedb', 1);

/// Continue with the instalation
$db->debug = false;
$DB->set_debug(false);
if ($status) {

/// Groups install is now in core above.
Expand Down Expand Up @@ -335,7 +327,7 @@
upgrade_language_pack();

print_heading($strdatabasechecking);
$db->debug=true;
$DB->set_debug(true);
/// Launch the old main upgrade (if exists)
$status = true;
if (function_exists('main_upgrade')) {
Expand All @@ -345,7 +337,7 @@
if ($status && function_exists('xmldb_main_upgrade')) {
$status = xmldb_main_upgrade($CFG->version);
}
$db->debug=false;
$DB->set_debug(false);
/// If successful, continue upgrading roles and setting everything properly
if ($status) {
if (!update_capabilities()) {
Expand Down Expand Up @@ -473,7 +465,7 @@
$newsite->students = get_string("defaultcoursestudents");
$newsite->timemodified = time();

if (!$newid = insert_record('course', $newsite)) {
if (!$newid = $DB->insert_record('course', $newsite)) {
print_error('cannotsetupsite', 'error');
}
// make sure course context exists
Expand All @@ -486,7 +478,7 @@
$cat = new object();
$cat->name = get_string('miscellaneous');
$cat->depth = 1;
if (!$catid = insert_record('course_categories', $cat)) {
if (!$catid = $DB->insert_record('course_categories', $cat)) {
print_error('cannotsetupcategory', 'error');
}
// make sure category context exists
Expand All @@ -505,10 +497,10 @@
blocks_repopulate_page($page);

//add admin_tree block to site if not already present
if ($admintree = get_record('block', 'name', 'admin_tree')) {
if ($admintree = $DB->get_record('block', array('name'=>'admin_tree'))) {
$page = page_create_object(PAGE_COURSE_VIEW, SITEID);
blocks_execute_action($page, blocks_get_by_page($page), 'add', (int)$admintree->id, false, false);
if ($admintreeinstance = get_record('block_instance', 'pagetype', $page->type, 'pageid', SITEID, 'blockid', $admintree->id)) {
if ($admintreeinstance = $DB->get_record('block_instance', array('pagetype'=>$page->type, 'pageid'=>SITEID, 'blockid'=>$admintree->id))) {
blocks_execute_action($page, blocks_get_by_page($page), 'moveleft', $admintreeinstance, false, false);
}
}
Expand All @@ -522,7 +514,7 @@
}

/// Check if the guest user exists. If not, create one.
if (! record_exists("user", "username", "guest")) {
if (!$DB->record_exists('user', array('username'=>'guest'))) {
if (! $guest = create_guest_record()) {
notify("Could not create guest user record !!!");
}
Expand Down
65 changes: 33 additions & 32 deletions admin/innodb.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
<?php

require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');

admin_externalpage_setup('toinodb');
admin_externalpage_setup('toinodb');

$confirm = optional_param('confirm', 0, PARAM_BOOL);
$confirm = optional_param('confirm', 0, PARAM_BOOL);

require_login();
require_login();

require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));

admin_externalpage_print_header();
print_heading('Convert all MySQL tables from MYISAM to InnoDB');
admin_externalpage_print_header();
print_heading('Convert all MySQL tables from MYISAM to InnoDB');

if ($CFG->dbfamily != 'mysql') {
if ($CFG->dbfamily != 'mysql') {
notice('This function is for MySQL databases only!', 'index.php');
}

if (data_submitted() and $confirm and confirm_sesskey()) {

notify('Please be patient and wait for this to complete...', 'notifysuccess');

if ($tables = $db->MetaTables()) {
$db->debug = true;
foreach ($tables as $table) {
execute_sql("ALTER TABLE $table TYPE=INNODB; ");
}
$db->debug = false;
}
notify('... done.', 'notifysuccess');
print_continue('index.php');
admin_externalpage_print_footer();

} else {
$optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey());
notice_yesno('Are you sure you want convert all your tables to the InnoDB format?',
'innodb.php', 'index.php', $optionsyes, NULL, 'post', 'get');
admin_externalpage_print_footer();
}
}

if (data_submitted() and $confirm and confirm_sesskey()) {

notify('Please be patient and wait for this to complete...', 'notifysuccess');

if ($tables = $DB->get_tables()) {
$DB->set_debug(true);
foreach ($tables as $table) {
$fulltable = $DB->get_prefix().$table;
$DB->change_database_structure("ALTER TABLE $fulltable TYPE=INNODB");
}
$DB->set_debug(false);
}
notify('... done.', 'notifysuccess');
print_continue('index.php');
admin_externalpage_print_footer();

} else {
$optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey());
notice_yesno('Are you sure you want convert all your tables to the InnoDB format?',
'innodb.php', 'index.php', $optionsyes, NULL, 'post', 'get');
admin_externalpage_print_footer();
}

?>
12 changes: 6 additions & 6 deletions admin/mnet/access_control.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
admin_externalpage_print_header();

if (!extension_loaded('openssl')) {
print_error('requiresopenssl', 'mnet', '', NULL, true);
print_error('requiresopenssl', 'mnet');
}

$sitecontext = get_context_instance(CONTEXT_SYSTEM);
$sesskey = sesskey();
$formerror = array();

// grab the mnet hosts and remove the localhost
$mnethosts = get_records_menu('mnet_host', '', '', 'name', 'id, name');
$mnethosts = $DB->get_records_menu('mnet_host', array(), 'name', 'id, name');
if (array_key_exists($CFG->mnet_localhost_id, $mnethosts)) {
unset($mnethosts[$CFG->mnet_localhost_id]);
}
Expand All @@ -39,13 +39,13 @@

// boot if insufficient permission
if (!has_capability('moodle/user:delete', $sitecontext)) {
error(get_string('nomodifyacl','mnet'));
print_error('nomodifyacl','mnet');
}

// fetch the record in question
$id = required_param('id', PARAM_INT);
if (!$idrec = get_record('mnet_sso_access_control', 'id', $id)) {
error(get_string('recordnoexists','mnet'), "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
print_error('recordnoexists','mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
}

switch ($action) {
Expand All @@ -60,7 +60,7 @@
// require the access parameter, and it must be 'allow' or 'deny'
$accessctrl = trim(strtolower(required_param('accessctrl', PARAM_ALPHA)));
if ($accessctrl != 'allow' and $accessctrl != 'deny') {
error(get_string('invalidaccessparam', 'mnet') , "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
print_error('invalidaccessparam', 'mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
}

if (mnet_update_sso_access_control($idrec->username, $idrec->mnet_host_id, $accessctrl)) {
Expand All @@ -84,7 +84,7 @@

// check permissions and verify form input
if (!has_capability('moodle/user:delete', $sitecontext)) {
error(get_string('nomodifyacl','mnet'), "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
print_error('nomodifyacl','mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
}
if (empty($form->username)) {
$formerror['username'] = get_string('enterausername','mnet');
Expand Down
27 changes: 12 additions & 15 deletions admin/multilangupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}


if (!$tables = $db->Metatables() ) { // No tables yet at all.
if (!$tables = $DB->get_tables() ) { // No tables yet at all.
print_error('notables', 'debug');
}

Expand All @@ -38,37 +38,35 @@

echo '<strong>Progress:</strong>';
$i = 0;
$skiptables = array($CFG->prefix.'config', $CFG->prefix.'user_students', $CFG->prefix.'user_teachers');//, $CFG->prefix.'sessions2');
$skiptables = array('config', 'user_students', 'user_teachers');//, 'sessions2');

foreach ($tables as $table) {
if (($CFG->prefix && strpos($table, $CFG->prefix) !== 0)
or strpos($table, $CFG->prefix.'pma') === 0) { // Not our tables
if (strpos($table,'pma') === 0) { // Not our tables
continue;
}
if (in_array($table, $skiptables)) { // Don't process these
continue;
}
if ($columns = $db->MetaColumns($table, false)) {
$fulltable = $DB->get_prefix().$table;
if ($columns = $DB->get_columns($table)) {
if (!array_key_exists('id', $columns) and !array_key_exists('ID', $columns)) {
continue; // moodle tables have id
}
foreach ($columns as $column => $data) {
if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) { // Text stuff only
// first find candidate records
$rs = get_recordset_sql("SELECT id, $column FROM $table WHERE $column LIKE '%</lang>%' OR $column LIKE '%<span lang=%'");
if ($rs) {
while (!$rs->EOF) {
$text = $rs->fields[$column];
$id = $rs->fields['id'];

$sql = "SELECT id, $column FROM $fulltable WHERE $column LIKE '%</lang>%' OR $column LIKE '%<span lang=%'";
if ($rs = $DB->get_recordset_sql($sql)) {
foreach ($rs as $data) {
$text = $data->$column;
$id = $data->id;
if ($i % 600 == 0) {
echo '<br />';
}
if ($i % 10 == 0) {
echo '.';
}
$i++;
$rs->MoveNext();

if (empty($text) or is_numeric($text)) {
continue; // nothing to do
Expand All @@ -82,11 +80,10 @@
}

if ($newtext != $text) {
$newtext = addslashes($newtext);
execute_sql("UPDATE $table SET $column='$newtext' WHERE id=$id", false);
$DB->execute("UPDATE $fulltable SET $column=? WHERE id=?", array($newtext, $id));
}
}
rs_close($rs);
$rs->close();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions admin/replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@

print_simple_box_start('center');

if (!db_replace($search, $replace)) {
if (!db_replace(stripslashes($search), stripslashes($replace))) {
print_error('erroroccur', debug);
}

print_simple_box_end();

/// Rebuild course cache which might be incorrect now
notify('Rebuilding course cache...');
notify('Rebuilding course cache...', 'notifysuccess');
rebuild_course_cache();
notify('...finished');
notify('...finished', 'notifysuccess');

print_continue('index.php');

Expand Down
Loading

0 comments on commit f33e1ed

Please sign in to comment.