From 2e45eb8ad69d8978220e0b3ea4314545cb08fa6f Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 30 Jun 2014 14:48:03 +0200 Subject: [PATCH 1/2] Return 503 in public.php and OCS API when upgrade is due To prevent unexpected behavior, public.php and the OCS API calls will return 503 Service Unavailable when an upgrade is due. --- ocs/v1.php | 8 ++++++++ public.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/ocs/v1.php b/ocs/v1.php index d69904fc49..624355a850 100644 --- a/ocs/v1.php +++ b/ocs/v1.php @@ -23,6 +23,14 @@ require_once '../lib/base.php'; +if (\OCP\Util::needUpgrade()) { + // since the behavior of apps or remotes are unpredictable during + // an upgrade, return a 503 directly + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); + OC_Template::printErrorPage('Service unavailable'); + exit; +} + use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Exception\MethodNotAllowedException; diff --git a/public.php b/public.php index eed6394811..1f858fd073 100644 --- a/public.php +++ b/public.php @@ -3,6 +3,14 @@ try { require_once 'lib/base.php'; + if (\OCP\Util::needUpgrade()) { + // since the behavior of apps or remotes are unpredictable during + // an upgrade, return a 503 directly + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); + OC_Template::printErrorPage('Service unavailable'); + exit; + } + OC::checkMaintenanceMode(); OC::checkSingleUserMode(); $pathInfo = OC_Request::getPathInfo(); From 972fffbe02d1e0493d498859b76de698ecf5d067 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 30 Jun 2014 15:37:38 +0200 Subject: [PATCH 2/2] Return 503 OCS response with requested format --- lib/private/api.php | 2 +- ocs/v1.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/private/api.php b/lib/private/api.php index 7488769095..e9c144564f 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -301,7 +301,7 @@ class OC_API { * @param OC_OCS_Result $result * @param string $format the format xml|json */ - private static function respond($result, $format='xml') { + public static function respond($result, $format='xml') { // Send 401 headers if unauthorised if($result->getStatusCode() === self::RESPOND_UNAUTHORISED) { header('WWW-Authenticate: Basic realm="Authorisation Required"'); diff --git a/ocs/v1.php b/ocs/v1.php index 624355a850..0a86fb0641 100644 --- a/ocs/v1.php +++ b/ocs/v1.php @@ -27,7 +27,8 @@ if (\OCP\Util::needUpgrade()) { // since the behavior of apps or remotes are unpredictable during // an upgrade, return a 503 directly OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); - OC_Template::printErrorPage('Service unavailable'); + $response = new OC_OCS_Result(null, OC_Response::STATUS_SERVICE_UNAVAILABLE, 'Service unavailable'); + OC_API::respond($response, OC_API::requestedFormat()); exit; }