Skip to content

Commit ce94a43

Browse files
committed
Export: new option --from-date
1 parent 81d8fcd commit ce94a43

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

Diff for: src/files/custom/Espo/Modules/ExportImport/Tools/Export.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ private function exportEntity(Params $params, string $entityType): EntityResult
227227
->withSkipCustomization($params->getSkipCustomization())
228228
->withSkipPassword($params->getSkipPassword())
229229
->withUserSkipList($params->getUserSkipList())
230-
->withAllAttributes($params->getAllAttributes());
230+
->withAllAttributes($params->getAllAttributes())
231+
->withFromDate($params->getFromDate());
231232

232233
$export = $this->injectableFactory->create(EntityExportTool::class);
233234
$export->setParams($exportParams);

Diff for: src/files/custom/Espo/Modules/ExportImport/Tools/Export/EntityExport.php

+21-3
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@
3131
namespace Espo\Modules\ExportImport\Tools\Export;
3232

3333
use Espo\Core\Acl;
34-
use Espo\ORM\Entity;
3534
use RuntimeException;
3635
use Espo\Core\Acl\Table;
3736
use Espo\ORM\Collection;
38-
use Espo\Core\Utils\Json;
3937
use Espo\ORM\EntityManager;
4038
use Espo\Core\Utils\Metadata;
4139
use Espo\Core\Utils\FieldUtil;
4240
use Espo\Core\Exceptions\Error;
4341
use Espo\Core\Select\SearchParams;
4442
use Espo\Core\Record\ServiceContainer;
4543
use Espo\Core\Select\SelectBuilderFactory;
44+
use Espo\Core\Select\Where\Item as WhereItem;
45+
use Espo\Core\Utils\DateTime as DateTimeUtil;
4646
use Espo\Core\FieldProcessing\ListLoadProcessor;
4747
use Espo\Core\Utils\File\Manager as FileManager;
48+
use Espo\Modules\ExportImport\Tools\Export\Util;
4849
use Espo\Modules\ExportImport\Tools\Export\Params;
4950
use Espo\Core\FieldProcessing\Loader\Params as LoaderParams;
5051
use Espo\Modules\ExportImport\Tools\Processor\Utils as ToolUtils;
5152
use Espo\Modules\ExportImport\Tools\Processor\Data as ProcessorData;
5253
use Espo\Modules\ExportImport\Tools\Processor\Exceptions\Skip as SkipException;
53-
use Espo\Modules\ExportImport\Tools\Export\Util;
5454

5555
class EntityExport
5656
{
@@ -188,9 +188,27 @@ private function getCollection(Params $params): Collection
188188

189189
$entityType = $params->getEntityType();
190190

191+
$entityDefs = $this->entityManager
192+
->getDefs()
193+
->getEntity($entityType);
194+
191195
$searchParams = $params->getSearchParams()
192196
->withOrder(SearchParams::ORDER_ASC);
193197

198+
if ($params->getFromDate() && $entityDefs->hasAttribute('modifiedAt')) {
199+
$after = $params->getFromDate()->format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT);
200+
201+
$searchParams = $searchParams
202+
->withWhereAdded(
203+
WhereItem
204+
::createBuilder()
205+
->setAttribute('modifiedAt')
206+
->setType(WhereItem\Type::AFTER)
207+
->setValue($after)
208+
->build()
209+
);
210+
}
211+
194212
$builder = $this->selectBuilderFactory
195213
->create()
196214
->from($entityType)

Diff for: src/files/custom/Espo/Modules/ExportImport/Tools/Export/Params.php

+17
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
namespace Espo\Modules\ExportImport\Tools\Export;
3131

32+
use DateTime;
3233
use Espo\Core\Utils\Util;
3334
use Espo\Core\Select\SearchParams;
3435
use Espo\Modules\ExportImport\Tools\Processor\ProcessHook;
@@ -75,6 +76,8 @@ class Params implements IParams
7576

7677
private bool $allAttributes;
7778

79+
private ?DateTime $fromDate;
80+
7881
public function __construct(string $entityType)
7982
{
8083
$this->entityType = $entityType;
@@ -247,6 +250,15 @@ public function withAllAttributes(bool $value): self
247250
return $obj;
248251
}
249252

253+
public function withFromDate(?DateTime $value): self
254+
{
255+
$obj = clone $this;
256+
257+
$obj->fromDate = $value;
258+
259+
return $obj;
260+
}
261+
250262
/**
251263
* Get search params.
252264
*/
@@ -418,4 +430,9 @@ public function getAllAttributes(): bool
418430
{
419431
return $this->allAttributes;
420432
}
433+
434+
public function getFromDate(): ?DateTime
435+
{
436+
return $this->fromDate;
437+
}
421438
}

0 commit comments

Comments
 (0)