コード例 #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());
     }
 }
コード例 #2
0
 private static function getBoardIndexData()
 {
     $database = new DatabaseManager();
     BoardManager::verifyTable($database);
     $resource = $database->query("SELECT * FROM `addon_boards`");
     if (!$resource) {
         throw new Exception("Error getting data from database: " . $database->error());
     }
     $boardData = array();
     while ($row = $resource->fetch_object()) {
         $boardData[$row->id] = new BoardObject($row);
     }
     $resource->close();
     return $boardData;
 }
コード例 #3
0
 public static function verifyTable($database)
 {
     /*TO DO:
     			- screenshots
     			- tags
     			- approval info should probably be in a different table,
     			or actually maybe not I dunno
     			- do we really need stable vs testing vs dev?
     			- bargain/danger should probably be boards
     			- figure out how data is split between addon and file
     			- I don't know much about how the file system works, but
     			having 'name', 'file', 'filename', and a separate 'addon_files'
     			table doesn't seem ideal.
     			- Maybe we should just keep track of total downloads instead
     			of 3 different columns
     			- I think users should just credit people in their descriptions
     			instead of having a dedicated authorInfo json object
     		*/
     if ($database->debug()) {
         require_once realpath(dirname(__FILE__) . '/UserManager.php');
         require_once realpath(dirname(__FILE__) . '/BoardManager.php');
         UserManager::verifyTable($database);
         BoardManager::verifyTable($database);
         //why is the blid foreign key constraint removed?
         //If you want to be able to set blid to null, you should reconsider.
         //blid is used to determine which account has control over the addon.
         //There is no need to set it to null.  Just default it to some admin.
         if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_addons` (\n\t\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t\t`board` INT,\n\t\t\t\t`blid` INT NOT NULL,\n\t\t\t\t`name` VARCHAR(30) NOT NULL,\n\t\t\t\t`filename` TEXT NOT NULL,\n\t\t\t\t`description` TEXT NOT NULL,\n\t\t\t\t`versionInfo` TEXT NOT NULL,\n\t\t\t\t`authorInfo` TEXT NOT NULL,\n\t\t\t\t`reviewInfo` TEXT NOT NULL,\n\t\t\t\t`repositoryInfo` TEXT NOT NULL,\n\t\t\t\t`deleted` TINYINT NOT NULL DEFAULT 0,\n\t\t\t\t`approved` TINYINT NOT NULL DEFAULT 0,\n\t\t\t\t`uploadDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t\t\tFOREIGN KEY (`board`)\n\t\t\t\t\tREFERENCES addon_boards(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,,\n\t\t\t\tFOREIGN KEY (`blid`)\n\t\t\t\t\tREFERENCES users(`blid`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,\n\t\t\t\tPRIMARY KEY (`id`))")) {
             throw new Exception("Failed to create table addon_addons: " . $database->error());
         }
     }
 }
コード例 #4
0
 public static function verifyTable($database)
 {
     /*TO DO:
     			- screenshots
     			- approval info should probably be in a different table,
     			or actually maybe not I dunno
     			- do we really need stable vs testing vs dev?
     			- bargain/danger should probably be boards
     			- figure out how data is split between addon and file
     			- I don't know much about how the file system works, but
     			having 'name', 'file', 'filename', and a separate 'addon_files'
     			table doesn't seem ideal.
     			- Maybe we should just keep track of total downloads instead
     			of 3 different columns
     			- I think users should just credit people in their descriptions
     			instead of having a dedicated authorInfo json object
     		*/
     require_once realpath(dirname(__FILE__) . '/UserManager.php');
     require_once realpath(dirname(__FILE__) . '/BoardManager.php');
     UserManager::verifyTable($database);
     BoardManager::verifyTable($database);
     if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_addons` (\n\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t`board` INT,\n\t\t\t`blid` INT NOT NULL,\n\t\t\t`name` VARCHAR(30) NOT NULL,\n\t\t\t`filename` TEXT NOT NULL,\n\t\t\t`description` TEXT NOT NULL,\n\t\t\t`version` TEXT NOT NULL,\n\t\t\t`authorInfo` TEXT NOT NULL,\n\t\t\t`reviewInfo` TEXT NOT NULL,\n\t\t\t`repositoryInfo` TEXT NULL DEFAULT NULL,\n\t\t\t`deleted` TINYINT NOT NULL DEFAULT 0,\n\t\t\t`approved` TINYINT NOT NULL DEFAULT 0,\n\t\t\t`betaVersion` TEXT DEFAULT NULL,\n\t\t\t`rating` int(11) NOT NULL DEFAULT 0,\n\t\t\t`uploadDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t\t`type` TEXT NOT NULL,\n\t\t\tFOREIGN KEY (`board`)\n\t\t\t\tREFERENCES addon_boards(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t\tPRIMARY KEY (`id`))")) {
         throw new Exception("Failed to create table addon_addons: " . $database->error());
     }
     if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_updates` (\n\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `aid` int(11) NOT NULL,\n\t\t  `version` text NOT NULL,\n\t\t  `tempfile` text NOT NULL,\n\t\t  `changelog` text NOT NULL,\n\t\t  `submitted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t  `upstream` bit(1) NOT NULL DEFAULT b'0',\n\t\t  `restart` bit(1) NOT NULL DEFAULT b'0',\n\t\t  `approved` bit(1) DEFAULT NULL,\n\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t  PRIMARY KEY (`id`),\n\t\t  UNIQUE KEY `id` (`id`))")) {
         throw new Exception("Failed to create table addon_updates: " . $database->error());
     }
     if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_ratings` (\n\t\t  `aid` int(11) NOT NULL,\n\t\t\t`blid` int(11) NOT NULL,\n\t\t\t`rating` int(11) NOT NULL,\n\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE)")) {
         throw new Exception("Failed to create table addon_updates: " . $database->error());
     }
 }