public static function loadBasicDummyData() { TestManager::clearDatabase(); $database = new DatabaseManager(); UserManager::verifyTable($database); AddonManager::verifyTable($database); BoardManager::verifyTable($database); TagManager::verifyTable($database); GroupManager::verifyTable($database); DependencyManager::verifyTable($database); CommentManager::verifyTable($database); RatingManager::verifyTable($database); BuildManager::verifyTable($database); StatManager::verifyTable($database); ScreenshotManager::verifyTable($database); if (!$database->query("INSERT INTO `addon_boards` (name, video, description) VALUES ('General Content', 'general_content_bg', 'Bricks, Events, Sounds, Prints, Environments, and much more!')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `addon_boards` (name, video, description) VALUES ('Minigames', 'minigames_bg', 'Weapons, Vehicles, Gamemodes, and all your gaming needs!')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `addon_boards` (name, video, description) VALUES ('Client Mods', 'client_mods_bg', 'Mods that run on your client.')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `addon_boards` (name, video, description) VALUES ('Bargain Bin', 'bargain_bin_bg', 'A home for \\'special\\' content.')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `users` (username, blid, password, email, salt, verified) VALUES ('testuser', '4833', '1d8436e97ef95a7a6151f47b909167c77cfe1985ee5500efa8d46cfe825abc59', '*****@*****.**', '273eb4', '1')")) { throw new Exception("Database error: " . $database->error()); } //the default json types likely need to be reworked if (!$database->query("INSERT INTO `addon_addons` (board, blid, name, filename, description, approved, versionInfo, authorInfo, reviewInfo) VALUES ('1', '4833', 'crapy adon', 'sciprt_hax.zip', 'bad addone pls delete', '1', '{}', '[]', '[]')")) { throw new Exception("Database error: " . $database->error()); } StatManager::addStatsToAddon(1); if (!$database->query("INSERT INTO `addon_tags` (name, base_color, icon) VALUES ('dum tag', 'ff6600', 'brokenimage')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `addon_tagmap` (aid, tid) VALUES ('1', '1')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `group_groups` (leader, name, description, color, icon) VALUES ('4833', 'legion of dumies', 'a group for people who just want to be in a group', '00ff00', 'brokenimage')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `group_usermap` (gid, blid, administrator) VALUES ('1', '4833', '1')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `addon_comments` (blid, aid, comment) VALUES ('4833', '1', 'glorious addon comrade')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `addon_ratings` (blid, aid, rating) VALUES ('4833', '1', '1')")) { throw new Exception("Database error: " . $database->error()); } }
public static function getAllAddonDownloads($type) { if ($type == "ingame") { $sql = "ingameDownloads"; } else { if ($type == "update" || $type == "updates") { $sql = "updateDownloads"; } else { $sql = "webDownloads"; } } $db = new DatabaseManager(); StatManager::verifyTable($db); $res = $db->query("SELECT sum(`{$sql}`) as sum FROM `addon_stats`"); $sum = $res->fetch_object()->sum; return $sum; }
public static function endInteration() { $database = new DatabaseManager(); StatManager::verifyTable($database); //gather lifetime counts //do we include AND `banned` = 0 ? $resource = $database->query("SELECT COUNT(*) FROM `users` WHERE `verified` = 1"); if (!$resource) { throw new Exception("Database error: " . $database->error()); } else { $users = $resource->fetch_row()[0]; $resource->close(); } $resource = $database->query("SELECT COUNT(*) FROM `addon_addons` WHERE `deleted` = 0"); if (!$resource) { throw new Exception("Database error: " . $database->error()); } else { $addons = $resource->fetch_row()[0]; $resource->close(); } $resource = $database->query("SELECT SUM(totalDownloads) FROM `addon_stats`"); if (!$resource) { throw new Exception("Database error: " . $database->error()); } else { $downloads = $resource->fetch_row()[0]; $resource->close(); } $resource = $database->query("SELECT COUNT(*) FROM `group_groups`"); if (!$resource) { throw new Exception("Database error: " . $database->error()); } else { $groups = $resource->fetch_row()[0]; $resource->close(); } $resource = $database->query("SELECT COUNT(*) FROM `build_builds` WHERE `deleted` = 0"); if (!$resource) { throw new Exception("Database error: " . $database->error()); } else { $builds = $resource->fetch_row()[0]; $resource->close(); } $resource = $database->query("SELECT COUNT(*) FROM `addon_tags`"); if (!$resource) { throw new Exception("Database error: " . $database->error()); } else { $tags = $resource->fetch_row()[0]; $resource->close(); } //gather top addons, tags, and builds $resource = $database->query("SELECT `aid` FROM `addon_stats`\n\t\t\tORDER BY `iterationDownloads` DESC\n\t\t\tLIMIT '" . $database->sanitize(StatManager::$addonCount) . "'"); if (!$resource) { throw new Exception("Database error: " . $database->error()); } $topAddonID = []; $topAddonDownloads = []; for ($i = 0; $i < StatManager::$addonCount; $i++) { if ($row = $resource->fetch_object()) { $topAddonID[] = $row->aid; $topAddonDownloads[] = $row->iterationDownloads; } else { $topAddonID[] = 1; $topAddonDownloads[] = 0; } } $resource->close(); $resource = $database->query("SELECT `tid` FROM `tag_stats`\n\t\t\tORDER BY `iterationDownloads` DESC\n\t\t\tLIMIT '" . $database->sanitize(StatManager::$tagCount) . "'"); if (!$resource) { throw new Exception("Database error: " . $database->error()); } $topTagID = []; $topTagDownloads = []; for ($i = 0; $i < StatManager::$tagCount; $i++) { if ($row = $resource->fetch_object()) { $topTagID[] = $row->tid; $topTagDownloads[] = $row->iterationDownloads; } else { $topTagID[] = 1; $topTagDownloads[] = 0; } } $resource->close(); $resource = $database->query("SELECT `bid` FROM `build_stats` ORDER BY `iterationDownloads` DESC LIMIT '" . $database->sanitize(StatManager::$buildCount) . "'"); if (!$resource) { throw new Exception("Database error: " . $database->error()); } $topBuildID = []; $topBuildDownloads = []; for ($i = 0; $i < StatManager::$buildCount; $i++) { if ($row = $resource->fetch_object()) { $topBuildID[] = $row->tid; $topBuildDownloads[] = $row->iterationDownloads; } else { $topBuildID[] = 1; $topBuildDownloads[] = 0; } } $resource->close(); //construct a query $baseQuery = "INSERT INTO `statistics` (`users`, `addons`, `downloads`, `groups`, `comments`, `builds`, `tags`"; $valQuery = ") VALUES ('" . $database->sanitize($users) . "', '" . $database->sanitize($addons) . "', '" . $database->sanitize($downloads) . "', '" . $database->sanitize($groups) . "', '" . $database->sanitize($comments) . "', '" . $database->sanitize($builds) . "', '" . $database->sanitize($tags) . "'"; $endQuery = ")"; $addonBase = ""; $addonVal = ""; $tagBase = ""; $tagVal = ""; $buildBase = ""; $buildVal = ""; for ($i = 0; $i < StatManager::$addonCount; $i++) { $addonBase .= ", `addon" . $i . "`, `addonDownloads" . $i . "`"; $addonVal .= ", '" . $database->sanitize($topAddon[$i]) . "', '" . $database->sanitize($topAddonDownloads[$i]) . "'"; } for ($i = 0; $i < StatManager::$tagCount; $i++) { $tagBase .= ", `tag" . $i . "`, `tagDownloads" . $i . "`"; $tagVal .= ", '" . $database->sanitize($topTag[$i]) . "', '" . $database->sanitize($topTagDownloads[$i]) . "'"; } for ($i = 0; $i < StatManager::$buildCount; $i++) { $buildBase .= ", `build" . $i . "`, `buildDownloads" . $i . "`"; $buildVal .= ", '" . $database->sanitize($topBuild[$i]) . "', '" . $database->sanitize($topBuildDownloads[$i]) . "'"; } //push stats into database if (!$database->query($baseQuery . $addonBase . $tagBase . $buildBase . $valQuery . $addonVal . $tagVal . $buildVal . $endQuery)) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("UPDATE `addon_stats` SET `iterationDownloads` = 0")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("UPDATE `tag_stats` SET `iterationDownloads` = 0")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("UPDATE `build_stats` SET `iterationDownloads` = 0")) { throw new Exception("Database error: " . $database->error()); } apc_delete('lastStats'); }