Skip to content

Commit

Permalink
MDL-30610 remove outdated enrol upgrade code
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Dec 23, 2011
1 parent 612d65d commit 3751e28
Show file tree
Hide file tree
Showing 13 changed files with 1 addition and 487 deletions.
76 changes: 0 additions & 76 deletions enrol/authorize/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,81 +23,5 @@
function xmldb_enrol_authorize_upgrade($oldversion) {
global $CFG, $DB, $OUTPUT;

$dbman = $DB->get_manager();

//===== 1.9.0 upgrade line ======//

if ($oldversion < 2008092700) {
/// enrol_authorize.transid
/// Define index transid (not unique) to be dropped form enrol_authorize
$table = new xmldb_table('enrol_authorize');
$index = new xmldb_index('transid', XMLDB_INDEX_NOTUNIQUE, array('transid'));
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}

/// Changing precision of field transid on table enrol_authorize to (20)
$table = new xmldb_table('enrol_authorize');
$field = new xmldb_field('transid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'userid');
$dbman->change_field_precision($table, $field);

/// Launch add index transid again
$table = new xmldb_table('enrol_authorize');
$index = new xmldb_index('transid', XMLDB_INDEX_NOTUNIQUE, array('transid'));
$dbman->add_index($table, $index);

/// enrol_authorize_refunds.transid
/// Define index transid (not unique) to be dropped form enrol_authorize_refunds
$table = new xmldb_table('enrol_authorize_refunds');
$index = new xmldb_index('transid', XMLDB_INDEX_NOTUNIQUE, array('transid'));
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}

/// Changing precision of field transid on table enrol_authorize_refunds to (20)
$table = new xmldb_table('enrol_authorize_refunds');
$field = new xmldb_field('transid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, '0', 'amount');
$dbman->change_field_precision($table, $field);

/// Launch add index transid again
$table = new xmldb_table('enrol_authorize_refunds');
$index = new xmldb_index('transid', XMLDB_INDEX_NOTUNIQUE, array('transid'));
$dbman->add_index($table, $index);

/// authorize savepoint reached
upgrade_plugin_savepoint(true, 2008092700, 'enrol', 'authorize');
}

/// Dropping all enums/check contraints from core. MDL-18577
if ($oldversion < 2009042700) {

/// Changing list of values (enum) of field paymentmethod on table enrol_authorize to none
$table = new xmldb_table('enrol_authorize');
$field = new xmldb_field('paymentmethod', XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, 'cc', 'id');

/// Launch change of list of values for field paymentmethod
$dbman->drop_enum_from_field($table, $field);

/// authorize savepoint reached
upgrade_plugin_savepoint(true, 2009042700, 'enrol', 'authorize');
}

// Add instanceid field to enrol_authorize table
if ($oldversion < 2010081203) {
$table = new xmldb_table('enrol_authorize');
$field = new xmldb_field('instanceid');
if (!$dbman->field_exists($table, $field)) {
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'userid');
$dbman->add_field($table, $field);
}
upgrade_plugin_savepoint(true, 2010081203, 'enrol', 'authorize');
}

// Moodle v2.1.0 release upgrade line
// Put any upgrade step following this

// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this

return true;
}
40 changes: 0 additions & 40 deletions enrol/category/db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,4 @@
function xmldb_enrol_category_install() {
global $CFG, $DB;

if (!$DB->record_exists_select('role_assignments', "contextid IN (SELECT id FROM {context} WHERE contextlevel = ?)", array(CONTEXT_COURSECAT))) {
// fresh install or nobody used category enrol
return;
}

// existing sites need a way to keep category role enrols, but we do not want to encourage that on new sites

// extremely ugly hack, the sync depends on the capabilities so we unfortunately force update of caps here
// note: this is not officially supported and should not be copied elsewhere! :-(
update_capabilities('enrol_category');
$syscontext = get_context_instance(CONTEXT_SYSTEM);
$archetypes = array('student', 'teacher', 'editingteacher');
$enableplugin = false;
foreach ($archetypes as $archetype) {
$roles = get_archetype_roles($archetype);
foreach ($roles as $role) {
if (!$DB->record_exists_select('role_assignments', "roleid = ? AND contextid IN (SELECT id FROM {context} WHERE contextlevel = ?)", array($role->id, CONTEXT_COURSECAT))) {
continue;
}
assign_capability('enrol/category:synchronised', CAP_ALLOW, $role->id, $syscontext->id, true);
$levels = get_role_contextlevels($role->id);
$levels[] = CONTEXT_COURSECAT;
set_role_contextlevels($role->id, $levels);
$enableplugin = true;
}
}

if (!$enableplugin) {
return;
}

// enable this plugin
$enabledplugins = explode(',', $CFG->enrol_plugins_enabled);
$enabledplugins[] = 'category';
$enabledplugins = array_unique($enabledplugins);
set_config('enrol_plugins_enabled', implode(',', $enabledplugins));

// brute force course resync, this may take a while
require_once("$CFG->dirroot/enrol/category/locallib.php");
enrol_category_sync_full();
}
79 changes: 0 additions & 79 deletions enrol/database/db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,83 +28,4 @@
function xmldb_enrol_database_install() {
global $CFG, $DB;

// migrate old config settings first
if (isset($CFG->enrol_dbtype)) {
set_config('dbtype', $CFG->enrol_dbtype, 'enrol_database');
unset_config('enrol_dbtype');
}
if (isset($CFG->enrol_dbhost)) {
set_config('dbhost', $CFG->enrol_dbhost, 'enrol_database');
unset_config('enrol_dbhost');
}
if (isset($CFG->enrol_dbuser)) {
set_config('dbuser', $CFG->enrol_dbuser, 'enrol_database');
unset_config('enrol_dbuser');
}
if (isset($CFG->enrol_dbpass)) {
set_config('dbpass', $CFG->enrol_dbpass, 'enrol_database');
unset_config('enrol_dbpass');
}
if (isset($CFG->enrol_dbname)) {
set_config('dbname', $CFG->enrol_dbname, 'enrol_database');
unset_config('enrol_dbname');
}
if (isset($CFG->enrol_dbtable)) {
set_config('remoteenroltable', $CFG->enrol_dbtable, 'enrol_database');
unset_config('enrol_dbtable');
}
if (isset($CFG->enrol_localcoursefield)) {
set_config('localcoursefield', $CFG->enrol_localcoursefield, 'enrol_database');
unset_config('enrol_localcoursefield');
}
if (isset($CFG->enrol_localuserfield)) {
set_config('localuserfield', $CFG->enrol_localuserfield, 'enrol_database');
unset_config('enrol_localuserfield');
}
if (isset($CFG->enrol_db_localrolefield)) {
set_config('localrolefield', $CFG->enrol_db_localrolefield, 'enrol_database');
unset_config('enrol_db_localrolefield');
}
if (isset($CFG->enrol_remotecoursefield)) {
set_config('remotecoursefield', $CFG->enrol_remotecoursefield, 'enrol_database');
unset_config('enrol_remotecoursefield');
}
if (isset($CFG->enrol_remoteuserfield)) {
set_config('remoteuserfield', $CFG->enrol_remoteuserfield, 'enrol_database');
unset_config('enrol_remoteuserfield');
}
if (isset($CFG->enrol_db_remoterolefield)) {
set_config('remoterolefield', $CFG->enrol_db_remoterolefield, 'enrol_database');
unset_config('enrol_db_remoterolefield');
}
if (isset($CFG->enrol_db_defaultcourseroleid)) {
set_config('defaultrole', $CFG->enrol_db_defaultcourseroleid, 'enrol_database');
unset_config('enrol_db_defaultcourseroleid');
}
unset_config('enrol_db_autocreate'); // replaced by new coruse temple sync
if (isset($CFG->enrol_db_category)) {
set_config('defaultcategory', $CFG->enrol_db_category, 'enrol_database');
unset_config('enrol_db_category');
}
if (isset($CFG->enrol_db_template)) {
set_config('templatecourse', $CFG->enrol_db_template, 'enrol_database');
unset_config('enrol_db_template');
}
if (isset($CFG->enrol_db_ignorehiddencourse)) {
set_config('ignorehiddencourses', $CFG->enrol_db_ignorehiddencourse, 'enrol_database');
unset_config('enrol_db_ignorehiddencourse');
}

unset_config('enrol_db_disableunenrol');






// just make sure there are no leftovers after disabled plugin
if (!$DB->record_exists('enrol', array('enrol'=>'database'))) {
role_unassign_all(array('component'=>'enrol_database'));
return;
}
}
15 changes: 0 additions & 15 deletions enrol/database/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,5 @@
function xmldb_enrol_database_upgrade($oldversion) {
global $DB;

$dbman = $DB->get_manager();

// fix leftovers after incorrect 2.x upgrade in install.php
if ($oldversion < 2010073101) {
unset_config('enrol_db_localrolefield');
unset_config('enrol_db_remoterolefield');
unset_config('enrol_db_disableunenrol');

upgrade_plugin_savepoint(true, 2010073101, 'enrol', 'database');
}


// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this

return true;
}
38 changes: 1 addition & 37 deletions enrol/flatfile/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,5 @@
function xmldb_enrol_flatfile_upgrade($oldversion) {
global $CFG, $DB;

$result = TRUE;
$dbman = $DB->get_manager();

if ($oldversion < 2010091400) {

// Define table enrol_flatfile to be created
$table = new xmldb_table('enrol_flatfile');

// Adding fields to table enrol_flatfile
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('action', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
$table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('timestart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('timeend', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');

// Adding keys to table enrol_flatfile
$table->add_key('id', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('courseid-id', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
$table->add_key('userid-id', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
$table->add_key('roleid-id', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));

// Conditionally launch create table for enrol_flatfile
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}

// flatfile savepoint reached
upgrade_plugin_savepoint(true, 2010091400, 'enrol', 'flatfile');
}

// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this

return $result;
return true;
}
47 changes: 0 additions & 47 deletions enrol/imsenterprise/db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,51 +28,4 @@
function xmldb_enrol_imsenterprise_install() {
global $CFG, $DB;

// NOTE: this file is executed during upgrade from 1.9.x!


// this plugin does not use the new file api - lets undo the migration
$fs = get_file_storage();

if ($DB->record_exists('course', array('id'=>1))) { //course 1 is hardcoded here intentionally!
if ($context = get_context_instance(CONTEXT_COURSE, 1)) {
if ($file = $fs->get_file($context->id, 'course', 'legacy', 0, '/', 'imsenterprise-enrol.xml')) {
if (!file_exists("$CFG->dataroot/1/imsenterprise-enrol.xml")) {
check_dir_exists($CFG->dataroot.'/');
$file->copy_content_to("$CFG->dataroot/1/imsenterprise-enrol.xml");
}
$file->delete();
}
}
}

if (!empty($CFG->enrol_imsfilelocation)) {
if (strpos($CFG->enrol_imsfilelocation, "$CFG->dataroot/") === 0) {
$location = str_replace("$CFG->dataroot/", '', $CFG->enrol_imsfilelocation);
$location = str_replace('\\', '/', $location);
$parts = explode('/', $location);
$courseid = array_shift($parts);
if (is_number($courseid) and $DB->record_exists('course', array('id'=>$courseid))) {
if ($context = get_context_instance(CONTEXT_COURSE, $courseid)) {
$file = array_pop($parts);
if ($parts) {
$dir = '/'.implode('/', $parts).'/';
} else {
$dir = '/';
}
if ($file = $fs->get_file($context->id, 'course', 'legacy', 0, $dir, $file)) {
if (!file_exists($CFG->enrol_imsfilelocation)) {
check_dir_exists($CFG->dataroot.'/'.$courseid.$dir);
$file->copy_content_to($CFG->enrol_imsfilelocation);
}
$file->delete();
}
}
}
}
}


// TODO: migrate old config settings

}
58 changes: 0 additions & 58 deletions enrol/imsenterprise/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,64 +28,6 @@
function xmldb_enrol_imsenterprise_upgrade($oldversion) {
global $CFG, $DB, $OUTPUT;

$dbman = $DB->get_manager();


//NOTE: this file is not executed during upgrade from 1.9.x!


if ($oldversion < 2011013000) {
// this plugin does not use the new file api - lets undo the migration

$fs = get_file_storage();

if ($DB->record_exists('course', array('id'=>1))) { //course 1 is hardcoded here intentionally!
if ($context = get_context_instance(CONTEXT_COURSE, 1)) {
if ($file = $fs->get_file($context->id, 'course', 'legacy', 0, '/', 'imsenterprise-enrol.xml')) {
if (!file_exists("$CFG->dataroot/1/imsenterprise-enrol.xml")) {
check_dir_exists($CFG->dataroot.'/');
$file->copy_content_to("$CFG->dataroot/1/imsenterprise-enrol.xml");
}
$file->delete();
}
}
}

if (!empty($CFG->enrol_imsfilelocation)) {
if (strpos($CFG->enrol_imsfilelocation, "$CFG->dataroot/") === 0) {
$location = str_replace("$CFG->dataroot/", '', $CFG->enrol_imsfilelocation);
$location = str_replace('\\', '/', $location);
$parts = explode('/', $location);
$courseid = array_shift($parts);
if (is_number($courseid) and $DB->record_exists('course', array('id'=>$courseid))) {
if ($context = get_context_instance(CONTEXT_COURSE, $courseid)) {
$file = array_pop($parts);
if ($parts) {
$dir = '/'.implode('/', $parts).'/';
} else {
$dir = '/';
}
if ($file = $fs->get_file($context->id, 'course', 'legacy', 0, $dir, $file)) {
if (!file_exists($CFG->enrol_imsfilelocation)) {
check_dir_exists($CFG->dataroot.'/'.$courseid.$dir);
$file->copy_content_to($CFG->enrol_imsfilelocation);
}
$file->delete();
}
}
}
}
}

upgrade_plugin_savepoint(true, 2011013000, 'enrol', 'imsenterprise');
}

// Moodle v2.1.0 release upgrade line
// Put any upgrade step following this

// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this

return true;
}

Expand Down
Loading

0 comments on commit 3751e28

Please sign in to comment.