Skip to content
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.2] Add offline mode support in the API #34151

Draft
wants to merge 24 commits into
base: 5.2-dev
Choose a base branch
from

Conversation

wilsonge
Copy link
Contributor

@wilsonge wilsonge commented May 23, 2021

Pull Request for Issue # .

Summary of Changes

Adds support for the onBeforeRender and onAfterRender events to the API. It should be noted our core plugin correctly checks for html document types or if in site/admin modes in most places. The only exception to this is the cache plugin. However I think this won't change much because we don't call onAfterRoute in the API which does all the initialisation anyhow.

Adds support for offline mode to the API - if the site is in offline mode the API now should not be made available to users who cannot access it alongside an appropriate 503 status code

Testing Instructions

Turn on Offline mode. Before this PR check that the API is accessible. After PR you get a 503 error code.

For the Plugin events this should be as easy as dropping some test functions into an existing plugin.

Documentation Changes Required

N/A

@wilsonge wilsonge changed the title Add offline mode support in the API [4.0] Add offline mode support in the API May 23, 2021
@richard67
Copy link
Member

Testing instructions
Turn on API mode.

@wilsonge I assume you meant "offline mode" and not "API mode", or there is a new feature "API mode" in J4 of which I don't know yet.

@richard67
Copy link
Member

@wilsonge It seems you have to adjust the API tests to the changes in this PR. Currently they fail with:

1) BasicCest: Test route not found
 Test  tests/Codeception/api/BasicCest.php:testRouteNotFound
 Step  See response code is 404
 Fail  Expected HTTP Status Code: 404 (Not Found). Actual Status Code: 503 (Service Unavailable)
Failed asserting that 503 matches expected 404.

@wilsonge
Copy link
Contributor Author

Yup I did mean Offline mode - fixed that. Will look at tests tonight :)

@wilsonge
Copy link
Contributor Author

Tests fixed

@alikon
Copy link
Contributor

alikon commented May 25, 2021

humm got 500 shoduln't be 503 ?

{
    "errors": [
        {
            "code": 500,
            "title": "Internal server error",
            "detail": "Joomla\\CMS\\Application\\Exception\\OfflineWebsiteException: This site is down for maintenance.<br />Please check back again soon. in /var/www/html/cloud/libraries/src/Application/ApiApplication.php:162\nStack trace:\n#0 /var/www/html/cloud/libraries/src/Application/CMSApplication.php(284): Joomla\\CMS\\Application\\ApiApplication->render()\n#1 /var/www/html/cloud/api/includes/app.php(54): Joomla\\CMS\\Application\\CMSApplication->execute()\n#2 /var/www/html/cloud/api/index.php(31): require_once('/var/www/html/c...')\n#3 {main}"
        }
    ]
}

@wilsonge
Copy link
Contributor Author

Fixed

@alikon
Copy link
Contributor

alikon commented Jun 4, 2021

something is going wrong in your merge

$errors->registerHandler(new InstallLanguageExceptionHandler);

fe93f16

@alikon
Copy link
Contributor

alikon commented Jun 5, 2021

i dunno if this was already there...
anyway with
core.login.offline = false and wrong request articlesx
got this from postman

Screenshot from 2021-06-05 11-07-57

my usual dirty hack wilsonge#67

@wilsonge
Copy link
Contributor Author

wilsonge commented Jun 5, 2021

That one is a bit hacky :) will debug when I’m in front of my laptop this evening. May be there’s nothing better but 🤷‍♂️

@laoneo laoneo changed the base branch from 4.2-dev to 4.3-dev October 21, 2022 11:54
@joomla-cms-bot joomla-cms-bot added Language Change This is for Translators PR-4.3-dev labels Oct 21, 2022
@joomla-cms-bot joomla-cms-bot removed the Language Change This is for Translators label Oct 22, 2022
@@ -146,8 +146,32 @@ public function addFormatMap($contentHeader, $format)
*/
protected function render()
{
// Trigger the onBeforeRender event.
PluginHelper::importPlugin('system');
Copy link
Member

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.

// Render the document
$this->setBody($this->document->render($this->allowCache()));

// Trigger the onAfterRender event.
$this->triggerEvent('onAfterRender');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as comment above.

@HLeithner HLeithner removed the psr12 label Oct 23, 2022
@laoneo
Copy link
Member

laoneo commented Oct 27, 2022

@wilsonge any interest to move this one forward?

@Quy Quy added Language Change This is for Translators psr12 and removed PR-4.2-dev labels Oct 27, 2022
@Hackwar Hackwar removed the psr12 label Feb 21, 2023
@Hackwar Hackwar added the Feature label Apr 6, 2023
@HLeithner HLeithner changed the base branch from 4.3-dev to 5.0-dev May 8, 2023 15:03
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.0-dev. No new features will be merged into Joomla! 4.3 series. Joomla! 4.4 series is a bridge release to make migration from Joomla! 4 to 5 as smooth as possible.

@HLeithner HLeithner marked this pull request as draft September 17, 2023 17:14
@HLeithner HLeithner changed the base branch from 5.0-dev to 5.1-dev September 30, 2023 22:52
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.1-dev.

@HLeithner HLeithner changed the base branch from 5.1-dev to 5.2-dev April 24, 2024 09:10
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.2-dev.

@HLeithner HLeithner changed the title [4.0] Add offline mode support in the API [5.2] Add offline mode support in the API Apr 24, 2024
@joomla-cms-bot joomla-cms-bot added PR-5.2-dev and removed Language Change This is for Translators labels Apr 24, 2024
@laoneo laoneo removed their assignment May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet