Пример #1
0
 /**
  * Validates zip contents and deploys the problem
  *
  * @param Request $r
  * @param type $isUpdate
  * @throws InvalidFilesystemOperationException
  */
 public function deploy()
 {
     $this->validateZip();
     if (!file_exists("{$this->tmpDir}/cases/in")) {
         mkdir("{$this->tmpDir}/cases/in", 0755, true);
     }
     if (!file_exists("{$this->tmpDir}/cases/out")) {
         mkdir("{$this->tmpDir}/cases/out", 0755, true);
     }
     try {
         // Unzip the user's zip
         ZipHandler::DeflateZip($this->zipPath, $this->tmpDir, $this->filesToUnzip);
         // Move all .in and .out files to their folder.
         $dh = opendir("{$this->tmpDir}/cases/");
         while (($file = readdir($dh)) !== false) {
             if (ProblemDeployer::endsWith($file, '.out', true)) {
                 rename("{$this->tmpDir}/cases/{$file}", "{$this->tmpDir}/cases/out/{$file}");
             } elseif (ProblemDeployer::endsWith($file, '.in', true)) {
                 rename("{$this->tmpDir}/cases/{$file}", "{$this->tmpDir}/cases/in/{$file}");
             }
         }
         closedir($dh);
         if ($this->isInteractive) {
             $target = "{$this->tmpDir}/interactive/generated/";
             if (!is_dir($target)) {
                 mkdir($target, 0755);
             }
             $this->handleInteractive("{$this->tmpDir}/{$this->idlFile}", $target);
         }
         // Handle statements
         $this->handleStatements($this->filesToUnzip);
         // Verify at least one statement was extracted.
         if (!is_dir("{$this->tmpDir}/statements")) {
             throw new InvalidParameterException('problemDeployerNoStatements');
         }
         // Handle cases
         $this->handleCases($this->tmpDir, $this->casesFiles);
     } catch (ApiException $e) {
         throw $e;
     } catch (Exception $e) {
         $this->log->error("Deployment exception {$e}");
         throw new ProblemDeploymentFailedException('problemDeployerFailed', $e);
     }
 }