| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,343 @@ |
| 1 |
+<?php |
|
| 2 |
+// ---------------------------------------------------------------------- |
|
| 3 |
+// eFiction 3.0 |
|
| 4 |
+// Copyright (c) 2007 by Tammy Keefer |
|
| 5 |
+// Valid HTML 4.01 Transitional |
|
| 6 |
+// Based on eFiction 1.1 |
|
| 7 |
+// Copyright (C) 2003 by Rebecca Smallwood. |
|
| 8 |
+// http://efiction.sourceforge.net/ |
|
| 9 |
+// ---------------------------------------------------------------------- |
|
| 10 |
+// LICENSE |
|
| 11 |
+// |
|
| 12 |
+// This program is free software; you can redistribute it and/or |
|
| 13 |
+// modify it under the terms of the GNU General Public License (GPL) |
|
| 14 |
+// as published by the Free Software Foundation; either version 2 |
|
| 15 |
+// of the License, or (at your option) any later version. |
|
| 16 |
+// |
|
| 17 |
+// This program is distributed in the hope that it will be useful, |
|
| 18 |
+// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 |
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 |
+// GNU General Public License for more details. |
|
| 21 |
+// |
|
| 22 |
+// To read the license please visit http://www.gnu.org/copyleft/gpl.html |
|
| 23 |
+// ---------------------------------------------------------------------- |
|
| 24 |
+$current = "update"; |
|
| 25 |
+ |
|
| 26 |
+include("header.php");
|
|
| 27 |
+ |
|
| 28 |
+$blocks['news']['status'] = 0; |
|
| 29 |
+$blocks['info']['status'] = 0; |
|
| 30 |
+ |
|
| 31 |
+//make a new TemplatePower object |
|
| 32 |
+if(file_exists("$skindir/default.tpl")) $tpl = new TemplatePower( "$skindir/default.tpl" );
|
|
| 33 |
+else $tpl = new TemplatePower("default_tpls/default.tpl");
|
|
| 34 |
+include("includes/pagesetup.php");
|
|
| 35 |
+if(file_exists("languages/".$language."_admin.php")) include_once("languages/".$language."_admin.php");
|
|
| 36 |
+else include_once("languages/en_admin.php");
|
|
| 37 |
+// end basic page setup |
|
| 38 |
+ |
|
| 39 |
+if(!isADMIN) {
|
|
| 40 |
+$output .= "<script language=\"javascript\" type=\"text/javascript\"> |
|
| 41 |
+location = \"maintenance.php\"; |
|
| 42 |
+</script>"; |
|
| 43 |
+$tpl->assign( "output", $output ); |
|
| 44 |
+$tpl->printToScreen(); |
|
| 45 |
+dbclose( ); |
|
| 46 |
+exit( ); |
|
| 47 |
+} |
|
| 48 |
+$oldVersion = explode(".", $settings['version']);
|
|
| 49 |
+$confirm = isset($_GET['confirm']) ? $_GET['confirm'] : false; |
|
| 50 |
+if($oldVersion[0] == 3 && ($oldVersion[1] < 5 || $oldVersion[2] < 3)) {
|
|
| 51 |
+if($confirm == "yes") {
|
|
| 52 |
+ // For the slow-pokes who haven't updated to 3.1 |
|
| 53 |
+ if($oldVersion[1] == 0 ) {
|
|
| 54 |
+ list($field) = dbrow(dbquery("SELECT field_id FROM ".TABLEPREFIX."fanfiction_authorfields WHERE field_name = 'betareader'"));
|
|
| 55 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorinfo SET info = '"._YES."' WHERE field = '$field' AND info = '1'");
|
|
| 56 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorinfo SET info = '"._NO."' WHERE field = '$field' AND info != '"._YES."'");
|
|
| 57 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_authorinfo add primary key(uid,field);");
|
|
| 58 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_blocks drop index block_name;");
|
|
| 59 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_blocks add unique index block_name (block_name);");
|
|
| 60 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_categories drop index category;");
|
|
| 61 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_categories drop index parentcatid;");
|
|
| 62 |
+ dbquery("create index byparent on ".TABLEPREFIX."fanfiction_categories (parentcatid,displayorder);");
|
|
| 63 |
+ dbquery("create index forstoryblock on ".TABLEPREFIX."fanfiction_chapters (sid,validated);");
|
|
| 64 |
+ dbquery("create index byname on ".TABLEPREFIX."fanfiction_classes (class_type,class_name,class_id);");
|
|
| 65 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_classtypes drop index classtype_title;");
|
|
| 66 |
+ dbquery("create unique index classtype_name on ".TABLEPREFIX."fanfiction_classtypes(classtype_name);");
|
|
| 67 |
+ dbquery("create index code_type on ".TABLEPREFIX."fanfiction_codeblocks(code_type);");
|
|
| 68 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_comments drop index nid;");
|
|
| 69 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_comments add index commentlist (nid,time);");
|
|
| 70 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_favorites drop index uid;");
|
|
| 71 |
+ dbquery("create unique index byitem on ".TABLEPREFIX."fanfiction_favorites (item,type,uid);");
|
|
| 72 |
+ dbquery("create unique index byuid on ".TABLEPREFIX."fanfiction_favorites (uid,type,item);");
|
|
| 73 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index seriesid;");
|
|
| 74 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index inorder;");
|
|
| 75 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_inseries add index (seriesid,inorder);");
|
|
| 76 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index sid;");
|
|
| 77 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_inseries add primary key (sid,seriesid);");
|
|
| 78 |
+ dbquery("create index message_name on ".TABLEPREFIX."fanfiction_messages (message_name);");
|
|
| 79 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_pagelinks drop index link_text;");
|
|
| 80 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_panels drop index panel_hidden;");
|
|
| 81 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_panels drop index panel_type;");
|
|
| 82 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_panels add index panel_type (panel_type,panel_name);");
|
|
| 83 |
+ dbquery("create index avgrating on ".TABLEPREFIX."fanfiction_reviews(type,item,rating);");
|
|
| 84 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_reviews drop index sid;");
|
|
| 85 |
+ dbquery("create index bychapter on ".TABLEPREFIX."fanfiction_reviews (chapid,rating);");
|
|
| 86 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_reviews add index byuid (uid,item,type);");
|
|
| 87 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_series drop index owner;");
|
|
| 88 |
+ dbquery("create index owner on ".TABLEPREFIX."fanfiction_series (uid,title);");
|
|
| 89 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_stories drop index validated;");
|
|
| 90 |
+ dbquery("create index validateduid on ".TABLEPREFIX."fanfiction_stories (validated,uid);");
|
|
| 91 |
+ dbquery("create index recent on ".TABLEPREFIX."fanfiction_stories (updated,validated);");
|
|
| 92 |
+ $alltables = dbquery("SHOW TABLES");
|
|
| 93 |
+ } |
|
| 94 |
+ // Still a little behind. |
|
| 95 |
+ if($oldVersion[1] < 2) {
|
|
| 96 |
+ dbquery("
|
|
| 97 |
+CREATE TABLE `".TABLEPREFIX."fanfiction_stats` ( |
|
| 98 |
+ `sitekey` varchar(50) NOT NULL default '0', |
|
| 99 |
+ `stories` int(11) NOT NULL default '0', |
|
| 100 |
+ `chapters` int(11) NOT NULL default '0', |
|
| 101 |
+ `series` int(11) NOT NULL default '0', |
|
| 102 |
+ `reviews` int(11) NOT NULL default '0', |
|
| 103 |
+ `wordcount` int(11) NOT NULL default '0', |
|
| 104 |
+ `authors` int(11) NOT NULL default '0', |
|
| 105 |
+ `members` int(11) NOT NULL default '0', |
|
| 106 |
+ `reviewers` int(11) NOT NULL default '0', |
|
| 107 |
+ `newestmember` int(11) NOT NULL default '0' |
|
| 108 |
+) ENGINE=MyISAM"); |
|
| 109 |
+ dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_stats(`sitekey`) VALUES('SITEKEY')");
|
|
| 110 |
+ dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_inseries` DROP `updated`");
|
|
| 111 |
+ dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_news` ADD `comments` INT NOT NULL DEFAULT '0'");
|
|
| 112 |
+ dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_series` ADD `numstories` INT NOT NULL DEFAULT '0'");
|
|
| 113 |
+ dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_pagelinks` ADD `link_key` CHAR( 1 ) NULL AFTER `link_text`");
|
|
| 114 |
+ if(!isset($allowseries)) dbquery("ALTER TABLE `".$settingsprefix."fanfiction_settings` ADD `allowseries` TINYINT NOT NULL DEFAULT '2' AFTER `roundrobins`");
|
|
| 115 |
+ dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_log` CHANGE `log_ip` `log_ip` INT( 11 ) UNSIGNED NULL DEFAULT NULL");
|
|
| 116 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_inseries SET confirmed = 1");
|
|
| 117 |
+ $serieslist = dbquery("SELECT seriesid FROM ".TABLEPREFIX."fanfiction_series");
|
|
| 118 |
+ $totalseries = dbnumrows($serieslist); |
|
| 119 |
+ while($s = dbassoc($serieslist)) {
|
|
| 120 |
+ $numstories = count(storiesInSeries($s['seriesid'])); |
|
| 121 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET numstories = '$numstories' WHERE seriesid = ".$s['seriesid']." LIMIT 1");
|
|
| 122 |
+ } |
|
| 123 |
+ |
|
| 124 |
+ $newslist = dbquery("SELECT count(cid) as count, nid FROM ".TABLEPREFIX."fanfiction_comments GROUP BY nid");
|
|
| 125 |
+ while($n = dbassoc($newslist)) {
|
|
| 126 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_news SET comments = '".$n['count']."' WHERE nid = ".$n['nid']);
|
|
| 127 |
+ } |
|
| 128 |
+ |
|
| 129 |
+ $storiesquery =dbquery("SELECT COUNT(sid) as totals, COUNT(DISTINCT uid) as totala, SUM(wordcount) as totalwords FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 ");
|
|
| 130 |
+ list($stories, $authors, $words) = dbrow($storiesquery); |
|
| 131 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET stories = '$stories', authors = '$authors', wordcount = '$words' WHERE sitekey = 'SITEKEY'");
|
|
| 132 |
+ |
|
| 133 |
+ $chapterquery = dbquery("SELECT COUNT(chapid) as chapters FROM ".TABLEPREFIX."fanfiction_chapters where validated > 0");
|
|
| 134 |
+ list($chapters) = dbrow($chapterquery); |
|
| 135 |
+ |
|
| 136 |
+ $authorquery = dbquery("SELECT COUNT("._UIDFIELD.") as totalm FROM "._AUTHORTABLE);
|
|
| 137 |
+ list($members) = dbrow($authorquery); |
|
| 138 |
+ |
|
| 139 |
+ list($newest) = dbrow(dbquery("SELECT "._UIDFIELD." as uid FROM "._AUTHORTABLE." ORDER BY "._UIDFIELD." DESC LIMIT 1"));
|
|
| 140 |
+ $reviewquery = dbquery("SELECT COUNT(reviewid) as totalr FROM ".TABLEPREFIX."fanfiction_reviews WHERE review != 'No Review'");
|
|
| 141 |
+ list($reviews) = dbrow($reviewquery); |
|
| 142 |
+ $reviewquery = dbquery("SELECT COUNT(DISTINCT uid) FROM ".TABLEPREFIX."fanfiction_reviews WHERE review != 'No Review' AND uid > 0");
|
|
| 143 |
+ list($reviewers) = dbrow($reviewquery); |
|
| 144 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET series = '$totalseries', chapters = '$chapters', members = '$members', newestmember = '$newest', reviews = '$reviews', reviewers = '$reviewers' WHERE sitekey = 'SITEKEY'");
|
|
| 145 |
+ $news = dbquery("SELECT count(nid) as count, nid FROM ".TABLEPREFIX."fanfiction_comments GROUP BY nid");
|
|
| 146 |
+ while($n = dbassoc($news)) {
|
|
| 147 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_news SET comments = '".$n['count']."' WHERE nid = '".$n['nid']."' LIMIT 1");
|
|
| 148 |
+ } |
|
| 149 |
+ } // End version 3.2 updates. |
|
| 150 |
+ if($oldVersion[1] < 3) {
|
|
| 151 |
+ dbquery("
|
|
| 152 |
+CREATE TABLE `".TABLEPREFIX."fanfiction_modules` ( |
|
| 153 |
+ `id` int(11) NOT NULL auto_increment, |
|
| 154 |
+ `name` varchar(100) NOT NULL default 'Test Module', |
|
| 155 |
+ `version` varchar(10) NOT NULL default '1.0', |
|
| 156 |
+ PRIMARY KEY (`id`), |
|
| 157 |
+ KEY `name_version` (`name`,`version`) |
|
| 158 |
+)"); |
|
| 159 |
+ list($panelCount) = dbrow(dbquery("SELECT count(panel_name) AS count FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_type = 'A' AND panel_level = '1' AND panel_hidden = '0'"));
|
|
| 160 |
+ $panelCount++; |
|
| 161 |
+ dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_panels` (`panel_name`, `panel_title`, `panel_url`, `panel_level`, `panel_order`, `panel_hidden`, `panel_type`) VALUES ('modules', 'Modules', '', 1, ".$panelCount.", 0, 'A')");
|
|
| 162 |
+ // Insert the modules into the table. |
|
| 163 |
+ $dir = opendir(_BASEDIR."modules"); |
|
| 164 |
+ while($folder = readdir($dir)) {
|
|
| 165 |
+ if($folder == "." || $folder == ".." || !is_dir("modules/$folder")) continue;
|
|
| 166 |
+ if(file_exists("modules/$folder/version.php")) {
|
|
| 167 |
+ $moduleVersion = ""; $moduleName = ""; |
|
| 168 |
+ include("modules/$folder/version.php");
|
|
| 169 |
+ if(empty($moduleName)) $moduleName = $folder; |
|
| 170 |
+ // The next few lines try to determine if the module is installed. |
|
| 171 |
+ if($folder == "challenges" && !isset($anonchallenges)) continue; |
|
| 172 |
+ if($folder == "recommendations" && !isset($anonrecs)) continue; |
|
| 173 |
+ |
|
| 174 |
+ dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_modules(`name`, `version`) VALUES('$moduleName', '1.0')");
|
|
| 175 |
+ } |
|
| 176 |
+ } |
|
| 177 |
+ if($ratings == "1") dbquery("UPDATE ".TABLEPREFIX."fanfiction_reviews SET rating = '-1' WHERE rating = '0'");
|
|
| 178 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '0', reviews = '0'"); // Set them all to 0 before we re-insert.
|
|
| 179 |
+ $stories = dbquery("SELECT AVG(rating) as average, item FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY item");
|
|
| 180 |
+ while($s = dbassoc($stories)) {
|
|
| 181 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($s['average'])."' WHERE sid = '".$s['item']."'");
|
|
| 182 |
+ } |
|
| 183 |
+ $stories = dbquery("SELECT COUNT(reviewid) as count, item FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND review != 'No Review' GROUP BY item");
|
|
| 184 |
+ while($s = dbassoc($stories)) {
|
|
| 185 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET reviews = '".$s['count']."' WHERE sid = '".$s['item']."'");
|
|
| 186 |
+ } |
|
| 187 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '0', reviews = '0'");
|
|
| 188 |
+ $chapters = dbquery("SELECT AVG(rating) as average, chapid FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY chapid");
|
|
| 189 |
+ while($c = dbassoc($chapters)) {
|
|
| 190 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '".round($c['average'])."' WHERE chapid = '".$c['chapid']."'");
|
|
| 191 |
+ } |
|
| 192 |
+ $chapters = dbquery("SELECT COUNT(reviewid) as count, chapid FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND review != 'No Review' GROUP BY chapid");
|
|
| 193 |
+ while($c = dbassoc($chapters)) {
|
|
| 194 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET reviews = '".$c['count']."' WHERE chapid = '".$c['chapid']."'");
|
|
| 195 |
+ } |
|
| 196 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET rating = '0', reviews = '0'");
|
|
| 197 |
+ $series = dbquery("SELECT seriesid FROM ".TABLEPREFIX."fanfiction_series");
|
|
| 198 |
+ while($s = dbassoc($series)) {
|
|
| 199 |
+ $thisseries = $s['seriesid']; |
|
| 200 |
+ include("includes/seriesreviews.php");
|
|
| 201 |
+ } |
|
| 202 |
+ } // End 3.3 updates |
|
| 203 |
+ // Version 3.3.1 updates |
|
| 204 |
+ if($oldVersion[1] == 3 && empty($oldVersion[2])) {
|
|
| 205 |
+ if(isset($anonchallenges)) dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_codeblocks` (`code_text`, `code_type`, `code_module`) VALUES('include(_BASEDIR.\"modules/challenges/stats.php\");', 'sitestats', 'challenges');");
|
|
| 206 |
+ } |
|
| 207 |
+ // Versin 3.4 updates |
|
| 208 |
+ if($oldVersion[1] < 4) {
|
|
| 209 |
+ dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_coauthors` (
|
|
| 210 |
+ `sid` int(11) NOT NULL default '0', |
|
| 211 |
+ `uid` int(11) NOT NULL default '0', |
|
| 212 |
+ PRIMARY KEY (`sid`,`uid`) |
|
| 213 |
+) ENGINE=MyISAM;"); |
|
| 214 |
+ dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authorprefs` ADD `stories` INT NOT NULL DEFAULT '0'");
|
|
| 215 |
+ $alist = array( ); |
|
| 216 |
+ $authors = dbquery("SELECT uid, count(uid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 GROUP BY uid");
|
|
| 217 |
+ while($a = dbassoc($authors)) {
|
|
| 218 |
+ $alist[$a['uid']] = $a['count']; |
|
| 219 |
+ } |
|
| 220 |
+ $coauthors = dbquery("SELECT coauthors,sid FROM ".TABLEPREFIX."fanfiction_stories WHERE coauthors != '0'");
|
|
| 221 |
+ while($ca = dbassoc($coauthors)) {
|
|
| 222 |
+ $co = explode(",", $ca['coauthors']);
|
|
| 223 |
+ foreach($co AS $a) {
|
|
| 224 |
+ if(!isNumber($a)) continue; |
|
| 225 |
+ if(in_array($a, $alist)) $alist[$a]++; |
|
| 226 |
+ else $alist[$a] = 1; |
|
| 227 |
+ dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_coauthors(`uid`, `sid`) VALUES('$a', '".$ca['sid']."')");
|
|
| 228 |
+ } |
|
| 229 |
+ } |
|
| 230 |
+ foreach($alist AS $a => $s) {
|
|
| 231 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
|
|
| 232 |
+ } |
|
| 233 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET coauthors = '1' WHERE coauthors != '0'");
|
|
| 234 |
+ } |
|
| 235 |
+ if($oldVersion[1] == 4 && !isset($oldVersion[2])) {
|
|
| 236 |
+ $statsupdate = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET sitekey = '".SITEKEY."' WHERE sitekey = 'SITEKEY' LIMIT 1");
|
|
| 237 |
+ $coauthors = dbquery("SHOW TABLES LIKE '".TABLEPREFIX."fanfiction_coauthors'");
|
|
| 238 |
+ if(!dbnumrows($coauthors)) {
|
|
| 239 |
+ dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_coauthors` (
|
|
| 240 |
+ `sid` int(11) NOT NULL default '0', |
|
| 241 |
+ `uid` int(11) NOT NULL default '0', |
|
| 242 |
+ PRIMARY KEY (`sid`,`uid`) |
|
| 243 |
+ ) ENGINE=MyISAM;"); |
|
| 244 |
+ dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authorprefs` ADD `stories` INT NOT NULL DEFAULT '0'");
|
|
| 245 |
+ } |
|
| 246 |
+ $authors = dbquery("SELECT uid, count(uid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 GROUP BY uid");
|
|
| 247 |
+ while($a = dbassoc($authors)) {
|
|
| 248 |
+ $alist[$a['uid']] = $a['count']; |
|
| 249 |
+ } |
|
| 250 |
+ $coauthors = dbquery("SELECT uid, count(sid) AS count FROM ".TABLEPREFIX."fanfiction_coauthors GROUP BY uid");
|
|
| 251 |
+ while($ca = dbassoc($coauthors)) {
|
|
| 252 |
+ if(in_array($ca['uid'], $alist)) $alist[$ca['uid']] = $alist[$ca['uid']] + $ca['count']; |
|
| 253 |
+ else $alist[$ca['uid']] = $ca['count']; |
|
| 254 |
+ } |
|
| 255 |
+ foreach($alist AS $a => $s) {
|
|
| 256 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
|
|
| 257 |
+ } |
|
| 258 |
+ } |
|
| 259 |
+ if($oldVersion[1] == 4 && $oldVersion[2] < 2) {
|
|
| 260 |
+ $coauthors = dbquery("SHOW TABLES LIKE '".TABLEPREFIX."fanfiction_coauthors'");
|
|
| 261 |
+ if(!dbnumrows($coauthors)) {
|
|
| 262 |
+ dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_coauthors` (
|
|
| 263 |
+ `sid` int(11) NOT NULL default '0', |
|
| 264 |
+ `uid` int(11) NOT NULL default '0', |
|
| 265 |
+ PRIMARY KEY (`sid`,`uid`) |
|
| 266 |
+ ) ENGINE=MyISAM;"); |
|
| 267 |
+ dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authorprefs` ADD `stories` INT NOT NULL DEFAULT '0'");
|
|
| 268 |
+ } |
|
| 269 |
+ $storiesAdded = dbquery("SHOW COLUMNS FROM ".TABLEPREFIX."fanfiction_authorprefs LIKE 'stories'");
|
|
| 270 |
+ if(!$storiesAdded) {
|
|
| 271 |
+ dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authorprefs` ADD `stories` INT NOT NULL DEFAULT '0'");
|
|
| 272 |
+ $authors = dbquery("SELECT uid, count(uid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 GROUP BY uid");
|
|
| 273 |
+ while($a = dbassoc($authors)) {
|
|
| 274 |
+ $alist[$a['uid']] = $a['count']; |
|
| 275 |
+ } |
|
| 276 |
+ $coauthors = dbquery("SELECT uid, count(sid) AS count FROM ".TABLEPREFIX."fanfiction_coauthors GROUP BY uid");
|
|
| 277 |
+ while($ca = dbassoc($coauthors)) {
|
|
| 278 |
+ if(in_array($ca['uid'], $alist)) $alist[$ca['uid']] = $alist[$ca['uid']] + $ca['count']; |
|
| 279 |
+ else $alist[$ca['uid']] = $ca['count']; |
|
| 280 |
+ } |
|
| 281 |
+ foreach($alist AS $a => $s) {
|
|
| 282 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
|
|
| 283 |
+ } |
|
| 284 |
+ } |
|
| 285 |
+ } |
|
| 286 |
+ if($oldVersion[1] == 5) { // Try to fix some errors for people
|
|
| 287 |
+ // Recalculate the story count for authors. |
|
| 288 |
+ $authors = dbquery("SELECT uid, count(uid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 GROUP BY uid");
|
|
| 289 |
+ $alist = array( ); |
|
| 290 |
+ while($a = dbassoc($authors)) {
|
|
| 291 |
+ $alist[$a['uid']] = $a['count']; |
|
| 292 |
+ } |
|
| 293 |
+ $coauthors = dbquery("SELECT uid, count(sid) AS count FROM ".TABLEPREFIX."fanfiction_coauthors GROUP BY uid");
|
|
| 294 |
+ while($ca = dbassoc($coauthors)) {
|
|
| 295 |
+ if(isset($alist[$ca['uid']])) $alist[$ca['uid']] = $alist[$ca['uid']] + $ca['count']; |
|
| 296 |
+ else $alist[$ca['uid']] = $ca['count']; |
|
| 297 |
+ } |
|
| 298 |
+ foreach($alist AS $a => $s) {
|
|
| 299 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
|
|
| 300 |
+ } |
|
| 301 |
+ // Recalculate the number of authors |
|
| 302 |
+ list($authors) = dbrow(dbquery("SELECT count(uid) FROM ".TABLEPREFIX."fanfiction_authorprefs WHERE stories > 0"));
|
|
| 303 |
+ dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET authors = '$authors' WHERE sitekey = '".SITEKEY."'");
|
|
| 304 |
+ } |
|
| 305 |
+ if($oldVersion[1] == 5 && $oldVersion[2] < 3) {
|
|
| 306 |
+ // fix the indexes for the inseries table. |
|
| 307 |
+ $exists = dbnumrows(dbquery("SHOW INDEX FROM ".TABLEPREFIX."fanfiction_inseries WHERE Key_name = 'seriesid'"));
|
|
| 308 |
+ if($exists) dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index seriesid;");
|
|
| 309 |
+ $exists = dbnumrows(dbquery("SHOW INDEX FROM ".TABLEPREFIX."fanfiction_inseries WHERE Key_name = 'inorder'"));
|
|
| 310 |
+ if($exists) dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index inorder;");
|
|
| 311 |
+ dbquery("alter table ".TABLEPREFIX."fanfiction_inseries add index (seriesid,inorder);");
|
|
| 312 |
+ $exists = dbnumrows(dbquery("SHOW INDEX FROM ".TABLEPREFIX."fanfiction_inseries WHERE Key_name = 'sid'"));
|
|
| 313 |
+ if($exists) dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index sid;");
|
|
| 314 |
+ $exists = dbnumrows(dbquery("SHOW INDEX FROM ".TABLEPREFIX."fanfiction_inseries WHERE Key_name = 'PRIMARY'"));
|
|
| 315 |
+ if($exists) dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop primary key");
|
|
| 316 |
+ // dbquery("alter ignore table ".TABLEPREFIX."fanfiction_inseries add primary key (sid,seriesid,subseriesid);");
|
|
| 317 |
+ dbquery("alter table " . TABLEPREFIX . "fanfiction_inseries add primary key (sid,seriesid);");
|
|
| 318 |
+ } |
|
| 319 |
+ $update = dbquery("UPDATE ".$settingsprefix."fanfiction_settings SET version = '3.5.5' WHERE sitekey = '".SITEKEY."'");
|
|
| 320 |
+ if($update) {
|
|
| 321 |
+ $output .= write_message(_ACTIONSUCCESSFUL); |
|
| 322 |
+ header("Location: update.php");
|
|
| 323 |
+ exit(); |
|
| 324 |
+ } |
|
| 325 |
+ else $output .= write_error(_ERROR); |
|
| 326 |
+} |
|
| 327 |
+else if($confirm == "no") {
|
|
| 328 |
+ $output .= write_message(_ACTIONCANCELLED); |
|
| 329 |
+} |
|
| 330 |
+else {
|
|
| 331 |
+ if($oldVersion[0] == 3 && ($oldVersion[1] < 4 || $oldVersion[1] == 4 && (!isset($oldVersion[2]) || $oldVersion[2] < 3))) $output .= write_message(_CONFIRMUPDATE. "<br /> <a href='update355.php?confirm=yes'>"._YES."</a> "._OR. " <a href='update355.php?confirm=no'>"._NO."</a>"); |
|
| 332 |
+ else $output .= write_message("Are you ready to update? <a href='update355.php?confirm=yes'>"._YES."</a> "._OR." <a href='update355.php?confirm=no'>"._NO."</a>");
|
|
| 333 |
+} |
|
| 334 |
+} |
|
| 335 |
+else {
|
|
| 336 |
+ $output .= write_message(_ALREADYUPDATED); |
|
| 337 |
+ header("Location: update.php");
|
|
| 338 |
+ exit(); |
|
| 339 |
+} |
|
| 340 |
+$tpl->assign( "output", $output ); |
|
| 341 |
+$tpl->printToScreen(); |
|
| 342 |
+dbclose( ); |
|
| 343 |
+?> |
|
| 0 | 344 |
\ No newline at end of file |