OSDN Git Service

merged from v3.31sp1
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / upgrades / upgrade1.5.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.5.php,v 1.3.2.1 2007/10/24 05:39:16 kimitake Exp $
16  *
17  */
18
19 function upgrade_do15() {
20
21         if (upgrade_checkinstall(15))
22                 return "already installed";
23         
24         // create nucleus_plugin_event
25         if (upgrade_checkIfTableExists('plugin_events')) {//present in dev version
26                 upgrade_query('Renaming table nucleus_plugins_events','RENAME TABLE '.sql_table('plugins_events').' TO '.sql_table('plugin_event'));
27         }elseif (!upgrade_checkIfTableExists('plugin_event')) {
28                 $query = 'CREATE TABLE '.sql_table('plugin_event').' (pid int(11) NOT NULL, event varchar(40)) TYPE=MyISAM;';
29                 upgrade_query("Creating nucleus_plugin_event table",$query);
30         }
31
32         // create nucleus_plugin
33         if (upgrade_checkIfTableExists('plugins')) {//present in dev version
34                 upgrade_query('Renaming table nucleus_plugins','RENAME TABLE '.sql_table('plugins').' TO '.sql_table('plugin'));
35         }elseif (!upgrade_checkIfTableExists('plugin')) {
36                 $query = 'CREATE TABLE '.sql_table('plugin')." (pid int(11) NOT NULL auto_increment, pfile varchar(40) NOT NULL, porder int(11) not null, PRIMARY KEY(pid)) TYPE=MyISAM;";
37                 upgrade_query("Creating nucleus_plugin table",$query);
38         }
39
40         // add MaxUploadSize to config  
41         if (!upgrade_checkIfCVExists('MaxUploadSize')) {
42                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('MaxUploadSize','1048576')";
43                 upgrade_query('MaxUploadSize setting',$query);
44         }
45         
46
47         // try to add cblog column when it does not exists yet
48         //The logic on the old code seems off, but my replacement may not be correct either--AWB
49         //$query = 'SELECT * FROM '.sql_table('comment').' WHERE cblog=0 LIMIT 1';
50         //$res = mysql_query($query);
51         //if (!$res || (mysql_num_rows($res) > 0)) {
52         
53         if(!upgrade_checkIfColumnExists('comment', 'cblog')){
54                 $query = 'ALTER TABLE '.sql_table('comment')." ADD cblog int(11) NOT NULL default '0'";
55                 upgrade_query('Adding cblog column in table nucleus_comment',$query);
56
57                 $query = 'SELECT inumber, iblog FROM '.sql_table('item').', '.sql_table('comment').' WHERE inumber=citem AND cblog=0';
58                 $res = sql_query($query);
59
60                 while($o = mysql_fetch_object($res)) {
61                         $query = 'UPDATE '.sql_table('comment')." SET cblog='".$o->iblog."' WHERE citem='".$o->inumber."'";
62                         upgrade_query('Filling cblog column for item ' . $o->inumber, $query);
63                 }
64         }       
65         
66         // add 'pluginURL' to config
67         global $CONF;
68         if (!upgrade_checkIfCVExists('PluginURL')) {
69                 $pluginURL = $CONF['AdminURL'] . "plugins/";
70                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('PluginURL', '$pluginURL');";
71                 upgrade_query('PluginURL setting', $query);
72         }
73         
74         // add 'EDITLINK' to all templates
75         $query = 'SELECT tdnumber FROM '.sql_table('template_desc');
76         $res = sql_query($query);       // get all template ids
77         while ($obj = mysql_fetch_object($res)) {
78                 $tid = $obj->tdnumber;  // template id
79         
80                 $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'EDITLINK', '<a href=\"<%editlink%>\" onclick=\"<%editpopupcode%>\">edit</a>');";
81                 upgrade_query("Adding editlink code to template $tid",$query);
82                 
83         }
84         
85         // in templates: update DATE_HEADER templates
86         $res = sql_query('SELECT * FROM '.sql_table('template').' WHERE tpartname=\'DATE_HEADER\'');
87         while ($o = mysql_fetch_object($res)) {
88                 $newval = str_replace('<%daylink%>','<%%daylink%%>',$o->tcontent);
89                 $query = 'UPDATE '.sql_table('template').' SET tcontent=\''. addslashes($newval).'\' WHERE tdesc=' . $o->tdesc . ' AND tpartname=\'DATE_HEADER\'';
90                 upgrade_query('Updating DATE_HEADER part in template ' . $o->tdesc, $query);
91         }
92         
93         // in templates: add 'comments'-templatevar to all non-empty ITEM templates     
94         $res = sql_query('SELECT * FROM '.sql_table('template').' WHERE tpartname=\'ITEM\'');
95         while ($o = mysql_fetch_object($res)) {
96                 if (!strstr($o->tcontent,'<%comments%>')) {
97                         $newval = $o->tcontent . '<%comments%>';
98                         $query = 'UPDATE '.sql_table('template').' SET tcontent=\''. addslashes($newval).'\' WHERE tdesc=' . $o->tdesc . ' AND tpartname=\'ITEM\'';
99                         upgrade_query('Updating ITEM part in template ' . $o->tdesc, $query);
100                 }
101         }
102
103         // new setting: NonmemberMail
104         if (!upgrade_checkIfCVExists('NonmemberMail')) {
105                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('NonmemberMail', '0');";
106                 upgrade_query("Adding setting NonmemberMail",$query);
107         }
108         
109         // new setting: ProtectMemNames
110         if (!upgrade_checkIfCVExists('ProtectMemNames')) {
111                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('ProtectMemNames', '1');";
112                 upgrade_query("Adding setting ProtectMemNames",$query);
113         }
114
115         // create new table: nucleus_plugin_option
116         global $upgrade_failures;
117         if (0==$upgrade_failures && !upgrade_checkIfTableExists('plugin_option')) {
118                 $query = 'CREATE TABLE '.sql_table('plugin_option')." (opid int(11) NOT NULL, oname varchar(20) NOT NULL, ovalue varchar(128) not null, odesc varchar(255), otype varchar(8), PRIMARY KEY(opid, oname)) TYPE=MyISAM;";
119                 upgrade_query("Creating nucleus_plugin_option table",$query);
120         }else{
121                 echo "<li>Creating nucleus_plugin_option table ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";
122         }
123 }
124
125 ?>