public static function uploadNewAddon($user, $name, $type, $file, $filename, $description) { $database = new DatabaseManager(); AddonManager::verifyTable($database); $rsc = $database->query("SELECT * FROM `addon_addons` WHERE `name` = '" . $database->sanitize($name) . "' LIMIT 1"); //I think we should enforce a unique file name, but not a unique addon name if ($rsc->num_rows > 0) { $response = ["message" => "An add-on by this name already exists!"]; $rsc->close(); return $response; } $rsc->close(); $rsc = $database->query("SELECT * FROM `addon_addons` WHERE `filename` = '" . $database->sanitize($filename) . "'"); if ($rsc->num_rows > 0) { $response = ["message" => "An add-on with this filename already exists!"]; $rsc->close(); return $response; } $rsc->close(); $bid = 1; // TODO Specify branch in upload //generate blank version data $versionInfo = AddonFileHandler::getVersionInfo($file); var_dump($versionInfo); if ($versionInfo !== false) { // information to use for upstream repos $version = new stdClass(); $version->stable = new stdClass(); $version->stable->version = $versionInfo->version; $version->stable->restart = "0.0.0"; $url = parse_url($versionInfo->repo->url); if (!isset($url['host'])) { $url['host'] = $versionInfo->repo->url; } if ($url['host'] == "blocklandglass.com" || $url['host'] == "api.blocklandglass.com") { // nothing? } else { $upstream = new stdClass(); $upstream->url = $versionInfo->repo->url; if (isset($versionInfo->repo->mod)) { $upstream->mod = $versionInfo->repo->mod; } $upstream->branch = array(); $upstream->branch[$bid] = $versionInfo->channel; $version->upstream = $upstream; } } else { $version = new stdClass(); $version->stable = new stdClass(); $version->stable->version = "0.0.0"; $version->stable->restart = "0.0.0"; $repo = new stdClass(); } $authorInfo = new stdClass(); $authorInfo->blid = $user->getBlid(); $authorInfo->main = true; $authorInfo->role = "Manager"; $authorArray = [$authorInfo]; // NOTE boards will be decided by reviewers now, they just seem to confuse and anger people // I think making that change at this point will cause more problems than it solves. // It is better to just have reviewers move boards $res = $database->query("INSERT INTO `addon_addons` (`id`, `board`, `blid`, `name`, `filename`, `description`, `versionInfo`, `authorInfo`, `reviewInfo`, `deleted`, `approved`, `uploadDate`) VALUES " . "(NULL," . "NULL," . "'" . $database->sanitize($user->getBlid()) . "'," . "'" . $database->sanitize($name) . "'," . "'" . $database->sanitize($filename) . "'," . "'" . $database->sanitize($description) . "'," . "'" . $database->sanitize(json_encode($version)) . "'," . "'" . $database->sanitize(json_encode($authorArray)) . "'," . "'{}'," . "'0'," . "'0'," . "CURRENT_TIMESTAMP);"); if (!$res) { throw new Exception("Database error: " . $database->error()); } $id = $database->fetchMysqli()->insert_id; AddonFileHandler::injectGlassFile($id, $file); //AddonFileHandler::injectVersionInfo($id, $bid, $file); // TODO need to specify branch in upload require_once realpath(dirname(__FILE__) . '/AWSFileManager.php'); //AWSFileManager::uploadNewAddon($id, $bid, $filename, $file); require_once realpath(dirname(__FILE__) . '/StatManager.php'); StatManager::addStatsToAddon($id); $response = ["redirect" => "/addons/upload/success.php?id=" . $id]; return $response; }
public static function approveUpdate($update) { $database = new DatabaseManager(); AddonManager::verifyTable($database); $id = $update->getId(); if ($update->status !== null) { throw new Exception("Attempted to approve already approved update"); } $update->status = true; $database->query("UPDATE `addon_updates` SET `approved` = b'1' WHERE `id` = '" . $database->sanitize($id) . "'"); $database->query("UPDATE `addon_addons` SET `version` = '" . $database->sanitize($update->version) . "' WHERE `id` = '" . $database->sanitize($update->aid) . "'"); AddonFileHandler::injectGlassFile($update->aid, $update->getFile()); AddonFileHandler::injectVersionInfo($update->aid, 1, $update->getFile()); AWSFileManager::uploadNewAddon($update->aid, 1, $update->getAddon()->getFilename(), $update->getFile()); $params = new stdClass(); $addon = new stdClass(); $addon->type = "addon"; $addon->id = $update->getAddon()->getId(); $params->vars[] = $addon; NotificationManager::createNotification($manager, 'Your update to $1 was approved', $params); @unlink($update->getFile()); }