mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Fixes for imports
This commit is contained in:
parent
03b76d8479
commit
0c9f982bdf
@ -96,7 +96,7 @@ class Import implements ShouldQueue
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $data; //the file path - using a different JSON parser here.
|
||||
private $file_path; //the file path - using a different JSON parser here.
|
||||
|
||||
/**
|
||||
* @var Company
|
||||
@ -163,9 +163,9 @@ class Import implements ShouldQueue
|
||||
* @param User $user
|
||||
* @param array $resources
|
||||
*/
|
||||
public function __construct(string $data, Company $company, User $user, array $resources = [])
|
||||
public function __construct(string $file_path, Company $company, User $user, array $resources = [])
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->file_path = $file_path;
|
||||
$this->company = $company;
|
||||
$this->user = $user;
|
||||
$this->resources = $resources;
|
||||
@ -180,20 +180,27 @@ class Import implements ShouldQueue
|
||||
{
|
||||
set_time_limit(0);
|
||||
|
||||
$jsonStream = \JsonMachine\JsonMachine::fromFile($this->data, "/data");
|
||||
// $jsonStream = \JsonMachine\JsonMachine::fromFile($this->file_path, "/data");
|
||||
$array = json_decode(file_get_contents($this->file_path), 1);
|
||||
$data = $array['data'];
|
||||
|
||||
foreach ($jsonStream as $key => $resource) {
|
||||
if (! in_array($key, $this->available_imports)) {
|
||||
info(array_keys($data));
|
||||
|
||||
foreach ($this->available_imports as $import) {
|
||||
|
||||
info("the key = {$import}");
|
||||
|
||||
if (! array_key_exists($import, $data)) {
|
||||
//throw new ResourceNotAvailableForMigration("Resource {$key} is not available for migration.");
|
||||
info("Resource {$key} is not available for migration.");
|
||||
info("Resource {$import} is not available for migration.");
|
||||
continue;
|
||||
}
|
||||
|
||||
$method = sprintf('process%s', Str::ucfirst(Str::camel($key)));
|
||||
$method = sprintf('process%s', Str::ucfirst(Str::camel($import)));
|
||||
|
||||
info("Importing {$key}");
|
||||
info("Importing {$import}");
|
||||
|
||||
$this->{$method}($resource);
|
||||
$this->{$method}($data[$import]);
|
||||
}
|
||||
|
||||
$this->setInitialCompanyLedgerBalances();
|
||||
|
@ -600,7 +600,7 @@ trait GeneratesCounter
|
||||
$replace[] = str_replace($format, $date, $matches[1]);
|
||||
}
|
||||
|
||||
if($entity instanceof Client){
|
||||
if($entity instanceof Client || $entity instanceof Vendor){
|
||||
$search[] = '{$client_custom1}';
|
||||
$replace[] = $entity->custom_value1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user