예제 #1
0
 /**
  *  Upload a build with contents as an array of strings
  */
 public static function uploadBuild($blid, $buildName, $fileName, $contents, $tempPath, $description = false)
 {
     //to do, generate a random name for storage?, and allow the build name to contain any characters and be not unique - done - check
     //if(!preg_match("/^[a-zA-Z0-9\-\_\ \'\!]{1,56}\.bls$/", $fileName)) {
     if (!BuildManager::validateFileName($fileName)) {
         $response = ["message" => "Invalid File Name - You may use up to 56 characters followed by '.bls' and include letters, numbers, spaces, and the following symbols: -, ', _, and !"];
         return $response;
     }
     //if(!preg_match("/^.{1,60}$/", $buildName)) {
     if (!BuildManager::validateTitle($buildName)) {
         $response = ["message" => "Your Build Title can only contain up to 60 characters and cannot contain line breaks"];
         return $response;
     }
     //temporary file storage for now
     //$targetPath = dirname(__DIR__) . "/../builds/uploads/" . $buildName . ".bls";
     $check = BuildManager::validateBLSContents($contents);
     //to do:
     //actual file saving - check
     //create database entries - check
     //start stat tracking - check?
     //redirect user to manage page - check
     //event logging
     if (!$check['ok']) {
         $response = ["message" => $check['message']];
         return $response;
     }
     if ($description === false) {
         $description = $check['description'];
     }
     //it's go time
     $database = new DatabaseManager();
     BuildManager::verifyTable($database);
     if (!$database->query("INSERT INTO `build_builds` (`blid`, `name`, `filename`, `bricks`, `description`) VALUES ('" . $database->sanitize($blid) . "', '" . $database->sanitize($buildName) . "', '" . $database->sanitize($fileName) . "', '" . $database->sanitize($check['brickcount']) . "', '" . $database->sanitize($description) . "')")) {
         throw new Exception("Database error: " . $database->error());
     }
     $id = $database->fetchMysqli()->insert_id;
     require_once realpath(dirname(__FILE__) . '/AWSFileManager.php');
     AWSFileManager::uploadNewBuild($id, $fileName, $tempPath);
     require_once realpath(dirname(__FILE__) . '/StatManager.php');
     StatManager::addStatsToBuild($id);
     $response = ["redirect" => "/builds/manage.php?id=" . $id];
     return $response;
 }