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 function upgrade_do110() {
14 global $upgrade_failures;
16 if (upgrade_checkinstall(110))
19 // 1. add some options to nucleus_config
20 if (!upgrade_checkIfCVExists('CookiePath')) {
21 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookiePath', '/');";
22 upgrade_query('CookiePath setting',$query);
24 if (!upgrade_checkIfCVExists('CookieDomain')) {
25 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookieDomain', '');";
26 upgrade_query('CookieDomain setting',$query);
28 if (!upgrade_checkIfCVExists('CookieSecure')) {
29 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookieSecure', '0');";
30 upgrade_query('CookieSecure setting',$query);
32 if (!upgrade_checkIfCVExists('MediaPrefix')) {
33 $query = 'INSERT INTO '.sql_table('config')." VALUES ('MediaPrefix', '1');";
34 upgrade_query('MediaPrefix setting',$query);
37 // 2. add language field to member table
38 if(!upgrade_checkIfColumnExists('member', 'deflang')){
39 upgrade_query("Language setting (member)",
40 'ALTER TABLE '.sql_table('member')." ADD deflang varchar(20) NOT NULL default '';");
43 // 3. create category table and update other tables (nucleus_item and nucleus_blog)
44 $mark=$upgrade_failures;
45 if (!upgrade_checkIfTableExists('plugin')) {
46 $query = 'CREATE TABLE '.sql_table('category').' ('
47 ." catid int(11) NOT NULL auto_increment,"
48 ." cblog int(11) NOT NULL, "
49 ." cname varchar(40),"
50 ." cdesc varchar(200),"
51 ." PRIMARY KEY (catid)"
53 upgrade_query('New table '.sql_table('category'), $query);
55 if(!upgrade_checkIfColumnExists('item', 'icat')){
56 upgrade_query("Adding category attribute to item-table",
57 'ALTER TABLE '.sql_table('item').' ADD icat int(11)');
59 if(!upgrade_checkIfColumnExists('blog', 'bdefcat')){
60 upgrade_query("Adding defcat attribute to blog-table",
61 'ALTER TABLE '.sql_table('blog').' ADD bdefcat int(11)');
64 //The following blocks should check for existing values and only update as needed.
65 if($mark==$upgrade_failures){
66 // 4. add 'general' categories for all blogs, and update nucleus_item
67 $catid = 1; // generate catids ourself
68 $query = 'SELECT bnumber FROM '.sql_table('blog');
69 $res = mysql_query($query);
70 while ($current = mysql_fetch_object($res)) {
71 $blogid = $current->bnumber;
73 $query = 'INSERT INTO '.sql_table('category')." (catid, cblog, cname, cdesc) VALUES ($catid, $blogid, 'General', 'Items that do not fit in other categories')";
74 $r = upgrade_query("Adding category 'general' for blog " . $blogid, $query);
76 // only perform next actions when insert went ok
78 $query = 'UPDATE '.sql_table('blog')." SET bdefcat=$catid WHERE bnumber=$blogid";
79 upgrade_query("Setting the default category for blog $blogid to the 'General' category", $query);
81 $query = 'UPDATE '.sql_table('item')." SET icat=$catid WHERE iblog=$blogid";
82 upgrade_query("Assigning all existing items of blog $blogid to the 'General' category",$query);
88 // 5. add template parts for category lists to all templates
89 $query = 'SELECT tdnumber FROM '.sql_table('template_desc');
90 $res = sql_query($query); // get all template ids
91 while ($obj = mysql_fetch_object($res)) {
92 $tid = $obj->tdnumber; // template id
94 $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_HEADER', '<ul><li><a href=\"<%blogurl%>\">All</a></li>');";
95 $query2 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_LISTITEM', '<li><a href=\"<%catlink%>\"><%catname%></a></li>');";
96 $query3 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_FOOTER', '</ul>');";
97 upgrade_query("Adding categorylist header to template $tid",$query);
98 upgrade_query("Adding categorylist item to template $tid",$query2);
99 upgrade_query("Adding categorylist footer to template $tid",$query3);
104 // 6. add content type field to skins
105 if(!upgrade_checkIfColumnExists('skin_desc', 'sdtype')){
106 $query = 'ALTER TABLE '.sql_table('skin_desc')." ADD sdtype VARCHAR(40) NOT NULL DEFAULT 'text/html'";
107 upgrade_query("Adding content type field to skins (text/html)", $query);
110 // 7. try to set content type for xml-rss skin to text/xml
111 $query = 'UPDATE '.sql_table('skin_desc')." SET sdtype='text/xml' WHERE sdname='xmlrss'";
112 upgrade_query("Setting content type for xmlrss skin to text/xml", $query);
114 // 8. add bnotifytype column to blog tables
115 if(0==$upgrade_failures && !upgrade_checkIfColumnExists('blog', 'bnotifytype')){
116 upgrade_query("Adding Notify Type Setting",
117 'ALTER TABLE '.sql_table('blog')." ADD bnotifytype INT(11) NOT NULL default '15';");
119 echo "<li>Adding Notify Type Setting ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";