Skip to content

EspoCRM – Open Source CRM Application

ref

Yuri Kuznetsov489a5befdef0
diff --git a/application/Espo/Core/Portal/Application.php b/application/Espo/Core/Portal/Application.php
index 3a8de3c6a7..4054f8f5d8 100644
--- a/application/Espo/Core/Portal/Application.php
+++ b/application/Espo/Core/Portal/Application.php
@@ -31,23 +31,21 @@ namespace Espo\Core\Portal;
use Espo\Entities\Portal;
use Espo\ORM\EntityManager;
-
-use Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
-
use Espo\Core\Application as BaseApplication;
use Espo\Core\Container\ContainerBuilder;
use Espo\Core\Portal\Container as PortalContainer;
use Espo\Core\Portal\Container\ContainerConfiguration as PortalContainerConfiguration;
use Espo\Core\Portal\Utils\Config;
+use LogicException;
class Application extends BaseApplication
{
/**
* @throws Forbidden
- * @throws Error
* @throws NotFound
+ * @noinspection PhpMissingParentConstructorInspection
*/
public function __construct(?string $portalId)
{
@@ -59,15 +57,6 @@ class Application extends BaseApplication
$this->initPreloads();
}
- public function getContainer(): Container
- {
- /** @var Container */
- return parent::getContainer();
- }
-
- /**
- * @throws Error
- */
protected function initContainer(): void
{
$container = (new ContainerBuilder())
@@ -77,7 +66,7 @@ class Application extends BaseApplication
->build();
if (!$container instanceof PortalContainer) {
- throw new Error("Wrong container created.");
+ throw new LogicException("Wrong container created.");
}
$this->container = $container;
@@ -85,13 +74,12 @@ class Application extends BaseApplication
/**
* @throws Forbidden
- * @throws Error
* @throws NotFound
*/
protected function initPortal(?string $portalId): void
{
if (!$portalId) {
- throw new Error("Portal ID was not passed to Portal\Application.");
+ throw new LogicException("Portal ID was not passed to Portal\Application.");
}
$entityManager = $this->container->getByClass(EntityManager::class);
@@ -100,22 +88,25 @@ class Application extends BaseApplication
if (!$portal) {
$portal = $entityManager
- ->getRDBRepository(Portal::ENTITY_TYPE)
+ ->getRDBRepositoryByClass(Portal::class)
->where(['customId' => $portalId])
->findOne();
}
if (!$portal) {
- throw new NotFound("Portal {$portalId} not found.");
+ throw new NotFound("Portal $portalId not found.");
}
- if (!$portal->get('isActive')) {
- throw new Forbidden("Portal {$portalId} is not active.");
+ if (!$portal->isActive()) {
+ throw new Forbidden("Portal $portalId is not active.");
}
- /** @var PortalContainer $container */
$container = $this->container;
+ if (!$container instanceof PortalContainer) {
+ throw new LogicException();
+ }
+
$container->setPortal($portal);
}
diff --git a/application/Espo/Core/Portal/Utils/Url.php b/application/Espo/Core/Portal/Utils/Url.php
index ff8f7b992d..d41b39c0ba 100644
--- a/application/Espo/Core/Portal/Utils/Url.php
+++ b/application/Espo/Core/Portal/Utils/Url.php
@@ -39,9 +39,13 @@ class Url
return $portalId;
}
- $url = $_SERVER['REQUEST_URI'];
+ $url = $_SERVER['REQUEST_URI'] ?? null;
$scriptName = $_SERVER['SCRIPT_NAME'];
+ if (!$url) {
+ return null;
+ }
+
$scriptNameModified = str_replace('public/api/', 'api/', $scriptName);
return explode('/', $url)[count(explode('/', $scriptNameModified)) - 1] ?? null;
@@ -60,15 +64,17 @@ class Url
return $portalId;
}
- $url = $_SERVER['REQUEST_URI'];
+ $url = $_SERVER['REQUEST_URI'] ?? null;
$scriptName = $_SERVER['SCRIPT_NAME'];
$scriptNameModified = str_replace('public/api/', 'api/', $scriptName);
- $portalId = explode('/', $url)[count(explode('/', $scriptNameModified)) - 1] ?? null;
+ if ($url) {
+ $portalId = explode('/', $url)[count(explode('/', $scriptNameModified)) - 1] ?? null;
- if (strpos($url, '=') !== false) {
- $portalId = null;
+ if (str_contains($url, '=')) {
+ $portalId = null;
+ }
}
if ($portalId) {
diff --git a/application/Espo/Entities/Portal.php b/application/Espo/Entities/Portal.php
index 35cdf7e772..be4fd83b67 100644
--- a/application/Espo/Entities/Portal.php
+++ b/application/Espo/Entities/Portal.php
@@ -30,9 +30,10 @@
namespace Espo\Entities;
use Espo\Core\Field\Link;
+use Espo\Core\ORM\Entity;
use Espo\Repositories\Portal as PortalRepository;
-class Portal extends \Espo\Core\ORM\Entity
+class Portal extends Entity
{
public const ENTITY_TYPE = 'Portal';
@@ -87,4 +88,9 @@ class Portal extends \Espo\Core\ORM\Entity
/** @var ?Link */
return $this->getValueObject('layoutSet');
}
+
+ public function isActive(): bool
+ {
+ return $this->get('isActive');
+ }
}