-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.3] Add offline mode support in the API #34151
Draft
wilsonge
wants to merge
24
commits into
joomla:5.3-dev
Choose a base branch
from
wilsonge:feature/offline-mode-api
base: 5.3-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d2b7d88
Add offline mode support in the API
wilsonge efcedb3
Ensure API is not cached
wilsonge 4ba043b
Fix year
wilsonge e25c35f
Fix year
wilsonge 13ebabc
Remove my useless code
wilsonge 8501b40
Fix handler
wilsonge 9586572
Fix exception path
wilsonge dc9beb1
Update libraries/src/Error/JsonApi/OfflineWebsiteExceptionHandler.php
zero-24 e0727da
Merge branch '4.0-dev' into feature/offline-mode-api
zero-24 e1f17c8
remove InstallLanguageExceptionHandler
alikon 487f726
Merge pull request #66 from alikon/patch-81
wilsonge c968a2d
Remove unused use
wilsonge 12b9267
Update libraries/src/Error/JsonApi/OfflineWebsiteExceptionHandler.php
wilsonge dc95d45
Update libraries/src/Error/JsonApi/OfflineWebsiteExceptionHandler.php
wilsonge c17055e
Update libraries/src/Error/JsonApi/OfflineWebsiteExceptionHandler.php
wilsonge c8f755e
Update libraries/src/Application/ApiApplication.php
wilsonge fb97862
Merge branch '4.1-dev' into feature/offline-mode-api
chmst 4c13992
Merge tag 'psr12anchor' into psr12/merge/34151
joomla-bot aeb1f9c
Phase 1 convert BRANCH to PSR-12
joomla-bot 71ea1cd
Phase 2 convert BRANCH to PSR-12
joomla-bot 5733d95
Merge tag 'psr12final' into psr12/merge/34151
joomla-bot 0700bec
Merge branch '4.2-dev' into feature/offline-mode-api
laoneo d46dbf1
Merge branch '4.3-dev' into feature/offline-mode-api
laoneo f51a4b7
Merge branch '4.3-dev' into feature/offline-mode-api
laoneo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,8 +146,32 @@ public function addFormatMap($contentHeader, $format) | |
*/ | ||
protected function render() | ||
{ | ||
// Trigger the onBeforeRender event. | ||
PluginHelper::importPlugin('system'); | ||
$this->triggerEvent('onBeforeRender'); | ||
|
||
/** | ||
* Check we aren't in offline mode. In which case for users who can't access the site the API is disabled | ||
* and we won't show anything! | ||
*/ | ||
if ($this->get('offline') && !$this->getIdentity()->authorise('core.login.offline')) { | ||
$offlineMessage = ''; | ||
|
||
if ($this->get('display_offline_message', true) == true) { | ||
$offlineMessage = $this->get('offline_message'); | ||
} | ||
|
||
throw new Exception\OfflineWebsiteException($offlineMessage); | ||
} | ||
|
||
// Render the document | ||
$this->setBody($this->document->render($this->allowCache())); | ||
|
||
// Trigger the onAfterRender event. | ||
$this->triggerEvent('onAfterRender'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as comment above. |
||
|
||
// Mark afterRender in the profiler. | ||
JDEBUG ? $this->profiler->mark('afterRender') : null; | ||
} | ||
|
||
/** | ||
|
19 changes: 19 additions & 0 deletions
19
libraries/src/Application/Exception/OfflineWebsiteException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org> | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\CMS\Application\Exception; | ||
|
||
/** | ||
* Exception class for a website that is in offline mode! | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class OfflineWebsiteException extends \RuntimeException | ||
{ | ||
} |
61 changes: 61 additions & 0 deletions
61
libraries/src/Error/JsonApi/OfflineWebsiteExceptionHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org> | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\CMS\Error\JsonApi; | ||
|
||
use Exception; | ||
use Joomla\CMS\Application\Exception\OfflineWebsiteException; | ||
use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface; | ||
use Tobscure\JsonApi\Exception\Handler\ResponseBag; | ||
|
||
/** | ||
* Handler for the site being in offline mode | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class OfflineWebsiteExceptionHandler implements ExceptionHandlerInterface | ||
{ | ||
/** | ||
* If the exception handler is able to format a response for the provided exception, | ||
* then the implementation should return true. | ||
* | ||
* @param \Exception $e The exception to be handled | ||
* | ||
* @return boolean | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function manages(Exception $e) | ||
{ | ||
return $e instanceof OfflineWebsiteException; | ||
} | ||
|
||
/** | ||
* Handle the provided exception. | ||
* | ||
* @param Exception $e The exception being handled | ||
* | ||
* @return \Tobscure\JsonApi\Exception\Handler\ResponseBag | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function handle(Exception $e) | ||
{ | ||
$status = 503; | ||
$error = ['title' => $e->getMessage()]; | ||
|
||
$code = $e->getCode(); | ||
|
||
if ($code) { | ||
$error['code'] = $code; | ||
} | ||
|
||
return new ResponseBag($status, [$error]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this event triggering, so we can merge it in 4.3 and make a new pr on 5.0. I fear these events will have some undesired effect, so it is better to add it in 5.0 and document it properly.