3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2011 The Nucleus Group
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)
13 * @license http://nucleuscms.org/license.txt GNU General Public License
14 * @copyright Copyright (C) 2002-2011 The Nucleus Group
16 * $NucleusJP: upgrade1.1.php,v 1.3.2.1 2007/10/24 05:39:16 kimitake Exp $
20 function upgrade_do110() {
21 global $upgrade_failures;
23 if (upgrade_checkinstall(110))
26 // 1. add some options to nucleus_config
27 if (!upgrade_checkIfCVExists('CookiePath')) {
28 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookiePath', '/');";
29 upgrade_query('CookiePath setting',$query);
31 if (!upgrade_checkIfCVExists('CookieDomain')) {
32 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookieDomain', '');";
33 upgrade_query('CookieDomain setting',$query);
35 if (!upgrade_checkIfCVExists('CookieSecure')) {
36 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookieSecure', '0');";
37 upgrade_query('CookieSecure setting',$query);
39 if (!upgrade_checkIfCVExists('MediaPrefix')) {
40 $query = 'INSERT INTO '.sql_table('config')." VALUES ('MediaPrefix', '1');";
41 upgrade_query('MediaPrefix setting',$query);
44 // 2. add language field to member table
45 if(!upgrade_checkIfColumnExists('member', 'deflang')){
46 upgrade_query("Language setting (member)",
47 'ALTER TABLE '.sql_table('member')." ADD deflang varchar(20) NOT NULL default '';");
50 // 3. create category table and update other tables (nucleus_item and nucleus_blog)
51 $mark=$upgrade_failures;
52 if (!upgrade_checkIfTableExists('plugin')) {
53 $query = 'CREATE TABLE '.sql_table('category').' ('
54 ." catid int(11) NOT NULL auto_increment,"
55 ." cblog int(11) NOT NULL, "
56 ." cname varchar(40),"
57 ." cdesc varchar(200),"
58 ." PRIMARY KEY (catid)"
60 upgrade_query('New table '.sql_table('category'), $query);
62 if(!upgrade_checkIfColumnExists('item', 'icat')){
63 upgrade_query("Adding category attribute to item-table",
64 'ALTER TABLE '.sql_table('item').' ADD icat int(11)');
66 if(!upgrade_checkIfColumnExists('blog', 'bdefcat')){
67 upgrade_query("Adding defcat attribute to blog-table",
68 'ALTER TABLE '.sql_table('blog').' ADD bdefcat int(11)');
71 //The following blocks should check for existing values and only update as needed.
72 if($mark==$upgrade_failures){
73 // 4. add 'general' categories for all blogs, and update nucleus_item
74 $catid = 1; // generate catids ourself
75 $query = 'SELECT bnumber FROM '.sql_table('blog');
76 $res = mysql_query($query);
77 while ($current = mysql_fetch_object($res)) {
78 $blogid = $current->bnumber;
80 $query = 'INSERT INTO '.sql_table('category')." (catid, cblog, cname, cdesc) VALUES ($catid, $blogid, 'General', 'Items that do not fit in other categories')";
81 $r = upgrade_query("Adding category 'general' for blog " . $blogid, $query);
83 // only perform next actions when insert went ok
85 $query = 'UPDATE '.sql_table('blog')." SET bdefcat=$catid WHERE bnumber=$blogid";
86 upgrade_query("Setting the default category for blog $blogid to the 'General' category", $query);
88 $query = 'UPDATE '.sql_table('item')." SET icat=$catid WHERE iblog=$blogid";
89 upgrade_query("Assigning all existing items of blog $blogid to the 'General' category",$query);
95 // 5. add template parts for category lists to all templates
96 $query = 'SELECT tdnumber FROM '.sql_table('template_desc');
97 $res = sql_query($query); // get all template ids
98 while ($obj = mysql_fetch_object($res)) {
99 $tid = $obj->tdnumber; // template id
101 $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_HEADER', '<ul><li><a href=\"<%blogurl%>\">All</a></li>');";
102 $query2 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_LISTITEM', '<li><a href=\"<%catlink%>\"><%catname%></a></li>');";
103 $query3 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_FOOTER', '</ul>');";
104 upgrade_query("Adding categorylist header to template $tid",$query);
105 upgrade_query("Adding categorylist item to template $tid",$query2);
106 upgrade_query("Adding categorylist footer to template $tid",$query3);
111 // 6. add content type field to skins
112 if(!upgrade_checkIfColumnExists('skin_desc', 'sdtype')){
113 $query = 'ALTER TABLE '.sql_table('skin_desc')." ADD sdtype VARCHAR(40) NOT NULL DEFAULT 'text/html'";
114 upgrade_query("Adding content type field to skins (text/html)", $query);
117 // 7. try to set content type for xml-rss skin to text/xml
118 $query = 'UPDATE '.sql_table('skin_desc')." SET sdtype='text/xml' WHERE sdname='xmlrss'";
119 upgrade_query("Setting content type for xmlrss skin to text/xml", $query);
121 // 8. add bnotifytype column to blog tables
122 if(0==$upgrade_failures && !upgrade_checkIfColumnExists('blog', 'bnotifytype')){
123 upgrade_query("Adding Notify Type Setting",
124 'ALTER TABLE '.sql_table('blog')." ADD bnotifytype INT(11) NOT NULL default '15';");
126 echo "<li>Adding Notify Type Setting ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";