Navigation Menu

Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Put SQL update directly in PHP update code instead of SQL file
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jun 22, 2014
1 parent 907dfe6 commit 3d5e5fb
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion dist/php/5.3.1.sql → dist/php/5.3.1.php
@@ -1,3 +1,21 @@
<?php
// FORCE bootstrap_context copy, otherwise it won't reboot
if (is_file(AJXP_INSTALL_PATH."/conf/bootstrap_context.php".".new-".date("Ymd"))) {
rename(AJXP_INSTALL_PATH."/conf/bootstrap_context.php", AJXP_INSTALL_PATH."/conf/bootstrap_context.php.pre-update");
rename(AJXP_INSTALL_PATH."/conf/bootstrap_context.php".".new-".date("Ymd"), AJXP_INSTALL_PATH."/conf/bootstrap_context.php");
}

// FORCE bootstrap_context copy, otherwise it won't reboot
if (is_file(AJXP_INSTALL_PATH."/conf/bootstrap_repositories.php".".new-".date("Ymd"))) {
rename(AJXP_INSTALL_PATH."/conf/bootstrap_repositories.php", AJXP_INSTALL_PATH."/conf/bootstrap_repositories.php.pre-update");
rename(AJXP_INSTALL_PATH."/conf/bootstrap_repositories.php".".new-".date("Ymd"), AJXP_INSTALL_PATH."/conf/bootstrap_repositories.php");
}

echo "The bootstrap_context and bootstrap_repositories files were replaced by the new version, the .pre-update version is kept.";

echo "Upgrading database ...";

$dbInst = "
/* SEPARATOR */
ALTER TABLE ajxp_user_rights ADD INDEX (login), ADD INDEX (repo_uuid);
/* SEPARATOR */
Expand Down Expand Up @@ -54,4 +72,44 @@
/* SEPARATOR */
DROP TABLE `ajxp_log`;
/* SEPARATOR */
RENAME TABLE `ajxp_log2` TO `ajxp_log`;
RENAME TABLE `ajxp_log2` TO `ajxp_log`;
";


$confDriver = ConfService::getConfStorageImpl();
$authDriver = ConfService::getAuthDriverImpl();
$logger = AJXP_Logger::getInstance();
if (is_a($confDriver, "sqlConfDriver")) {
$test = $confDriver->getOption("SQL_DRIVER");
if (!isSet($test["driver"])) {
$test = AJXP_Utils::cleanDibiDriverParameters($confDriver->getOption("SQL_DRIVER"));
}
if (is_array($test) && isSet($test["driver"])) {

$parts = array_map("trim", explode("/* SEPARATOR */", $dbInst));
$results = array();
$errors = array();

require_once(AJXP_BIN_FOLDER."/dibi.compact.php");
dibi::connect($test);
dibi::begin();
foreach ($parts as $sqlPart) {
if(empty($sqlPart)) continue;
try {
dibi::nativeQuery($sqlPart);
echo "<div class='upgrade_result success'>$sqlPart ... OK</div>";
} catch (DibiException $e) {
$errors[] = $e->getMessage();
echo "<div class='upgrade_result success'>$sqlPart ... FAILED (".$e->getMessage().")</div>";
}
}
dibi::commit();
dibi::disconnect();

} else {
echo "Nothing to do for the DB";
}

} else {
echo "Nothing to do for the DB";
}

0 comments on commit 3d5e5fb

Please sign in to comment.