コード例 #1
0
 private function getIdlFile()
 {
     if (!$this->checkedForInteractive) {
         $this->checkedForInteractive = true;
         $dirpath = $this->tmpDir . '/interactive/';
         if (($handle = @opendir($dirpath)) !== false) {
             while (($entry = readdir($handle)) !== false) {
                 if (ProblemDeployer::endsWith($entry, '.idl', true)) {
                     $this->idlFile = '/interactive/' . $entry;
                     break;
                 }
             }
             closedir($handle);
         }
     }
     return $this->idlFile;
 }
コード例 #2
0
 /**
  * Updates problem statement only
  *
  * @param Request $r
  * @return array
  * @throws ApiException
  * @throws InvalidDatabaseOperationException
  */
 public static function apiUpdateStatement(Request $r)
 {
     self::authenticateRequest($r);
     self::validateCreateOrUpdate($r, true);
     // Validate statement
     Validators::isStringNonEmpty($r['statement'], 'statement');
     Validators::isStringNonEmpty($r['message'], 'message');
     // Check that lang is in the ISO 639-1 code list, default is "es".
     $iso639_1 = array('ab', 'aa', 'af', 'ak', 'sq', 'am', 'ar', 'an', 'hy', 'as', 'av', 'ae', 'ay', 'az', 'bm', 'ba', 'eu', 'be', 'bn', 'bh', 'bi', 'bs', 'br', 'bg', 'my', 'ca', 'ch', 'ce', 'ny', 'zh', 'cv', 'kw', 'co', 'cr', 'hr', 'cs', 'da', 'dv', 'nl', 'dz', 'en', 'eo', 'et', 'ee', 'fo', 'fj', 'fi', 'fr', 'ff', 'gl', 'ka', 'de', 'el', 'gn', 'gu', 'ht', 'ha', 'he', 'hz', 'hi', 'ho', 'hu', 'ia', 'id', 'ie', 'ga', 'ig', 'ik', 'io', 'is', 'it', 'iu', 'ja', 'jv', 'kl', 'kn', 'kr', 'ks', 'kk', 'km', 'ki', 'rw', 'ky', 'kv', 'kg', 'ko', 'ku', 'kj', 'la', 'lb', 'lg', 'li', 'ln', 'lo', 'lt', 'lu', 'lv', 'gv', 'mk', 'mg', 'ms', 'ml', 'mt', 'mi', 'mr', 'mh', 'mn', 'na', 'nv', 'nd', 'ne', 'ng', 'nb', 'nn', 'no', 'ii', 'nr', 'oc', 'oj', 'cu', 'om', 'or', 'os', 'pa', 'pi', 'fa', 'pl', 'ps', 'pt', 'qu', 'rm', 'rn', 'ro', 'ru', 'sa', 'sc', 'sd', 'se', 'sm', 'sg', 'sr', 'gd', 'sn', 'si', 'sk', 'sl', 'so', 'st', 'es', 'su', 'sw', 'ss', 'sv', 'ta', 'te', 'tg', 'th', 'ti', 'bo', 'tk', 'tl', 'tn', 'to', 'tr', 'ts', 'tt', 'tw', 'ty', 'ug', 'uk', 'ur', 'uz', 've', 'vi', 'vo', 'wa', 'cy', 'wo', 'fy', 'xh', 'yi', 'yo', 'za', 'zu');
     Validators::isInEnum($r['lang'], 'lang', $iso639_1, false);
     if (is_null($r['lang'])) {
         $r['lang'] = UserController::getPreferredLanguage($r);
     }
     $problemDeployer = new ProblemDeployer($r['problem_alias'], ProblemDeployer::UPDATE_STATEMENTS);
     try {
         $problemDeployer->updateStatement($r['lang'], $r['statement']);
         $problemDeployer->commit("{$r['lang']}.markdown: {$r['message']}", $r['current_user']);
         // Invalidar problem statement cache
         Cache::deleteFromCache(Cache::PROBLEM_STATEMENT, $r['problem']->getAlias() . '-' . $r['lang'] . '-' . 'html');
         Cache::deleteFromCache(Cache::PROBLEM_STATEMENT, $r['problem']->getAlias() . '-' . $r['lang'] . '-' . 'markdown');
         Cache::deleteFromCache(Cache::PROBLEM_SAMPLE, $r['problem']->getAlias() . '-sample.in');
     } catch (ApiException $e) {
         throw $e;
     } catch (Exception $e) {
         throw new InvalidDatabaseOperationException($e);
     } finally {
         $problemDeployer->cleanup();
     }
     // All clear
     $response['status'] = 'ok';
     return $response;
 }
コード例 #3
0
 /**
  * Updates problem statement only
  *
  * @param Request $r
  * @return array
  * @throws ApiException
  * @throws InvalidDatabaseOperationException
  */
 public static function apiUpdateStatement(Request $r)
 {
     self::authenticateRequest($r);
     self::validateCreateOrUpdate($r, true);
     // Validate statement
     Validators::isStringNonEmpty($r["statement"], "statement");
     Validators::isStringNonEmpty($r["message"], "message");
     // Check that lang is in the ISO 639-1 code list, default is "es".
     $iso639_1 = array("ab", "aa", "af", "ak", "sq", "am", "ar", "an", "hy", "as", "av", "ae", "ay", "az", "bm", "ba", "eu", "be", "bn", "bh", "bi", "bs", "br", "bg", "my", "ca", "ch", "ce", "ny", "zh", "cv", "kw", "co", "cr", "hr", "cs", "da", "dv", "nl", "dz", "en", "eo", "et", "ee", "fo", "fj", "fi", "fr", "ff", "gl", "ka", "de", "el", "gn", "gu", "ht", "ha", "he", "hz", "hi", "ho", "hu", "ia", "id", "ie", "ga", "ig", "ik", "io", "is", "it", "iu", "ja", "jv", "kl", "kn", "kr", "ks", "kk", "km", "ki", "rw", "ky", "kv", "kg", "ko", "ku", "kj", "la", "lb", "lg", "li", "ln", "lo", "lt", "lu", "lv", "gv", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mh", "mn", "na", "nv", "nd", "ne", "ng", "nb", "nn", "no", "ii", "nr", "oc", "oj", "cu", "om", "or", "os", "pa", "pi", "fa", "pl", "ps", "pt", "qu", "rm", "rn", "ro", "ru", "sa", "sc", "sd", "se", "sm", "sg", "sr", "gd", "sn", "si", "sk", "sl", "so", "st", "es", "su", "sw", "ss", "sv", "ta", "te", "tg", "th", "ti", "bo", "tk", "tl", "tn", "to", "tr", "ts", "tt", "tw", "ty", "ug", "uk", "ur", "uz", "ve", "vi", "vo", "wa", "cy", "wo", "fy", "xh", "yi", "yo", "za", "zu");
     Validators::isInEnum($r["lang"], "lang", $iso639_1, false);
     if (is_null($r["lang"])) {
         $r['lang'] = UserController::getPreferredLanguage($r);
     }
     $problemDeployer = new ProblemDeployer($r['problem_alias'], ProblemDeployer::UPDATE_STATEMENTS);
     try {
         $problemDeployer->updateStatement($r['lang'], $r['statement']);
         $problemDeployer->commit("{$r['lang']}.markdown: {$r['message']}", $r['current_user']);
         // Invalidar problem statement cache
         Cache::deleteFromCache(Cache::PROBLEM_STATEMENT, $r["problem"]->getAlias() . "-" . $r["lang"] . "-" . "html");
         Cache::deleteFromCache(Cache::PROBLEM_STATEMENT, $r["problem"]->getAlias() . "-" . $r["lang"] . "-" . "markdown");
         Cache::deleteFromCache(Cache::PROBLEM_SAMPLE, $r["problem"]->getAlias() . "-sample.in");
     } catch (ApiException $e) {
         throw $e;
     } catch (Exception $e) {
         throw new InvalidDatabaseOperationException($e);
     } finally {
         $problemDeployer->cleanup();
     }
     // All clear
     $response["status"] = "ok";
     return $response;
 }