Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
* Indexes the children of a document in their menu order.
*
* Child listings (getDocumentChildren, getActiveChildren, the document tree)
* filter by parent and sort by menuindex. With an index on parent alone the
* database reads every child and sorts them before applying a limit; with
* (parent, menuindex) it reads the first rows of the index in order.
*/
class AddParentMenuindexIndexToSiteContent extends Migration {
public function up() {
if (!Schema::hasTable('site_content') || Schema::hasIndex('site_content', ['parent', 'menuindex'])) {
return;
}

Schema::table('site_content', function (Blueprint $table) {
$table->index(['parent', 'menuindex'], \DB::getTablePrefix() . $table->getTable() . '_parent_menuindex');
});
}

public function down() {
if (Schema::hasTable('site_content') && Schema::hasIndex('site_content', ['parent', 'menuindex'])) {
Schema::table('site_content', function (Blueprint $table) {
$table->dropIndex(\DB::getTablePrefix() . $table->getTable() . '_parent_menuindex');
});
}
}
}
24 changes: 15 additions & 9 deletions core/factory/settings.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php return [
<?php

// $known: settings the caller already has a value for. Their defaults are not
// translated (`??` skips the call), since the caller's value replaces them anyway.
$known ??= [];

return [
'site_name' => 'My Evolution CMS Site',
'site_start' => 1,
'error_page' => 1,
Expand All @@ -11,8 +17,8 @@
'enable_filter' => 0,
'enable_at_syntax' => 0,
'minifyphp_incache' => 0,
'rss_url_releases' => __('global.rss_url_releases_default', [], $factoryLocale),
'rss_url_extras' => __('global.rss_url_extras_default', [], $factoryLocale),
'rss_url_releases' => $known['rss_url_releases'] ?? __('global.rss_url_releases_default', [], $factoryLocale),
'rss_url_extras' => $known['rss_url_extras'] ?? __('global.rss_url_extras_default', [], $factoryLocale),
'friendly_urls' => 0,
'friendly_url_prefix' => '',
'friendly_url_suffix' => '/',
Expand All @@ -33,15 +39,15 @@
'error_reporting' => '1',
'send_errormail' => '0',
'enable_bindings' => 1,
'captcha_words' => __('global.captcha_words_default', [], $factoryLocale),
'captcha_words' => $known['captcha_words'] ?? __('global.captcha_words_default', [], $factoryLocale),
'emailsender' => '[email protected]',
'smtp_host' => 'smtp.example.com',
'smtp_port' => 25,
'smtp_username' => 'emailsender',
'emailsubject' => __('global.emailsubject_default', [], $factoryLocale),
'signupemail_message' => __('global.system_email_signup', [], $factoryLocale),
'websignupemail_message' => __('global.system_email_websignup', [], $factoryLocale),
'webpwdreminder_message' => __('global.system_email_webreminder', [], $factoryLocale),
'emailsubject' => $known['emailsubject'] ?? __('global.emailsubject_default', [], $factoryLocale),
'signupemail_message' => $known['signupemail_message'] ?? __('global.system_email_signup', [], $factoryLocale),
'websignupemail_message' => $known['websignupemail_message'] ?? __('global.system_email_websignup', [], $factoryLocale),
'webpwdreminder_message' => $known['webpwdreminder_message'] ?? __('global.system_email_webreminder', [], $factoryLocale),
'warning_visibility' => 1,
'tree_page_click' => 27,
'use_breadcrumbs' => 0,
Expand Down Expand Up @@ -79,7 +85,7 @@
'denyExtensionRename' => 0,
'showHiddenFiles' => 0,
'session_timeout' => 15,
'site_unavailable_message' => __('global.siteunavailable_message_default', [], $factoryLocale),
'site_unavailable_message' => $known['site_unavailable_message'] ?? __('global.siteunavailable_message_default', [], $factoryLocale),
'allow_eval' => 'with_scan',
'safe_functions_at_eval' => 'time,date,strtotime,strftime',
'use_udperms' => '1',
Expand Down
53 changes: 32 additions & 21 deletions core/src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -2928,16 +2928,16 @@ public function getDocumentObject($method, $identifier, $isPrepareResponse = fal
$documentObject = null;
if ($this->isFrontend() && $method === 'id') {
// Public documents need no group lookup. Keep the ACL query below for private documents.
$documentObject = SiteContent::query()
$documentObject = SiteContent::toArrays(SiteContent::query()
->where('site_content.id', $identifier)
->where('site_content.privateweb', 0)
->first();
->limit(1))[0] ?? null;
}
if (is_null($documentObject)) {
$documentObject = SiteContent::query()
$documentObject = SiteContent::toArrays(SiteContent::query()
->withoutProtected()
->where('site_content.' . $method, $identifier)
->first();
->limit(1))[0] ?? null;
}
if (is_null($documentObject)) {
$seclimit = 0;
Expand All @@ -2961,9 +2961,10 @@ public function getDocumentObject($method, $identifier, $isPrepareResponse = fal
$this->sendErrorPage();
}
}
// No such document (this used to end in a fatal error on null->toArray()).
$this->sendErrorPage();
}
//this is now the document :)
$documentObject = $documentObject->toArray();
unset($documentObject['document_group'], $documentObject['document']);
$documentObject['id'] = $identifier;

Expand Down Expand Up @@ -2992,7 +2993,7 @@ public function getDocumentObject($method, $identifier, $isPrepareResponse = fal
->leftJoin('site_tmplvar_contentvalues', function ($join) use ($documentObject) {
$join->on('site_tmplvar_contentvalues.tmplvarid', '=', 'site_tmplvars.id');
$join->on('site_tmplvar_contentvalues.contentid', '=', \DB::raw((int) $documentObject['id']));
})->where('site_tmplvar_templates.templateid', $documentObject['template'])->get();
})->where('site_tmplvar_templates.templateid', $documentObject['template'])->toBase()->get();

$tmplvars = [];
foreach ($tvs as $tv) {
Expand Down Expand Up @@ -3242,15 +3243,24 @@ public function executeParser()
$this->documentIdentifier = UrlProcessor::getFacadeRoot()->documentListing[$alias];
} else {
if ($this->getConfig('aliaslistingfolder') == 1 || $this->getConfig('full_aliaslisting') == 1) {
$parent = $virtualDir ? UrlProcessor::getIdFromAlias($virtualDir) : 0;
$doc = SiteContent::select('id')
->where('deleted', 0)
->where('parent', $parent)
->where('alias', $this->documentIdentifier)->first();
if (is_null($doc)) {
$docId = null;
// A folder path not in the listing took a query per segment; a path
// of plain aliases is resolved with one, anything else as before.
if ($virtualDir != '' && !isset(UrlProcessor::getFacadeRoot()->documentListing[$virtualDir])) {
$docId = UrlProcessor::getFacadeRoot()->findIdByAliasPath($alias);
}
if ($docId === null) {
$parent = $virtualDir ? UrlProcessor::getIdFromAlias($virtualDir) : 0;
$docId = SiteContent::query()
->where('deleted', 0)
->where('parent', $parent)
->where('alias', $this->documentIdentifier)
->toBase()->value('id');
}
if (is_null($docId)) {
$this->sendErrorPage();
}
$this->documentIdentifier = $doc->getKey();
$this->documentIdentifier = (int) $docId;
} else {
$this->sendErrorPage();
}
Expand All @@ -3261,13 +3271,14 @@ public function executeParser()
$this->documentIdentifier = UrlProcessor::getFacadeRoot()
->documentListing[$this->documentIdentifier];
} else {
$doc = SiteContent::select('id')
$docId = SiteContent::query()
->where('deleted', 0)
->where('alias', $this->documentIdentifier)->first();
if (is_null($doc)) {
->where('alias', $this->documentIdentifier)
->toBase()->value('id');
if (is_null($docId)) {
$this->sendErrorPage();
}
$this->documentIdentifier = $doc->getKey();
$this->documentIdentifier = (int) $docId;
}
}
$this->documentMethod = 'id';
Expand Down Expand Up @@ -4261,7 +4272,7 @@ public function getAllChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $fiel
$content->withoutProtected();
}
// build query
$resourceArray = $content->get()->toArray();
$resourceArray = SiteContent::toArrays($content);
$this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
return $resourceArray;

Expand Down Expand Up @@ -4302,7 +4313,7 @@ public function getActiveChildren($id = 0, $sort = 'menuindex', $dir = 'ASC', $f
$content->withoutProtected();
}
// build query
$resourceArray = $content->get()->toArray();
$resourceArray = SiteContent::toArrays($content);
$this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;
return $resourceArray;
}
Expand Down Expand Up @@ -4386,7 +4397,7 @@ public function getDocumentChildren(
if (is_numeric($limit)) {
$documentChildren = $documentChildren->take($limit);
}
$resourceArray = $documentChildren->get()->toArray();
$resourceArray = SiteContent::toArrays($documentChildren);

$this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;

Expand Down Expand Up @@ -4478,7 +4489,7 @@ public function getDocuments(
if (is_numeric($limit)) {
$documentChildren = $documentChildren->take($limit);
}
$resourceArray = $documentChildren->get()->toArray();
$resourceArray = SiteContent::toArrays($documentChildren);

$this->tmpCache[__FUNCTION__][$cacheKey] = $resourceArray;

Expand Down
7 changes: 7 additions & 0 deletions core/src/Legacy/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ protected function writeSiteCache($evo)
$content .= '$c[\'' . $systemSetting->setting_name . '\']="' . $this->escapeDoubleQuotes($systemSetting->setting_value) . '";';
$config[$systemSetting->setting_name] = $systemSetting->setting_value;
}
// Text defaults the database does not store, already translated: a request
// then reads them here instead of building the translator for them.
if (method_exists($evo, 'getFactoryTextDefaults')) {
foreach ($evo->getFactoryTextDefaults($config) as $name => $value) {
$content .= '$c[\'' . $name . '\']="' . $this->escapeDoubleQuotes($value) . '";';
}
}

if (isset($config['enable_filter']) && $config['enable_filter'] == 1) {
if (Models\SitePlugin::activePhx()->count()) {
Expand Down
Loading
Loading