3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2012 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-2012 The Nucleus Group
15 * @version $Id: upgrade1.1.php 1809 2012-05-01 14:48:30Z sakamocchi $
18 function upgrade_do110() {
19 global $upgrade_failures;
21 if (upgrade_checkinstall(110))
22 return "already installed";
24 // 1. add some options to nucleus_config
25 if (!upgrade_checkIfCVExists('CookiePath')) {
26 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookiePath', '/');";
27 upgrade_query('CookiePath setting',$query);
29 if (!upgrade_checkIfCVExists('CookieDomain')) {
30 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookieDomain', '');";
31 upgrade_query('CookieDomain setting',$query);
33 if (!upgrade_checkIfCVExists('CookieSecure')) {
34 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookieSecure', '0');";
35 upgrade_query('CookieSecure setting',$query);
37 if (!upgrade_checkIfCVExists('MediaPrefix')) {
38 $query = 'INSERT INTO '.sql_table('config')." VALUES ('MediaPrefix', '1');";
39 upgrade_query('MediaPrefix setting',$query);
42 // 2. add language field to member table
43 if(!upgrade_checkIfColumnExists('member', 'deflang')){
44 upgrade_query("Language setting (member)",
45 'ALTER TABLE '.sql_table('member')." ADD deflang varchar(20) NOT NULL default '';");
48 // 3. create category table and update other tables (nucleus_item and nucleus_blog)
49 $mark=$upgrade_failures;
50 if (!upgrade_checkIfTableExists('plugin')) {
51 $query = 'CREATE TABLE '.sql_table('category').' ('
52 ." catid int(11) NOT NULL auto_increment,"
53 ." cblog int(11) NOT NULL, "
54 ." cname varchar(40),"
55 ." cdesc varchar(200),"
56 ." PRIMARY KEY (catid)"
58 upgrade_query('New table '.sql_table('category'), $query);
60 if(!upgrade_checkIfColumnExists('item', 'icat')){
61 upgrade_query("Adding category attribute to item-table",
62 'ALTER TABLE '.sql_table('item').' ADD icat int(11)');
64 if(!upgrade_checkIfColumnExists('blog', 'bdefcat')){
65 upgrade_query("Adding defcat attribute to blog-table",
66 'ALTER TABLE '.sql_table('blog').' ADD bdefcat int(11)');
69 //The following blocks should check for existing values and only update as needed.
70 if($mark==$upgrade_failures){
71 // 4. add 'general' categories for all blogs, and update nucleus_item
72 $catid = 1; // generate catids ourself
73 $query = 'SELECT bnumber FROM '.sql_table('blog');
74 $res = mysql_query($query);
75 while ($current = mysql_fetch_object($res)) {
76 $blogid = $current->bnumber;
78 $query = 'INSERT INTO '.sql_table('category')." (catid, cblog, cname, cdesc) VALUES ($catid, $blogid, 'General', 'Items that do not fit in other categories')";
79 $r = upgrade_query("Adding category 'general' for blog " . $blogid, $query);
81 // only perform next actions when insert went ok
83 $query = 'UPDATE '.sql_table('blog')." SET bdefcat=$catid WHERE bnumber=$blogid";
84 upgrade_query("Setting the default category for blog $blogid to the 'General' category", $query);
86 $query = 'UPDATE '.sql_table('item')." SET icat=$catid WHERE iblog=$blogid";
87 upgrade_query("Assigning all existing items of blog $blogid to the 'General' category",$query);
93 // 5. add template parts for category lists to all templates
94 $query = 'SELECT tdnumber FROM '.sql_table('template_desc');
95 $res = sql_query($query); // get all template ids
96 while ($obj = mysql_fetch_object($res)) {
97 $tid = $obj->tdnumber; // template id
99 $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_HEADER', '<ul><li><a href=\"<%blogurl%>\">All</a></li>');";
100 $query2 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_LISTITEM', '<li><a href=\"<%catlink%>\"><%catname%></a></li>');";
101 $query3 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_FOOTER', '</ul>');";
102 upgrade_query("Adding categorylist header to template $tid",$query);
103 upgrade_query("Adding categorylist item to template $tid",$query2);
104 upgrade_query("Adding categorylist footer to template $tid",$query3);
109 // 6. add content type field to skins
110 if(!upgrade_checkIfColumnExists('skin_desc', 'sdtype')){
111 $query = 'ALTER TABLE '.sql_table('skin_desc')." ADD sdtype VARCHAR(40) NOT NULL DEFAULT 'text/html'";
112 upgrade_query("Adding content type field to skins (text/html)", $query);
115 // 7. try to set content type for xml-rss skin to text/xml
116 $query = 'UPDATE '.sql_table('skin_desc')." SET sdtype='text/xml' WHERE sdname='xmlrss'";
117 upgrade_query("Setting content type for xmlrss skin to text/xml", $query);
119 // 8. add bnotifytype column to blog tables
120 if(0==$upgrade_failures && !upgrade_checkIfColumnExists('blog', 'bnotifytype')){
121 upgrade_query("Adding Notify Type Setting",
122 'ALTER TABLE '.sql_table('blog')." ADD bnotifytype INT(11) NOT NULL default '15';");
124 echo "<li>Adding Notify Type Setting ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";