/**
  * Save the Testresult for the given TestNode
  * @param tx_caretaker_TestNode $uid
  * @param tx_caretaker_TestResult $result tx_caretaker_TestResult
  */
 function saveTestResultForNode(tx_caretaker_TestNode $test, $testResult)
 {
     $values = array('test_uid' => $test->getUid(), 'instance_uid' => $test->getInstance()->getUid(), 'result_status' => TX_CARETAKER_UNDEFINED, 'tstamp' => $testResult->getTstamp(), 'result_status' => $testResult->getState(), 'result_value' => $testResult->getValue(), 'result_msg' => $testResult->getMessage()->getText(), 'result_values' => serialize($testResult->getMessage()->getValues()), 'result_submessages' => serialize($testResult->getSubMessages()));
     // store log of results
     $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_caretaker_testresult', $values);
     // store last results for fast access
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tx_caretaker_lasttestresult', 'test_uid = ' . $test->getUid() . ' AND instance_uid = ' . $test->getInstance()->getUid(), '', '', 1);
     if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_caretaker_lasttestresult', 'uid = ' . $row['uid'], $values);
     } else {
         $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_caretaker_lasttestresult', $values);
     }
 }
 /**
  *
  * @param tx_caretaker_TestServiceInterface $testService
  * @param tx_caretaker_TestNode $node
  * @param tx_caretaker_NodeResult $latestTestResult
  * @param array $options
  * @return tx_caretaker_NodeResult
  */
 protected function executeTestServiceRun($testService, $node, $latestTestResult, $options)
 {
     // check wether the test can be executed
     if ($testService && $testService->isExecutable()) {
         try {
             $result = $testService->runTest();
         } catch (Exception $e) {
             $result = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, '{LLL:EXT:caretaker/locallang_fe.xml:service_exception}' . $e->getMessage);
         }
         // retry if not ok and retrying is enabled
         if ($result->getState() != 0 && $node->getTestRetry() > 0) {
             $round = 0;
             while ($round < $node->getTestRetry() && $result->getState() != 0) {
                 // TODO make sleep time between retry configurable
                 sleep(1);
                 try {
                     $result = $testService->runTest();
                 } catch (Exception $e) {
                     $result = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, '{LLL:EXT:caretaker/locallang_fe.xml:service_exception}' . $e->getMessage);
                 }
                 $round++;
             }
             $result->addSubMessage(new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:retry_info', array('number' => $round)));
         }
         // save to repository after reading the previous result
         $resultRepository = tx_caretaker_TestResultRepository::getInstance();
         $resultRepository->saveTestResultForNode($node, $result);
         // trigger notification
         $node->notify('updatedTestResult', $result, $latestTestResult);
         return $result;
     } else {
         $result = tx_caretaker_TestResult::undefined();
         $result->addSubMessage(new tx_caretaker_ResultMessage('test service was not executable this time so the cached result is used'));
         $node->notify('cachedTestResult', $result, $latestTestResult);
         return $latestTestResult;
     }
 }
 /**
  * Convert Test DB-Row to Object
  *
  * @param array $row
  * @param tx_caretaker_AbstractNode $parent
  * @return tx_caretaker_TestNode
  */
 private function dbrow2test($row, $parent = false)
 {
     if (!$parent) {
         return false;
     }
     $test = new tx_caretaker_TestNode($row['uid'], $row['title'], $parent, $row['test_service'], $row['test_conf'], $row['test_interval'], $row['test_retry'], $row['test_due'], $row['test_interval_start_hour'], $row['test_interval_stop_hour'], $row['hidden']);
     if ($row['description']) {
         $test->setDescription($row['description']);
     }
     $test->setDbRow($row);
     return $test;
 }