Browse code

update files

Jimako authored on 2023/09/05 17:13:34
Showing 2 changed files
... ...
@@ -29,306 +29,149 @@ $blocks['news']['status'] = 0;
29 29
 $blocks['info']['status'] = 0;
30 30
 
31 31
 //make a new TemplatePower object
32
-if(file_exists("$skindir/default.tpl")) $tpl = new TemplatePower( "$skindir/default.tpl" );
32
+if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
33 33
 else $tpl = new TemplatePower("default_tpls/default.tpl");
34 34
 include("includes/pagesetup.php");
35
-if(file_exists("languages/".$language."_admin.php")) include_once("languages/".$language."_admin.php");
35
+if (file_exists("languages/" . $language . "_admin.php")) include_once("languages/" . $language . "_admin.php");
36 36
 else include_once("languages/en_admin.php");
37 37
 // end basic page setup
38 38
 
39
-if(!isADMIN) {
40
-$output .= "<script language=\"javascript\" type=\"text/javascript\">
39
+if (!isADMIN)
40
+{
41
+	$output .= "<script language=\"javascript\" type=\"text/javascript\">
41 42
 location = \"maintenance.php\";
42 43
 </script>";
43
-$tpl->assign( "output", $output );
44
-$tpl->printToScreen();
45
-dbclose( );
46
-exit( );
44
+	$tpl->assign("output", $output);
45
+	$tpl->printToScreen();
46
+	dbclose();
47
+	exit();
47 48
 }
48 49
 $oldVersion = explode(".", $settings['version']);
50
+
49 51
 $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
-		}
52
+if ($oldVersion[0] == 3 && ($oldVersion[1] < 5 || $oldVersion[2] < 6))  //3.5.5
53
+{
54
+	if ($confirm == "yes")
55
+	{
56
+		if ($oldVersion[1] == 5 && $oldVersion[2] < 6)
57
+		{
58
+			/****************************************************************************************************************/
59
+ 
60
+			/* trying not to lost data */
61
+			$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_authors LIKE 'date_tmp'"));
62
+			if (!$updated)
63
+			{
64
+				dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_authors` ADD `date_tmp` int(11) NOT NULL default '0'");
65
+			}
123 66
 
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'"); 
67
+			dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_authors` SET `date_tmp` = UNIX_TIMESTAMP( `date` )");
68
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_authors` CHANGE `date` `date` INT NOT NULL");
69
+			dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_authors` set date = date_tmp");
70
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_authors` DROP `date_tmp`");
132 71
 
133
-		$chapterquery = dbquery("SELECT COUNT(chapid) as chapters FROM ".TABLEPREFIX."fanfiction_chapters where validated > 0");
134
-		list($chapters) = dbrow($chapterquery);
72
+			/****************************************************************************************************************/
73
+ 
74
+			$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_log LIKE 'date_tmp'"));
75
+			if (!$updated)
76
+			{
77
+				dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_log` ADD `date_tmp` int(11) NOT NULL default '0'");
78
+			}
135 79
 
136
-		$authorquery = dbquery("SELECT COUNT("._UIDFIELD.") as totalm FROM "._AUTHORTABLE);
137
-		list($members) = dbrow($authorquery);
80
+			dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_log` SET `date_tmp` = UNIX_TIMESTAMP( `log_timestamp` )");
81
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_log` CHANGE `log_timestamp` `log_timestamp` INT NOT NULL");
82
+			dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_log` set log_timestamp = date_tmp");
83
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_log` DROP `date_tmp`");
138 84
 
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;
85
+			/****************************************************************************************************************/
86
+			/* fanfiction_comments   `time` datetime NOT NULL default '0000-00-00 00:00:00'  */
87
+			$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_comments LIKE 'time_tmp'"));
88
+			if (!$updated)
89
+			{
90
+				dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_comments` ADD `time_tmp` int(11) NOT NULL default '0'");
91
+			}
92
+
93
+			dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_comments` SET `time_tmp` = UNIX_TIMESTAMP( `time` )");
94
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_comments` CHANGE `time` `time` INT NOT NULL");
95
+			dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_comments` set time = time_tmp");
96
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_comments` DROP `time_tmp`");
173 97
 			
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']."')");
98
+			/****************************************************************************************************************/
99
+			/* fanfiction_inseries  `updated` datetime NOT NULL default '0000-00-00 00:00:00'  */
100
+			$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_inseries LIKE 'updated_tmp'"));
101
+			if (!$updated)
102
+			{
103
+				dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_inseries` ADD `updated_tmp` int(11) NOT NULL default '0'");
228 104
 			}
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'];
105
+
106
+			dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_inseries` SET `updated_tmp` = UNIX_TIMESTAMP( `updated` )");
107
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_inseries` CHANGE `updated` `updated` INT NOT NULL");
108
+			dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_inseries` set updated = updated_tmp");
109
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_inseries` DROP `updated_tmp`");
110
+ 
111
+			/****************************************************************************************************************/
112
+			/* fanfiction_reviews   `date` datetime NOT NULL default '0000-00-00 00:00:00', */
113
+			$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_reviews LIKE 'date_tmp'"));
114
+			if (!$updated)
115
+			{
116
+				dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_reviews` ADD `date_tmp` int(11) NOT NULL default '0'");
275 117
 			}
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'];
118
+
119
+			dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_reviews` SET `date_tmp` = UNIX_TIMESTAMP( `date` )");
120
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_reviews` CHANGE `date` `date` INT NOT NULL");
121
+			dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_reviews` set date = date_tmp");
122
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_reviews` DROP `date_tmp`");
123
+
124
+			/****************************************************************************************************************/
125
+			/* fanfiction_stories `date` datetime NOT NULL default '0000-00-00 00:00:00',   */
126
+			$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'date_tmp'"));
127
+			if (!$updated)
128
+			{
129
+				dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_stories` ADD `date_tmp` int(11) NOT NULL default '0'");
280 130
 			}
281
-			foreach($alist AS $a => $s) {
282
-				dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
131
+
132
+			dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_stories` SET `date_tmp` = UNIX_TIMESTAMP( `date` )");
133
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_stories` CHANGE `date` `date` INT NOT NULL");
134
+			dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_stories` set date = date_tmp");
135
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_stories` DROP `date_tmp`");
136
+
137
+			/* fanfiction_stories `updated` datetime NOT NULL default '0000-00-00 00:00:00', */
138
+			$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'updated_tmp'"));
139
+			if (!$updated)
140
+			{
141
+				dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_stories` ADD `updated_tmp` int(11) NOT NULL default '0'");
283 142
 			}
143
+
144
+			dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_stories` SET `updated_tmp` = UNIX_TIMESTAMP( `updated` )");
145
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_stories` CHANGE `updated` `updated` INT NOT NULL");
146
+			dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_stories` set updated = updated_tmp");
147
+			dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_stories` DROP `updated_tmp`");
148
+			
149
+			
150
+
284 151
 		}
152
+		$update = dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '" . $version . "' WHERE sitekey = '" . SITEKEY . "'");
153
+		if ($update) $output .= write_message(_ACTIONSUCCESSFUL);
154
+		else $output .= write_error(_ERROR);
285 155
 	}
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."'"); 
156
+	else if ($confirm == "no")
157
+	{
158
+		$output .= write_message(_ACTIONCANCELLED);
159
+	}
160
+	else
161
+	{
162
+		if ($oldVersion[0] == 3 && ($oldVersion[1] < 4 || $oldVersion[1] == 4 && (!isset($oldVersion[2]) || $oldVersion[2] < 6)))
163
+			$output .= write_message(_CONFIRMUPDATE . "<br /> <a href='update.php?confirm=yes'>" . _YES . "</a> " . _OR . " <a href='update.php?confirm=no'>" . _NO . "</a>");
164
+		else $output .= write_message("Are you ready to update? <a href='update.php?confirm=yes'>" . _YES . "</a> " . _OR . " <a href='update.php?confirm=no'>" . _NO . "</a>");
304 165
 	}
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
-	}	
318
-	$update = dbquery("UPDATE ".$settingsprefix."fanfiction_settings SET version = '".$version."' WHERE sitekey = '".SITEKEY."'");
319
-	if($update) $output .= write_message(_ACTIONSUCCESSFUL);
320
-	else $output .= write_error(_ERROR);
321
-}
322
-else if($confirm == "no") {
323
-	$output .= write_message(_ACTIONCANCELLED);
324
-}
325
-else {
326
-  	if($oldVersion[0] == 3 && ($oldVersion[1] < 4 || $oldVersion[1] == 4 && (!isset($oldVersion[2]) || $oldVersion[2] < 3))) $output .= write_message(_CONFIRMUPDATE."<br /> <a href='update.php?confirm=yes'>"._YES."</a> "._OR." <a href='update.php?confirm=no'>"._NO."</a>");
327
-	else $output .= write_message("Are you ready to update? <a href='update.php?confirm=yes'>"._YES."</a> "._OR." <a href='update.php?confirm=no'>"._NO."</a>");
328 166
 }
167
+elseif ($oldVersion[0] == 4) //3.5.5
168
+{
169
+	/* quick fix for switching between version on dev */
170
+	$update = dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '3.5.5' WHERE sitekey = '" . SITEKEY . "'");
171
+	header("Location: update.php");
172
+	exit();
329 173
 }
330 174
 else $output .= write_message(_ALREADYUPDATED);
331
-$tpl->assign( "output", $output );
175
+$tpl->assign("output", $output);
332 176
 $tpl->printToScreen();
333
-dbclose( );
334
-?>
335 177
\ No newline at end of file
178
+dbclose();
... ...
@@ -1,4 +1,3 @@
1 1
 <?php
2 2
 if(!defined("_CHARSET")) exit( );
3
-$version = "3.5.5";
4
-?>
5 3
\ No newline at end of file
4
+$version = "3.5.6";
6 5
\ No newline at end of file