Пример #1
0
function exceptionHandler($errno, $errstr, $errfile, $errline)
{
    // Log the exception:
    logException('<b>Error ' . $errno . ' on line ' . $errline . ' in ' . basename($errfile) . '</b>: ' . $errstr);
    // Quit:
    return true;
}
Пример #2
0
function uncaughtExceptionHandler($e)
{
    logException($e);
    ob_end_clean();
    header('HTTP/1.1 500 Internal Server Error');
    ViewRenderer::render('views/errorPage.php', array('exception' => $e));
    die;
}
Пример #3
0
 public static function run($contactId)
 {
     $db = DatabaseHelper::getInstance();
     try {
         $db->beginTransaction();
         if (!$db->deleteRideByContact($contactId)) {
             throw new Exception("Could not delete rides for contact {$contact}`Id");
         }
         if (!$db->deleteContact($contactId)) {
             throw new Exception("Could not delete contact {$contactId}");
         }
         $db->commit();
         AuthHandler::logout();
     } catch (Exception $e) {
         logException($e);
         $db->rollBack();
         throw $e;
     }
 }
 protected function _loadUserConfig()
 {
     $configFile = new XmlConfig($this->dao->toInternalPath('~/.config/locale.xml'));
     $config = $configFile->read();
     // Detect the browser locale
     $browserLocale = $this->detectLanguage();
     $locale = isset($config['locale']) ? $config['locale'] : $browserLocale;
     $language = isset($config['language']) ? $config['language'] : $browserLocale;
     if ($this->dao->exists('~')) {
         // If the user is logged
         $config['locale'] = $locale;
         $config['language'] = $language;
         try {
             $configFile->write($config);
         } catch (\Exception $e) {
             // Cannot write config, not so important - just log the error
             logException($e);
         }
     }
     $this->locale = $locale;
     $this->language = $language;
 }
Пример #5
0
        throw new Exception("No ride found for contact {$contactId}");
    }
    $rideId = $ride['Id'];
    if ($ride['Active'] == RIDE_ACTIVE) {
        // Hidden status is always status + 2
        $newStatus = RIDE_INACTIVE;
        $msg = _("Ride de-activated. From now on, this ride will not appear in the search results.");
    } else {
        if ($ride['Active'] == RIDE_INACTIVE) {
            $newStatus = RIDE_ACTIVE;
            $msg = _("Ride activated. You are back in business!");
        } else {
            throw new Exception("Illegal status");
        }
    }
    if (!$server->updateRideActive($rideId, $newStatus)) {
        throw new Exception("Could not change status to ride {$rideId}");
    }
    GlobalMessage::setGlobalMessage($msg);
    echo json_encode(array('status' => 'ok'));
} catch (PDOException $e) {
    logException($e);
    echo json_encode(array('status' => 'err'));
} catch (Exception $e) {
    logException($e);
    if (ENV == ENV_DEVELOPMENT) {
        echo json_encode(array('status' => 'err', 'msg' => $e->getMessage()));
    } else {
        echo json_encode(array('status' => 'err'));
    }
}
Пример #6
0
 function insertQuestionAnswer($id, $langId, $question, $answer)
 {
     debug(__METHOD__ . "({$id}, {$langId}, {$question}, {$answer})");
     try {
         $stmt = $this->_db->prepare('INSERT INTO QuestionsAnswers (Id, Lang, Question, Answer) VALUES (:id, :lang, :question, :answer)');
         $stmt->bindParam(':question', $question);
         $stmt->bindParam(':answer', $answer);
         $stmt->bindParam(':id', $id);
         $stmt->bindParam(':lang', $langId);
         return $stmt->execute();
     } catch (PDOException $e) {
         logException($e);
         return false;
     }
 }
Пример #7
0
 /**
  * Formats a timestamp to the current user's timezone.
  *
  * @param int $Timestamp The timestamp in gmt.
  * @return int The timestamp according to the user's timezone.
  */
 public static function toTimezone($Timestamp)
 {
     static $GuestHourOffset;
     $Now = time();
     // Alter the timestamp based on the user's hour offset
     $Session = Gdn::session();
     $HourOffset = 0;
     if ($Session->UserID > 0) {
         $HourOffset = $Session->User->HourOffset;
     } elseif (class_exists('DateTimeZone')) {
         if (!isset($GuestHourOffset)) {
             $GuestTimeZone = c('Garden.GuestTimeZone');
             if ($GuestTimeZone) {
                 try {
                     $TimeZone = new DateTimeZone($GuestTimeZone);
                     $Offset = $TimeZone->getOffset(new DateTime('now', new DateTimeZone('UTC')));
                     $GuestHourOffset = floor($Offset / 3600);
                 } catch (Exception $Ex) {
                     $GuestHourOffset = 0;
                     logException($Ex);
                 }
             }
         }
         $HourOffset = $GuestHourOffset;
     }
     if ($HourOffset != 0) {
         $SecondsOffset = $HourOffset * 3600;
         $Timestamp += $SecondsOffset;
         $Now += $SecondsOffset;
     }
     return $Timestamp;
 }
Пример #8
0
 function GetNbMessages()
 {
     try {
         $query = 'SELECT COUNT(IdChatRoom) FROM ChatMessage';
         $req = $this->db->prepare($query);
         $req->execute();
         $result = $req->fetchAll();
         if (is_null($result) || count($result) != 1) {
             return -1;
         }
         $resultRow = $result[0];
         return $resultRow[0];
     } catch (Exception $e) {
         logException($e);
         die('Error: database error.');
     }
 }
Пример #9
0
/**
 * @internal
 *
 * Mango Framework uncaught exception handler
 *
 * Default Exception handler for mango. This gets called by the system
 * every time there is an uncaught exception thrown.
 *
 * @param Exception	$exception	The exception thrown
 *
 * @return void
 */
function mango_exception_handler($exception)
{
    if (!MAppDelegate()->didRecoverFromUncaughtException($exception)) {
        logException($exception);
        if (!isRunningFromCommandLine() || isRunningInSimulatedRequestMode()) {
            $response = new MHTTPViewControllerResponse(new MErrorViewController(MHTTPResponse::RESPONSE_INTERNAL_SERVER_ERROR, N(MHTTPResponse::RESPONSE_INTERNAL_SERVER_ERROR), S("Internal Server Error"), S("Sorry but the page you are looking for could not be loaded due to an internal server error")));
            $response->setCode(MHTTPResponse::RESPONSE_INTERNAL_SERVER_ERROR);
            MDie($response);
        } else {
            MDie(null, 1);
        }
    }
}
Пример #10
0
 /**
  * This function needs to be called after creating your instance of MApplication.
  * This is the entry point for your application's execution
  *
  * When you call this function, the Mango environment parses all the information
  * it needs, sets itself up and boots up its classes
  *
  * This is also where routing occours. The system finds the controller class for
  * the specified URL and loads it
  *
  * The system takes care of handling top-level errors that may occur. For example,
  * if the URL requested by the user has no registered controllers, the system returns
  * a 404 View to the user and responds with the appropriate HTTP code.
  *
  * The same thing happens if an exception is thrown and not caught or if another error
  * occurs in the execution of your code. The system catches the error, outputs the
  * appropriate error information to the error log and returns an 500 Internal Server
  * Error view to the client
  *
  * @return void
  */
 public function run()
 {
     $response = null;
     $returnCode = 0;
     if ($this->isRunningFromCommandLine()) {
         $returnCode = $this->delegate()->didFinishLaunchingFromCommandLineWithArguments($this->commandLineArguments());
     } else {
         $viewController = null;
         try {
             $this->delegate()->didFinishLaunching();
             $viewController = $this->rootViewController();
         } catch (MBadRequestException $e) {
             logException($e);
             $viewController = MObject::newInstanceOfClassWithParameters($this->errorViewControllerClass(), A(MHTTPResponse::RESPONSE_BAD_REQUEST, N(MHTTPResponse::RESPONSE_BAD_REQUEST), S("Bad Request"), $e->description()));
         } catch (MException $e) {
             logException($e);
             $viewController = MObject::newInstanceOfClassWithParameters($this->errorViewControllerClass(), A(MHTTPResponse::RESPONSE_INTERNAL_SERVER_ERROR, N(MHTTPResponse::RESPONSE_INTERNAL_SERVER_ERROR), S("Internal Server Error"), S("Sorry but the page you are looking for could not be loaded due to an internal server error")));
         }
         if (!$viewController) {
             $viewController = MObject::newInstanceOfClassWithParameters($this->errorViewControllerClass(), A(MHTTPResponse::RESPONSE_NOT_FOUND, N(MHTTPResponse::RESPONSE_NOT_FOUND), S("Not Found"), S("Sorry but the page you are looking for could not be found")));
         }
         $response = new MHTTPViewControllerResponse($viewController);
     }
     MDie($response, $returnCode);
 }