OSDN Git Service

FIX:アップグレードスクリプトがNucleus3.6上で動作するように修正
[nucleus-jp/nucleus-next.git] / nucleus / upgrades / upgrade1.5.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  * @license http://nucleuscms.org/license.txt GNU General Public License
14  * @copyright Copyright (C) 2002-2012 The Nucleus Group
15  * @version $Id: upgrade1.5.php 1889 2012-06-17 08:46:45Z sakamocchi $
16  */
17
18 function upgrade_do150() {
19
20         if (upgrade_checkinstall(150))
21                 return "already installed";
22         
23         // create nucleus_plugin_event
24         if (upgrade_checkIfTableExists('plugin_events')) {//present in dev version
25                 upgrade_query('Renaming table nucleus_plugins_events','RENAME TABLE '.sql_table('plugins_events').' TO '.sql_table('plugin_event'));
26         }elseif (!upgrade_checkIfTableExists('plugin_event')) {
27                 $query = 'CREATE TABLE '.sql_table('plugin_event').' (pid int(11) NOT NULL, event varchar(40)) ENGINE=MyISAM;';
28                 upgrade_query("Creating nucleus_plugin_event table",$query);
29         }
30
31         // create nucleus_plugin
32         if (upgrade_checkIfTableExists('plugins')) {//present in dev version
33                 upgrade_query('Renaming table nucleus_plugins','RENAME TABLE '.sql_table('plugins').' TO '.sql_table('plugin'));
34         }elseif (!upgrade_checkIfTableExists('plugin')) {
35                 $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)) ENGINE=MyISAM;";
36                 upgrade_query("Creating nucleus_plugin table",$query);
37         }
38
39         // add MaxUploadSize to config  
40         if (!upgrade_checkIfCVExists('MaxUploadSize')) {
41                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('MaxUploadSize','1048576')";
42                 upgrade_query('MaxUploadSize setting',$query);
43         }
44         
45
46         // try to add cblog column when it does not exists yet
47         //The logic on the old code seems off, but my replacement may not be correct either--AWB
48         //$query = 'SELECT * FROM '.sql_table('comment').' WHERE cblog=0 LIMIT 1';
49         //$res = mysql_query($query);
50         //if (!$res || (mysql_num_rows($res) > 0)) {
51         
52         if(!upgrade_checkIfColumnExists('comment', 'cblog')){
53                 $query = 'ALTER TABLE '.sql_table('comment')." ADD cblog int(11) NOT NULL default '0'";
54                 upgrade_query('Adding cblog column in table nucleus_comment',$query);
55
56                 $query = 'SELECT inumber, iblog FROM '.sql_table('item').', '.sql_table('comment').' WHERE inumber=citem AND cblog=0';
57                 $res = sql_query($query);
58
59                 while($o = mysql_fetch_object($res)) {
60                         $query = 'UPDATE '.sql_table('comment')." SET cblog='".$o->iblog."' WHERE citem='".$o->inumber."'";
61                         upgrade_query('Filling cblog column for item ' . $o->inumber, $query);
62                 }
63         }       
64         
65         // add 'pluginURL' to config
66         global $CONF;
67         if (!upgrade_checkIfCVExists('PluginURL')) {
68                 $pluginURL = $CONF['AdminURL'] . "plugins/";
69                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('PluginURL', '$pluginURL');";
70                 upgrade_query('PluginURL setting', $query);
71         }
72         
73         // add 'EDITLINK' to all templates
74         $query = 'SELECT tdnumber FROM '.sql_table('template_desc');
75         $res = sql_query($query);       // get all template ids
76         while ($obj = mysql_fetch_object($res)) {
77                 $tid = $obj->tdnumber;  // template id
78         
79                 $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'EDITLINK', '<a href=\"<%editlink%>\" onclick=\"<%editpopupcode%>\">edit</a>');";
80                 upgrade_query("Adding editlink code to template $tid",$query);
81                 
82         }
83         
84         // in templates: update DATE_HEADER templates
85         $res = sql_query('SELECT * FROM '.sql_table('template').' WHERE tpartname=\'DATE_HEADER\'');
86         while ($o = mysql_fetch_object($res)) {
87                 $newval = str_replace('<%daylink%>','<%%daylink%%>',$o->tcontent);
88                 $query = 'UPDATE '.sql_table('template').' SET tcontent=\''. addslashes($newval).'\' WHERE tdesc=' . $o->tdesc . ' AND tpartname=\'DATE_HEADER\'';
89                 upgrade_query('Updating DATE_HEADER part in template ' . $o->tdesc, $query);
90         }
91         
92         // in templates: add 'comments'-templatevar to all non-empty ITEM templates     
93         $res = sql_query('SELECT * FROM '.sql_table('template').' WHERE tpartname=\'ITEM\'');
94         while ($o = mysql_fetch_object($res)) {
95                 if (!strstr($o->tcontent,'<%comments%>')) {
96                         $newval = $o->tcontent . '<%comments%>';
97                         $query = 'UPDATE '.sql_table('template').' SET tcontent=\''. addslashes($newval).'\' WHERE tdesc=' . $o->tdesc . ' AND tpartname=\'ITEM\'';
98                         upgrade_query('Updating ITEM part in template ' . $o->tdesc, $query);
99                 }
100         }
101
102         // new setting: NonmemberMail
103         if (!upgrade_checkIfCVExists('NonmemberMail')) {
104                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('NonmemberMail', '0');";
105                 upgrade_query("Adding setting NonmemberMail",$query);
106         }
107         
108         // new setting: ProtectMemNames
109         if (!upgrade_checkIfCVExists('ProtectMemNames')) {
110                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('ProtectMemNames', '1');";
111                 upgrade_query("Adding setting ProtectMemNames",$query);
112         }
113
114         // create new table: nucleus_plugin_option
115         global $upgrade_failures;
116         if (0==$upgrade_failures && !upgrade_checkIfTableExists('plugin_option')) {
117                 $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)) ENGINE=MyISAM;";
118                 upgrade_query("Creating nucleus_plugin_option table",$query);
119         }else{
120                 echo "<li>Creating nucleus_plugin_option table ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";
121         }
122 }
123
124 ?>