OSDN Git Service

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/nucleus-jp/trunk@1211 1ca29...
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / upgrades / upgrade1.0.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2011 The Nucleus Group
5  *
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)
11  */
12 /**
13  * @license http://nucleuscms.org/license.txt GNU General Public License
14  * @copyright Copyright (C) 2002-2011 The Nucleus Group
15  * @version $Id$
16  * $NucleusJP: upgrade1.0.php,v 1.3.2.1 2007/10/24 05:39:15 kimitake Exp $
17  *
18  */
19
20 function upgrade_do100() {
21     
22     if (upgrade_checkinstall(100))
23         return 'インストール済みです';
24     
25     // 1. add extra indices to tables
26     if (!upgrade_checkIfIndexExists('item', array('iblog', 'itime'))) {
27         $query = 'ALTER TABLE '.sql_table('item').' ADD INDEX(iblog, itime);';
28         upgrade_query("Adding extra index to nucleus_item",$query);
29     }
30     if (!upgrade_checkIfIndexExists('comment', array('citem'))) {
31         $query = 'ALTER TABLE '.sql_table('comment').' ADD INDEX(citem);';
32         upgrade_query("Adding extra index to nucleus_comment",$query);
33     }
34     
35     // 2. add DisableJsTools to config
36     if (!upgrade_checkIfCVExists('DisableJsTools')) {
37         $query = 'INSERT INTO '.sql_table('config')." VALUES ('DisableJsTools', '0');";
38         upgrade_query("Adding setting DisableJsTools",$query);
39     }
40     
41     // 3. Drop primary key in nucleus_actionlog
42     $query = 'ALTER TABLE '.sql_table('actionlog').' DROP PRIMARY KEY;';
43     upgrade_query("Dropping primary key for actionlog table",$query);
44
45     // 4. add mcookiekey to nucleus_member
46     if(0==$upgrade_failures && !upgrade_checkIfColumnExists('member', 'mcookiekey')){
47         $query =  'ALTER TABLE '.sql_table('member')
48                . " ADD mcookiekey varchar(40) ";
49         $res = upgrade_query("Adding cookiekey attribute to members",$query);       
50         
51         // only do this when the previous query succeeds
52         //A more efficent query might be 'UPDATE '.sql_table('member')." SET mpassword=MD5(mpassword)"
53         if ($res) {
54             // 5. for all members: hash their password and also copy it to mcookiekey
55             $query = 'SELECT * FROM '.sql_table('member');
56             $res = mysql_query($query);
57             while ($current = mysql_fetch_object($res)) {
58                 $hashedpw = md5($current->mpassword);
59                 $updquery = 'UPDATE '.sql_table('member')." SET mpassword='$hashedpw' WHERE mnumber=" . $current->mnumber;
60                 upgrade_query("Encrypting password for member " . $current->mnumber,$updquery);
61             }
62         }
63     }else{
64         echo "<li>Adding cookiekey attribute to members ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";
65     }
66 }
67
68
69 ?>