OSDN Git Service

eb684d43201d0bce7ef13b4c77fada6c8cf11b75
[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-2009 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-2009 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 = DB::getResult($query);
58
59                 foreach ( $res as $row ) {
60                         $query = 'UPDATE '.sql_table('comment')." SET cblog='".$row['iblog']."' WHERE citem='".$row['inumber']."'";
61                         upgrade_query('Filling cblog column for item ' . $row['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 = DB::getResult($query);   // get all template ids
76         foreach ( $res as $row ) {
77                 $tid = $row['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 = DB::getResult('SELECT * FROM '.sql_table('template').' WHERE tpartname=\'DATE_HEADER\'');
86         foreach ( $res as $row ) {
87                 $newval = str_replace('<%daylink%>','<%%daylink%%>',$row['tcontent']);
88                 $query = 'UPDATE '.sql_table('template').' SET tcontent='. DB::quoteValue($newval).' WHERE tdesc=' . $row['tdesc'] . ' AND tpartname=\'DATE_HEADER\'';
89                 upgrade_query('Updating DATE_HEADER part in template ' . $row['tdesc'], $query);
90         }
91         
92         // in templates: add 'comments'-templatevar to all non-empty ITEM templates     
93         $res = DB::getResult('SELECT * FROM '.sql_table('template').' WHERE tpartname=\'ITEM\'');
94         foreach ( $res as $row )
95         {
96                 if ( i18n::strpos($row['tcontent'],'<%comments%>') === FALSE )
97                 {
98                         $newval = $row['tcontent'] . '<%comments%>';
99                         $query = 'UPDATE '.sql_table('template').' SET tcontent='. DB::quoteValue($newval).' WHERE tdesc=' . $row['tdesc'] . ' AND tpartname=\'ITEM\'';
100                         upgrade_query('Updating ITEM part in template ' . $row['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)) ENGINE=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 ?>