2 function upgrade_do11() {
3 global $upgrade_failures;
5 if (upgrade_checkinstall(11))
6 return "already installed";
8 // 1. add some options to nucleus_config
9 if (!upgrade_checkIfCVExists('CookiePath')) {
10 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookiePath', '/');";
11 upgrade_query('CookiePath setting',$query);
13 if (!upgrade_checkIfCVExists('CookieDomain')) {
14 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookieDomain', '');";
15 upgrade_query('CookieDomain setting',$query);
17 if (!upgrade_checkIfCVExists('CookieSecure')) {
18 $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookieSecure', '0');";
19 upgrade_query('CookieSecure setting',$query);
21 if (!upgrade_checkIfCVExists('MediaPrefix')) {
22 $query = 'INSERT INTO '.sql_table('config')." VALUES ('MediaPrefix', '1');";
23 upgrade_query('MediaPrefix setting',$query);
26 // 2. add language field to member table
27 if(!upgrade_checkIfColumnExists('member', 'deflang')){
28 upgrade_query("Language setting (member)",
29 'ALTER TABLE '.sql_table('member')." ADD deflang varchar(20) NOT NULL default '';");
32 // 3. create category table and update other tables (nucleus_item and nucleus_blog)
33 $mark=$upgrade_failures;
34 if (!upgrade_checkIfTableExists('plugin')) {
35 $query = 'CREATE TABLE '.sql_table('category').' ('
36 ." catid int(11) NOT NULL auto_increment,"
37 ." cblog int(11) NOT NULL, "
38 ." cname varchar(40),"
39 ." cdesc varchar(200),"
40 ." PRIMARY KEY (catid)"
42 upgrade_query('New table '.sql_table('category'), $query);
44 if(!upgrade_checkIfColumnExists('item', 'icat')){
45 upgrade_query("Adding category attribute to item-table",
46 'ALTER TABLE '.sql_table('item').' ADD icat int(11)');
48 if(!upgrade_checkIfColumnExists('blog', 'bdefcat')){
49 upgrade_query("Adding defcat attribute to blog-table",
50 'ALTER TABLE '.sql_table('blog').' ADD bdefcat int(11)');
53 //The following blocks should check for existing values and only update as needed.
54 if($mark==$upgrade_failures){
55 // 4. add 'general' categories for all blogs, and update nucleus_item
56 $catid = 1; // generate catids ourself
57 $query = 'SELECT bnumber FROM '.sql_table('blog');
58 $res = mysql_query($query);
59 while ($current = mysql_fetch_object($res)) {
60 $blogid = $current->bnumber;
62 $query = 'INSERT INTO '.sql_table('category')." (catid, cblog, cname, cdesc) VALUES ($catid, $blogid, 'General', 'Items that do not fit in other categories')";
63 $r = upgrade_query("Adding category 'general' for blog " . $blogid, $query);
65 // only perform next actions when insert went ok
67 $query = 'UPDATE '.sql_table('blog')." SET bdefcat=$catid WHERE bnumber=$blogid";
68 upgrade_query("Setting the default category for blog $blogid to the 'General' category", $query);
70 $query = 'UPDATE '.sql_table('item')." SET icat=$catid WHERE iblog=$blogid";
71 upgrade_query("Assigning all existing items of blog $blogid to the 'General' category",$query);
77 // 5. add template parts for category lists to all templates
78 $query = 'SELECT tdnumber FROM '.sql_table('template_desc');
79 $res = sql_query($query); // get all template ids
80 while ($obj = mysql_fetch_object($res)) {
81 $tid = $obj->tdnumber; // template id
83 $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_HEADER', '<ul><li><a href=\"<%blogurl%>\">All</a></li>');";
84 $query2 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_LISTITEM', '<li><a href=\"<%catlink%>\"><%catname%></a></li>');";
85 $query3 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_FOOTER', '</ul>');";
86 upgrade_query("Adding categorylist header to template $tid",$query);
87 upgrade_query("Adding categorylist item to template $tid",$query2);
88 upgrade_query("Adding categorylist footer to template $tid",$query3);
93 // 6. add content type field to skins
94 if(!upgrade_checkIfColumnExists('skin_desc', 'sdtype')){
95 $query = 'ALTER TABLE '.sql_table('skin_desc')." ADD sdtype VARCHAR(40) NOT NULL DEFAULT 'text/html'";
96 upgrade_query("Adding content type field to skins (text/html)", $query);
99 // 7. try to set content type for xml-rss skin to text/xml
100 $query = 'UPDATE '.sql_table('skin_desc')." SET sdtype='text/xml' WHERE sdname='xmlrss'";
101 upgrade_query("Setting content type for xmlrss skin to text/xml", $query);
103 // 8. add bnotifytype column to blog tables
104 if(0==$upgrade_failures && !upgrade_checkIfColumnExists('blog', 'bnotifytype')){
105 upgrade_query("Adding Notify Type Setting",
106 'ALTER TABLE '.sql_table('blog')." ADD bnotifytype INT(11) NOT NULL default '15';");
108 echo "<li>Adding Notify Type Setting ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";