3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2012 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
13 * @license http://nucleuscms.org/license.txt GNU General Public License
14 * @copyright Copyright (C) 2002-2012 The Nucleus Group
15 * @version $Id: upgrade1.0.php 1809 2012-05-01 14:48:30Z sakamocchi $
18 function upgrade_do100() {
20 if (upgrade_checkinstall(100))
21 return "already installed";
23 // 1. add extra indices to tables
24 if (!upgrade_checkIfIndexExists('item', array('iblog', 'itime'))) {
25 $query = 'ALTER TABLE '.sql_table('item').' ADD INDEX(iblog, itime);';
26 upgrade_query("Adding extra index to nucleus_item",$query);
28 if (!upgrade_checkIfIndexExists('comment', array('citem'))) {
29 $query = 'ALTER TABLE '.sql_table('comment').' ADD INDEX(citem);';
30 upgrade_query("Adding extra index to nucleus_comment",$query);
33 // 2. add DisableJsTools to config
34 if (!upgrade_checkIfCVExists('DisableJsTools')) {
35 $query = 'INSERT INTO '.sql_table('config')." VALUES ('DisableJsTools', '0');";
36 upgrade_query("Adding setting DisableJsTools",$query);
39 // 3. Drop primary key in nucleus_actionlog
40 $query = 'ALTER TABLE '.sql_table('actionlog').' DROP PRIMARY KEY;';
41 upgrade_query("Dropping primary key for actionlog table",$query);
43 // 4. add mcookiekey to nucleus_member
44 if(0==$upgrade_failures && !upgrade_checkIfColumnExists('member', 'mcookiekey')){
45 $query = 'ALTER TABLE '.sql_table('member')
46 . " ADD mcookiekey varchar(40) ";
47 $res = upgrade_query("Adding cookiekey attribute to members",$query);
49 // only do this when the previous query succeeds
50 //A more efficent query might be 'UPDATE '.sql_table('member')." SET mpassword=MD5(mpassword)"
52 // 5. for all members: hash their password and also copy it to mcookiekey
53 $query = 'SELECT * FROM '.sql_table('member');
54 $res = DB::getResult($query);
55 foreach ( $res as $current ) {
56 $hashedpw = md5($current['mpassword']);
57 $updquery = 'UPDATE '.sql_table('member')." SET mpassword='$hashedpw' WHERE mnumber=" . $current['mnumber'];
58 upgrade_query("Encrypting password for member " . $current['mnumber'], $updquery);
62 echo "<li>Adding cookiekey attribute to members ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";