public function doAction()
 {
     switch ($this->__postInput['exec']) {
         case 'stayAnonymous':
             unset($_SESSION['_anonym_pid']);
             unset($_SESSION['incomingUrl']);
             unset($_SESSION['_newProject']);
             break;
         case 'ping':
             $db = Database::obtain();
             $db->query("SELECT 1");
             $this->result['data'] = array("OK", time());
             break;
         case 'checkTMKey':
             //get MyMemory apiKey service
             $tmxHandler = new TMSService();
             $tmxHandler->setTmKey($this->__postInput['tm_key']);
             //validate the key
             try {
                 $keyExists = $tmxHandler->checkCorrectKey();
             } catch (Exception $e) {
                 /* PROVIDED KEY IS NOT VALID OR WRONG, $keyExists IS NOT SET */
                 Log::doLog($e->getMessage());
             }
             if (!isset($keyExists) || $keyExists === false) {
                 $this->result['errors'][] = array("code" => -9, "message" => "TM key is not valid.");
                 Log::doLog(__METHOD__ . " -> TM key is not valid.");
                 $this->result['success'] = false;
             } else {
                 $this->result['errors'] = array();
                 $this->result['success'] = true;
             }
             break;
     }
 }
Example #2
0
 /**
  * When Called it perform the controller action to retrieve/manipulate data
  *
  * @return void
  */
 function doAction()
 {
     //if some error occured, stop execution.
     if (count(@$this->result['errors'])) {
         return;
     }
     try {
         $tmService = new TMSService();
         $tmService->setTmKey($this->key);
         //validate the key
         try {
             $keyExists = $tmService->checkCorrectKey();
         } catch (Exception $e) {
             /* PROVIDED KEY IS NOT VALID OR WRONG, $keyExists IS NOT SET */
             Log::doLog($e->getMessage());
         }
         if (!isset($keyExists) || $keyExists === false) {
             Log::doLog(__METHOD__ . " -> TM key is not valid.");
             throw new Exception("TM key is not valid.", -4);
         }
         $tmKeyStruct = new TmKeyManagement_TmKeyStruct();
         $tmKeyStruct->key = $this->key;
         $tmKeyStruct->name = $this->description;
         $tmKeyStruct->tm = true;
         $tmKeyStruct->glos = true;
         $mkDao = new TmKeyManagement_MemoryKeyDao(Database::obtain());
         $memoryKeyToUpdate = new TmKeyManagement_MemoryKeyStruct();
         $memoryKeyToUpdate->uid = $this->uid;
         $memoryKeyToUpdate->tm_key = $tmKeyStruct;
         switch ($this->exec) {
             case 'delete':
                 $userMemoryKeys = $mkDao->disable($memoryKeyToUpdate);
                 break;
             case 'update':
                 $userMemoryKeys = $mkDao->update($memoryKeyToUpdate);
                 break;
             case 'newKey':
                 $userMemoryKeys = $mkDao->create($memoryKeyToUpdate);
                 break;
             default:
                 throw new Exception("Unexpected Exception", -4);
         }
         if (!$userMemoryKeys) {
             throw new Exception("This key wasn't found in your keyring.", -3);
         }
     } catch (Exception $e) {
         $this->result['data'] = 'KO';
         $this->result['errors'][] = array("code" => $e->getCode(), "message" => $e->getMessage());
     }
 }
 public function doAction()
 {
     switch ($this->__postInput['exec']) {
         case 'stayAnonymous':
             unset($_SESSION['_anonym_pid']);
             unset($_SESSION['incomingUrl']);
             unset($_SESSION['_newProject']);
             break;
         case 'ping':
             $db = Database::obtain();
             $db->query("SELECT 1");
             $this->result['data'] = array("OK", time());
             break;
         case 'checkTMKey':
             //get MyMemory apiKey service
             $tmxHandler = new TMSService();
             $tmxHandler->setTmKey($this->__postInput['tm_key']);
             //validate the key
             try {
                 $keyExists = $tmxHandler->checkCorrectKey();
             } catch (Exception $e) {
                 /* PROVIDED KEY IS NOT VALID OR WRONG, $keyExists IS NOT SET */
                 Log::doLog($e->getMessage());
             }
             if (!isset($keyExists) || $keyExists === false) {
                 $this->result['errors'][] = array("code" => -9, "message" => "TM key is not valid.");
                 Log::doLog(__METHOD__ . " -> TM key is not valid.");
                 $this->result['success'] = false;
             } else {
                 $this->result['errors'] = array();
                 $this->result['success'] = true;
             }
             break;
         case 'clearNotCompletedUploads':
             try {
                 Utils::deleteDir(INIT::$UPLOAD_REPOSITORY . '/' . $_COOKIE['upload_session'] . '/');
             } catch (Exception $e) {
                 Log::doLog("ajaxUtils::clearNotCompletedUploads : " . $e->getMessage());
             }
             setcookie("upload_session", null, -1, '/');
             unset($_COOKIE['upload_session']);
             break;
     }
 }