type fixes
This commit is contained in:
@@ -64,12 +64,12 @@ class Export
|
||||
/**
|
||||
* @var ?Params
|
||||
*/
|
||||
private $params;
|
||||
private ?Params $params = null;
|
||||
|
||||
/**
|
||||
* @phpstan-var (Collection&iterable<Entity>)|null $collection
|
||||
* @var ?Collection<Entity>
|
||||
*/
|
||||
private $collection = null;
|
||||
private ?Collection $collection = null;
|
||||
|
||||
private $processorFactory;
|
||||
|
||||
@@ -123,7 +123,7 @@ class Export
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param Collection&iterable<Entity> $collection
|
||||
* @param Collection<Entity> $collection
|
||||
*/
|
||||
public function setCollection(Collection $collection): self
|
||||
{
|
||||
@@ -237,6 +237,9 @@ class Export
|
||||
return new Result($attachment->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getAttributeFromEntity(Entity $entity, string $attribute)
|
||||
{
|
||||
$methodName = 'getAttribute' . ucfirst($attribute). 'FromEntity';
|
||||
@@ -351,7 +354,7 @@ class Export
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-return Collection&iterable<Entity>
|
||||
* @return Collection<Entity>
|
||||
*/
|
||||
private function getCollection(Params $params): Collection
|
||||
{
|
||||
@@ -375,7 +378,7 @@ class Export
|
||||
|
||||
$query = $builder->build();
|
||||
|
||||
/** @phpstan-var Collection&iterable<Entity> */
|
||||
/** @var Collection<Entity> */
|
||||
return $this->entityManager
|
||||
->getRDBRepository($entityType)
|
||||
->clone($query)
|
||||
@@ -383,11 +386,14 @@ class Export
|
||||
->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function getAttributeList(Params $params): array
|
||||
{
|
||||
$list = [];
|
||||
$list = [];
|
||||
|
||||
$entityType = $params->getEntityType();
|
||||
$entityType = $params->getEntityType();
|
||||
|
||||
$entityDefs = $this->entityManager
|
||||
->getDefs()
|
||||
@@ -430,6 +436,10 @@ class Export
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
private function getAttributeListFromFieldList(Params $params): array
|
||||
{
|
||||
$entityType = $params->getEntityType();
|
||||
@@ -452,6 +462,9 @@ class Export
|
||||
return $attributeList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?string[]
|
||||
*/
|
||||
private function getFieldList(Params $params, Processor $processor): ?array
|
||||
{
|
||||
$entityDefs = $this->entityManager
|
||||
|
||||
@@ -38,27 +38,37 @@ use RuntimeException;
|
||||
|
||||
class Params
|
||||
{
|
||||
private $entityType;
|
||||
private string $entityType;
|
||||
|
||||
/**
|
||||
* @var ?string[]
|
||||
*/
|
||||
private $attributeList = null;
|
||||
|
||||
/**
|
||||
* @var ?string[]
|
||||
*/
|
||||
private $fieldList = null;
|
||||
|
||||
private $fileName = null;
|
||||
private ?string $fileName = null;
|
||||
|
||||
private $format = null;
|
||||
private ?string $format = null;
|
||||
|
||||
private $name = null;
|
||||
private ?string $name = null;
|
||||
|
||||
private $searchParams = null;
|
||||
private ?SearchParams $searchParams = null;
|
||||
|
||||
private $applyAccessControl = true;
|
||||
private bool $applyAccessControl = true;
|
||||
|
||||
public function __construct(string $entityType)
|
||||
{
|
||||
$this->entityType = $entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $params
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public static function fromRaw(array $params): self
|
||||
{
|
||||
$entityType = $params['entityType'] ?? null;
|
||||
@@ -172,6 +182,9 @@ class Params
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ?string[] $fieldList
|
||||
*/
|
||||
public function withFieldList(?array $fieldList): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
@@ -181,6 +194,9 @@ class Params
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ?string[] $attributeList
|
||||
*/
|
||||
public function withAttributeList(?array $attributeList): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
@@ -245,6 +261,8 @@ class Params
|
||||
|
||||
/**
|
||||
* Get attributes to be exported.
|
||||
*
|
||||
* @return ?string[]
|
||||
*/
|
||||
public function getAttributeList(): ?array
|
||||
{
|
||||
@@ -253,6 +271,8 @@ class Params
|
||||
|
||||
/**
|
||||
* Get fields to be exported.
|
||||
*
|
||||
* @return ?string[]
|
||||
*/
|
||||
public function getFieldList(): ?array
|
||||
{
|
||||
|
||||
@@ -31,13 +31,23 @@ namespace Espo\Tools\Export\Processor;
|
||||
|
||||
class Data
|
||||
{
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
private $resource;
|
||||
|
||||
/**
|
||||
* @param resource $resource
|
||||
*/
|
||||
public function __construct($resource)
|
||||
{
|
||||
$this->resource = $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ?mixed[]
|
||||
*/
|
||||
public function readRow(): ?array
|
||||
{
|
||||
$line = fgets($this->resource);
|
||||
|
||||
@@ -31,16 +31,26 @@ namespace Espo\Tools\Export\Processor;
|
||||
|
||||
class Params
|
||||
{
|
||||
private $fileName;
|
||||
private string $fileName;
|
||||
|
||||
private $attributeList = null;
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $attributeList;
|
||||
|
||||
/**
|
||||
* @var ?string[]
|
||||
*/
|
||||
private $fieldList = null;
|
||||
|
||||
private $name = null;
|
||||
private ?string $name = null;
|
||||
|
||||
private $entityType = null;
|
||||
private ?string $entityType = null;
|
||||
|
||||
/**
|
||||
* @param string[] $attributeList
|
||||
* @param ?string[] $fieldList
|
||||
*/
|
||||
public function __construct(string $fileName, array $attributeList, ?array $fieldList)
|
||||
{
|
||||
$this->fileName = $fileName;
|
||||
@@ -71,11 +81,17 @@ class Params
|
||||
return $this->fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAttributeList(): array
|
||||
{
|
||||
return $this->attributeList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?string[]
|
||||
*/
|
||||
public function getFieldList(): ?array
|
||||
{
|
||||
return $this->fieldList;
|
||||
|
||||
@@ -38,9 +38,9 @@ use LogicException;
|
||||
|
||||
class ProcessorFactory
|
||||
{
|
||||
private $injectableFactory;
|
||||
private InjectableFactory $injectableFactory;
|
||||
|
||||
private $metadata;
|
||||
private Metadata $metadata;
|
||||
|
||||
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata)
|
||||
{
|
||||
@@ -54,6 +54,7 @@ class ProcessorFactory
|
||||
throw new LogicException("Not supported export format '{$format}'.");
|
||||
}
|
||||
|
||||
/** @var ?class-string */
|
||||
$className = $this->metadata->get(['app', 'export', 'processorClassNameMap', $format]);
|
||||
|
||||
if (!$className) {
|
||||
|
||||
@@ -92,6 +92,10 @@ class Csv implements Processor
|
||||
return new Stream($fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $row
|
||||
* @return mixed[]
|
||||
*/
|
||||
protected function prepareRow(array $row): array
|
||||
{
|
||||
$preparedRow = [];
|
||||
@@ -107,6 +111,9 @@ class Csv implements Processor
|
||||
return $preparedRow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $fieldList
|
||||
*/
|
||||
public function loadAdditionalFields(Entity $entity, array $fieldList): void
|
||||
{
|
||||
if (!$entity instanceof CoreEntity) {
|
||||
|
||||
@@ -357,6 +357,12 @@ class Xlsx implements Processor
|
||||
return $stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $row
|
||||
* @param string[] $fieldList
|
||||
* @param string[] $azRange
|
||||
* @param array<string,string> $typesCache
|
||||
*/
|
||||
private function processRow(
|
||||
string $entityType,
|
||||
array $row,
|
||||
@@ -745,6 +751,9 @@ class Xlsx implements Processor
|
||||
return '[$'.$currencySymbol.'-409]#,##0.00;-[$'.$currencySymbol.'-409]#,##0.00';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $fieldList
|
||||
*/
|
||||
public function loadAdditionalFields(Entity $entity, array $fieldList): void
|
||||
{
|
||||
if (!$entity instanceof CoreEntity) {
|
||||
@@ -789,6 +798,10 @@ class Xlsx implements Processor
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $fieldList
|
||||
* @return string[]
|
||||
*/
|
||||
public function filterFieldList(string $entityType, array $fieldList, bool $exportAllFields): array
|
||||
{
|
||||
if ($exportAllFields) {
|
||||
@@ -804,6 +817,10 @@ class Xlsx implements Processor
|
||||
return array_values($fieldList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $attributeList
|
||||
* @param string[] $fieldList
|
||||
*/
|
||||
public function addAdditionalAttributes(string $entityType, array &$attributeList, array $fieldList): void
|
||||
{
|
||||
$linkList = [];
|
||||
@@ -886,6 +903,10 @@ class Xlsx implements Processor
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $row
|
||||
* @return mixed[]
|
||||
*/
|
||||
private function sanitizeRow(array $row): array
|
||||
{
|
||||
return array_map(
|
||||
|
||||
Reference in New Issue
Block a user