forked from pixelant/pxa_lpeh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [FEATURE] Added fallback to PageContentErrorHandler Wrapped in a try block. If this still doesn't return a result, we show a generic error page. * [BUGFIX] Compatibility with TYPO3 v9 and v10 * [FEATURE] Override default Page Content error handler by default Can be disabled through extension configuration. * [TASK] Increased PHP dependency to ^7.2 * [TASK] Updated description and contact info * [FEATURE] Handle language fallback and use TYPO3 APIs * [DOCS] Updated README.md
- Loading branch information
Showing
7 changed files
with
125 additions
and
52 deletions.
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
26 changes: 17 additions & 9 deletions
26
Configuration/SiteConfiguration/Overrides/site_errorhandling.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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
<?php | ||
// Show both errorPhpClassFQCN and errorContentSource for PHP Class error handler | ||
$currentShowItem = $GLOBALS['SiteConfiguration']['site_errorhandling']['types']['PHP']['showitem']; | ||
if (strpos($currentShowItem, 'errorContentSource') === false) { | ||
// Add errorContentSource for PHP Class error handler if not already present | ||
$GLOBALS['SiteConfiguration']['site_errorhandling']['types']['PHP']['showitem'] = str_replace( | ||
'errorPhpClassFQCN', | ||
'errorPhpClassFQCN, errorContentSource', | ||
$GLOBALS['SiteConfiguration']['site_errorhandling']['types']['PHP']['showitem'] | ||
); | ||
|
||
if ( | ||
!TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( | ||
TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class | ||
) | ||
->get('pxa_lpeh', 'disableXClass') | ||
) { | ||
// Show both errorPhpClassFQCN and errorContentSource for PHP Class error handler | ||
$currentShowItem = $GLOBALS['SiteConfiguration']['site_errorhandling']['types']['PHP']['showitem']; | ||
if (strpos($currentShowItem, 'errorContentSource') === false) { | ||
// Add errorContentSource for PHP Class error handler if not already present | ||
$GLOBALS['SiteConfiguration']['site_errorhandling']['types']['PHP']['showitem'] = str_replace( | ||
'errorPhpClassFQCN', | ||
'errorPhpClassFQCN, errorContentSource', | ||
$GLOBALS['SiteConfiguration']['site_errorhandling']['types']['PHP']['showitem'] | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,14 +1,47 @@ | ||
# pxa_lpeh | ||
# Local Page Error Handler for TYPO3 | ||
|
||
Local Page Error Handler | ||
This extension speeds up error page handling and frees up PHP workers by loading local page content without issuing an external HTTP request. | ||
|
||
To use as error handler, go to site configuration "Error Handler" tab. | ||
The speed increase depends on the round-trip time for external HTTP requests for your server (including resolving the DNS), but it could easily be 3x what you're having today. | ||
|
||
## Installation | ||
|
||
1. Download from the TYPO3 Extension Repository or require the extension using Composer: `composer req pixelant/pxa-lpeh` | ||
2. Enable the extension in the Admin tools > Extensions module or run `vendor/bin/typo3 extension:activate pxa_lpeh` | ||
|
||
## Configuration | ||
|
||
### Default Configuration | ||
|
||
No configuration is required by default. | ||
|
||
The extension will use the configuration for any "Show Content from Page" error handler. | ||
|
||
* Make internal requests where Show Content From Page is to an internal TYPO3 page, e.g. "t3://page?uid=404". | ||
* External requests will behave normally and issue an external request. E.g. where Show Content From Page points to "https://www.example.com". | ||
|
||
### Disabling Page Content Error Handler Override | ||
|
||
By default, this extension overrides the `PageContentErrorHandler` class and calls this class only if the Error Handler configuration explicitly requires an external request. | ||
|
||
You can disable this override in the Admin tools > Settings > Extension Configuration by checking the box "Don't replace the standard 'Show Content from Page' error handler, use 'PHP Class' instead". | ||
|
||
This extension can still be used by explicitly configuring a PHP Error Handler Class in Site management > Sites > [Your Site] > Error Handling: | ||
|
||
1. Create a new error handling | ||
2. Set "HTTP Error Status Code" to 404 | ||
3. Set "How to handle Errors" to "PHP Class" | ||
4. Set "ErrorHandler Class Target (FQCN)" to ```Pixelant\PxaLpeh\Error\PageErrorHandler\LocalPageErrorHandler``` | ||
5. Set "Show Content from Page" to a *page* in current Site to generate a link e.g. t3://page?uid=78 | ||
|
||
If TYPO3 fails to fetch the page, a "generic" TYPO3 error page will be displayed with the http status code. | ||
This might be e.g. the link isn't to a page, the page doesn't exist in this site etc. | ||
### Avoiding Hung HTTP Requests | ||
|
||
External requests for error pages can hang your site during high-load situations. We recommend setting `$GLOBALS['TYPO3_CONF_VARS']['HTTP']['timeout']` to a non-zero value to alleviate this problem. | ||
|
||
## Ultimate Error Fallback | ||
|
||
If fetching the page fails, a "generic" TYPO3 error page will be displayed with the http status code. This might be e.g. the link isn't to a page, the page doesn't exist in this site etc. | ||
|
||
## Issues and Contribution | ||
|
||
Please feel free to submit issues or contribute pull requests to this extension. |
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
{ | ||
"name": "pixelant/pxa-lpeh", | ||
"description": "Local Page Error Handler for TYPO3 CMS.", | ||
"description": "Speeds up error page handling and frees up PHP workers by loading local page content without issuing an external HTTP request.", | ||
"version": "1.0.0", | ||
"type": "typo3-cms-extension", | ||
"license": "GPL-3.0+", | ||
"authors": [ | ||
{ | ||
"name": "Pixelant", | ||
"email": "[email protected]", | ||
"homepage": "https://www.pixelant.se", | ||
"role": "Developer" | ||
} | ||
|
@@ -23,7 +24,7 @@ | |
"pixelant/pxa-lpeh": "self.version" | ||
}, | ||
"require": { | ||
"php": ">= 7.0, <=7.3", | ||
"php": "^7.2", | ||
"typo3/cms-core": "^9.5.0 || ^10.1.0" | ||
}, | ||
"autoload": { | ||
|
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,2 @@ | ||
# cat=Runtime; type=boolean; label=Don't replace the standard "Show Content from Page" error handler, use "PHP Class" instead | ||
disableXClass = 0 |
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
<?php | ||
$EM_CONF[$_EXTKEY] = array( | ||
'title' => 'Local Page Error Handler', | ||
'description' => 'Add Local Page Error Handler to TYPO3', | ||
'description' => 'Speeds up error page handling and frees up PHP workers by loading local page content without issuing an external HTTP request.', | ||
'category' => 'fe', | ||
'author' => 'Pixelant', | ||
'author_email' => '', | ||
'author_email' => '[email protected]', | ||
'author_company' => 'Pixelant', | ||
'state' => 'alpha', | ||
'state' => 'stable', | ||
'uploadfolder' => 0, | ||
'createDirs' => '', | ||
'clearCacheOnLoad' => 0, | ||
|
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 | ||
defined('TYPO3_MODE') or die(); | ||
|
||
$boot = function() { | ||
if ( | ||
!TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( | ||
TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class | ||
) | ||
->get('pxa_lpeh', 'disableXClass') | ||
) { | ||
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][TYPO3\CMS\Core\Error\PageErrorHandler\PageContentErrorHandler::class] = [ | ||
'className' => Pixelant\PxaLpeh\Error\PageErrorHandler\LocalPageErrorHandler::class | ||
]; | ||
} | ||
|
||
}; | ||
|
||
$boot(); | ||
unset($boot); |