OSDN Git Service

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