MDL-15246 moving all remaining ddl function to adminlib, keeping old lib/ddllib.php only for BC withexisting code; fixed inline docs related to ddl
This commit is contained in:
@@ -9,6 +9,22 @@
|
||||
* @package moodlecore
|
||||
*/
|
||||
|
||||
/// Add required XMLDB constants
|
||||
require_once($CFG->libdir.'/xmldb/xmldb_constants.php');
|
||||
|
||||
/// Add required XMLDB DB classes
|
||||
require_once($CFG->libdir.'/xmldb/xmldb_object.php');
|
||||
require_once($CFG->libdir.'/xmldb/xmldb_file.php');
|
||||
require_once($CFG->libdir.'/xmldb/xmldb_structure.php');
|
||||
require_once($CFG->libdir.'/xmldb/xmldb_table.php');
|
||||
require_once($CFG->libdir.'/xmldb/xmldb_field.php');
|
||||
require_once($CFG->libdir.'/xmldb/xmldb_key.php');
|
||||
require_once($CFG->libdir.'/xmldb/xmldb_index.php');
|
||||
require_once($CFG->libdir.'/xmldb/xmldb_statement.php');
|
||||
|
||||
/// Add other libraries
|
||||
require_once($CFG->libdir.'/xmlize.php');
|
||||
|
||||
function upgrade_main_savepoint($result, $version) {
|
||||
global $CFG;
|
||||
|
||||
@@ -39,6 +55,146 @@ function upgrade_blocks_savepoint($result, $version, $type) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all plugin tables
|
||||
* @name string name of plugin, used as table prefix
|
||||
* @file string path to install.xml file
|
||||
* @feedback boolean
|
||||
*/
|
||||
function drop_plugin_tables($name, $file, $feedback=true) {
|
||||
global $CFG, $DB;
|
||||
|
||||
// first try normal delete
|
||||
if ($DB->get_manager()->delete_tables_from_xmldb_file($file, $feedback)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// then try to find all tables that start with name and are not in any xml file
|
||||
$used_tables = get_used_table_names();
|
||||
|
||||
$tables = $DB->get_tables();
|
||||
|
||||
/// Iterate over, fixing id fields as necessary
|
||||
foreach ($tables as $table) {
|
||||
if (in_array($table, $used_tables)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// found orphan table --> delete it
|
||||
if ($DB->get_manager()->table_exists($table)) {
|
||||
$xmldb_table = new xmldb_table($table);
|
||||
$DB->get_manager()->drop_table($xmldb_table, true, $feedback);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns names of all known tables == tables that moodle knowns about.
|
||||
* @return array of lowercase table names
|
||||
*/
|
||||
function get_used_table_names() {
|
||||
$table_names = array();
|
||||
$dbdirs = get_db_directories();
|
||||
|
||||
foreach ($dbdirs as $dbdir) {
|
||||
$file = $dbdir.'/install.xml';
|
||||
|
||||
$xmldb_file = new xmldb_file($file);
|
||||
|
||||
if (!$xmldb_file->fileExists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$loaded = $xmldb_file->loadXMLStructure();
|
||||
$structure =& $xmldb_file->getStructure();
|
||||
|
||||
if ($loaded and $tables = $structure->getTables()) {
|
||||
foreach($tables as $table) {
|
||||
$table_names[] = strtolower($table->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $table_names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of all directories where we expect install.xml files
|
||||
* @return array of paths
|
||||
*/
|
||||
function get_db_directories() {
|
||||
global $CFG;
|
||||
|
||||
$dbdirs = array();
|
||||
|
||||
/// First, the main one (lib/db)
|
||||
$dbdirs[] = $CFG->libdir.'/db';
|
||||
|
||||
/// Now, activity modules (mod/xxx/db)
|
||||
if ($plugins = get_list_of_plugins('mod')) {
|
||||
foreach ($plugins as $plugin) {
|
||||
$dbdirs[] = $CFG->dirroot.'/mod/'.$plugin.'/db';
|
||||
}
|
||||
}
|
||||
|
||||
/// Now, assignment submodules (mod/assignment/type/xxx/db)
|
||||
if ($plugins = get_list_of_plugins('mod/assignment/type')) {
|
||||
foreach ($plugins as $plugin) {
|
||||
$dbdirs[] = $CFG->dirroot.'/mod/assignment/type/'.$plugin.'/db';
|
||||
}
|
||||
}
|
||||
|
||||
/// Now, question types (question/type/xxx/db)
|
||||
if ($plugins = get_list_of_plugins('question/type')) {
|
||||
foreach ($plugins as $plugin) {
|
||||
$dbdirs[] = $CFG->dirroot.'/question/type/'.$plugin.'/db';
|
||||
}
|
||||
}
|
||||
|
||||
/// Now, backup/restore stuff (backup/db)
|
||||
$dbdirs[] = $CFG->dirroot.'/backup/db';
|
||||
|
||||
/// Now, block system stuff (blocks/db)
|
||||
$dbdirs[] = $CFG->dirroot.'/blocks/db';
|
||||
|
||||
/// Now, blocks (blocks/xxx/db)
|
||||
if ($plugins = get_list_of_plugins('blocks', 'db')) {
|
||||
foreach ($plugins as $plugin) {
|
||||
$dbdirs[] = $CFG->dirroot.'/blocks/'.$plugin.'/db';
|
||||
}
|
||||
}
|
||||
|
||||
/// Now, course formats (course/format/xxx/db)
|
||||
if ($plugins = get_list_of_plugins('course/format', 'db')) {
|
||||
foreach ($plugins as $plugin) {
|
||||
$dbdirs[] = $CFG->dirroot.'/course/format/'.$plugin.'/db';
|
||||
}
|
||||
}
|
||||
|
||||
/// Now, enrolment plugins (enrol/xxx/db)
|
||||
if ($plugins = get_list_of_plugins('enrol', 'db')) {
|
||||
foreach ($plugins as $plugin) {
|
||||
$dbdirs[] = $CFG->dirroot.'/enrol/'.$plugin.'/db';
|
||||
}
|
||||
}
|
||||
|
||||
/// Now admin report plugins (admin/report/xxx/db)
|
||||
if ($plugins = get_list_of_plugins($CFG->admin.'/report', 'db')) {
|
||||
foreach ($plugins as $plugin) {
|
||||
$dbdirs[] = $CFG->dirroot.'/'.$CFG->admin.'/report/'.$plugin.'/db';
|
||||
}
|
||||
}
|
||||
|
||||
/// Local database changes, if the local folder exists.
|
||||
if (file_exists($CFG->dirroot . '/local')) {
|
||||
$dbdirs[] = $CFG->dirroot.'/local/db';
|
||||
}
|
||||
|
||||
return $dbdirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade plugins
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user