Skip to content

Commit 392b199

Browse files
committed
code review
1 parent d225e93 commit 392b199

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

app/base/abstracts/Controllers/BaseHtmlPage.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ abstract class BaseHtmlPage extends BasePage implements HtmlPageInterface
5757
*/
5858
protected ?Template $template = null;
5959

60+
protected ?Rewrite $rewriteObject = null;
61+
6062
/**
6163
* BasePage constructor.
6264
*
@@ -253,6 +255,10 @@ public function getFpcCacheKey() : string
253255
*/
254256
public function getRewriteObject() : ?Rewrite
255257
{
258+
if ($this->rewriteObject instanceof Rewrite) {
259+
return $this->rewriteObject;
260+
}
261+
256262
if ($this->getRouteInfo()->getRewrite()) {
257263
return $this->containerCall([Rewrite::class, 'load'], ['id' => $this->getRouteInfo()->getRewrite()]);
258264
}

app/base/controllers/Admin/Blocks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(
7373
/** @var Block $new_block */
7474
$new_block = $this->containerMake(Block::class);
7575
$new_block->setRegion(null);
76-
$new_block->setTitle(str_replace("App\\Site\\Blocks\\", "", $blockClass));
76+
$new_block->setTitle(static::getClassBasename($blockClass));
7777
$new_block->setLocale(null);
7878
$new_block->setInstanceClass($blockClass);
7979
$new_block->setContent(null);

app/base/migrations/CreateProductStockTableMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function addDBTableDefinition(Table $table): Table
4242
->addColumn('updated_at', 'TIMESTAMP', null, [], false, 'CURRENT_TIMESTAMP()')
4343
->addIndex(null, 'id', Index::TYPE_PRIMARY)
4444
->addForeignKey('fk_stock_website_id', ['website_id'], 'website', ['id'])
45-
->addForeignKey('fk_stock_owner_id', ['user_id'], 'user', ['id'])
45+
// ->addForeignKey('fk_stock_owner_id', ['user_id'], 'user', ['id'])
4646
->setAutoIncrementColumn('id');
4747

4848
return $table;

app/base/routers/Web.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,18 @@ protected function checkRewrites(string $uri): ?Rewrite
185185
$domain = $website->getDomain();
186186
$website_id = $website->getId();
187187

188-
$rewrite = Rewrite::getCollection()->where(['url' => $uri, 'website_id' => $website_id])->getFirst();
188+
if (isset($cached_routes[$domain][$uri])) {
189+
// create a Rewrite with cached data
190+
return $this->containerCall([Rewrite::class, 'new'], ['initial_data' => $cached_routes[$domain][$uri]]);
191+
}
192+
193+
// $rewrite = Rewrite::getCollection()->where(['url' => $uri, 'website_id' => [$website_id, null]])->getFirst();
194+
$rewrite = Rewrite::getCollection()
195+
->where(['url' => $uri, 'website_id' => [$website_id, null]])
196+
->addSelect('*')->addSelect('IF(website_id = ' . $website_id . ', 1, 0) AS is_current_website')
197+
->addOrder(['is_current_website' => 'DESC'], 'start')
198+
->getFirst();
199+
189200
if ($rewrite instanceof Rewrite) {
190201
$cached_routes[$domain][$uri] = $rewrite->getData();
191202
$this->setCachedRoutes($cached_routes);

app/base/tools/Utils/HtmlPartsRenderer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use App\Base\Abstracts\Controllers\AdminManageFrontendModelsPage;
3434
use App\Base\Abstracts\Controllers\AdminManageModelsPage;
3535
use App\Base\Abstracts\Controllers\AdminPage;
36+
use App\Base\Abstracts\Controllers\BaseHtmlPage;
3637
use App\Base\Abstracts\Models\BaseCollection;
3738
use App\Base\Controllers\Admin\Login;
3839
use App\Base\Models\Block;
@@ -368,8 +369,12 @@ public function renderBlocks(string $region, ?string $locale = null, ?BasePage $
368369
return $this->getCache()->get($cache_key);
369370
}
370371

371-
if ($current_rewrite == null && ($route_info instanceof RouteInfo) && is_numeric($route_info->getRewrite())) {
372-
$current_rewrite = $this->containerCall([Rewrite::class, 'load'], ['id' => $route_info->getRewrite()]);
372+
if ($current_page instanceof BaseHtmlPage) {
373+
$current_rewrite = $current_page->getRewriteObject();
374+
375+
if ($current_rewrite == null && ($route_info instanceof RouteInfo) && is_numeric($route_info->getRewrite())) {
376+
$current_rewrite = $this->containerCall([Rewrite::class, 'load'], ['id' => $route_info->getRewrite()]);
377+
}
373378
}
374379

375380
if (is_null($pageBlocks)) {

0 commit comments

Comments
 (0)