diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 586ec2d90a8f..fbbb8c7ab094 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -96,7 +96,7 @@ class Import implements ShouldQueue /** * @var array */ - private $data; + private $data; //the file path - using a different JSON parser here. /** * @var Company @@ -163,7 +163,7 @@ class Import implements ShouldQueue * @param User $user * @param array $resources */ - public function __construct(array $data, Company $company, User $user, array $resources = []) + public function __construct(string $data, Company $company, User $user, array $resources = []) { $this->data = $data; $this->company = $company; @@ -180,9 +180,9 @@ class Import implements ShouldQueue { set_time_limit(0); -info(print_r(array_keys($this->data),1)); + $jsonStream = \JsonMachine\JsonMachine::fromFile($this->data, "/data"); - foreach ($this->data as $key => $resource) { + foreach ($jsonStream as $key => $resource) { if (! in_array($key, $this->available_imports)) { //throw new ResourceNotAvailableForMigration("Resource {$key} is not available for migration."); info("Resource {$key} is not available for migration."); @@ -779,8 +779,8 @@ info(print_r(array_keys($this->data),1)); } private function processPayments(array $data): void - {info(print_r($this->ids,1)); - + { + Payment::reguard(); $rules = [ diff --git a/app/Jobs/Util/StartMigration.php b/app/Jobs/Util/StartMigration.php index b3cb4e6540fc..f80e963c6adb 100644 --- a/app/Jobs/Util/StartMigration.php +++ b/app/Jobs/Util/StartMigration.php @@ -107,9 +107,9 @@ class StartMigration implements ShouldQueue throw new NonExistingMigrationFile('Migration file does not exist, or it is corrupted.'); } - $data = json_decode(file_get_contents($file), 1); - - Import::dispatchNow($data['data'], $this->company, $this->user); + //$data = json_decode(file_get_contents($file), 1); + //Import::dispatchNow($data['data'], $this->company, $this->user); + Import::dispatchNow($file, $this->company, $this->user); } catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) { Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage())); diff --git a/composer.json b/composer.json index 8b9865fa9164..d64163f2f0b6 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,7 @@ "fzaninotto/faker": "^1.4", "google/apiclient": "^2.7", "guzzlehttp/guzzle": "^7.0.1", + "halaxa/json-machine": "^0.4.0", "hashids/hashids": "^3.0", "intervention/image": "^2.5", "laracasts/presenter": "^0.2.1", diff --git a/composer.lock b/composer.lock index e5bd8516b38a..ddd667c09f91 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7e448a70f9bd66e655c3a9dab1159d66", + "content-hash": "a178576541f03dbaf5e757fb4c89b474", "packages": [ { "name": "asgrim/ofxparser", @@ -2287,6 +2287,54 @@ }, "time": "2020-09-30T07:37:11+00:00" }, + { + "name": "halaxa/json-machine", + "version": "0.4.0", + "source": { + "type": "git", + "url": "https://github.com/halaxa/json-machine.git", + "reference": "b99d7a9a1efc8ba633da4581cf079b3a6f1ed219" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/halaxa/json-machine/zipball/b99d7a9a1efc8ba633da4581cf079b3a6f1ed219", + "reference": "b99d7a9a1efc8ba633da4581cf079b3a6f1ed219", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "ext-json": "*", + "guzzlehttp/guzzle": "^6", + "phpunit/phpunit": "^5.7.27" + }, + "type": "library", + "autoload": { + "psr-4": { + "JsonMachine\\": "src/" + }, + "files": [ + "src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Filip Halaxa", + "email": "filip@halaxa.cz" + } + ], + "description": "Efficient, easy-to-use and fast JSON pull parser", + "support": { + "issues": "https://github.com/halaxa/json-machine/issues", + "source": "https://github.com/halaxa/json-machine/tree/0.4.0" + }, + "time": "2020-11-09T13:28:55+00:00" + }, { "name": "hashids/hashids", "version": "3.0.0",