OSDN Git Service

sync with trunk
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / upgrades / upgrade0.96.php
1 <?php
2 function upgrade_do96() {
3
4         if (upgrade_checkinstall(96))
5                 return "already installed";
6
7         // 1. create nucleus_actionlog
8         if (!upgrade_checkIfTableExists('actionlog')) {
9                 $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)) TYPE=MyISAM;";
10                 upgrade_query("Creating nucleus_actionlog table",$query);
11         }
12         
13         // 2. create nucleus_ban
14         if (!upgrade_checkIfTableExists('ban')) {
15                 $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') TYPE=MyISAM;";
16                 upgrade_query("Creating nucleus_ban table",$query);
17         }
18         
19         // 3. add ikarma to nucleus_item
20         if (!upgrade_checkIfColumnExists('item','ikarma')) {
21                 $query =  'ALTER TABLE '.sql_table('item')
22                            . " ADD ikarma int(11) NOT NULL default '0'";
23                 upgrade_query("Adding karma-votes to items",$query);
24         }
25         
26         // 4. create nucleus_karma
27         if (!upgrade_checkIfTableExists('karma')) {
28                 $query = 'CREATE TABLE '.sql_table('karma')." ("
29                         ."  itemid int(11) NOT NULL default '0',"
30                         ."  ip char(15) NOT NULL default ''"
31                         .") TYPE=MyISAM;";
32                 upgrade_query("Creating nucleus_karma table",$query);
33         }
34         
35         // 5. nucleus_config: add MediaURL, AllowedTypes, AllowLoginEdit, AllowUpload
36         
37         // create MediaURL out of IndexURL
38         $mediaURL = $CONF['IndexURL'] . "media/";
39         
40         if (!upgrade_checkIfCVExists('MediaURL')) {
41                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('MediaURL', '$mediaURL');";
42                 upgrade_query("New setting MediaURL",$query);
43         }
44         if (!upgrade_checkIfCVExists('AllowedTypes')) {
45                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('AllowedTypes', 'jpg,jpeg,gif,mpg,mpeg,avi,mov,mp3,swf,png');";
46                 upgrade_query("New setting AllowedTypes",$query);
47         }
48         if (!upgrade_checkIfCVExists('AllowLoginEdit')) {
49                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('AllowLoginEdit', '0');";
50                 upgrade_query("New setting AllowLoginEdit",$query);
51         }
52         if (!upgrade_checkIfCVExists('AllowUpload')) {
53                 $query = 'INSERT INTO '.sql_table('config')." VALUES ('AllowUpload', '1');";
54                 upgrade_query("New setting AllowUpload",$query);
55         }
56         
57         //The following blocks (6 and 7) should check for existing values and only update as needed.
58         // 6. add 'imagepopup' skincontents in skin 'default'
59         
60         $query = 'SELECT sdnumber FROM '.sql_table('skin_desc')." WHERE sdname='default'";
61         $res = sql_query($query);
62         $obj = mysql_fetch_object($res);
63         $skinid = $obj->sdnumber;
64         $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>');";
65         upgrade_query("Adding 'imagepopup' skinparts",$query);
66         
67         // 7. add POPUP_CODE, MEDIA_CODE, IMAGE_CODE to ALL templates
68         $query = 'SELECT tdnumber FROM '.sql_table('template_desc');
69         $res = sql_query($query);       // get all template ids
70         while ($obj = mysql_fetch_object($res)) {
71                 $tid = $obj->tdnumber;  // template id
72         
73                 $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'POPUP_CODE', '<%popuplink%>');";
74                 $query2 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'MEDIA_CODE', '<%media%>');";
75                 $query3 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'IMAGE_CODE', '<%image%>');";
76                 upgrade_query("Adding popupcode to template $tid",$query);
77                 upgrade_query("Adding mediacode to template $tid",$query2);
78                 upgrade_query("Adding imagecode to template $tid",$query3);
79                 
80         }
81         
82         // 8. add cip to nucleus_comment
83         if(0==$upgrade_failures && !upgrade_checkIfColumnExists('comment', 'cip')){
84                 $query =  'ALTER TABLE '.sql_table('comment')
85                            . " ADD cip varchar(15) NOT NULL default ''";
86                 upgrade_query("Adding IP attribute to comments",$query);
87         }else{
88                 echo "<li>Adding IP attribute to comments ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";
89         }
90 }
91
92
93 ?>