Commit e6e87597 authored by Son Nguyen's avatar Son Nguyen
Browse files

Fix errors when dropping old tables



and add a new flag 'runfresh' to the script in order to
run behat tests on a new fresh database

Change-Id: Ia29e3d33aa994e06aef1dc26a6bf7d5afa118837
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent 1725ae01
......@@ -682,7 +682,7 @@ function uninstall_from_xmldb_file($file) {
if ($tables = array_reverse($structure->getTables())) {
foreach ($tables as $table) {
// for MySQL, skip dropping indexs and keys
// for MySQL, skip dropping indices and keys
// as they will be dropped when the table is dropped
if (!is_mysql() && $indexes = $table->getIndexes()) {
foreach ($indexes as $index) {
......
......@@ -1819,8 +1819,8 @@ function db_drop_trigger($name, $table) {
if (is_postgres()) {
$functionname = $name . '_function';
$triggername = $name . '_trigger';
execute_sql('DROP TRIGGER IF EXISTS {' . $triggername . '} ON {' . $table . '}');
execute_sql('DROP FUNCTION IF EXISTS {' . $functionname . '}()');
execute_sql('DROP TRIGGER IF EXISTS {' . $triggername . '} ON {' . $table . '} CASCADE');
execute_sql('DROP FUNCTION IF EXISTS {' . $functionname . '}() CASCADE');
}
else if (is_mysql()) {
$triggername = $name . '_trigger';
......
......@@ -640,40 +640,70 @@ abstract class TestingUtil {
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('unmark_quota_exeed_notified_on_update_setting', 'artefact_config');
db_drop_trigger('unmark_quota_exeed_notified_on_update_usr_setting', 'usr');
db_drop_trigger('update_unread_insert2', 'artefact_multirecipient_userrelation');
db_drop_trigger('update_unread_update2', 'artefact_multirecipient_userrelation');
db_drop_trigger('update_unread_delete2', 'artefact_multirecipient_userrelation');
db_drop_trigger('unmark_quota_exceed_upd_usr_set', 'usr');
}
catch (Exception $e) {
exit(1);
}
// Drop plugins' tables
log_info('Uninstalling plugins');
$dotsonline = 0;
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');
// 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;
}
if ($dotsonline == 60) {
if ($displayprogress) {
echo "\n";
$btdirhandle = opendir($btlocation);
while (false !== ($btdir = readdir($btdirhandle))) {
if (strpos($btdir, '.') === 0 or 'CVS' == $btdir) {
continue;
}
$dotsonline = 0;
}
if ($displayprogress) {
echo '.';
if (!is_dir(get_config('docroot') . $plugin . '/' . $dir . '/blocktype/' . $btdir)) {
continue;
}
$plugins[] = array('blocktype', $dir . '/' . $btdir);
}
$dotsonline += 1;
}
}
}
if ($displayprogress) {
echo "\n";
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 {
......
......@@ -121,9 +121,10 @@ class BehatTestingUtil extends TestingUtil {
throw new MaharaBehatTestException('This method can be only used by Behat CLI tool');
}
self::reset_dataroot();
self::drop_dataroot();
self::drop_database(true);
if (table_exists(new XMLDBTable('config'))) {
self::drop_dataroot();
self::drop_database(true);
}
}
/**
......
......@@ -57,9 +57,15 @@ then
PERFORM=$2
php htdocs/testing/frameworks/behat/cli/util.php --$PERFORM
elif [ "$ACTION" = "run" -o "$ACTION" = "runheadless" -o "$ACTION" = "rundebug" ]
elif [ "$ACTION" = "run" -o "$ACTION" = "runheadless" -o "$ACTION" = "rundebug" -o "$ACTION" = "runfresh" ]
then
if [ $ACTION = 'runheadless' -o "$ACTION" = "runfresh" ]
then
echo "Drop the old test site if exist"
php htdocs/testing/frameworks/behat/cli/util.php --drop
fi
# Initialise the behat environment
php htdocs/testing/frameworks/behat/cli/init.php
......@@ -108,9 +114,6 @@ then
php --server localhost:8000 --docroot $MAHARAROOT/htdocs &>/dev/null &
SERVER=$!
echo "Enable test site"
php htdocs/testing/frameworks/behat/cli/util.php --enable
BEHATCONFIGFILE=`php htdocs/testing/frameworks/behat/cli/util.php --config`
echo "Run Behat..."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment