Skip to content

Commit 001cd85

Browse files
committed
fixes
1 parent b59c280 commit 001cd85

File tree

5 files changed

+187
-203
lines changed

5 files changed

+187
-203
lines changed

app/base/abstracts/Controllers/FrontendPage.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,6 @@ public function renderPage(RouteInfo $route_info = null, $route_data = [])
247247
*
248248
* @param bool $reset
249249
* @return Rewrite|null
250-
* @throws BasicException
251-
* @throws DependencyException
252-
* @throws NotFoundException
253250
*/
254251
public function getRewrite($reset = false): ?Rewrite
255252
{
@@ -339,17 +336,18 @@ public function getCurrentWebsite()
339336
*
340337
* @return array
341338
* @throws BasicException
342-
* @throws DependencyException
343-
* @throws NotFoundException
344339
*/
345340
public function getTranslations(): array
346341
{
347-
return array_map(
348-
function ($el) {
349-
return $el->url;
350-
},
351-
$this->getRewrite()->getTranslations()
352-
);
342+
if ($this->getRewrite() != null) {
343+
return array_map(
344+
function ($el) {
345+
return $el->url;
346+
},
347+
$this->getRewrite()->getTranslations()
348+
);
349+
}
350+
return [];
353351
}
354352

355353

app/base/abstracts/Models/FrontendModel.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public function getRewrite(): ?Rewrite
5252
if (!($this->rewriteObj instanceof Rewrite)) {
5353
try {
5454
$this->rewriteObj = $this->getContainer()->call([Rewrite::class, 'loadBy'], ['field' => 'route', 'value' => '/' . $this->getRewritePrefix() . '/' . $this->getId()]);
55-
} catch (Exception $e) {}
55+
} catch (Exception $e) {
56+
$this->rewriteObj = $this->getContainer()->call([Rewrite::class, 'new']);
57+
}
5658
}
5759
return $this->rewriteObj;
5860
}

app/site/blocks/ChangeLanguage.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use \App\Base\Abstracts\Blocks\BaseCodeBlock;
1616
use \App\Base\Abstracts\Controllers\BasePage;
17+
use App\Base\Abstracts\Controllers\FrontendPage;
1718
use \Degami\PHPFormsApi as FAPI;
1819
use \App\Site\Models\Language;
1920
use \Exception;
@@ -42,7 +43,8 @@ public function renderHTML(BasePage $current_page = null, $data = []): string
4243
];
4344
}
4445

45-
if (is_callable([$current_page, 'getTranslations'])) {
46+
47+
if (($current_page instanceof FrontendPage) && is_callable([$current_page, 'getTranslations'])) {
4648
if (($translations = $current_page->getTranslations()) && !empty($translations)) {
4749
$changelanguage_links = $this->getContainer()->make(TagElement::class, ['options' => [
4850
'tag' => 'ul',

app/site/migrations/InitialDataMigration.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,15 @@ private function addAdmin(): BaseModel
129129
* @param string $permission_name
130130
* @throws BasicException
131131
* @throws InvalidValueException
132-
* @throws DependencyException
133-
* @throws NotFoundException
134132
*/
135133
private function addPermission(Role $role_model, string $permission_name)
136134
{
137-
$permission_dbrow = $this->getDb()->table('permission')->where(['name' => $permission_name])->fetch();
138-
$permission_model = Permission::new($this->getContainer());
139-
if ($permission_dbrow) {
140-
$permission_model = $this->getContainer()->make(Permission::class, ['db_row' => $permission_dbrow]);
141-
} else {
142-
$permission_model->setName($permission_name);
135+
/** @var Permission $permission_model */
136+
$permission_model = null;
137+
try {
138+
$permission_model = $this->getContainer()->call([Permission::class, 'loadBy'], ['field' => 'name', 'value' => $permission_name]);
139+
} catch (\Exception $e) {
140+
$permission_model = $this->getContainer()->call([Permission::class, 'new'], ['initial_data' => ['name' => $permission_name]]);
143141
$permission_model->persist();
144142
}
145143

@@ -154,8 +152,6 @@ private function addPermission(Role $role_model, string $permission_name)
154152
*
155153
* @throws BasicException
156154
* @throws InvalidValueException
157-
* @throws DependencyException
158-
* @throws NotFoundException
159155
*/
160156
private function addRolesPermissions()
161157
{
@@ -247,11 +243,11 @@ private function addLanguages()
247243
* @param User $owner_model
248244
* @return Page
249245
* @throws BasicException
250-
* @throws InvalidValueException
251246
*/
252247
private function addHomePage(Website $website_model, User $owner_model): Page
253248
{
254-
$page_model = Page::new($this->getContainer());
249+
/** @var Page $page_model */
250+
$page_model = $this->getContainer()->call([Page::class, 'new']);
255251

256252
$page_model->setWebsiteId($website_model->getId());
257253
$page_model->setUrl('homepage');

0 commit comments

Comments
 (0)