1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-24 23:31:01 +02:00

Various minor pending updates and optimiations to several classes

This commit is contained in:
Ryan Cramer
2019-11-08 10:29:58 -05:00
parent dd87518987
commit b972aab11b
13 changed files with 301 additions and 157 deletions

View File

@@ -102,8 +102,8 @@ class FieldtypePassword extends Fieldtype {
*
* @param Page $page
* @param Field $field
* @param string|int|array $value
* @return string|int|array|object $value
* @param array $value
* @return Password
*
*/
public function ___wakeupValue(Page $page, Field $field, $value) {

View File

@@ -415,7 +415,7 @@ class LanguageSupportPageNames extends WireData implements Module, ConfigurableM
if($event) {}
if($this->force404) {
$this->force404 = false; // prevent another 404 on the 404 page
throw new Wire404Exception();
throw new Wire404Exception('Not available in requested language', Wire404Exception::codeLanguage);
// $page = $event->wire('page');
// if(!$page || ($page->id != $event->wire('config')->http404PageID)) {
// throw new Wire404Exception();

View File

@@ -487,8 +487,12 @@ class ProcessPageAdd extends Process implements ConfigurableModule, WirePageEdit
if(!$this->parent_id) return $this->renderChooseTemplate();
$this->parent = $this->pages->get((int) $this->parent_id);
if(!$this->parent->id) throw new Wire404Exception("Unable to load parent page $this->parent_id");
if(!$this->isAllowedParent($this->parent, true, $this->template)) throw new WireException($this->errors('string'));
if(!$this->parent->id) {
throw new Wire404Exception("Unable to load parent page $this->parent_id", Wire404Exception::codeSecondary);
}
if(!$this->isAllowedParent($this->parent, true, $this->template)) {
throw new WireException($this->errors('string'));
}
if(count($this->parent->template->childTemplates) == 1) {
// only one type of template is allowed for the parent

View File

@@ -390,7 +390,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
if(!$id) {
$this->session->redirect('./bookmarks/');
throw new Wire404Exception($this->noticeUnknown); // Init error: no page provided
throw new Wire404Exception($this->noticeUnknown, Wire404Exception::codeSecondary); // Init error: no page provided
}
$this->page = $this->loadPage($id);

View File

@@ -186,7 +186,7 @@ class ProcessPageList extends Process implements ConfigurableModule {
if($this->openPage->id && $this->speed > 50) $this->speed = floor($this->speed / 2);
$this->page = $pages->get("id=" . ($this->id > 0 ? $this->id : 1) . ", status<" . Page::statusMax);
if(!$this->page) throw new Wire404Exception("Unable to load page {$this->id}");
if(!$this->page) throw new Wire404Exception("Unable to load page {$this->id}", Wire404Exception::codeSecondary);
if(!$this->page->listable()) throw new WirePermissionException("You don't have access to list page {$this->page->url}");
$this->page->setOutputFormatting(false);

View File

@@ -2216,7 +2216,9 @@ class ProcessPageLister extends Process implements ConfigurableModule {
} else {
$bookmarkID = '';
}
if(!$bookmarkID || !$this->checkBookmark($bookmarkID)) throw new Wire404Exception();
if(!$bookmarkID || !$this->checkBookmark($bookmarkID)) {
throw new Wire404Exception('Unknown Lister action', Wire404Exception::codeNonexist);
}
return $this->execute();
}

View File

@@ -162,7 +162,9 @@ class ProcessPageView extends Process {
$_page = $page;
$page = $this->checkAccess($page);
if(!$page || $_page->id == $config->http404PageID) {
return $this->pageNotFound($_page, $this->requestURL, true, 'access not allowed');
$s = 'access not allowed';
$e = new Wire404Exception($s, Wire404Exception::codePermission);
return $this->pageNotFound($_page, $this->requestURL, true, $s, $e);
}
if(!$this->delayRedirects) {
@@ -851,10 +853,10 @@ class ProcessPageView extends Process {
// use the static hasPath first to make sure this page actually has a files directory
// this ensures one isn't automatically created when we call $page->filesManager->path below
if(!PagefilesManager::hasPath($page)) throw new Wire404Exception($err);
if(!PagefilesManager::hasPath($page)) throw new Wire404Exception($err, Wire404Exception::codeFile);
$filename = $page->filesManager->path() . $basename;
if(!is_file($filename)) throw new Wire404Exception($err);
if(!is_file($filename)) throw new Wire404Exception($err, Wire404Exception::codeFile);
if($page->isPublic()) {
// deprecated, only necessary for method 2 in checkRequestFile
@@ -881,7 +883,10 @@ class ProcessPageView extends Process {
*/
protected function ___pageNotFound($page, $url, $triggerReady = false, $reason = '', $exception = null) {
if(!$exception) $exception = new Wire404Exception($reason); // create but do not throw
if(!$exception) {
// create exception but do not throw
$exception = new Wire404Exception($reason, Wire404Exception::codeNonexist);
}
$this->failed($exception, $reason, $page, $url);
$this->responseType = self::responseTypeError;