OSDN Git Service

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