Skip to content

Commit

Permalink
Initial work restoring 404 handling in Datasources and catching recur…
Browse files Browse the repository at this point in the history
…sive 404's. RE: #1539
  • Loading branch information
brendo committed Jan 14, 2013
1 parent 71d6178 commit 1f86823
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 15 deletions.
25 changes: 21 additions & 4 deletions symphony/lib/core/class.frontend.php
Expand Up @@ -112,7 +112,7 @@ public function display($page) {
*
* @see core.FrontendPageNotFoundExceptionHandler
*/
Class FrontendPageNotFoundException extends Exception{
Class FrontendPageNotFoundException extends Exception {

/**
* The constructor for `FrontendPageNotFoundException` sets the default
Expand All @@ -121,9 +121,11 @@ public function display($page) {
public function __construct() {
parent::__construct();
$pagename = getCurrentPage();

if (empty($pagename)) {
$this->message = __('The page you requested does not exist.');
} else {
}
else {
$this->message = __('The page you requested, %s, does not exist.', array('<code>' . $pagename . '</code>'));
}
$this->code = E_USER_NOTICE;
Expand Down Expand Up @@ -151,8 +153,10 @@ public function __construct() {
*/
public static function render(Exception $e){
$page = PageManager::fetchPageByType('404');
$previous_exception = Frontend::instance()->getException();

if(is_null($page['id'])){
// No 404 detected, throw default Symphony error page
if(is_null($page['id'])) {
parent::render(new SymphonyErrorPage(
$e->getMessage(),
__('Page Not Found'),
Expand All @@ -162,9 +166,22 @@ public static function render(Exception $e){
)
);
}
else{
// Recursive 404
else if (isset($previous_exception)) {
parent::render(new SymphonyErrorPage(
__('This error occurred whilst attempting to resolve the 404 page for the original request.') . ' ' . $e->getMessage(),
__('Page Not Found'),
'generic',
array(),
Page::HTTP_STATUS_NOT_FOUND
)
);
}
// Handle 404 page
else {
$url = '/' . PageManager::resolvePagePath($page['id']) . '/';

Frontend::instance()->setException($e);
$output = Frontend::instance()->display($url);
echo $output;
exit;
Expand Down
28 changes: 28 additions & 0 deletions symphony/lib/core/class.symphony.php
Expand Up @@ -75,6 +75,13 @@
*/
private static $namespace = false;

/**
* A previous exception that has been fired. Defaults to null.
* @since Symphony 2.3.2
* @var Exception
*/
private $exception = null;

/**
* An instance of the Cookie class
* @var Cookie
Expand Down Expand Up @@ -565,6 +572,27 @@ public function throwCustomError($message, $heading='Symphony Fatal Error', $sta
throw new SymphonyErrorPage($message, $heading, $template, $additional, $status);
}

/**
* Setter accepts a previous Exception. Useful for determining the context
* of a current exception (ie. detecting recursion).
*
* @since Symphony 2.3.2
* @param Exception $ex
*/
public function setException(Exception $ex) {
$this->exception = $ex;
}

/**
* Accessor for `$this->exception`.
*
* @since Symphony 2.3.2
* @return Exception|null
*/
public function getException() {
return $this->exception;
}

/**
* Given the `$page_id` and a `$column`, this function will return an
* array of the given `$column` for the Page, including all parents.
Expand Down
12 changes: 6 additions & 6 deletions symphony/lib/toolkit/data-sources/class.datasource.section.php
Expand Up @@ -13,6 +13,9 @@
* @since Symphony 2.3
* @link http://symphony-cms.com/learn/concepts/view/data-sources/
*/

require_once(TOOLKIT . '/class.entrymanager.php');

Class SectionDatasource extends Datasource {

/**
Expand Down Expand Up @@ -361,13 +364,10 @@ public function processFilters(&$where, &$joins, &$group) {
public function execute(array &$param_pool) {
$result = new XMLElement($this->dsParamROOTELEMENT);
$this->_param_pool = $param_pool;

$where = NULL;
$joins = NULL;
$where = null;
$joins = null;
$group = false;

include_once(TOOLKIT . '/class.entrymanager.php');

if(!$section = SectionManager::fetch((int)$this->getSource())){
$about = $this->about();
trigger_error(__('The Section, %s, associated with the Data source, %s, could not be found.', array($this->getSource(), '<code>' . $about['name'] . '</code>')), E_USER_ERROR);
Expand Down Expand Up @@ -459,7 +459,7 @@ public function execute(array &$param_pool) {
));

if(($entries['total-entries'] <= 0 || $include_pagination_element === true) && (!is_array($entries['records']) || empty($entries['records'])) || $this->dsParamSTARTPAGE == '0'){
if($this->dsParamREDIRECTONEMPTY == 'yes'){
if($this->dsParamREDIRECTONEMPTY == 'yes') {
throw new FrontendPageNotFoundException;
}
$this->_force_empty_result = false;
Expand Down
29 changes: 24 additions & 5 deletions symphony/template/blueprints.datasource.tpl
Expand Up @@ -2,20 +2,20 @@

require_once(TOOLKIT . '/class.datasource.php');

Class datasource<!-- CLASS NAME --> extends <!-- CLASS EXTENDS -->{
Class datasource<!-- CLASS NAME --> extends <!-- CLASS EXTENDS --> {
<!-- VAR LIST -->
<!-- FILTERS -->
<!-- INCLUDED ELEMENTS -->
public function __construct($env=NULL, $process_params=true){
public function __construct($env=NULL, $process_params=true) {
parent::__construct($env, $process_params);
$this->_dependencies = array(<!-- DS DEPENDENCY LIST -->);
}

public function about(){
public function about() {
return array(
'name' => '<!-- NAME -->',
'author' => array(
Expand All @@ -27,12 +27,31 @@
);
}

public function getSource(){
public function getSource() {
return '<!-- SOURCE -->';
}

public function allowEditorToParse(){
public function allowEditorToParse() {
return true;
}

public function execute($param_pool = null) {

This comment has been minimized.

Copy link
@designermonkey

designermonkey Feb 6, 2013

Member

$param_pool must be $param_pool = array()

try{
$result = parent::execute();

This comment has been minimized.

Copy link
@designermonkey

designermonkey Feb 6, 2013

Member

This needs $param_pool passing in

}
catch(FrontendPageNotFoundException $e){
// Work around. This ensures the 404 page is displayed and
// is not picked up by the default catch() statement below
FrontendPageNotFoundExceptionHandler::render($e);
}
catch(Exception $e){
$result->appendChild(new XMLElement('error', $e->getMessage()));

This comment has been minimized.

Copy link
@designermonkey

designermonkey Feb 6, 2013

Member

This will fail as $result is not defined anywhere.

return $result;
}

if($this->_force_empty_result) $result = $this->emptyXMLSet();

return $result;
}

}

2 comments on commit 1f86823

@brendo
Copy link
Member Author

@brendo brendo commented on 1f86823 Feb 6, 2013

Choose a reason for hiding this comment

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

All very true. Will update ASAP.

edit This has already been resolved, f235a0a and 0eed2c9

@designermonkey
Copy link
Member

Choose a reason for hiding this comment

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

I looked through the entire commit history last night and missed both of those o_O

Sorry.

Please sign in to comment.