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 function upgrade_do100() {
15 if (upgrade_checkinstall(100))
18 // 1. add extra indices to tables
19 if (!upgrade_checkIfIndexExists('item', array('iblog', 'itime'))) {
20 $query = 'ALTER TABLE '.sql_table('item').' ADD INDEX(iblog, itime);';
21 upgrade_query("Adding extra index to nucleus_item",$query);
23 if (!upgrade_checkIfIndexExists('comment', array('citem'))) {
24 $query = 'ALTER TABLE '.sql_table('comment').' ADD INDEX(citem);';
25 upgrade_query("Adding extra index to nucleus_comment",$query);
28 // 2. add DisableJsTools to config
29 if (!upgrade_checkIfCVExists('DisableJsTools')) {
30 $query = 'INSERT INTO '.sql_table('config')." VALUES ('DisableJsTools', '0');";
31 upgrade_query("Adding setting DisableJsTools",$query);
34 // 3. Drop primary key in nucleus_actionlog
35 $query = 'ALTER TABLE '.sql_table('actionlog').' DROP PRIMARY KEY;';
36 upgrade_query("Dropping primary key for actionlog table",$query);
38 // 4. add mcookiekey to nucleus_member
39 if(0==$upgrade_failures && !upgrade_checkIfColumnExists('member', 'mcookiekey')){
40 $query = 'ALTER TABLE '.sql_table('member')
41 . " ADD mcookiekey varchar(40) ";
42 $res = upgrade_query("Adding cookiekey attribute to members",$query);
44 // only do this when the previous query succeeds
45 //A more efficent query might be 'UPDATE '.sql_table('member')." SET mpassword=MD5(mpassword)"
47 // 5. for all members: hash their password and also copy it to mcookiekey
48 $query = 'SELECT * FROM '.sql_table('member');
49 $res = mysql_query($query);
50 while ($current = mysql_fetch_object($res)) {
51 $hashedpw = md5($current->mpassword);
52 $updquery = 'UPDATE '.sql_table('member')." SET mpassword='$hashedpw' WHERE mnumber=" . $current->mnumber;
53 upgrade_query("Encrypting password for member " . $current->mnumber,$updquery);
57 echo "<li>Adding cookiekey attribute to members ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";