Skip to content

Commit

Permalink
Allow remove old crs tables from 1.8.x versions - refs #8279
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Oct 3, 2016
1 parent e0a1567 commit 4862653
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
65 changes: 65 additions & 0 deletions main/install/ajax.php
@@ -0,0 +1,65 @@
<?php
/* For licensing terms, see /license.txt */

/**
* Chamilo installation
* AJAX requests for the installation
* @package chamilo.install
*/

ini_set('display_errors', '1');
ini_set('log_errors', '1');
error_reporting(-1);

require_once __DIR__ . '/../../vendor/autoload.php';

define('SYSTEM_INSTALLATION', 1);
define('INSTALL_TYPE_UPDATE', 'update');
define('FORM_FIELD_DISPLAY_LENGTH', 40);
define('DATABASE_FORM_FIELD_DISPLAY_LENGTH', 25);
define('MAX_FORM_FIELD_LENGTH', 80);

// Including necessary libraries.
require_once '../inc/lib/api.lib.php';

session_start();

require_once api_get_path(LIBRARY_PATH) . 'database.constants.inc.php';
require_once 'install.lib.php';

$action = isset($_POST['a']) ? $_POST['a'] : null;

$dbHost = isset($_POST['db_host']) ? $_POST['db_host'] : 'localhost';
$dbUsername = isset($_POST['db_username']) ? $_POST['db_username'] : 'root';
$dbPass = isset($_POST['db_pass']) ? $_POST['db_pass'] : '';
$dbName = isset($_POST['db_name']) ? $_POST['db_name'] : 'chamilo';
$dbPort = isset($_POST['db_port']) ? $_POST['db_port'] : 3306;

$manager = connectToDatabase($dbHost, $dbUsername, $dbPass, $dbName, $dbPort);

$db_prefix = api_get_configuration_value('db_prefix') ? api_get_configuration_value('db_prefix') : 'chamilo_';
$db_c_prefix = api_get_configuration_value('table_prefix') ? api_get_configuration_value('table_prefix') : 'crs_';

switch ($action) {
case 'check_crs_tables':
$countOfTables = $manager
->getConnection()
->executeQuery("SHOW TABLES LIKE '$db_c_prefix$db_prefix%'")
->rowCount();

echo $countOfTables;
break;
case 'remove_crs_tables':

$statement = $manager
->getConnection()
->executeQuery("SHOW TABLES LIKE '$db_c_prefix$db_prefix%'");

while ($table = $statement->fetch(PDO::FETCH_NUM)) {
$manager->getConnection()->executeQuery("DROP TABLE {$table[0]}");
}

break;
default:
break;
}
59 changes: 59 additions & 0 deletions main/install/index.php
Expand Up @@ -629,6 +629,65 @@ function send_contact_information() {
}
?>

<div id="pnl-check-crs-tables" class="alert alert-warning hide">
<p><?php echo get_lang('CRSTablesIntro') ?></p>
<p>
<button type="button" class="btn btn-warning btn-xs" id="btn-remove-crs-table" data-removing-text="<?php echo get_lang('Removing') ?>" autocomplete="off">
<span class="fa-stack" aria-hidden="true">
<span class="fa fa-circle-thin fa-stack-2x"></span>
<span class="fa fa-trash-o fa-stack-1x"></span>
</span>
<?php echo get_lang('CheckForCRSTables') ?>
</button>
</p>
</div>
<script>
$(document).on('ready', function () {
$.post('<?php echo api_get_path(WEB_CODE_PATH); ?>install/ajax.php', {
a: 'check_crs_tables',
db_host: '<?php echo $dbHostForm; ?>',
db_username: '<?php echo $dbUsernameForm; ?>',
db_pass: '<?php echo $dbPassForm; ?>',
db_name: '<?php echo $dbNameForm ?>',
db_port: '<?php echo $dbPortForm; ?>'
}, function (response) {
if (!parseInt(response)) {
return;
}

$('#pnl-check-crs-tables').removeClass('hide');

$('#btn-remove-crs-table').on('click', function (e) {
e.preventDefault();

var sure = confirm('<?php echo get_lang('AreYouSureToDelete') ?>');

if (!sure) {
return;
}

var $btnNext = $('button.btn-success:submit'),
$btnRemove = $(this).button('removing');

$btnNext.prop('disabled', true);

$.post('<?php echo api_get_path(WEB_CODE_PATH) ?>install/ajax.php', {
a: 'remove_crs_tables',
db_host: '<?php echo $dbHostForm; ?>',
db_username: '<?php echo $dbUsernameForm; ?>',
db_pass: '<?php echo $dbPassForm; ?>',
db_name: '<?php echo $dbNameForm ?>',
db_port: '<?php echo $dbPortForm; ?>'
}, function () {
$btnRemove.remove();

$btnNext.prop('disabled', false);
});
});
});
});
</script>

<table width="100%">
<tr>
<td>
Expand Down

0 comments on commit 4862653

Please sign in to comment.