field loading usage and changes

This commit is contained in:
Yuri Kuznetsov
2021-04-28 10:06:30 +03:00
parent f9d47de8f2
commit 9d7582caa6
5 changed files with 77 additions and 20 deletions
@@ -0,0 +1,65 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2021 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\Import;
use Espo\Core\{
FieldProcessing\Loader,
FieldProcessing\LoaderParams,
ORM\Entity,
ORM\EntityManager,
};
use Espo\Repositories\Import as ImportRepository;
class CountsLoader implements Loader
{
private $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function process(Entity $entity, LoaderParams $params): void
{
/* @var $repository ImportRepository */
$repository = $this->entityManager->getRepository('Import');
$importedCount = $repository->countResultRecords($entity, 'imported');
$duplicateCount = $repository->countResultRecords($entity, 'duplicates');
$updatedCount = $repository->countResultRecords($entity, 'updated');
$entity->set([
'importedCount' => $importedCount,
'duplicateCount' => $duplicateCount,
'updatedCount' => $updatedCount,
]);
}
}
@@ -27,7 +27,7 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\FieldProcessing\Misc;
namespace Espo\Core\FieldProcessing\Stream;
use Espo\Core\{
ORM\Entity,
@@ -42,7 +42,7 @@ use Espo\Entities\User;
use Espo\Services\Stream as StreamService;
class StreamLoader implements LoaderInterface
class FollowersLoader implements LoaderInterface
{
private const FOLLOWERS_LIMIT = 5;
@@ -6,7 +6,7 @@
"Espo\\Core\\FieldProcessing\\LinkParent\\Loader",
"Espo\\Core\\FieldProcessing\\EmailAddress\\Loader",
"Espo\\Core\\FieldProcessing\\PhoneNumber\\Loader",
"Espo\\Core\\FieldProcessing\\Misc\\StreamLoader"
"Espo\\Core\\FieldProcessing\\Stream\\FollowersLoader"
],
"listLoaderClassNameList": [
"Espo\\Core\\FieldProcessing\\LinkParent\\Loader",
@@ -0,0 +1,5 @@
{
"readLoaderClassNameList": [
"Espo\\Classes\\FieldProcessing\\Import\\CountsLoader"
]
}
+4 -17
View File
@@ -40,7 +40,6 @@ use Espo\Core\{
};
use Espo\{
ORM\Entity,
Services\Record,
Tools\Import\Import as ImportTool,
};
@@ -58,21 +57,6 @@ class Import extends Record implements
const REVERT_PERMANENTLY_REMOVE_PERIOD_DAYS = 2;
public function loadAdditionalFields(Entity $entity)
{
parent::loadAdditionalFields($entity);
$importedCount = $this->getRepository()->countResultRecords($entity, 'imported');
$duplicateCount = $this->getRepository()->countResultRecords($entity, 'duplicates');
$updatedCount = $this->getRepository()->countResultRecords($entity, 'updated');
$entity->set([
'importedCount' => $importedCount,
'duplicateCount' => $duplicateCount,
'updatedCount' => $updatedCount,
]);
}
public function findLinked(string $id, string $link, array $params): RecordCollection
{
if (!in_array($link, ['imported', 'duplicates', 'updated'])) {
@@ -337,7 +321,10 @@ class Import extends Record implements
}
public function import(
string $entityType, array $attributeList, string $attachmentId, array $params = []
string $entityType,
array $attributeList,
string $attachmentId,
array $params = []
): StdClass {
$result = $this->createImportTool()