/**
  * completely uninstall mahara, drop all tables.
  * this just does what install does, but in reverse order
  * reversing the order of tables, and indexes
  * to respect referential integrity
  */
 public function uninstall_mahara()
 {
     // this can't be done in a transaction because sometimes
     // things exist in the database that aren't in the file or the other way around
     // in the case where there are stale tables and then the code is upgraded
     foreach (array_reverse(plugin_types_installed()) as $t) {
         if ($installed = plugins_installed($t, true)) {
             foreach ($installed as $p) {
                 $location = get_config('docroot') . $t . '/' . $p->name . '/db/';
                 log_info('Uninstalling ' . $location);
                 if (is_readable($location . 'install.xml')) {
                     uninstall_from_xmldb_file($location . 'install.xml');
                 }
             }
         }
     }
     // now uninstall core
     log_info('Uninstalling core');
     // These constraints must be dropped manually as they cannot be
     // created with xmldb due to ordering issues
     if (is_postgres()) {
         try {
             execute_sql('ALTER TABLE {usr} DROP CONSTRAINT {usr_pro_fk}');
         } catch (Exception $e) {
         }
         try {
             execute_sql('ALTER TABLE {institution} DROP CONSTRAINT {inst_log_fk}');
         } catch (Exception $e) {
         }
     } else {
         try {
             execute_sql('ALTER TABLE {usr} DROP FOREIGN KEY {usr_pro_fk}');
         } catch (Exception $e) {
         }
         try {
             execute_sql('ALTER TABLE {institution} DROP FOREIGN KEY {inst_log_fk}');
         } catch (Exception $e) {
         }
     }
     uninstall_from_xmldb_file(get_config('docroot') . 'lib/db/install.xml');
 }
Exemple #2
0
 /**
  * Drop the whole test database
  * @static
  * @param bool $displayprogress
  */
 protected static function drop_database($displayprogress = false)
 {
     // Drop triggers
     try {
         db_drop_trigger('update_unread_insert', 'notification_internal_activity');
         db_drop_trigger('update_unread_update', 'notification_internal_activity');
         db_drop_trigger('update_unread_delete', 'notification_internal_activity');
         db_drop_trigger('update_unread_insert2', 'module_multirecipient_userrelation');
         db_drop_trigger('update_unread_update2', 'module_multirecipient_userrelation');
         db_drop_trigger('update_unread_delete2', 'module_multirecipient_userrelation');
         db_drop_trigger('unmark_quota_exceed_upd_usr_set', 'usr');
     } catch (Exception $e) {
         exit(1);
     }
     // Drop plugins' tables
     // Find all plugins from the code base
     // and drop their tables from database if exists
     $plugins = array();
     $pluginstocheck = plugin_types();
     foreach ($pluginstocheck as $plugin) {
         $dirhandle = opendir(get_config('docroot') . $plugin);
         while (false !== ($dir = readdir($dirhandle))) {
             if (strpos($dir, '.') === 0 or 'CVS' == $dir) {
                 continue;
             }
             if (!is_dir(get_config('docroot') . $plugin . '/' . $dir)) {
                 continue;
             }
             $plugins[] = array($plugin, $dir);
             if ($plugin == 'artefact') {
                 // go check it for blocks as well
                 $btlocation = get_config('docroot') . $plugin . '/' . $dir . '/blocktype';
                 if (!is_dir($btlocation)) {
                     continue;
                 }
                 $btdirhandle = opendir($btlocation);
                 while (false !== ($btdir = readdir($btdirhandle))) {
                     if (strpos($btdir, '.') === 0 or 'CVS' == $btdir) {
                         continue;
                     }
                     if (!is_dir(get_config('docroot') . $plugin . '/' . $dir . '/blocktype/' . $btdir)) {
                         continue;
                     }
                     $plugins[] = array('blocktype', $dir . '/' . $btdir);
                 }
             }
         }
     }
     foreach ($plugins as $plugin) {
         $plugintype = $plugin[0];
         $pluginname = $plugin[1];
         $pluginpath = "{$plugin['0']}/{$plugin['1']}";
         $pluginkey = "{$plugin['0']}.{$plugin['1']}";
         if ($plugintype == 'blocktype' && strpos($pluginname, '/') !== false) {
             // sigh.. we're a bit special...
             $bits = explode('/', $pluginname);
             $pluginpath = 'artefact/' . $bits[0] . '/blocktype/' . $bits[1];
         }
         log_info("Uninstalling {$plugintype}.{$pluginname}");
         $location = get_config('docroot') . $pluginpath . '/db';
         if (is_readable($location . '/install.xml')) {
             uninstall_from_xmldb_file($location . '/install.xml');
         }
     }
     // These constraints must be dropped manually as they cannot be
     // created with xmldb due to ordering issues
     try {
         if (is_postgres()) {
             execute_sql('ALTER TABLE {usr} DROP CONSTRAINT {usr_pro_fk}');
             execute_sql('ALTER TABLE {institution} DROP CONSTRAINT {inst_log_fk}');
         }
     } catch (Exception $e) {
         exit(1);
     }
     // now uninstall core
     if (is_mysql()) {
         execute_sql('SET foreign_key_checks = 0');
     }
     log_info('Uninstalling core');
     uninstall_from_xmldb_file(get_config('docroot') . 'lib/db/install.xml');
     if (is_mysql()) {
         execute_sql('SET foreign_key_checks = 1');
     }
 }