------------------------------------------------------------
revno: 1077
committer: Roger Martin <[email protected]>
branch nick: aikiframework
timestamp: Sun 2012-02-05 18:33:06 +0100
message:
corrections in installer and upgrader
modified:
assets/apps/installer/installer.php
assets/apps/upgrader/library.php
assets/apps/upgrader/upgrades.php
libs/Util.php
--
lp:aikiframework
https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk
Your team Aiki Framework Developers is subscribed to branch lp:aikiframework.
To unsubscribe from this branch go to
https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk/+edit-subscription
=== modified file 'assets/apps/installer/installer.php'
--- assets/apps/installer/installer.php 2012-02-03 20:56:44 +0000
+++ assets/apps/installer/installer.php 2012-02-05 17:33:06 +0000
@@ -116,8 +116,8 @@
// read titles and welcome text, creating global var $INSTALLER_TITLE_TAG,
// $INSTALLER_TITLE, $INSTALLER_WELCOME_TEXT, $INSTALLER_REQUIREMENTS_TEXT,
include_once("defaults.php");
-if ( file_exists("siteDefaults.php") ){
- include_once("siteDefaults.php");
+if ( file_exists("defaultsSite.php") ){
+ include_once("defaultsSite.php");
}
$template[0]="<div class='error'>" . $t->t("Installation aborted")."</div><div class='error'>%s</div>";
@@ -325,7 +325,7 @@
if ( !$revisionNumber ){
$revisionNumber = 1057; // installer revision
}
- $db->query("INSERT INTO `aiki`.`aiki_configs` (`config_id`, `config_name`, `config_value`, `config_selector`, `config_important`, `config_weight`) VALUES (NULL, 'AIKI-REVISION', 'i:$revisionNumber', '*', '1', '10000');");
+ $db->query("INSERT INTO `aiki`.`aiki_configs` (`config_id`, `config_name`, `config_value`, `config_selector`, `config_important`, `config_weight`) VALUES (NULL, 'AIKI-REVISION', 'i:$revisionNumber;', '*', '1', '10000');");
}
break;
=== modified file 'assets/apps/upgrader/library.php'
--- assets/apps/upgrader/library.php 2012-02-04 23:37:40 +0000
+++ assets/apps/upgrader/library.php 2012-02-05 17:33:06 +0000
@@ -8,7 +8,7 @@
* This source file is subject to the AGPL-3.0 license that is bundled
* with this package in the file LICENSE.
*
- * @author Roger Martin, Aikilab http://www.aikilab.com
+ * @author Roger Martin, Aikilab http://www.aikilab.com
* @copyright (c) 2008-2011 Aiki Lab Pte Ltd
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html
* @link http://www.aikiframework.org
@@ -22,10 +22,10 @@
*/
-/**
+/**
*
* construct html form inserting buttons, and next step.
- *
+ *
* @param $step next step
* @param $buttons string with additional html controls.
*
@@ -39,20 +39,20 @@
$next = $t->t("Next:");
$cStep = $t->t( steps($step));
return "\n<div class='actions'>".
- ($withForm ? "\n<form method='post'>%s":"" ).
+ ($withForm ? "\n<form method='post'>%s":"" ).
"\n<input type='hidden' name='step' value='$step'>".
"\n<input type='submit' class='button next' value='$next $cStep'>".
($withForm ? "\n</form>": "") .
- "\n</div>\n";
+ "\n</div>\n";
}
-/**
+/**
*
* construct select control for language select
- *
+ *
* @param array translations available
- *
+ *
* @return string containg comple html select or "" if not necesary
*/
@@ -61,18 +61,18 @@
$translations = $t->translations();
if ( !is_array($translations) || count($translations)==0 ){
- return "";
+ return "";
}
-
- $options = "<option value='en'>English</option>";
+
+ $options = "<option value='en'>English</option>";
foreach ( $translations as $isoCode ){
$options .= "<option value='$isoCode'>" . Util::iso639($isoCode) ."</option>\n";
- }
- return
+ }
+ return
"<form id='f_language'><label for='language'>" . $t->t("Select language for installation") ."</label>\n" .
- "<select name='language' id='language' class='user-input'>".
+ "<select name='language' id='language' class='user-input'>".
$options.
- "</select><input type='submit' value='" . $t->t("Change") ."'></form>";
+ "</select><input type='submit' value='" . $t->t("Change") ."'></form>";
}
@@ -84,7 +84,7 @@
"Autentification",
"Upgrade database",
"Upgrade Aiki Data" );
-
+
if ( $step == -1 ){
return (count($steps)-1);
}
@@ -98,9 +98,9 @@
switch ( $step ) {
case 0:
return "<div class='error'>" . $t->t("Update canceled")."</div><div class='error'>%s</div>";
-
+
case 1:
- return
+ return
"<div id='welcome'>$UPGRADER_WELCOME_TEXT</div>
<div class='links'>
<a href='#changelog' class='toggle'>". $t->t("Changelog") ."</a>
@@ -123,87 +123,87 @@
</p>".
form_hidden(3,false)."
</form>";
-
+
case 3:
return "%s " . form_hidden(4);
-
+
case 4:
- return "%s " .
+ return "%s " .
sprintf("<div class='ok finished'>%s <em>%s</em>",
$t->t("Upgrade has finished") ,
$t->t("Thanks for using Aiki") );
- }
+ }
}
-/**
+/**
*
* check step
- *
+ *
* @param by value step.
- *
+ *
* @return message or "". Correct step.
*/
function check_step(&$step) {
global $t, $AIKI_ROOT_DIR, $db;
- switch ( $step) {
+ switch ( $step) {
case 0:
case 1:
case 2:
- $lastRevision = Util::get_last_revision();
+ $lastRevision = Util::get_last_revision();
if ( $lastRevision == 0){
$step=0;
- return $t->t("Can't get last revision").
+ return $t->t("Can't get last revision").
"<br><em>". $t->t("Copy .bzr/branch/last-version to config dir") ."</em>";
- }
-
+ }
+
$revision = config("AIKI-REVISION",0,"*");
-
+
if ( $lastRevision <= $revision ){
$step=0;
return $t->t("No upgrade is necesary.").
"<br><em>". t("Installed revision:") . " $revision </em>";
- }
+ }
if ( $step==0){
$step=1;
- }
+ }
break;
-
- case 3:
-
+
+ case 3:
+
$username = stripslashes($_REQUEST["login"] );
$password = md5(md5(stripslashes($_REQUEST["password"] )));
-
+
if ( md5($_REQUEST["captcha"]) != $_SESSION['captcha_key'] ){
$step=2;
return $t->t("Wrong captcha");
- }
-
+ }
+
$get_user = $db->get_row(
"SELECT * FROM aiki_users".
" WHERE username='$username' ".
" AND password='$password' ".
" AND usergroup=1 ".
- " AND is_active=1" .
+ " AND is_active=1" .
" LIMIT 1");
-
+
if (!$get_user) {
$step=2;
return $t->t("Wrong user name" );
- }
-
- session_start(); // don't remove this line. IT'S NECESSARY
- $_SESSION["updater_is_root"]=1;
+ }
+
+ session_start(); // don't remove this line. IT'S NECESSARY
+ $_SESSION["updater_is_root"]=1;
return "";
-
+
case 4:
case 5:
if ( !isset($_SESSION["updater_is_root"])){
- $step=2;
- }
+ $step=2;
+ }
}
-
+
}
@@ -226,27 +226,27 @@
"$AIKI_ROOT_DIR/sql/CreateTablesSite.sql");
$ret = "<strong>".$t->t("Database upgrading")."</strong>";
-
- // extract table(2), fields definition(3) and Engine(4) from a
+
+ // extract table(2), fields definition(3) and Engine(4) from a
// CREATE TABLE IF NOT EXISTS `table' (DEFINTIONs) ENGINE.charset;
// IF NOT EXISTS optional, `are optional
-
+
$pattern = '#CREATE\s+TABLE(\s+IF NOT EXISTS)?\s+`?([^ ]+)`?\s+\((.*)\)([^\);]*);#Uis';
-
+
foreach ($files as $file ){
- if ( file_exists($file) && preg_match_all ( $pattern, @file_get_contents($file), $sqls ) ) {
- foreach ( $sqls[2] as $i=>$table ){
- $upgradeDB->upgrade_table($table, trim($sqls[3][$i])) ;
+ if ( file_exists($file) && preg_match_all ( $pattern, @file_get_contents($file), $sqls ) ) {
+ foreach ( $sqls[2] as $i=>$table ){
+ $upgradeDB->upgrade_table($table, trim($sqls[3][$i])) ;
$ret .= "<br>". sprintf( $t->t( "%s upgraded"),$table);
- }
- }
+ }
+ }
}
-
+
return $ret;
}
-function upgradeAikiData (){
+function upgradeAikiData (){
global $t, $db, $AIKI_ROOT_DIR;
$lastRevision = Util::get_last_revision();
@@ -254,22 +254,29 @@
$replaces = array (
"@VERSION@" =>AIKI_VERSION,
"@REVISION@" =>$lastRevision );
-
+
// Re-install data: remove & insert -------------------------------
$files = array (
"$AIKI_ROOT_DIR/sql/UpdateDefaults.sql" => $t->t("Removing aiki core data"),
"$AIKI_ROOT_DIR/sql/InsertDefaults.sql" => $t->t("Inserting new aiki core data"),
"$AIKI_ROOT_DIR/sql/UpdateDefaultsSite.sql"=> $t->t("Preparing upgrading site"),
"$AIKI_ROOT_DIR/sql/InsertDefaultsSite.sql"=> $t->t("Upgrading site"));
-
+
$ret = "<strong>". $t->t("Update Aiki & Site Data") . "</strong>";
foreach ($files as $file => $message ){
- if ( file_exists($file) ) {
- $db->query ( strtr( Util::remove_comments( @file_get_contents($file)), $replaces));
- $ret .= "<br>$message";
- }
+ if ( $sqls = Util::get_sqls_statements($file) ) {
+ $result = "";
+ foreach ( $sqls as $i=>$sql ){
+ $db->last_error = false;
+ $db->query ( strtr( $sql, $replaces));
+ if ($db->last_error ){
+ $result .= "- in $i statement ".substr($sql,0,35) ."...<br>";
+ }
+ }
+ $ret .= "<br>$message " . ( $result=="" ? "ok" : " errors:<br>$result" );
+ }
}
-
+
// Manual upgrades by SQL statments -------------------------------
$sqls = array();
include_once "upgrades.php"; // creates $upgrades array
@@ -278,20 +285,26 @@
if ( $revision > $REVISION ) {
$sqls[$revision]= $sql;
}
- }
+ }
if ( count($sqls)>0 ){
ksort($sqls);
foreach ($sqls as $revision=>$sql){
- $db->query($sql);
+ if ( is_array ( $sql ) ) {
+ foreach ( $sql as $statements ){
+ $db->query($statements);
+ }
+ } else {
+ $db->query($sql);
+ }
$ret .= "<br>" . sprintf("%s updated", $revision );
}
}
-
+
// Set new aiki revision
config_set("AIKI-REVISION", $lastRevision, "*/*/* !important");
// paranoic check to ensure revision is good in all sites/views/language
$db->query("UPDATE aiki_configs SET config_value = 'i:$lastRevision;' WHERE config_name='AIKI-REVISION'");
-
-
+
+
return $ret;
-}
+}
=== modified file 'assets/apps/upgrader/upgrades.php'
--- assets/apps/upgrader/upgrades.php 2012-02-05 08:54:17 +0000
+++ assets/apps/upgrader/upgrades.php 2012-02-05 17:33:06 +0000
@@ -19,6 +19,12 @@
*
*/
+// Add sql as values for array $upgrades, where revision is key.
+// example: $upgrades[555] = "UPDATE aiki_foo SET bar='foo'"
+// if you need add more than one statement, make an array:
+// example: $upgrades[555] = array (
+// "UPDATE aiki_foo SET bar='foo'",
+// "UPDATE aiki_bar SET bar=1");
// Revision 942 changes old php script markup with new (script(....)script)
-$upgrades[942] = 'UPDATE aiki_widgets SET widget=REPLACE( REPLACE(widget,"<php ","(script("),"php>",")script)")';
+$upgrades[942] = 'UPDATE aiki_widgets SET widget=REPLACE( REPLACE(widget,"<php ","(script("),"php>",")script)");';
=== modified file 'libs/Util.php'
--- libs/Util.php 2012-02-04 22:51:53 +0000
+++ libs/Util.php 2012-02-05 17:33:06 +0000
@@ -254,10 +254,20 @@
return $ret;
}
- public static function remove_comments ( $inputText ){
- return preg_replace ("#/\*.*\*/#Us","" , $inputText);
- }
+ /**
+ * Returns sql statements contained in the input file. Statements must be
+ * separated by a "-- ------------------------------------------------------"
+ *
+ * @return array of false if file doesn't exist
+ */
+ public static function get_sqls_statements ( $file ){
+ $delimiters= "-- ------------------------------------------------------";
+ if ( file_exists($file) ) {
+ return explode($delimiters, preg_replace ("#/\*.*\*/#Us","" , @file_get_contents($file) ));
+ }
+ return false;
+ }
/**
* Returns the last revision of aiki if .bzr exists, or 0 assuming this
_______________________________________________
Mailing list: https://launchpad.net/~aikiframework-devel
Post to : [email protected]
Unsubscribe : https://launchpad.net/~aikiframework-devel
More help : https://help.launchpad.net/ListHelp