OSDN Git Service

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