Exemplo n.º 1
0
 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());
     }
 }
Exemplo n.º 2
0
 public static function removeTagFromAddon($tag, $addon)
 {
     $database = new DatabaseManager();
     TagManager::verifyTable($database);
     $resource = $database->query("SELECT 1 FROM `addon_tagmap` WHERE\n\t\t\t`tid` = '" . $database->sanitize($tag->getID()) . "' AND\n\t\t\t`aid` = '" . $database->sanitize($addon->getID()) . "' LIMIT 1");
     if (!$resource) {
         throw new Exception("Database error: " . $database->error());
     }
     if ($resource->num_rows == 0) {
         $resource->close();
         return false;
     }
     $resource->close();
     if (!$database->query("DELETE FROM `addon_tagmap` WHERE\n\t\t\t`tid` = '" . $database->sanitize($tag->getID()) . "' AND\n\t\t\t`aid` = '" . $database->sanitize($addon->getID()) . "'")) {
         throw new Exception("Error removing tagmap entry: " . $database->error());
     }
     if (!$tag->getImportant()) {
         //now check to see if there are any other instances of tag
         $resource = $database->query("SELECT 1 FROM `addon_tagmap` WHERE\n\t\t\t\t`tid` = '" . $database->sanitize($tag->getID()) . "' LIMIT 1");
         if ($resource->num_rows == 0) {
             if (!$database->query("DELETE FROM `addon_tags` WHERE\n\t\t\t\t\t`id` = '" . $database->sanitize($tag->getID()) . "'")) {
                 throw new Exception("Error deleting tag: " . $database->error());
             }
             apc_delete('tagObject_' . $tag->getID());
             apc_delete('allTags');
         }
         $resource->close();
     }
     apc_delete('addonTags_' . $addon->getID());
     apc_delete('tagAddons_' . $tag->getID());
     return true;
 }
Exemplo n.º 3
0
 public static function verifyTable($database)
 {
     if ($database->debug()) {
         UserManager::verifyTable($database);
         AddonManager::verifyTable($database);
         TagManager::verifyTable($database);
         BuildManager::verifyTable($database);
         GroupManager::verifyTable($database);
         if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_stats` (\n\t\t\t\t`aid` INT NOT NULL,\n\t\t\t\t`rating` FLOAT,\n\t\t\t\t`totalDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`iterationDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`webDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`ingameDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`updateDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\tKEY (`totalDownloads`),\n\t\t\t\tKEY (`iterationDownloads`),\n\t\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE)")) {
             throw new Exception("Failed to create addon stats table: " . $database->error());
         }
         if (!$database->query("CREATE TABLE IF NOT EXISTS `build_stats` (\n\t\t\t\t`bid` INT NOT NULL,\n\t\t\t\t`rating` FLOAT,\n\t\t\t\t`totalDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`iterationDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\tKEY (`totalDownloads`),\n\t\t\t\tKEY (`iterationDownloads`),\n\t\t\t\tFOREIGN KEY (`bid`)\n\t\t\t\t\tREFERENCES build_builds(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE)")) {
             throw new Exception("Failed to create build stats table: " . $database->error());
         }
         if (!$database->query("CREATE TABLE IF NOT EXISTS `tag_stats` (\n\t\t\t\t`tid` INT NOT NULL,\n\t\t\t\t`totalDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`iterationDownloads` INT NOT NULL DEFAULT 0,\n\t\t\t\tKEY (`totalDownloads`),\n\t\t\t\tKEY (`iterationDownloads`),\n\t\t\t\tFOREIGN KEY (`tid`)\n\t\t\t\t\tREFERENCES addon_tags(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE)")) {
             throw new Exception("Failed to create tag stats table: " . $database->error());
         }
         //includes a lot of foreign keys, not sure if it is a good idea to include them all
         if (!$database->query("CREATE TABLE IF NOT EXISTS `statistics` (\n\t\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t\t`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t\t\t`users` INT NOT NULL DEFAULT 0,\n\t\t\t\t`addons` INT NOT NULL DEFAULT 0,\n\t\t\t\t`downloads` INT NOT NULL DEFAULT 0,\n\t\t\t\t`groups` INT NOT NULL DEFAULT 0,\n\t\t\t\t`comments` INT NOT NULL DEFAULT 0,\n\t\t\t\t`builds` INT NOT NULL DEFAULT 0,\n\t\t\t\t`tags` INT NOT NULL DEFAULT 0,\n\t\t\t\t`addon0` INT NOT NULL,\n\t\t\t\t`addon1` INT NOT NULL,\n\t\t\t\t`addon2` INT NOT NULL,\n\t\t\t\t`addon3` INT NOT NULL,\n\t\t\t\t`addon4` INT NOT NULL,\n\t\t\t\t`addon5` INT NOT NULL,\n\t\t\t\t`addon6` INT NOT NULL,\n\t\t\t\t`addon7` INT NOT NULL,\n\t\t\t\t`addon8` INT NOT NULL,\n\t\t\t\t`addon9` INT NOT NULL,\n\t\t\t\t`addonDownloads0` INT NOT NULL,\n\t\t\t\t`addonDownloads1` INT NOT NULL,\n\t\t\t\t`addonDownloads2` INT NOT NULL,\n\t\t\t\t`addonDownloads3` INT NOT NULL,\n\t\t\t\t`addonDownloads4` INT NOT NULL,\n\t\t\t\t`addonDownloads5` INT NOT NULL,\n\t\t\t\t`addonDownloads6` INT NOT NULL,\n\t\t\t\t`addonDownloads7` INT NOT NULL,\n\t\t\t\t`addonDownloads8` INT NOT NULL,\n\t\t\t\t`addonDownloads9` INT NOT NULL,\n\t\t\t\t`tag0` INT NOT NULL,\n\t\t\t\t`tag1` INT NOT NULL,\n\t\t\t\t`tag2` INT NOT NULL,\n\t\t\t\t`tag3` INT NOT NULL,\n\t\t\t\t`tag4` INT NOT NULL,\n\t\t\t\t`tagDownloads0` INT NOT NULL,\n\t\t\t\t`tagDownloads1` INT NOT NULL,\n\t\t\t\t`tagDownloads2` INT NOT NULL,\n\t\t\t\t`tagDownloads3` INT NOT NULL,\n\t\t\t\t`tagDownloads4` INT NOT NULL,\n\t\t\t\t`build0` INT NOT NULL,\n\t\t\t\t`build1` INT NOT NULL,\n\t\t\t\t`build2` INT NOT NULL,\n\t\t\t\t`buildDownloads0` INT NOT NULL,\n\t\t\t\t`buildDownloads1` INT NOT NULL,\n\t\t\t\t`buildDownloads2` INT NOT NULL,\n\t\t\t\tKEY (`date`),\n\t\t\t\tPRIMARY KEY (`id`))")) {
             throw new Exception("Failed to create stat history table: " . $database->error());
         }
     }
 }