-<?php\r
-function upgrade_do10() {\r
- \r
-if (upgrade_checkinstall(10))\r
- return "already installed";\r
-\r
-// 1. add mcookiekey to nucleus_member\r
-$query = 'ALTER TABLE '.sql_table('member')\r
- . " ADD mcookiekey varchar(40) ";\r
-$res = upgrade_query("Adding cookiekey attribute to members",$query); \r
-\r
-// only do this when the previous query succeeds\r
-if ($res) {\r
- // 2. for all members: hash their password and also copy it to mcookiekey\r
- $query = 'SELECT * FROM '.sql_table('member');\r
- $res = mysql_query($query);\r
- while ($current = mysql_fetch_object($res)) {\r
- $hashedpw = md5($current->mpassword);\r
- $updquery = 'UPDATE '.sql_table('member')." SET mpassword='$hashedpw' WHERE mnumber=" . $current->mnumber;\r
- upgrade_query("Encrypting password for member " . $current->mnumber,$updquery);\r
- }\r
-}\r
-\r
-// 3. add extra indices to tables\r
-$query = 'ALTER TABLE '.sql_table('item').' ADD INDEX(iblog, itime);';\r
-upgrade_query("Adding extra index to nucleus_item",$query);\r
-$query = 'ALTER TABLE '.sql_table('comment').' ADD INDEX(citem);';\r
-upgrade_query("Adding extra index to nucleus_comment",$query);\r
-\r
-// 4. add DisableJsTools to config\r
-$query = 'INSERT INTO '.sql_table('config')." VALUES ('DisableJsTools', '0');";\r
-upgrade_query("Adding setting DisableJsTools",$query);\r
-\r
-// 5. Drop primary key in nucleus_actionlog\r
-$query = 'ALTER TABLE '.sql_table('actionlog').' DROP PRIMARY KEY;';\r
-upgrade_query("Dropping primary key for actionlog table",$query);\r
-\r
-}\r
-\r
-\r
-?>
\ No newline at end of file
+<?php
+/*
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
+ * Copyright (C) 2002-2007 The Nucleus Group
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * (see nucleus/documentation/index.html#license for more info)
+ */
+/**
+ * @license http://nucleuscms.org/license.txt GNU General Public License
+ * @copyright Copyright (C) 2002-2007 The Nucleus Group
+ * $NucleusJP: upgrade1.0.php,v 1.3.2.1 2007/10/24 05:39:15 kimitake Exp $
+ *
+ */
+
+function upgrade_do10() {
+
+ if (upgrade_checkinstall(10))
+ return "already installed";
+
+ // 1. add extra indices to tables
+ if (!upgrade_checkIfIndexExists('item', array('iblog', 'itime'))) {
+ $query = 'ALTER TABLE '.sql_table('item').' ADD INDEX(iblog, itime);';
+ upgrade_query("Adding extra index to nucleus_item",$query);
+ }
+ if (!upgrade_checkIfIndexExists('comment', array('citem'))) {
+ $query = 'ALTER TABLE '.sql_table('comment').' ADD INDEX(citem);';
+ upgrade_query("Adding extra index to nucleus_comment",$query);
+ }
+
+ // 2. add DisableJsTools to config
+ if (!upgrade_checkIfCVExists('DisableJsTools')) {
+ $query = 'INSERT INTO '.sql_table('config')." VALUES ('DisableJsTools', '0');";
+ upgrade_query("Adding setting DisableJsTools",$query);
+ }
+
+ // 3. Drop primary key in nucleus_actionlog
+ $query = 'ALTER TABLE '.sql_table('actionlog').' DROP PRIMARY KEY;';
+ upgrade_query("Dropping primary key for actionlog table",$query);
+
+ // 4. add mcookiekey to nucleus_member
+ if(0==$upgrade_failures && !upgrade_checkIfColumnExists('member', 'mcookiekey')){
+ $query = 'ALTER TABLE '.sql_table('member')
+ . " ADD mcookiekey varchar(40) ";
+ $res = upgrade_query("Adding cookiekey attribute to members",$query);
+
+ // only do this when the previous query succeeds
+ //A more efficent query might be 'UPDATE '.sql_table('member')." SET mpassword=MD5(mpassword)"
+ if ($res) {
+ // 5. for all members: hash their password and also copy it to mcookiekey
+ $query = 'SELECT * FROM '.sql_table('member');
+ $res = mysql_query($query);
+ while ($current = mysql_fetch_object($res)) {
+ $hashedpw = md5($current->mpassword);
+ $updquery = 'UPDATE '.sql_table('member')." SET mpassword='$hashedpw' WHERE mnumber=" . $current->mnumber;
+ upgrade_query("Encrypting password for member " . $current->mnumber,$updquery);
+ }
+ }
+ }else{
+ echo "<li>Adding cookiekey attribute to members ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";
+ }
+}
+
+
+?>