type fixes

This commit is contained in:
Yuri Kuznetsov
2021-11-03 11:39:41 +02:00
parent 901e0967fc
commit f5d324eb48
7 changed files with 82 additions and 25 deletions
+18 -1
View File
@@ -135,6 +135,8 @@ class Record extends RecordService implements
/**
* @deprecated Use `$this->config`.
*
* @return \Espo\Core\Utils\Config
*/
protected function getConfig()
{
@@ -143,6 +145,8 @@ class Record extends RecordService implements
/**
* @deprecated Use `$this->serviceFactory`.
*
* @return \Espo\Core\ServiceFactory
*/
protected function getServiceFactory()
{
@@ -159,6 +163,8 @@ class Record extends RecordService implements
/**
* @deprecated Use `$this->acl`.
*
* @return \Espo\Core\Acl
*/
protected function getAcl()
{
@@ -167,14 +173,17 @@ class Record extends RecordService implements
/**
* @deprecated Use `$this->user`.
*
* @return \Espo\Entities\User
*/
protected function getUser()
{
return $this->user;
}
/**
/**
* @deprecated Use `$this->aclManager`.
* @return \Espo\Core\AclManager
*/
protected function getAclManager()
{
@@ -183,6 +192,8 @@ class Record extends RecordService implements
/**
* @deprecated Use `$this->fileManager`.
*
* @return \Espo\Core\Utils\File\Manager
*/
protected function getFileManager()
{
@@ -191,6 +202,8 @@ class Record extends RecordService implements
/**
* @deprecated Use `$this->metadata`.
*
* @return \Espo\Core\Utils\Metadata
*/
protected function getMetadata()
{
@@ -207,6 +220,8 @@ class Record extends RecordService implements
/**
* @deprecated Use `$this->entityManager`.
*
* @return \Espo\ORM\EntityManager
*/
protected function getEntityManager()
{
@@ -243,6 +258,8 @@ class Record extends RecordService implements
/**
* @deprecated Use `$this->recordServiceContainer->get($name)`.
*
* @return \Espo\Core\Record\Service
*/
protected function getRecordService($name)
{
+27 -12
View File
@@ -30,6 +30,7 @@
namespace Espo\Services;
use Espo\Entities\User as UserEntity;
use Espo\Entities\Email as EmailEntity;
use Espo\Core\{
Exceptions\Forbidden,
@@ -101,6 +102,7 @@ class User extends Record implements
?string $currentPassword = null
): void {
/** @var UserEntity $user */
$user = $this->getEntityManager()->getEntity('User', $userId);
if (!$user) {
@@ -123,9 +125,9 @@ class User extends Record implements
$passwordHash = new PasswordHash($this->getConfig());
$u = $this->getEntityManager()
->getRepository('User')
->getRDBRepository('User')
->where([
'id' => $user->id,
'id' => $user->getId(),
'password' => $passwordHash->hash($currentPassword),
])
->findOne();
@@ -290,6 +292,7 @@ class User extends Record implements
$data->password = $this->hashPassword($data->password);
}
/** @var UserEntity $user */
$user = parent::create($data, $params);
if (!is_null($newPassword) && !empty($data->sendAccessInfo)) {
@@ -328,6 +331,7 @@ class User extends Record implements
unset($data->type);
}
/** @var UserEntity $user */
$user = parent::update($id, $data, $params);
if (!is_null($newPassword)) {
@@ -344,6 +348,8 @@ class User extends Record implements
public function prepareEntityForOutput(Entity $entity)
{
assert($entity instanceof UserEntity);
parent::prepareEntityForOutput($entity);
if ($entity->isApi()) {
@@ -368,6 +374,7 @@ class User extends Record implements
public function generateNewApiKeyForEntity(string $id): Entity
{
/** @var UserEntity $entity */
$entity = $this->getEntity($id);
if (!$entity) {
@@ -407,6 +414,7 @@ class User extends Record implements
}
}
/** @var UserEntity $user */
$user = $this->getEntity($id);
if (!$user) {
@@ -475,7 +483,7 @@ class User extends Record implements
protected function getInternalUserCount()
{
return $this->getEntityManager()
->getRepository('User')
->getRDBRepository('User')
->where([
'isActive' => true,
'type' => ['admin', 'regular'],
@@ -487,7 +495,7 @@ class User extends Record implements
protected function getPortalUserCount()
{
return $this->getEntityManager()
->getRepository('User')
->getRDBRepository('User')
->where([
'isActive' => true,
'type' => 'portal',
@@ -497,6 +505,8 @@ class User extends Record implements
protected function beforeCreateEntity(Entity $entity, $data)
{
/** @var UserEntity $entity */
if (
$this->getConfig()->get('userLimit') &&
!$this->getUser()->isSuperAdmin() &&
@@ -548,6 +558,8 @@ class User extends Record implements
protected function beforeUpdateEntity(Entity $entity, $data)
{
/** @var UserEntity $entity */
if ($this->getConfig()->get('userLimit') && !$this->getUser()->isSuperAdmin()) {
if (
(
@@ -607,7 +619,7 @@ class User extends Record implements
}
}
protected function sendPassword(Entity $user, $password)
protected function sendPassword(UserEntity $user, $password)
{
$emailAddress = $user->get('emailAddress');
@@ -615,6 +627,7 @@ class User extends Record implements
return;
}
/** @var EmailEntity $email */
$email = $this->getEntityManager()->getEntity('Email');
if (!$this->emailSender->hasSystemSmtp() && !$this->getConfig()->get('internalSmtpServer')) {
@@ -633,13 +646,13 @@ class User extends Record implements
$urlList = [];
$portalList = $this->getEntityManager()
->getRepository('Portal')
$portalList = $this->entityManager
->getRDBRepository('Portal')
->distinct()
->join('users')
->where([
'isActive' => true,
'users.id' => $user->id,
'users.id' => $user->getId(),
])
->find();
@@ -650,12 +663,12 @@ class User extends Record implements
else {
$url = $siteUrl . 'portal/';
if ($this->getConfig()->get('defaultPortalId') !== $portal->id) {
if ($this->getConfig()->get('defaultPortalId') !== $portal->getId()) {
if ($portal->get('customId')) {
$url .= $portal->get('customId');
}
else {
$url .= $portal->id;
$url .= $portal->getId();
}
}
@@ -724,6 +737,8 @@ class User extends Record implements
public function afterUpdateEntity(Entity $entity, $data)
{
assert($entity instanceof UserEntity);
parent::afterUpdateEntity($entity, $data);
if (
@@ -733,7 +748,7 @@ class User extends Record implements
property_exists($data, 'portalRolesIds') ||
property_exists($data, 'portalsIds')
) {
$this->clearRoleCache($entity->id);
$this->clearRoleCache($entity->getId());
}
if (
@@ -760,7 +775,7 @@ class User extends Record implements
$contact->set('firstName', $data->firstName);
}
if (array_key_exists('lastName', $data)) {
if (property_exists('lastName', $data)) {
$contact->set('lastName', $data->lastName);
}
@@ -87,6 +87,7 @@ class UserSecurity
throw new Forbidden();
}
/** @var User $user */
$user = $this->entityManager->getEntity('User', $id);
if (!$user) {
@@ -113,6 +114,7 @@ class UserSecurity
$isReset = $data->reset ?? false;
/** @var User $user */
$user = $this->entityManager->getEntity('User', $id);
if (!$user) {
@@ -161,6 +163,7 @@ class UserSecurity
throw new Forbidden();
}
/** @var User $user */
$user = $this->entityManager->getEntity('User', $id);
if (!$user) {
@@ -33,6 +33,8 @@ use Espo\Core\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\Entities\User;
use Espo\Core\{
Htmlizer\HtmlizerFactory as HtmlizerFactory,
Htmlizer\Htmlizer,
@@ -104,6 +106,7 @@ class AssignmentProcessor
throw new LogicException();
}
/** @var User $user */
$user = $this->entityManager->getEntity('User', $userId);
if (!$user) {
@@ -142,6 +145,8 @@ class AssignmentProcessor
return;
}
assert($entity instanceof Entity);
$this->loadParentNameFields($entity);
if (!$entity->hasLinkMultipleField('assignedUsers')) {
@@ -32,6 +32,8 @@ namespace Espo\Tools\EmailNotification;
use Espo\Core\Notification\EmailNotificationHandler;
use Espo\Core\Mail\SenderParams;
use Espo\Repositories\Portal as PortalRepository;
use Espo\{
ORM\Entity,
ORM\EntityManager,
@@ -187,7 +189,9 @@ class Processor
$sql = $this->entityManager->getQueryComposer()->compose($unionQuery);
$notificationList = $this->entityManager->getRepository('Notification')->findBySql($sql);
$notificationList = $this->entityManager
->getRDBRepository('Notification')
->findBySql($sql);
foreach ($notificationList as $notification) {
$notification->set('emailIsProcessed', true);
@@ -610,7 +614,7 @@ class Processor
if ($portalId) {
$portal = $this->entityManager->getEntity('Portal', $portalId);
$this->entityManager->getRepository('Portal')->loadUrlField($portal);
$this->getPortalRepository()->loadUrlField($portal);
$this->userIdPortalCacheMap[$user->id] = $portal;
}
@@ -768,7 +772,7 @@ class Processor
return;
}
$emailRepository = $this->entityManager->getRepository('Email');
$emailRepository = $this->entityManager->getRDBRepository('Email');
$eaList = $user->get('emailAddresses');
foreach ($eaList as $ea) {
@@ -880,4 +884,9 @@ class Processor
return $this->htmlizer;
}
private function getPortalRepository(): PortalRepository
{
return $this->entityManager->getRepository('Portal');
}
}
@@ -45,6 +45,9 @@ use Espo\Core\Utils\DateTime as DateTimeUtil;
use Espo\Entities\EmailTemplate;
use Espo\Entities\User;
use Espo\Entities\Attachment;
use Espo\Entities\EmailAddress;
use Espo\Repositories\EmailAddress as EmailAddressRepository;
use Exception;
use DateTime;
@@ -105,9 +108,9 @@ class Processor
$foundByAddressEntity = null;
if ($data->getEmailAddress()) {
$foundByAddressEntity = $this->entityManager
->getRepository('EmailAddress')
->getEntityByAddress($data->getEmailAddress(),
$foundByAddressEntity = $this->getEmailAddressRepository()
->getEntityByAddress(
$data->getEmailAddress(),
null,
['Contact', 'Lead', 'Account', 'User']
);
@@ -334,7 +337,7 @@ class Processor
}
$relatedEntity = $this->entityManager
->getRepository($entity->getEntityType())
->getRDBRepository($entity->getEntityType())
->getRelation($entity, $relation)
->findOne();
@@ -412,4 +415,9 @@ class Processor
return $this->htmlizerFactory->createForUser($user);
}
private function getEmailAddressRepository(): EmailAddressRepository
{
return $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE);
}
}
@@ -38,7 +38,7 @@ class NumberType implements Di\EntityManagerAware
public function onRead($scope, $name, &$defs, $options)
{
$number = $this->entityManager
->getRepository('NextNumber')
->getRDBRepository('NextNumber')
->where([
'entityType' => $scope,
'fieldName' => $name,
@@ -68,9 +68,9 @@ class NumberType implements Di\EntityManagerAware
return;
}
$number = $this
->entityManager
->getRepository('NextNumber')->where([
$number = $this->entityManager
->getRDBRepository('NextNumber')
->where([
'entityType' => $scope,
'fieldName' => $name
])
@@ -91,7 +91,7 @@ class NumberType implements Di\EntityManagerAware
public function afterRemove($scope, $name, $defs, $options)
{
$number = $this->entityManager
->getRepository('NextNumber')
->getRDBRepository('NextNumber')
->where([
'entityType' => $scope,
'fieldName' => $name