1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-11 17:24:46 +02:00

Various minor adjustments

This commit is contained in:
Ryan Cramer
2021-06-11 14:00:55 -04:00
parent 3229d2371e
commit c81aa1a82a
4 changed files with 31 additions and 13 deletions

View File

@@ -4,6 +4,7 @@
* ProcessWire Fieldtypes * ProcessWire Fieldtypes
* *
* #pw-summary Maintains a collection of Fieldtype modules. * #pw-summary Maintains a collection of Fieldtype modules.
* #pw-var $fieldtypes
* *
* ProcessWire 3.x, Copyright 2020 by Ryan Cramer * ProcessWire 3.x, Copyright 2020 by Ryan Cramer
* https://processwire.com * https://processwire.com

View File

@@ -1478,17 +1478,24 @@ class Session extends Wire implements \IteratorAggregate {
// prevent multiple calls, just in case // prevent multiple calls, just in case
$this->skipMaintenance = true; $this->skipMaintenance = true;
$historyCnt = (int) $this->config->sessionHistory; $config = $this->wire()->config;
$historyCnt = (int) ($config ? $config->sessionHistory : 0);
if($historyCnt) { if($historyCnt) {
$sanitizer = $this->wire()->sanitizer;
$input = $this->wire()->input;
$page = $this->wire()->page;
if(!$sanitizer || !$input || !$page) return;
$history = $this->get('_user', 'history'); $history = $this->get('_user', 'history');
if(!is_array($history)) $history = array(); if(!is_array($history)) $history = array();
$item = array( $item = array(
'time' => time(), 'time' => time(),
'url' => $this->wire('sanitizer')->entities($this->wire('input')->httpUrl()), 'url' => $sanitizer->entities($input->httpUrl()),
'page' => $this->wire('page')->id, 'page' => $page->id,
); );
$cnt = count($history); $cnt = count($history);

View File

@@ -716,15 +716,22 @@ class WireCache extends Wire {
public function maintenance($obj = null) { public function maintenance($obj = null) {
static $done = false; static $done = false;
$forceRun = false; $forceRun = false;
$database = $this->wire()->database;
$config = $this->wire()->config;
if(!$database || !$config) return false;
if(is_object($obj)) { if(is_object($obj)) {
// check to see if it is worthwhile to perform this kind of maintenance at all // check to see if it is worthwhile to perform this kind of maintenance at all
if(is_null($this->usePageTemplateMaintenance)) { if(is_null($this->usePageTemplateMaintenance)) {
$templates = $this->wire()->templates;
if(!$templates) $templates = array();
$minID = 999999; $minID = 999999;
$maxID = 0; $maxID = 0;
foreach($this->wire('templates') as $template) { foreach($templates as $template) {
if($template->id > $maxID) $maxID = $template->id; if($template->id > $maxID) $maxID = $template->id;
if($template->id < $minID) $minID = $template->id; if($template->id < $minID) $minID = $template->id;
} }
@@ -733,7 +740,7 @@ class WireCache extends Wire {
"WHERE (expires=:expireSave OR expires=:expireSelector) " . "WHERE (expires=:expireSave OR expires=:expireSelector) " .
"OR (expires>=:minID AND expires<=:maxID)"; "OR (expires>=:minID AND expires<=:maxID)";
$query = $this->wire('database')->prepare($sql); $query = $database->prepare($sql);
$query->bindValue(':expireSave', self::expireSave); $query->bindValue(':expireSave', self::expireSave);
$query->bindValue(':expireSelector', self::expireSelector); $query->bindValue(':expireSelector', self::expireSelector);
$query->bindValue(':minID', date(self::dateFormat, $minID)); $query->bindValue(':minID', date(self::dateFormat, $minID));
@@ -764,7 +771,7 @@ class WireCache extends Wire {
} }
// don't perform general maintenance during ajax requests // don't perform general maintenance during ajax requests
if($this->wire('config')->ajax && !$forceRun) return false; if($config->ajax && !$forceRun) return false;
// perform general maintenance now // perform general maintenance now
return $this->maintenanceGeneral(); return $this->maintenanceGeneral();
@@ -778,9 +785,10 @@ class WireCache extends Wire {
*/ */
protected function maintenanceGeneral() { protected function maintenanceGeneral() {
$sql = 'DELETE FROM caches WHERE (expires<=:now AND expires>:never) '; $database = $this->wire()->database;
$query = $this->wire('database')->prepare($sql, "cache.maintenance()"); $sql = 'DELETE FROM caches WHERE (expires<=:now AND expires>:never) ';
$query = $database->prepare($sql, "cache.maintenance()");
$query->bindValue(':now', date(self::dateFormat, time())); $query->bindValue(':now', date(self::dateFormat, time()));
$query->bindValue(':never', self::expireNever); $query->bindValue(':never', self::expireNever);
@@ -808,11 +816,13 @@ class WireCache extends Wire {
*/ */
protected function maintenancePage(Page $page) { protected function maintenancePage(Page $page) {
$database = $this->wire()->database;
if(is_null($this->cacheNameSelectors)) { if(is_null($this->cacheNameSelectors)) {
// locate all caches that specify selector strings and cache them so that // locate all caches that specify selector strings and cache them so that
// we don't have to re-load them on every page save // we don't have to re-load them on every page save
try { try {
$query = $this->wire('database')->prepare("SELECT * FROM caches WHERE expires=:expire"); $query = $database->prepare("SELECT * FROM caches WHERE expires=:expire");
$query->bindValue(':expire', self::expireSelector); $query->bindValue(':expire', self::expireSelector);
$query->execute(); $query->execute();
$this->cacheNameSelectors = array(); $this->cacheNameSelectors = array();
@@ -853,7 +863,7 @@ class WireCache extends Wire {
$sql .= "OR name=:$key "; $sql .= "OR name=:$key ";
} }
$query = $this->wire('database')->prepare("DELETE FROM caches WHERE $sql"); $query = $database->prepare("DELETE FROM caches WHERE $sql");
// bind values // bind values
$query->bindValue(':expireSave', self::expireSave); $query->bindValue(':expireSave', self::expireSave);
@@ -880,7 +890,7 @@ class WireCache extends Wire {
protected function maintenanceTemplate(Template $template) { protected function maintenanceTemplate(Template $template) {
$sql = 'DELETE FROM caches WHERE expires=:expireTemplateID OR expires=:expireSave'; $sql = 'DELETE FROM caches WHERE expires=:expireTemplateID OR expires=:expireSave';
$query = $this->wire('database')->prepare($sql); $query = $this->wire()->database->prepare($sql);
$query->bindValue(':expireSave', self::expireSave); $query->bindValue(':expireSave', self::expireSave);
$query->bindValue(':expireTemplateID', date(self::dateFormat, $template->id)); $query->bindValue(':expireTemplateID', date(self::dateFormat, $template->id));

View File

@@ -364,7 +364,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
$selector .= ", $s->value"; $selector .= ", $s->value";
} }
$template = $this->getSelectorTemplates($selector); $template = $this->getSelectorTemplates($selector);
if(count($template)) $this->set('template', reset($template)); if(count($template) === 1) $this->set('template', reset($template));
} }
if($input->post('reset_total')) { if($input->post('reset_total')) {