ref
This commit is contained in:
@@ -261,9 +261,7 @@ class Import extends Record implements
|
||||
$importAttributeList = $data->importAttributeList;
|
||||
$userId = $data->userId;
|
||||
|
||||
$params = ImportParams::fromRaw(
|
||||
json_decode(json_encode($data->params), true)
|
||||
);
|
||||
$params = ImportParams::fromRaw($data->params);
|
||||
|
||||
$user = $this->getEntityManager()->getEntity('User', $userId);
|
||||
|
||||
@@ -308,12 +306,8 @@ class Import extends Record implements
|
||||
$entityType = $import->get('entityType');
|
||||
$attributeList = $import->get('attributeList') ?? [];
|
||||
|
||||
$rawParams = $import->get('params') ?? (object) [];
|
||||
|
||||
$params = ImportParams
|
||||
::fromRaw(
|
||||
json_decode(json_encode($rawParams), true)
|
||||
)
|
||||
::fromRaw($import->get('params'))
|
||||
->withStartFromLastIndex($startFromLastIndex);
|
||||
|
||||
$attachmentId = $import->get('fileId');
|
||||
@@ -369,12 +363,9 @@ class Import extends Record implements
|
||||
$entityType = $source->get('entityType');
|
||||
$attributeList = $source->get('attributeList') ?? [];
|
||||
|
||||
$params = $source->get('params') ?? (object) [];
|
||||
|
||||
$params = json_decode(json_encode($params), true);
|
||||
|
||||
unset($params['idleMode']);
|
||||
unset($params['manualMode']);
|
||||
$params = ImportParams::fromRaw($source->get('params'))
|
||||
->withIdleMode(false)
|
||||
->withManualMode(false);
|
||||
|
||||
$attachmentId = $this->uploadFile($contents);
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
|
||||
namespace Espo\Tools\Import;
|
||||
|
||||
use stdClass;
|
||||
use TypeError;
|
||||
|
||||
class Params
|
||||
{
|
||||
public const ACTION_CREATE = 'create';
|
||||
@@ -59,7 +62,7 @@ class Params
|
||||
|
||||
private $updateBy = [];
|
||||
|
||||
private $defaultValues = [];
|
||||
private $defaultValues;
|
||||
|
||||
private $dateFormat = null;
|
||||
|
||||
@@ -71,6 +74,11 @@ class Params
|
||||
|
||||
private $decimalMark = null;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$this->defaultValues = (object) [];
|
||||
}
|
||||
|
||||
public function getAction(): ?string
|
||||
{
|
||||
return $this->action;
|
||||
@@ -126,7 +134,7 @@ class Params
|
||||
return $this->updateBy;
|
||||
}
|
||||
|
||||
public function getDefaultValues(): array
|
||||
public function getDefaultValues(): stdClass
|
||||
{
|
||||
return $this->defaultValues;
|
||||
}
|
||||
@@ -249,8 +257,23 @@ class Params
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function withDefaultValues(array $defaultValues): self
|
||||
/**
|
||||
* @param stdClass|array|null $defaultValues
|
||||
*/
|
||||
public function withDefaultValues($defaultValues): self
|
||||
{
|
||||
if (is_array($defaultValues)) {
|
||||
$defaultValues = (object) $defaultValues;
|
||||
}
|
||||
|
||||
if (is_null($defaultValues)) {
|
||||
$defaultValues = (object) [];
|
||||
}
|
||||
|
||||
if (!is_object($defaultValues)) {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
||||
$obj = clone $this;
|
||||
$obj->defaultValues = $defaultValues;
|
||||
|
||||
@@ -297,21 +320,27 @@ class Params
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public static function fromRaw(array $params): self
|
||||
/**
|
||||
* @param stdClass|array|null $params
|
||||
*/
|
||||
public static function fromRaw($params): self
|
||||
{
|
||||
$raw = (object) $params;
|
||||
|
||||
$defaultValues = $raw->defaultValues ?? [];
|
||||
if (is_object($defaultValues)) {
|
||||
$defaultValues = get_object_vars($defaultValues);
|
||||
if ($params === null) {
|
||||
$params = (object) [];
|
||||
}
|
||||
|
||||
if (is_array($params) && is_object($params)) {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
||||
$raw = (object) $params;
|
||||
|
||||
$obj = self::create()
|
||||
->withAction($raw->action ?? null)
|
||||
->withCurrency($raw->currency ?? null)
|
||||
->withDateFormat($raw->dateFormat ?? null)
|
||||
->withDecimalMark($raw->decimalMark ?? null)
|
||||
->withDefaultValues($defaultValues)
|
||||
->withDefaultValues($raw->defaultValues ?? null)
|
||||
->withDelimiter($raw->delimiter ?? null)
|
||||
->withHeaderRow($raw->headerRow ?? false)
|
||||
->withIdleMode($raw->idleMode ?? false)
|
||||
|
||||
Reference in New Issue
Block a user