OSDN Git Service

merged from v3.31sp1
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / upgrades / upgrade1.1.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2007 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-2007 The Nucleus Group
15  * $NucleusJP: upgrade1.1.php,v 1.3.2.1 2007/10/24 05:39:16 kimitake Exp $
16  *
17  */
18
19 function upgrade_do11() {
20         global $upgrade_failures;
21
22         if (upgrade_checkinstall(11))
23                 return "already installed";
24         
25         // 1. add some options to nucleus_config
26         if (!upgrade_checkIfCVExists('CookiePath')) {
27                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookiePath', '/');";
28                 upgrade_query('CookiePath setting',$query);
29         }
30         if (!upgrade_checkIfCVExists('CookieDomain')) {
31                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookieDomain', '');";
32                 upgrade_query('CookieDomain setting',$query);
33         }
34         if (!upgrade_checkIfCVExists('CookieSecure')) {
35                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookieSecure', '0');";
36                 upgrade_query('CookieSecure setting',$query);
37         }
38         if (!upgrade_checkIfCVExists('MediaPrefix')) {
39                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('MediaPrefix', '1');";
40                 upgrade_query('MediaPrefix setting',$query);
41         }
42         
43         // 2. add language field to member table
44         if(!upgrade_checkIfColumnExists('member', 'deflang')){
45                 upgrade_query("Language setting (member)", 
46                                           'ALTER TABLE '.sql_table('member')." ADD deflang varchar(20) NOT NULL default '';");
47         }
48
49         // 3. create category table and update other tables (nucleus_item and nucleus_blog)
50         $mark=$upgrade_failures;
51         if (!upgrade_checkIfTableExists('plugin')) {
52                 $query = 'CREATE TABLE '.sql_table('category').' ('
53                         ." catid int(11) NOT NULL auto_increment,"
54                         ." cblog int(11) NOT NULL, "
55                         ." cname varchar(40),"
56                         ." cdesc varchar(200),"
57                         ." PRIMARY KEY (catid)"
58                         .") ";
59                 upgrade_query('New table '.sql_table('category'), $query);
60         }
61         if(!upgrade_checkIfColumnExists('item', 'icat')){
62                 upgrade_query("Adding category attribute to item-table", 
63                         'ALTER TABLE '.sql_table('item').' ADD icat int(11)');
64         }
65         if(!upgrade_checkIfColumnExists('blog', 'bdefcat')){
66                 upgrade_query("Adding defcat attribute to blog-table", 
67                         'ALTER TABLE '.sql_table('blog').' ADD bdefcat int(11)');
68         }
69         
70         //The following blocks should check for existing values and only update as needed.
71         if($mark==$upgrade_failures){
72                 // 4. add 'general' categories for all blogs, and update nucleus_item
73                 $catid = 1;     // generate catids ourself
74                 $query = 'SELECT bnumber FROM '.sql_table('blog');
75                 $res = mysql_query($query);
76                 while ($current = mysql_fetch_object($res)) {
77                         $blogid = $current->bnumber;
78                         
79                         $query = 'INSERT INTO '.sql_table('category')." (catid, cblog, cname, cdesc) VALUES ($catid, $blogid, 'General', 'Items that do not fit in other categories')";
80                         $r = upgrade_query("Adding category 'general' for blog " . $blogid, $query);
81                         
82                         // only perform next actions when insert went ok
83                         if ($r) {
84                                 $query = 'UPDATE '.sql_table('blog')." SET bdefcat=$catid WHERE bnumber=$blogid";
85                                 upgrade_query("Setting the default category for blog $blogid to the 'General' category", $query);
86                         
87                                 $query = 'UPDATE '.sql_table('item')." SET icat=$catid WHERE iblog=$blogid";
88                                 upgrade_query("Assigning all existing items of blog $blogid to the 'General' category",$query);
89                         }
90                 
91                         $catid++;
92                 }
93                 
94                 // 5. add template parts for category lists to all templates
95                 $query = 'SELECT tdnumber FROM '.sql_table('template_desc');
96                 $res = sql_query($query);       // get all template ids
97                 while ($obj = mysql_fetch_object($res)) {
98                         $tid = $obj->tdnumber;  // template id
99                 
100                         $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_HEADER', '<ul><li><a href=\"<%blogurl%>\">All</a></li>');";
101                         $query2 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_LISTITEM', '<li><a href=\"<%catlink%>\"><%catname%></a></li>');";
102                         $query3 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_FOOTER', '</ul>');";
103                         upgrade_query("Adding categorylist header to template $tid",$query);
104                         upgrade_query("Adding categorylist item to template $tid",$query2);
105                         upgrade_query("Adding categorylist footer to template $tid",$query3);
106                         
107                 }
108         }
109         
110         // 6. add content type field to skins
111         if(!upgrade_checkIfColumnExists('skin_desc', 'sdtype')){
112                 $query = 'ALTER TABLE '.sql_table('skin_desc')." ADD sdtype VARCHAR(40) NOT NULL DEFAULT 'text/html'";
113                 upgrade_query("Adding content type field to skins (text/html)", $query);
114         }
115         
116         // 7. try to set content type for xml-rss skin to text/xml
117         $query = 'UPDATE '.sql_table('skin_desc')." SET sdtype='text/xml' WHERE sdname='xmlrss'";
118         upgrade_query("Setting content type for xmlrss skin to text/xml", $query);
119         
120         // 8. add bnotifytype column to blog tables
121         if(0==$upgrade_failures && !upgrade_checkIfColumnExists('blog', 'bnotifytype')){
122                 upgrade_query("Adding Notify Type Setting", 
123                                           'ALTER TABLE '.sql_table('blog')." ADD bnotifytype INT(11) NOT NULL default '15';");
124         }else{
125                 echo "<li>Adding Notify Type Setting ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";
126         }
127 }
128 ?>