From b709bcb1f2338e35d7d1b980757a24529c99adfa Mon Sep 17 00:00:00 2001 From: kimitake Date: Thu, 26 Apr 2007 06:20:19 +0000 Subject: [PATCH] sync with trunk git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/nucleus-jp/trunk@285 1ca29b6e-896d-4ea0-84a5-967f57386b96 --- utf8/nucleus/upgrades/index.php | 114 +++++++++-------- utf8/nucleus/upgrades/upgrade.functions.php | 189 +++++++++++++++++++--------- utf8/nucleus/upgrades/upgrade.php | 34 ++--- utf8/nucleus/upgrades/upgrade0.95.php | 17 +-- utf8/nucleus/upgrades/upgrade0.96.php | 145 +++++++++++---------- utf8/nucleus/upgrades/upgrade1.0.php | 76 ++++++----- utf8/nucleus/upgrades/upgrade1.1.php | 180 ++++++++++++++------------ utf8/nucleus/upgrades/upgrade1.5.php | 68 ++++++---- utf8/nucleus/upgrades/upgrade2.0.php | 84 ++++++++----- utf8/nucleus/upgrades/upgrade2.5.php | 140 ++++++++++++--------- utf8/nucleus/upgrades/upgrade3.0.php | 6 +- utf8/nucleus/upgrades/upgrade3.1.php | 6 +- utf8/nucleus/upgrades/upgrade3.2.php | 72 +++++------ utf8/nucleus/upgrades/upgrade3.3.php | 73 +++++------ 14 files changed, 681 insertions(+), 523 deletions(-) diff --git a/utf8/nucleus/upgrades/index.php b/utf8/nucleus/upgrades/index.php index 0c994a3..341f2d8 100755 --- a/utf8/nucleus/upgrades/index.php +++ b/utf8/nucleus/upgrades/index.php @@ -1,20 +1,24 @@ isLoggedIn()) { upgrade_showLogin('index.php'); @@ -40,25 +44,27 @@ upgrade_head();

-

自動でできるアップグレードはありません。データベースは既に最新の Nucleus 用にアップデートされています。

- -

ここをクリックしてデータベースを Nucleus v3.3 用にアップグレードします

- +

自動でできるアップグレードはありません。データベースは既に最新の Nucleus 用にアップデートされています。

+ +

ここをクリックしてデータベースを Nucleus v3.3 用にアップグレードします

+
@@ -88,7 +94,7 @@ if (phpversion() < '4.0.6') { } if ($sth == 0) - echo "

手動変更は必要ありません。今日はラッキーな日ですね!

"; + echo "

手動変更は必要ありません。今日はラッキーな日ですね!

"; @@ -100,7 +106,7 @@ function upgrade_todo($ver) { function upgrade_manual_96() { global $DIR_NUCLEUS; - + $guess = str_replace("/nucleus/","/media/",$DIR_NUCLEUS); ?>

Nucleus 0.96 用に必要な変更

@@ -111,16 +117,16 @@ function upgrade_manual_96() { // path to media dir $DIR_MEDIA = ''; - +

また、ディレクトリもあなた自身の手で作る必要があります。もしファイルのアップロードを可能にしたいのであれば、media/ ディレクトリのパーミッションを777にします。(Nucleus 0.96+ のためのパーミッションの設定に関するクイックガイドが documentation/tips.html にあります)

- +

Nucleus 2.0 用に必要な変更

@@ -131,13 +137,13 @@ function upgrade_manual_20() { // extra skin files for imported skins $DIR_SKINS = ''; - +

また、ディレクトリもあなた自身の手で作る必要があります。これでダウンロードしたスキンを上記ディレクトリに展開したり、Nucleus 管理画面から取り込んだりできるようになります。

- +

RSS 2.0 と RSD スキン

- +

Nucleus 2.0 を新規にインストールしたとき、RSD(Really Simple Discovery) 用のスキンの他に、RSS 2.0(Really Simple Syndication)用のスキンもまたインストールされます。xml-rss2.php と rsd.php の両ファイルはアップグレードされますが、スキンに関しては手動でインストールする必要があります。upgrade-filesの中身をアップロードしたあと、管理者画面を開き、管理ホームにあるスキンの「読込/書出」を開きます。そこから両スキンをインストールすることができます(もしインストールするつもりがなければ、しなくても結構です)。

- + - + diff --git a/utf8/nucleus/upgrades/upgrade.functions.php b/utf8/nucleus/upgrades/upgrade.functions.php index 8365aa8..ebc9d79 100755 --- a/utf8/nucleus/upgrades/upgrade.functions.php +++ b/utf8/nucleus/upgrades/upgrade.functions.php @@ -1,30 +1,45 @@ -= 250 LIMIT 1'; $minrows = 1; @@ -91,8 +106,8 @@ return $installed; } - - + + /** this function gets the nucleus version, even if the getNucleusVersion * function does not exist yet * return 96 for all versions < 100 @@ -101,13 +116,13 @@ if (!function_exists('getNucleusVersion')) return 96; return getNucleusVersion(); } - + function upgrade_showLogin($type) { upgrade_head(); ?>

まずはログインして下さい

下記の情報を入力して下さい:

- +
    @@ -119,12 +134,12 @@

    - + @@ -132,8 +147,10 @@ Nucleus アップグレード - + - + - - +

    エラー!

    メッセージは以下の通り:

    - +
    @@ -167,48 +185,48 @@ upgrade_foot(); exit; } - - + + function upgrade_start() { global $upgrade_failures; $upgrade_failures = 0; - + upgrade_head(); ?>

    アップグレードの実行

      0) $msg = "いくつかのデータベース操作に失敗しました。もし以前にこのアップグレードスクリプトを実行していたのであれば、問題ないと思われます。"; - + ?>
    - +

    アップグレード完了!

    - +

    アップグレード最初のページにもどる

    $friendly ... "; - $res = sql_query($query); + $res = mysql_query($query); if (!$res) { echo "失敗\n"; echo "
    失敗の理由: " . mysql_error() . "
    "; @@ -219,16 +237,32 @@ echo ""; return $res; } - + + /** + * Tries to update database version, gives a message when failed + * + * @param $version + * Schema version the database has been upgraded to + */ + function update_version($version) { + global $upgrade_failures; + $message='Updating DatabaseVersion in config table to '.$version; + if(0==$upgrade_failures){ + $query = 'UPDATE ' . sql_table('config') . ' set value=\''.$version.'\' where name=\'DatabaseVersion\''; + upgrade_query($message, $query); + }else + echo '
  • '.$message.' ... NOT EXECUTED\n
    Errors occurred during upgrade process.
    '; + } + /** - * @param $table + * @param $table * table to check (without prefix) * @param $aColumns * array of column names included */ function upgrade_checkIfIndexExists($table, $aColumns) { // get info for indices from database - + $aIndices = array(); $query = 'show index from ' . sql_table($table); $res = mysql_query($query); @@ -244,11 +278,52 @@ $aDiff = array_diff($aIndexColumns, $aColumns); if (count($aDiff) == 0) return 1; } - + return 0; } + /** + * Checks to see if a given table exists + * + * @param $table + * Name of table to check for existance of + * Uses sql_table internally + * @return true if table exists, false otherwise. + */ + function upgrade_checkIfTableExists($table){ + $query = 'SHOW TABLES LIKE \''.sql_table($table).'\''; + $res = mysql_query($query); + return ($res != 0) && (mysql_num_rows($res) == 1); + } + /** + * Checks to see if a given configuration value exists + * + * @param $value + * Config value to check for existance of. + * Paramater must be MySQL escaped + * @return true if configuration value exists, false otherwise. + */ + function upgrade_checkIfCVExists($value){ + $query = 'SELECT name from '.sql_table('config').' WHERE name = \''.$value.'\''; + $res = mysql_query($query); + return ($res != 0) && (mysql_num_rows($res) == 1); + } + /** + * Checks to see if a given column exists + * + * @param $table + * Name of table to check for column in + * Uses sql_table internally + * @param $col + * Name of column to check for existance of + * @return true if column exists, false otherwise. + */ + function upgrade_checkIfColumnExists($table, $col){ + $query = 'DESC `'.sql_table($table).'` `'.$col.'`'; + $res = mysql_query($query); + return ($res != 0) && (mysql_num_rows($res) == 1); + } ?> diff --git a/utf8/nucleus/upgrades/upgrade.php b/utf8/nucleus/upgrades/upgrade.php index c5e444d..13b0638 100755 --- a/utf8/nucleus/upgrades/upgrade.php +++ b/utf8/nucleus/upgrades/upgrade.php @@ -1,20 +1,23 @@ isLoggedIn()) { upgrade_showLogin('upgrade.php?from=' . intGetVar('from')); @@ -60,6 +63,7 @@ switch($from) { upgrade_do31(); case 31: upgrade_do32(); + break; case 32: upgrade_do33(); break; @@ -72,4 +76,4 @@ switch($from) { upgrade_end("アップグレード成功"); -?> +?> \ No newline at end of file diff --git a/utf8/nucleus/upgrades/upgrade0.95.php b/utf8/nucleus/upgrades/upgrade0.95.php index b854121..1aa9e8c 100755 --- a/utf8/nucleus/upgrades/upgrade0.95.php +++ b/utf8/nucleus/upgrades/upgrade0.95.php @@ -1,14 +1,17 @@ Adding 'send ping' and convert linebreaks options ... NOT EXECUTED\n
    Errors occurred during upgrade process.
    "; + } } ?> \ No newline at end of file diff --git a/utf8/nucleus/upgrades/upgrade0.96.php b/utf8/nucleus/upgrades/upgrade0.96.php index 3d85bdd..adc7987 100755 --- a/utf8/nucleus/upgrades/upgrade0.96.php +++ b/utf8/nucleus/upgrades/upgrade0.96.php @@ -4,70 +4,89 @@ function upgrade_do96() { if (upgrade_checkinstall(96)) return "already installed"; -// 1. create nucleus_actionlog -$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;"; -upgrade_query("Creating nucleus_actionlog table",$query); - -// 2. create nucleus_ban -$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;"; -upgrade_query("Creating nucleus_ban table",$query); - -// 4. add ikarma to nucleus_item -$query = 'ALTER TABLE '.sql_table('item') - . " ADD ikarma int(11) NOT NULL default '0'"; -upgrade_query("Adding karma-votes to items",$query); - -// 5. create nucleus_karma -$query = 'CREATE TABLE '.sql_table('karma')." (" - ." itemid int(11) NOT NULL default '0'," - ." ip char(15) NOT NULL default ''" - .") TYPE=MyISAM;"; -upgrade_query("Creating nucleus_karma table",$query); - - -// 6. nucleus_config: add MediaURL, AllowedTypes, AllowLoginEdit, AllowUpload - -// create MediaURL out of IndexURL -$mediaURL = $CONF['IndexURL'] . "media/"; - -$query = 'INSERT INTO '.sql_table('config')." VALUES ('MediaURL', '$mediaURL');"; -$query2 = 'INSERT INTO '.sql_table('config')." VALUES ('AllowedTypes', 'jpg,jpeg,gif,mpg,mpeg,avi,mov,mp3,swf,png');"; -$query3 = 'INSERT INTO '.sql_table('config')." VALUES ('AllowLoginEdit', '0');"; -$query4 = 'INSERT INTO '.sql_table('config')." VALUES ('AllowUpload', '1');"; -upgrade_query("New setting MediaURL",$query); -upgrade_query("New setting AllowedTypes",$query2); -upgrade_query("New setting AllowLoginEdit",$query3); -upgrade_query("New setting AllowUpload",$query4); - -// 7. add 'imagepopup' skincontents in skin 'default' - -$query = 'SELECT sdnumber FROM '.sql_table('skin_desc')." WHERE sdname='default'"; -$res = sql_query($query); -$obj = mysql_fetch_object($res); -$skinid = $obj->sdnumber; -$query = 'INSERT INTO '.sql_table('skin')." VALUES (" . $skinid . ", 'imagepopup', '\r\n\r\n <%imagetext%>\r\n \r\n\r\n\r\n <%image%>\r\n\r\n');"; -upgrade_query("Adding 'imagepopup' skinparts",$query); - -// 8. add POPUP_CODE, MEDIA_CODE, IMAGE_CODE to ALL templates -$query = 'SELECT tdnumber FROM '.sql_table('template_desc'); -$res = sql_query($query); // get all template ids -while ($obj = mysql_fetch_object($res)) { - $tid = $obj->tdnumber; // template id - - $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'POPUP_CODE', '<%popuplink%>');"; - $query2 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'MEDIA_CODE', '<%media%>');"; - $query3 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'IMAGE_CODE', '<%image%>');"; - upgrade_query("Adding popupcode to template $tid",$query); - upgrade_query("Adding mediacode to template $tid",$query2); - upgrade_query("Adding imagecode to template $tid",$query3); + // 1. create nucleus_actionlog + if (!upgrade_checkIfTableExists('actionlog')) { + $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;"; + upgrade_query("Creating nucleus_actionlog table",$query); + } -} - -// 3. add cip to nucleus_comment -$query = 'ALTER TABLE '.sql_table('comment') - . " ADD cip varchar(15) NOT NULL default ''"; -upgrade_query("Adding IP attribute to comments",$query); - + // 2. create nucleus_ban + if (!upgrade_checkIfTableExists('ban')) { + $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;"; + upgrade_query("Creating nucleus_ban table",$query); + } + + // 3. add ikarma to nucleus_item + if (!upgrade_checkIfColumnExists('item','ikarma')) { + $query = 'ALTER TABLE '.sql_table('item') + . " ADD ikarma int(11) NOT NULL default '0'"; + upgrade_query("Adding karma-votes to items",$query); + } + + // 4. create nucleus_karma + if (!upgrade_checkIfTableExists('karma')) { + $query = 'CREATE TABLE '.sql_table('karma')." (" + ." itemid int(11) NOT NULL default '0'," + ." ip char(15) NOT NULL default ''" + .") TYPE=MyISAM;"; + upgrade_query("Creating nucleus_karma table",$query); + } + + // 5. nucleus_config: add MediaURL, AllowedTypes, AllowLoginEdit, AllowUpload + + // create MediaURL out of IndexURL + $mediaURL = $CONF['IndexURL'] . "media/"; + + if (!upgrade_checkIfCVExists('MediaURL')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('MediaURL', '$mediaURL');"; + upgrade_query("New setting MediaURL",$query); + } + if (!upgrade_checkIfCVExists('AllowedTypes')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('AllowedTypes', 'jpg,jpeg,gif,mpg,mpeg,avi,mov,mp3,swf,png');"; + upgrade_query("New setting AllowedTypes",$query); + } + if (!upgrade_checkIfCVExists('AllowLoginEdit')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('AllowLoginEdit', '0');"; + upgrade_query("New setting AllowLoginEdit",$query); + } + if (!upgrade_checkIfCVExists('AllowUpload')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('AllowUpload', '1');"; + upgrade_query("New setting AllowUpload",$query); + } + + //The following blocks (6 and 7) should check for existing values and only update as needed. + // 6. add 'imagepopup' skincontents in skin 'default' + + $query = 'SELECT sdnumber FROM '.sql_table('skin_desc')." WHERE sdname='default'"; + $res = sql_query($query); + $obj = mysql_fetch_object($res); + $skinid = $obj->sdnumber; + $query = 'INSERT INTO '.sql_table('skin')." VALUES (" . $skinid . ", 'imagepopup', '\r\n\r\n <%imagetext%>\r\n \r\n\r\n\r\n <%image%>\r\n\r\n');"; + upgrade_query("Adding 'imagepopup' skinparts",$query); + + // 7. add POPUP_CODE, MEDIA_CODE, IMAGE_CODE to ALL templates + $query = 'SELECT tdnumber FROM '.sql_table('template_desc'); + $res = sql_query($query); // get all template ids + while ($obj = mysql_fetch_object($res)) { + $tid = $obj->tdnumber; // template id + + $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'POPUP_CODE', '<%popuplink%>');"; + $query2 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'MEDIA_CODE', '<%media%>');"; + $query3 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'IMAGE_CODE', '<%image%>');"; + upgrade_query("Adding popupcode to template $tid",$query); + upgrade_query("Adding mediacode to template $tid",$query2); + upgrade_query("Adding imagecode to template $tid",$query3); + + } + + // 8. add cip to nucleus_comment + if(0==$upgrade_failures && !upgrade_checkIfColumnExists('comment', 'cip')){ + $query = 'ALTER TABLE '.sql_table('comment') + . " ADD cip varchar(15) NOT NULL default ''"; + upgrade_query("Adding IP attribute to comments",$query); + }else{ + echo "
  • Adding IP attribute to comments ... NOT EXECUTED\n
    Errors occurred during upgrade process.
    "; + } } diff --git a/utf8/nucleus/upgrades/upgrade1.0.php b/utf8/nucleus/upgrades/upgrade1.0.php index a28c739..5287181 100755 --- a/utf8/nucleus/upgrades/upgrade1.0.php +++ b/utf8/nucleus/upgrades/upgrade1.0.php @@ -1,40 +1,50 @@ mpassword); - $updquery = 'UPDATE '.sql_table('member')." SET mpassword='$hashedpw' WHERE mnumber=" . $current->mnumber; - upgrade_query("Encrypting password for member " . $current->mnumber,$updquery); + if (upgrade_checkinstall(10)) + return "already installed"; + + // 1. add extra indices to tables + if (!upgrade_checkIfIndexExists('item', array('iblog', 'itime'))) { + $query = 'ALTER TABLE '.sql_table('item').' ADD INDEX(iblog, itime);'; + upgrade_query("Adding extra index to nucleus_item",$query); + } + if (!upgrade_checkIfIndexExists('comment', array('citem'))) { + $query = 'ALTER TABLE '.sql_table('comment').' ADD INDEX(citem);'; + upgrade_query("Adding extra index to nucleus_comment",$query); + } + + // 2. add DisableJsTools to config + if (!upgrade_checkIfCVExists('DisableJsTools')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('DisableJsTools', '0');"; + upgrade_query("Adding setting DisableJsTools",$query); + } + + // 3. Drop primary key in nucleus_actionlog + $query = 'ALTER TABLE '.sql_table('actionlog').' DROP PRIMARY KEY;'; + upgrade_query("Dropping primary key for actionlog table",$query); + + // 4. add mcookiekey to nucleus_member + if(0==$upgrade_failures && !upgrade_checkIfColumnExists('member', 'mcookiekey')){ + $query = 'ALTER TABLE '.sql_table('member') + . " ADD mcookiekey varchar(40) "; + $res = upgrade_query("Adding cookiekey attribute to members",$query); + + // only do this when the previous query succeeds + //A more efficent query might be 'UPDATE '.sql_table('member')." SET mpassword=MD5(mpassword)" + if ($res) { + // 5. for all members: hash their password and also copy it to mcookiekey + $query = 'SELECT * FROM '.sql_table('member'); + $res = mysql_query($query); + while ($current = mysql_fetch_object($res)) { + $hashedpw = md5($current->mpassword); + $updquery = 'UPDATE '.sql_table('member')." SET mpassword='$hashedpw' WHERE mnumber=" . $current->mnumber; + upgrade_query("Encrypting password for member " . $current->mnumber,$updquery); + } + } + }else{ + echo "
  • Adding cookiekey attribute to members ... NOT EXECUTED\n
    Errors occurred during upgrade process.
    "; } -} - -// 3. add extra indices to tables -$query = 'ALTER TABLE '.sql_table('item').' ADD INDEX(iblog, itime);'; -upgrade_query("Adding extra index to nucleus_item",$query); -$query = 'ALTER TABLE '.sql_table('comment').' ADD INDEX(citem);'; -upgrade_query("Adding extra index to nucleus_comment",$query); - -// 4. add DisableJsTools to config -$query = 'INSERT INTO '.sql_table('config')." VALUES ('DisableJsTools', '0');"; -upgrade_query("Adding setting DisableJsTools",$query); - -// 5. Drop primary key in nucleus_actionlog -$query = 'ALTER TABLE '.sql_table('actionlog').' DROP PRIMARY KEY;'; -upgrade_query("Dropping primary key for actionlog table",$query); - } diff --git a/utf8/nucleus/upgrades/upgrade1.1.php b/utf8/nucleus/upgrades/upgrade1.1.php index 763e6fb..b518232 100755 --- a/utf8/nucleus/upgrades/upgrade1.1.php +++ b/utf8/nucleus/upgrades/upgrade1.1.php @@ -1,89 +1,111 @@ bnumber; + if (upgrade_checkinstall(11)) + return "already installed"; - $query = 'INSERT INTO '.sql_table('category')." (catid, cblog, cname, cdesc) VALUES ($catid, $blogid, 'General', 'Items that do not fit in other categories')"; - $r = upgrade_query("Adding category 'general' for blog " . $blogid, $query); - - // only perform next actions when insert went ok - if ($r) { - $query = 'UPDATE '.sql_table('blog')." SET bdefcat=$catid WHERE bnumber=$blogid"; - upgrade_query("Setting the default category for blog $blogid to the 'General' category", $query); + // 1. add some options to nucleus_config + if (!upgrade_checkIfCVExists('CookiePath')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookiePath', '/');"; + upgrade_query('CookiePath setting',$query); + } + if (!upgrade_checkIfCVExists('CookieDomain')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookieDomain', '');"; + upgrade_query('CookieDomain setting',$query); + } + if (!upgrade_checkIfCVExists('CookieSecure')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookieSecure', '0');"; + upgrade_query('CookieSecure setting',$query); + } + if (!upgrade_checkIfCVExists('MediaPrefix')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('MediaPrefix', '1');"; + upgrade_query('MediaPrefix setting',$query); + } - $query = 'UPDATE '.sql_table('item')." SET icat=$catid WHERE iblog=$blogid"; - upgrade_query("Assigning all existing items of blog $blogid to the 'General' category",$query); + // 2. add language field to member table + if(!upgrade_checkIfColumnExists('member', 'deflang')){ + upgrade_query("Language setting (member)", + 'ALTER TABLE '.sql_table('member')." ADD deflang varchar(20) NOT NULL default '';"); } - $catid++; -} - -// 5. add content type field to skins -$query = 'ALTER TABLE '.sql_table('skin_desc')." ADD sdtype VARCHAR(40) NOT NULL DEFAULT 'text/html'"; -upgrade_query("Adding content type field to skins (text/html)", $query); - -// 6. try to set content type for xml-rss skin to text/xml -$query = 'UPDATE '.sql_table('skin_desc')." SET sdtype='text/xml' WHERE sdname='xmlrss'"; -upgrade_query("Setting content type for xmlrss skin to text/xml", $query); - -// 7. add template parts for category lists to all templates -$query = 'SELECT tdnumber FROM '.sql_table('template_desc'); -$res = sql_query($query); // get all template ids -while ($obj = mysql_fetch_object($res)) { - $tid = $obj->tdnumber; // template id - - $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_HEADER', '
    • \">All
    • ');"; - $query2 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_LISTITEM', '
    • \"><%catname%>
    • ');"; - $query3 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_FOOTER', '
    ');"; - upgrade_query("Adding categorylist header to template $tid",$query); - upgrade_query("Adding categorylist item to template $tid",$query2); - upgrade_query("Adding categorylist footer to template $tid",$query3); + // 3. create category table and update other tables (nucleus_item and nucleus_blog) + $mark=$upgrade_failures; + if (!upgrade_checkIfTableExists('plugin')) { + $query = 'CREATE TABLE '.sql_table('category').' (' + ." catid int(11) NOT NULL auto_increment," + ." cblog int(11) NOT NULL, " + ." cname varchar(40)," + ." cdesc varchar(200)," + ." PRIMARY KEY (catid)" + .") "; + upgrade_query('New table '.sql_table('category'), $query); + } + if(!upgrade_checkIfColumnExists('item', 'icat')){ + upgrade_query("Adding category attribute to item-table", + 'ALTER TABLE '.sql_table('item').' ADD icat int(11)'); + } + if(!upgrade_checkIfColumnExists('blog', 'bdefcat')){ + upgrade_query("Adding defcat attribute to blog-table", + 'ALTER TABLE '.sql_table('blog').' ADD bdefcat int(11)'); + } + //The following blocks should check for existing values and only update as needed. + if($mark==$upgrade_failures){ + // 4. add 'general' categories for all blogs, and update nucleus_item + $catid = 1; // generate catids ourself + $query = 'SELECT bnumber FROM '.sql_table('blog'); + $res = mysql_query($query); + while ($current = mysql_fetch_object($res)) { + $blogid = $current->bnumber; + + $query = 'INSERT INTO '.sql_table('category')." (catid, cblog, cname, cdesc) VALUES ($catid, $blogid, 'General', 'Items that do not fit in other categories')"; + $r = upgrade_query("Adding category 'general' for blog " . $blogid, $query); + + // only perform next actions when insert went ok + if ($r) { + $query = 'UPDATE '.sql_table('blog')." SET bdefcat=$catid WHERE bnumber=$blogid"; + upgrade_query("Setting the default category for blog $blogid to the 'General' category", $query); + + $query = 'UPDATE '.sql_table('item')." SET icat=$catid WHERE iblog=$blogid"; + upgrade_query("Assigning all existing items of blog $blogid to the 'General' category",$query); + } + + $catid++; + } + + // 5. add template parts for category lists to all templates + $query = 'SELECT tdnumber FROM '.sql_table('template_desc'); + $res = sql_query($query); // get all template ids + while ($obj = mysql_fetch_object($res)) { + $tid = $obj->tdnumber; // template id + + $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_HEADER', '
    • \">All
    • ');"; + $query2 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_LISTITEM', '
    • \"><%catname%>
    • ');"; + $query3 = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_FOOTER', '
    ');"; + upgrade_query("Adding categorylist header to template $tid",$query); + upgrade_query("Adding categorylist item to template $tid",$query2); + upgrade_query("Adding categorylist footer to template $tid",$query3); + + } + } + + // 6. add content type field to skins + if(!upgrade_checkIfColumnExists('skin_desc', 'sdtype')){ + $query = 'ALTER TABLE '.sql_table('skin_desc')." ADD sdtype VARCHAR(40) NOT NULL DEFAULT 'text/html'"; + upgrade_query("Adding content type field to skins (text/html)", $query); + } + + // 7. try to set content type for xml-rss skin to text/xml + $query = 'UPDATE '.sql_table('skin_desc')." SET sdtype='text/xml' WHERE sdname='xmlrss'"; + upgrade_query("Setting content type for xmlrss skin to text/xml", $query); + + // 8. add bnotifytype column to blog tables + if(0==$upgrade_failures && !upgrade_checkIfColumnExists('blog', 'bnotifytype')){ + upgrade_query("Adding Notify Type Setting", + 'ALTER TABLE '.sql_table('blog')." ADD bnotifytype INT(11) NOT NULL default '15';"); + }else{ + echo "
  • Adding Notify Type Setting ... NOT EXECUTED\n
    Errors occurred during upgrade process.
    "; + } } - -// 8. add bnotifytype column to blog tables -upgrade_query("Notify Type Setting", - 'ALTER TABLE '.sql_table('blog')." ADD bnotifytype INT(11) NOT NULL default '15';"); - - -} - ?> \ No newline at end of file diff --git a/utf8/nucleus/upgrades/upgrade1.5.php b/utf8/nucleus/upgrades/upgrade1.5.php index 637cf67..b148561 100755 --- a/utf8/nucleus/upgrades/upgrade1.5.php +++ b/utf8/nucleus/upgrades/upgrade1.5.php @@ -3,32 +3,37 @@ function upgrade_do15() { if (upgrade_checkinstall(15)) return "already installed"; - - // first two queries are needed for people running the development version - global $nucleus; - if (strstr($nucleus['version'],'dev')) { - upgrade_query('Renaming table nucleus_plugins_events','RENAME TABLE '.sql_table('plugins_events').' TO '.sql_table('plugin_event')); - upgrade_query('Renaming table nucleus_plugins','RENAME TABLE '.sql_table('plugins').' TO '.sql_table('plugin')); - } // create nucleus_plugin_event - $query = 'CREATE TABLE '.sql_table('plugin_event').' (pid int(11) NOT NULL, event varchar(40)) TYPE=MyISAM;'; - upgrade_query("Creating nucleus_plugin_event table",$query); + if (upgrade_checkIfTableExists('plugin_events')) {//present in dev version + upgrade_query('Renaming table nucleus_plugins_events','RENAME TABLE '.sql_table('plugins_events').' TO '.sql_table('plugin_event')); + }elseif (!upgrade_checkIfTableExists('plugin_event')) { + $query = 'CREATE TABLE '.sql_table('plugin_event').' (pid int(11) NOT NULL, event varchar(40)) TYPE=MyISAM;'; + upgrade_query("Creating nucleus_plugin_event table",$query); + } // create nucleus_plugin - $query = 'CREATE TABLE '.sql_table('plugin')." (pid int(11) NOT NULL auto_increment, pfile varchar(40) NOT NULL, porder int(11) not null, PRIMARY KEY(pid)) TYPE=MyISAM;"; - upgrade_query("Creating nucleus_plugin table",$query); + if (upgrade_checkIfTableExists('plugins')) {//present in dev version + upgrade_query('Renaming table nucleus_plugins','RENAME TABLE '.sql_table('plugins').' TO '.sql_table('plugin')); + }elseif (!upgrade_checkIfTableExists('plugin')) { + $query = 'CREATE TABLE '.sql_table('plugin')." (pid int(11) NOT NULL auto_increment, pfile varchar(40) NOT NULL, porder int(11) not null, PRIMARY KEY(pid)) TYPE=MyISAM;"; + upgrade_query("Creating nucleus_plugin table",$query); + } // add MaxUploadSize to config - $query = 'INSERT INTO '.sql_table('config')." VALUES ('MaxUploadSize','1048576')"; - upgrade_query('MaxUploadSize setting',$query); + if (!upgrade_checkIfCVExists('MaxUploadSize')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('MaxUploadSize','1048576')"; + upgrade_query('MaxUploadSize setting',$query); + } // try to add cblog column when it does not exists yet - $query = 'SELECT * FROM '.sql_table('comment').' WHERE cblog=0 LIMIT 1'; - $res = mysql_query($query); - if (!$res || (mysql_num_rows($res) > 0)) { - + //The logic on the old code seems off, but my replacement may not be correct either--AWB + //$query = 'SELECT * FROM '.sql_table('comment').' WHERE cblog=0 LIMIT 1'; + //$res = mysql_query($query); + //if (!$res || (mysql_num_rows($res) > 0)) { + + if(!upgrade_checkIfColumnExists('comment', 'cblog')){ $query = 'ALTER TABLE '.sql_table('comment')." ADD cblog int(11) NOT NULL default '0'"; upgrade_query('Adding cblog column in table nucleus_comment',$query); @@ -43,9 +48,11 @@ function upgrade_do15() { // add 'pluginURL' to config global $CONF; - $pluginURL = $CONF['AdminURL'] . "plugins/"; - $query = 'INSERT INTO '.sql_table('config')." VALUES ('PluginURL', '$pluginURL');"; - upgrade_query('PluginURL setting', $query); + if (!upgrade_checkIfCVExists('PluginURL')) { + $pluginURL = $CONF['AdminURL'] . "plugins/"; + $query = 'INSERT INTO '.sql_table('config')." VALUES ('PluginURL', '$pluginURL');"; + upgrade_query('PluginURL setting', $query); + } // add 'EDITLINK' to all templates $query = 'SELECT tdnumber FROM '.sql_table('template_desc'); @@ -77,16 +84,25 @@ function upgrade_do15() { } // new setting: NonmemberMail - upgrade_query('NonmemberMail setting', 'INSERT INTO '.sql_table('config')." VALUES ('NonmemberMail', '0');"); + if (!upgrade_checkIfCVExists('NonmemberMail')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('NonmemberMail', '0');"; + upgrade_query("Adding setting NonmemberMail",$query); + } // new setting: ProtectMemNames - upgrade_query('ProtectMemNames setting', 'INSERT INTO '.sql_table('config')." VALUES ('ProtectMemNames', '1');"); + if (!upgrade_checkIfCVExists('ProtectMemNames')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('ProtectMemNames', '1');"; + upgrade_query("Adding setting ProtectMemNames",$query); + } // create new table: nucleus_plugin_option - $query = 'CREATE TABLE '.sql_table('plugin_option')." (opid int(11) NOT NULL, oname varchar(20) NOT NULL, ovalue varchar(128) not null, odesc varchar(255), otype varchar(8), PRIMARY KEY(opid, oname)) TYPE=MyISAM;"; - upgrade_query("Creating nucleus_plugin_option table",$query); - - + global $upgrade_failures; + if (0==$upgrade_failures && !upgrade_checkIfTableExists('plugin_option')) { + $query = 'CREATE TABLE '.sql_table('plugin_option')." (opid int(11) NOT NULL, oname varchar(20) NOT NULL, ovalue varchar(128) not null, odesc varchar(255), otype varchar(8), PRIMARY KEY(opid, oname)) TYPE=MyISAM;"; + upgrade_query("Creating nucleus_plugin_option table",$query); + }else{ + echo "
  • Creating nucleus_plugin_option table ... NOT EXECUTED\n
    Errors occurred during upgrade process.
    "; + } } ?> \ No newline at end of file diff --git a/utf8/nucleus/upgrades/upgrade2.0.php b/utf8/nucleus/upgrades/upgrade2.0.php index c5e4a9e..f239689 100755 --- a/utf8/nucleus/upgrades/upgrade2.0.php +++ b/utf8/nucleus/upgrades/upgrade2.0.php @@ -7,14 +7,18 @@ function upgrade_do20() { // queries come here // add ikarmaneg - $query = 'ALTER TABLE '.sql_table('item') - . " ADD ikarmaneg int(11) NOT NULL default '0'"; - upgrade_query("Adding ikarmaneg column to items",$query); + if (!upgrade_checkIfColumnExists('item','ikarmaneg')) { + $query = 'ALTER TABLE '.sql_table('item') + . " ADD ikarmaneg int(11) NOT NULL default '0'"; + upgrade_query("Adding ikarmaneg column to items",$query); + } // rename ikarma to ikarmapos - $query = 'ALTER TABLE '.sql_table('item') - . " CHANGE ikarma ikarmapos int(11) NOT NULL default '0'"; - upgrade_query("Renaming ikarma column for items to ikarmapos",$query); + if (!upgrade_checkIfColumnExists('item','ikarmapos')) { + $query = 'ALTER TABLE '.sql_table('item') + . " CHANGE ikarma ikarmapos int(11) NOT NULL default '0'"; + upgrade_query("Renaming ikarma column for items to ikarmapos",$query); + } // drop key in actionlog $query = 'ALTER TABLE '.sql_table('actionlog').' DROP PRIMARY KEY'; @@ -25,44 +29,58 @@ function upgrade_do20() { upgrade_query("changing max email/url length of guest comments to 100",$query); // create default skin option - $skinid = SKIN::getIdFromName('default'); - $query = 'INSERT INTO '.sql_table('config')." VALUES ('BaseSkin', '$skinid');"; - upgrade_query("Adding setting BaseSkin",$query); + if (!upgrade_checkIfCVExists('BaseSkin')) { + $skinid = SKIN::getIdFromName('default'); + $query = 'INSERT INTO '.sql_table('config')." VALUES ('BaseSkin', '$skinid');"; + upgrade_query("Adding setting BaseSkin",$query); + } - // add SkinsURL setting global $CONF; - $skinsurl = str_replace('/media/','/skins/',$CONF['MediaURL']); - $query = 'INSERT INTO '.sql_table('config')." VALUES ('SkinsURL', '".addslashes($skinsurl)."');"; - upgrade_query("Adding setting SkinsURL",$query); + // add SkinsURL setting + if (!upgrade_checkIfCVExists('SkinsURL')) { + $skinsurl = str_replace('/media/','/skins/',$CONF['MediaURL']); + $query = 'INSERT INTO '.sql_table('config')." VALUES ('SkinsURL', '".addslashes($skinsurl)."');"; + upgrade_query("Adding setting SkinsURL",$query); + } // add ActionURL setting - $actionurl = str_replace('/media/','/action.php',$CONF['MediaURL']); - $query = 'INSERT INTO '.sql_table('config')." VALUES ('ActionURL', '".addslashes($actionurl)."');"; - upgrade_query("Adding setting ActionURL",$query); + if (!upgrade_checkIfCVExists('ActionURL')) { + $actionurl = str_replace('/media/','/action.php',$CONF['MediaURL']); + $query = 'INSERT INTO '.sql_table('config')." VALUES ('ActionURL', '".addslashes($actionurl)."');"; + upgrade_query("Adding setting ActionURL",$query); + } // time offset can also be decimal (for half time zones like GMT+3:30) - upgrade_query('Changing time offset column type to decimal','ALTER TABLE '.sql_table('blog')." CHANGE btimeoffset btimeoffset DECIMAL( 3, 1 ) DEFAULT '0' NOT NULL"); - - // add sdincmode and sdincpref to skins - $query = 'ALTER TABLE '.sql_table('skin_desc') - . " ADD sdincmode varchar(10) NOT NULL default 'normal'"; - upgrade_query('Adding IncludeMode property to skins',$query); - $query = 'ALTER TABLE '.sql_table('skin_desc') - . " ADD sdincpref varchar(50) NOT NULL default ''"; - upgrade_query('Adding IncludePrefix property to skins',$query); + $query = 'ALTER TABLE '.sql_table('blog')." CHANGE btimeoffset btimeoffset DECIMAL( 3, 1 ) DEFAULT '0' NOT NULL"; + upgrade_query('Changing time offset column type to decimal',$query); // add ballowpast option to nucleus_blog - $query = 'ALTER TABLE '.sql_table('blog')." ADD ballowpast tinyint(2) NOT NULL default '0'"; - upgrade_query("Adding 'Allow posting to the past' option to blogs",$query); + if (!upgrade_checkIfColumnExists('blog','ballowpast')) { + $query = 'ALTER TABLE '.sql_table('blog')." ADD ballowpast tinyint(2) NOT NULL default '0'"; + upgrade_query("Adding 'Allow posting to the past' option to blogs",$query); + } // URLMode - $query = 'INSERT INTO '.sql_table('config')." VALUES ('URLMode', 'normal');"; - upgrade_query("Adding setting URLMode",$query); + if (!upgrade_checkIfCVExists('URLMode')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('URLMode', 'normal');"; + upgrade_query("Adding setting URLMode",$query); + } // add id to nucleus_plugin_option (allows for ordening) - $query = 'ALTER TABLE '.sql_table('plugin_option').' ADD oid int(11) NOT NULL auto_increment UNIQUE '; - upgrade_query("Adding id attribute to plugin options table",$query); - -} + if (!upgrade_checkIfColumnExists('plugin_option','oid')) { + $query = 'ALTER TABLE '.sql_table('plugin_option').' ADD oid int(11) NOT NULL auto_increment UNIQUE '; + upgrade_query("Adding id attribute to plugin options table",$query); + } + // add sdincmode and sdincpref to skins + global $upgrade_failures; + if (0 == $upgrade_failures && !upgrade_checkIfColumnExists('skin_desc','sdincpref')) { + $query = 'ALTER TABLE '.sql_table('skin_desc') + . " ADD sdincmode varchar(10) NOT NULL default 'normal'," + . " ADD sdincpref varchar(50) NOT NULL default ''"; + upgrade_query('Adding IncludeMode and IncludePrefix properties to skins',$query); + }else{ + echo "
  • Adding IncludeMode and IncludePrefix properties to skins ... NOT EXECUTED\n
    Errors occurred during upgrade process.
    "; + } +} ?> \ No newline at end of file diff --git a/utf8/nucleus/upgrades/upgrade2.5.php b/utf8/nucleus/upgrades/upgrade2.5.php index 9e4860a..4467f6c 100755 --- a/utf8/nucleus/upgrades/upgrade2.5.php +++ b/utf8/nucleus/upgrades/upgrade2.5.php @@ -1,5 +1,7 @@ opid)."'," - ."'".addslashes($o->oname) ."'," - ."'global'," - ."'".addslashes($o->odesc) ."'," - ."'".addslashes($o->otype) ."')"; - upgrade_query('Moving option description for '.htmlspecialchars($o->oname).' to ' . sql_table('plugin_option_desc'), $query); - - // store new id - $aValues[] = array ( - 'id' => mysql_insert_id(), - 'value' => $o->ovalue - ); - + if (0 == $upgrade_failures){ + $query = 'DELETE FROM ' . sql_table('plugin_option_desc'); + upgrade_query('Flushing plugin option descriptions', $query); + $query = 'SELECT * FROM ' . sql_table('plugin_option') .' ORDER BY oid ASC'; + $res = sql_query($query); + $aValues = array(); + while ($o = mysql_fetch_object($res)) { + $query = 'INSERT INTO ' . sql_table('plugin_option_desc') + .' (opid, oname, ocontext, odesc, otype)' + ." VALUES (" + ."'".addslashes($o->opid)."'," + ."'".addslashes($o->oname) ."'," + ."'global'," + ."'".addslashes($o->odesc) ."'," + ."'".addslashes($o->otype) ."')"; + upgrade_query('Moving option description for '.htmlspecialchars($o->oname).' to ' . sql_table('plugin_option_desc'), $query); + + // store new id + $aValues[] = array ( + 'id' => mysql_insert_id(), + 'value' => $o->ovalue + ); + } } // 3. alter plugin_options table - $query = 'ALTER TABLE ' . sql_table('plugin_option') - .' DROP PRIMARY KEY,' - .' DROP KEY oid,' - .' DROP COLUMN opid,' - .' DROP COLUMN oname,' - .' DROP COLUMN odesc,' - .' DROP COLUMN otype,' - .' ADD ocontextid INT(11) NOT NULL,' - .' ADD PRIMARY KEY (oid, ocontextid)'; - upgrade_query('Altering ' . sql_table('plugin_option') . ' table', $query); - - // 4. delete from plugin_options - $query = 'DELETE FROM ' . sql_table('plugin_option'); - upgrade_query('Cleaning ' . sql_table('plugin_option'), $query); - - // 5. refill plugin_options - foreach ($aValues as $aInfo) { - $query = 'INSERT INTO ' . sql_table('plugin_option') - .' (oid, ocontextid, ovalue)' - ." VALUES (".$aInfo['id'].",'0','".addslashes($aInfo['value'])."')"; - upgrade_query('Re-filling ' . sql_table('plugin_option') . ' ('.$aInfo['id'].')', $query); - } + if (0 == $upgrade_failures && !upgrade_checkIfColumnExists('plugin_option','ocontextid')) { + $query = 'ALTER TABLE ' . sql_table('plugin_option') + .' DROP PRIMARY KEY,' + .' DROP KEY oid,' + .' DROP COLUMN opid,' + .' DROP COLUMN oname,' + .' DROP COLUMN odesc,' + .' DROP COLUMN otype,' + .' ADD ocontextid INT(11) NOT NULL,' + .' ADD PRIMARY KEY (oid, ocontextid)'; + upgrade_query('Altering ' . sql_table('plugin_option') . ' table', $query); + + if(0 == $upgrade_failures){ + // 4. delete from plugin_options + $query = 'DELETE FROM ' . sql_table('plugin_option'); + upgrade_query('Cleaning ' . sql_table('plugin_option'), $query); + + // 5. refill plugin_options + foreach ($aValues as $aInfo) { + $query = 'INSERT INTO ' . sql_table('plugin_option') + .' (oid, ocontextid, ovalue)' + ." VALUES (".$aInfo['id'].",'0','".addslashes($aInfo['value'])."')"; + upgrade_query('Re-filling ' . sql_table('plugin_option') . ' ('.$aInfo['id'].')', $query); + } + } + } } // -------------------- 2.0 -> 2.5 -------------------- @@ -95,13 +106,20 @@ function upgrade_do25() { $query = 'ALTER TABLE ' . sql_table('plugin_option') . ' MODIFY ovalue TEXT NOT NULL default \'\''; upgrade_query('Modifying plugin options column type', $query); - // insert database version (allows us to do better version checking in v3.0 upgrades) - $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'DatabaseVersion\',\'250\')'; - upgrade_query('Adding DatabaseVersion to config table', $query); - // insert External Authentication global option - $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'ExtAuth\',\'0\')'; - upgrade_query('Adding External Authentication option to config table', $query); + if (!upgrade_checkIfCVExists('ExtAuth')) { + $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'ExtAuth\',\'0\')'; + upgrade_query('Adding External Authentication option to config table', $query); + } + + // insert database version (allows us to do better version checking in v3.0 upgrades) + // But only if no errors in upgrade + if (0 == $upgrade_failures && !upgrade_checkIfCVExists('DatabaseVersion')) { + $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'DatabaseVersion\',\'250\')'; + upgrade_query('Adding DatabaseVersion to config table', $query); + }else{ + echo "
  • Adding DatabaseVersion to config table ... NOT EXECUTED\n
    Errors occurred during upgrade process.
    "; + } } -?> +?> \ No newline at end of file diff --git a/utf8/nucleus/upgrades/upgrade3.0.php b/utf8/nucleus/upgrades/upgrade3.0.php index d4126a2..b8846a3 100755 --- a/utf8/nucleus/upgrades/upgrade3.0.php +++ b/utf8/nucleus/upgrades/upgrade3.0.php @@ -6,10 +6,8 @@ function upgrade_do30() { // 2.5(beta/RC/...) -> 3.0 // update database version - $query = 'UPDATE ' . sql_table('config') . ' set value=\'300\' where name=\'DatabaseVersion\''; - upgrade_query('Updating DatabaseVersion in config table to 300', $query); - + update_version('300'); // nothing! } -?> +?> \ No newline at end of file diff --git a/utf8/nucleus/upgrades/upgrade3.1.php b/utf8/nucleus/upgrades/upgrade3.1.php index 828b575..f42642f 100755 --- a/utf8/nucleus/upgrades/upgrade3.1.php +++ b/utf8/nucleus/upgrades/upgrade3.1.php @@ -6,10 +6,8 @@ function upgrade_do31() { // 3.0 -> 3.1 // update database version - $query = 'UPDATE ' . sql_table('config') . ' set value=\'310\' where name=\'DatabaseVersion\''; - upgrade_query('Updating DatabaseVersion in config table to 310', $query); - + update_version('310'); // nothing! } -?> +?> \ No newline at end of file diff --git a/utf8/nucleus/upgrades/upgrade3.2.php b/utf8/nucleus/upgrades/upgrade3.2.php index 27ebf94..aa029ee 100755 --- a/utf8/nucleus/upgrades/upgrade3.2.php +++ b/utf8/nucleus/upgrades/upgrade3.2.php @@ -4,53 +4,41 @@ function upgrade_do32() { if (upgrade_checkinstall(32)) return 'already installed'; - // The version number of 3.20 and 3.21 are wrong, - // so this upgrade function will be called. - // But database already exists, should update db version only. - $query = 'SELECT * FROM ' . sql_table('activation'); - $res = mysql_query($query); - $installed = ($res != 0) && (mysql_num_rows($res) >= 0); - if ($installed) - { - // 3.1 -> 3.1+ - // update database version - $query = 'UPDATE ' . sql_table('config') . ' set value=\'323\' where name=\'DatabaseVersion\''; - upgrade_query('Updating DatabaseVersion in config table to 323', $query); - - return; - } - - // create nucleus_activation table - $query = 'CREATE TABLE ' . sql_table('activation') . ' (' - . ' vkey varchar(40) NOT NULL default \'\',' - . ' vtime datetime NOT NULL default \'0000-00-00 00:00:00\',' - . ' vmember int(11) NOT NULL default \'0\',' - . ' vtype varchar(15) NOT NULL default \'\',' - . ' vextra varchar(128) NOT NULL default \'\',' - . ' PRIMARY KEY (vkey) ' - . ' )'; - upgrade_query('Creating account activation table', $query); - + if (!upgrade_checkIfTableExists('tickets')) { + $query = 'CREATE TABLE ' . sql_table('activation') . ' (' + . ' vkey varchar(40) NOT NULL default \'\',' + . ' vtime datetime NOT NULL default \'0000-00-00 00:00:00\',' + . ' vmember int(11) NOT NULL default \'0\',' + . ' vtype varchar(15) NOT NULL default \'\',' + . ' vextra varchar(128) NOT NULL default \'\',' + . ' PRIMARY KEY (vkey) ' + . ' )'; + upgrade_query('Creating account activation table', $query); + } + // create CookiePrefix setting - $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookiePrefix','')"; - upgrade_query('Creating CookiePrefix config value',$query); - - // create nucleus_tickets table - $query = 'CREATE TABLE ' . sql_table('tickets') . ' (' - . ' ticket varchar(40) NOT NULL default \'\',' - . ' ctime datetime NOT NULL default \'0000-00-00 00:00:00\',' - . ' member int(11) NOT NULL default \'0\', ' - . ' PRIMARY KEY (ticket, member) ' - . ' )'; - upgrade_query('Creating ticket table', $query); + if (!upgrade_checkIfCVExists('CookiePrefix')) { + $query = 'INSERT INTO '.sql_table('config')." VALUES ('CookiePrefix','')"; + upgrade_query('Creating CookiePrefix config value',$query); + } - // 3.1 -> 3.1+ + // create nucleus_tickets table + if (!upgrade_checkIfTableExists('tickets')) { + $query = 'CREATE TABLE ' . sql_table('tickets') . ' (' + . ' ticket varchar(40) NOT NULL default \'\',' + . ' ctime datetime NOT NULL default \'0000-00-00 00:00:00\',' + . ' member int(11) NOT NULL default \'0\', ' + . ' PRIMARY KEY (ticket, member) ' + . ' )'; + upgrade_query('Creating ticket table', $query); + } + + // 3.1 -> 3.2 // update database version - $query = 'UPDATE ' . sql_table('config') . ' set value=\'323\' where name=\'DatabaseVersion\''; - upgrade_query('Updating DatabaseVersion in config table to 323', $query); + update_version('320'); // nothing! } -?> +?> \ No newline at end of file diff --git a/utf8/nucleus/upgrades/upgrade3.3.php b/utf8/nucleus/upgrades/upgrade3.3.php index 5385dc7..3be5dd5 100644 --- a/utf8/nucleus/upgrades/upgrade3.3.php +++ b/utf8/nucleus/upgrades/upgrade3.3.php @@ -4,55 +4,38 @@ function upgrade_do33() { if (upgrade_checkinstall(33)) return 'already installed'; - // alter nucleus_blog table - $query = 'ALTER TABLE ' . sql_table('blog') - . ' ADD breqemail TINYINT(2) DEFAULT \'0\' NOT NULL'; - upgrade_query('Altering ' . sql_table('blog') . ' table', $query); - - // insert breqemail default value - $query = 'UPDATE ' . sql_table('blog') - . ' SET breqemail=0'; - upgrade_query('Filling breqemail column of ' . sql_table('blog') . ' table', $query); - - // store cname from nucleus_category - $query = 'SELECT catid, cname FROM ' . sql_table('category') . ' ORDER By catid ASC'; - $res = sql_query($query); - $aValues = array(); - while ($o = mysql_fetch_object($res)) { - $aValues[] = array( - 'catid' => $o->catid, - 'cname' => $o->cname - ); + if (!upgrade_checkIfColumnExists('comment','cemail')) { + $query = " ALTER TABLE `" . sql_table('comment') . "` + ADD `cemail` VARCHAR( 100 ) AFTER `cmail` ;"; + + upgrade_query('Altering ' . sql_table('comment') . ' table', $query); } - // alter nucleus_category - $query = 'ALTER TABLE ' . sql_table('category') - . ' DROP COLUMN cname,' - . ' ADD cname varchar(200) default NULL AFTER cblog'; - upgrade_query('Altering ' . sql_table('category') . ' table', $query); - - // refill cname to nucleus_category - foreach ($aValues as $aInfo) { - $query = 'UPDATE ' . sql_table('category') - . ' SET cname=' - . " '" . addslashes($aInfo['cname']) . "'" - . " WHERE catid=" . $aInfo['catid']; - upgrade_query('Re-filling ' . sql_table('category') - . ' (' . $aInfo['catid'] . ')', $query); + if (!upgrade_checkIfColumnExists('blog','breqemail')) { + $query = " ALTER TABLE `" . sql_table('blog') . "` + ADD `breqemail` TINYINT( 2 ) DEFAULT '0' NOT NULL ;"; + + upgrade_query('Altering ' . sql_table('blog') . ' table', $query); + } + + if (!upgrade_checkIfColumnExists('item','posted')) { + $query = " ALTER TABLE `" . sql_table('item') . "` + ADD `iposted` TINYINT(2) DEFAULT 1 NOT NULL ;"; + + upgrade_query('Altering ' . sql_table('item') . ' table', $query); } - // alter nucleus_comment - $query = 'ALTER TABLE ' . sql_table('comment') - . ' ADD cemail varchar(100)' - . ' AFTER cmail'; - upgrade_query('Altering ' . sql_table('comment') . ' table', $query); - - // 3.2 -> 3.2+ - // update database version - $query = 'UPDATE ' . sql_table('config') . ' set value=\'330\' where name=\'DatabaseVersion\''; - upgrade_query('Updating DatabaseVersion in config table to 330', $query); - - // nothing! + if (!upgrade_checkIfColumnExists('blog','bfuturepost')) { + $query = " ALTER TABLE `" . sql_table('blog') . "` + ADD `bfuturepost` TINYINT(2) DEFAULT 0 NOT NULL ;"; + + upgrade_query('Altering ' . sql_table('blog') . ' table', $query); + } + + // 3.2 -> 3.3 + // update database version + update_version('330'); + } ?> -- 2.11.0