From 8ba1907b459bcbce55ff9785d6db82f71e860bac Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 22 Mar 2022 14:51:22 +0200 Subject: [PATCH] type fixes --- .../Espo/Core/Repositories/Database.php | 5 +-- application/Espo/Core/Repositories/Event.php | 40 ++++++++----------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/application/Espo/Core/Repositories/Database.php b/application/Espo/Core/Repositories/Database.php index 9a6596da9f..4235050749 100644 --- a/application/Espo/Core/Repositories/Database.php +++ b/application/Espo/Core/Repositories/Database.php @@ -255,10 +255,9 @@ class Database extends RDBRepository $foreignEntityType = $this->getRelationParam($entity, $relationName, 'entity'); if ($foreignEntityType) { - $foreign = $this->entityManager->getEntity($foreignEntityType); + $foreign = $this->entityManager->getNewEntity($foreignEntityType); $foreign->set('id', $foreignId); - $foreign->setAsFetched(); } } @@ -293,7 +292,7 @@ class Database extends RDBRepository $foreignEntityType = $this->getRelationParam($entity, $relationName, 'entity'); if ($foreignEntityType) { - $foreign = $this->entityManager->getEntity($foreignEntityType); + $foreign = $this->entityManager->getNewEntity($foreignEntityType); $foreign->set('id', $foreignId); $foreign->setAsFetched(); diff --git a/application/Espo/Core/Repositories/Event.php b/application/Espo/Core/Repositories/Event.php index c90cbf9045..303ab4e700 100644 --- a/application/Espo/Core/Repositories/Event.php +++ b/application/Espo/Core/Repositories/Event.php @@ -31,6 +31,8 @@ namespace Espo\Core\Repositories; use Espo\ORM\Entity; +use Espo\Core\Exceptions\Error; + use Espo\Core\{ Di, Utils\DateTime as DateTimeUtil, @@ -93,19 +95,14 @@ class Event extends Database implements $dateEndDate = $entity->get('dateEndDate'); if (!empty($dateEndDate)) { - $dateEnd = $this->convertDateTimeToDefaultTimezone($dateEndDate . ' 00:00:00'); + $dt = new DateTime( + $this->convertDateTimeToDefaultTimezone($dateEndDate . ' 00:00:00') + ); - $dt = null; + $dt->modify('+1 day'); - try { - $dt = new DateTime($dateEnd); - $dt->modify('+1 day'); - - $dateEnd = $dt->format('Y-m-d H:i:s'); - } - catch (Exception $e) {} - - $entity->set('dateEnd', $dateEnd); + $dateEnd = $dt->format('Y-m-d H:i:s'); + $entity->set('dateEnd', $dateEnd); } else { $entity->set('dateEndDate', null); @@ -162,7 +159,7 @@ class Event extends Database implements /** * @param string $string - * @return ?string + * @return string */ protected function convertDateTimeToDefaultTimezone($string) { @@ -170,19 +167,14 @@ class Event extends Database implements $tz = new DateTimeZone($timeZone); - $dt = null; + $dt = DateTime::createFromFormat( + DateTimeUtil::SYSTEM_DATE_TIME_FORMAT, + $string, + $tz + ); - try { - $dt = DateTime::createFromFormat( - DateTimeUtil::SYSTEM_DATE_TIME_FORMAT, - $string, - $tz - ); - } - catch (Exception $e) {} - - if (!$dt) { - return null; + if ($dt === false) { + throw new Error("Could not parse date-time `{$string}`."); } $utcTz = new DateTimeZone('UTC');