OSDN Git Service

FIX:アップグレードスクリプトがNucleus3.6上で動作するように修正
[nucleus-jp/nucleus-next.git] / nucleus / upgrades / upgrade0.96.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: upgrade0.96.php 1809 2012-05-01 14:48:30Z sakamocchi $
16  */
17
18 function upgrade_do96() {
19
20         if (upgrade_checkinstall(96))
21                 return "already installed";
22
23         // 1. create nucleus_actionlog
24         if (!upgrade_checkIfTableExists('actionlog')) {
25                 $query = 'CREATE TABLE '.sql_table('actionlog')." (timestamp datetime NOT NULL default '0000-00-00 00:00:00', message varchar(255) NOT NULL default '', PRIMARY KEY  (timestamp)) ENGINE=MyISAM;";
26                 upgrade_query("Creating nucleus_actionlog table",$query);
27         }
28         
29         // 2. create nucleus_ban
30         if (!upgrade_checkIfTableExists('ban')) {
31                 $query = 'CREATE TABLE '.sql_table('ban')." (  iprange varchar(15) NOT NULL default '',  reason varchar(255) NOT NULL default '',  blogid int(11) NOT NULL default '0') ENGINE=MyISAM;";
32                 upgrade_query("Creating nucleus_ban table",$query);
33         }
34         
35         // 3. add ikarma to nucleus_item
36         if (!upgrade_checkIfColumnExists('item','ikarma')) {
37                 $query =  'ALTER TABLE '.sql_table('item')
38                            . " ADD ikarma int(11) NOT NULL default '0'";
39                 upgrade_query("Adding karma-votes to items",$query);
40         }
41         
42         // 4. create nucleus_karma
43         if (!upgrade_checkIfTableExists('karma')) {
44                 $query = 'CREATE TABLE '.sql_table('karma')." ("
45                         ."  itemid int(11) NOT NULL default '0',"
46                         ."  ip char(15) NOT NULL default ''"
47                         .") ENGINE=MyISAM;";
48                 upgrade_query("Creating nucleus_karma table",$query);
49         }
50         
51         // 5. nucleus_config: add MediaURL, AllowedTypes, AllowLoginEdit, AllowUpload
52         
53         // create MediaURL out of IndexURL
54         $mediaURL = $CONF['IndexURL'] . "media/";
55         
56         if (!upgrade_checkIfCVExists('MediaURL')) {
57                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('MediaURL', '$mediaURL');";
58                 upgrade_query("New setting MediaURL",$query);
59         }
60         if (!upgrade_checkIfCVExists('AllowedTypes')) {
61                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('AllowedTypes', 'jpg,jpeg,gif,mpg,mpeg,avi,mov,mp3,swf,png');";
62                 upgrade_query("New setting AllowedTypes",$query);
63         }
64         if (!upgrade_checkIfCVExists('AllowLoginEdit')) {
65                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('AllowLoginEdit', '0');";
66                 upgrade_query("New setting AllowLoginEdit",$query);
67         }
68         if (!upgrade_checkIfCVExists('AllowUpload')) {
69                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('AllowUpload', '1');";
70                 upgrade_query("New setting AllowUpload",$query);
71         }
72         
73         //The following blocks (6 and 7) should check for existing values and only update as needed.
74         // 6. add 'imagepopup' skincontents in skin 'default'
75         
76         $query = 'SELECT sdnumber FROM '.sql_table('skin_desc')." WHERE sdname='default'";
77         $res = sql_query($query);
78         $obj = mysql_fetch_object($res);
79         $skinid = $obj->sdnumber;
80         $query = 'INSERT INTO '.sql_table('skin')." VALUES (" . $skinid . ", 'imagepopup', '<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n  <title><%imagetext%></title>\r\n  <style type=\"text/css\">\r\n   img { border: none; }\r\n  </style>\r\n</head>\r\n<body>\r\n  <a href=\"javascript:window.close();\"><%image%></a>\r\n</body>\r\n</html>');";
81         upgrade_query("Adding 'imagepopup' skinparts",$query);
82         
83         // 7. add POPUP_CODE, MEDIA_CODE, IMAGE_CODE to ALL templates
84         $query = 'SELECT tdnumber FROM '.sql_table('template_desc');
85         $res = sql_query($query);       // get all template ids
86         while ($obj = mysql_fetch_object($res)) {
87                 $tid = $obj->tdnumber;  // template id
88         
89                 $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'POPUP_CODE', '<%popuplink%>');";
90                 $query2 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'MEDIA_CODE', '<%media%>');";
91                 $query3 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'IMAGE_CODE', '<%image%>');";
92                 upgrade_query("Adding popupcode to template $tid",$query);
93                 upgrade_query("Adding mediacode to template $tid",$query2);
94                 upgrade_query("Adding imagecode to template $tid",$query3);
95                 
96         }
97         
98         // 8. add cip to nucleus_comment
99         if(0==$upgrade_failures && !upgrade_checkIfColumnExists('comment', 'cip')){
100                 $query =  'ALTER TABLE '.sql_table('comment')
101                            . " ADD cip varchar(15) NOT NULL default ''";
102                 upgrade_query("Adding IP attribute to comments",$query);
103         }else{
104                 echo "<li>Adding IP attribute to comments ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";
105         }
106 }
107
108
109 ?>