Merge pull request #4661 from turbo124/v5-develop

Document migration
This commit is contained in:
David Bomba 2021-01-10 21:21:15 +11:00 committed by GitHub
commit 41c84356f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 29 deletions

View File

@ -13,7 +13,7 @@ jobs:
strategy: strategy:
matrix: matrix:
operating-system: ['ubuntu-18.04', 'ubuntu-20.04'] operating-system: ['ubuntu-18.04', 'ubuntu-20.04']
php-versions: ['7.3', '7.4'] php-versions: ['7.4']
phpunit-versions: ['latest'] phpunit-versions: ['latest']
env: env:

View File

@ -101,6 +101,8 @@ class Import implements ShouldQueue
*/ */
private $company; private $company;
private $token;
/** /**
* @var array * @var array
*/ */
@ -229,6 +231,11 @@ class Import implements ShouldQueue
private function processAccount(array $data) :void private function processAccount(array $data) :void
{ {
if(array_key_exists('token', $data)){
$this->token = $data['token'];
unset($data['token']);
}
$account = $this->company->account; $account = $this->company->account;
$account->fill($data); $account->fill($data);
$account->save(); $account->save();
@ -965,41 +972,27 @@ class Import implements ShouldQueue
$entity = Expense::where('id', $expense_id)->withTrashed()->first(); $entity = Expense::where('id', $expense_id)->withTrashed()->first();
} }
$file_url = $resource['url']; $file_url = $resource['url'];
$file_name = basename($file_url); $file_name = $resource['name'];
$file_path = sys_get_temp_dir().'/'.$file_name; $file_path = sys_get_temp_dir().'/'.$file_name;
file_put_contents($file_path, file_get_contents($file_url), LOCK_EX); file_put_contents($file_path, $this->curlGet($file_url));
$finfo = new \finfo(FILEINFO_MIME_TYPE); $finfo = new \finfo(FILEINFO_MIME_TYPE);
$file_info = $finfo->file($file_path); $file_info = $finfo->file($file_path);
nlog($resource['url']); $uploaded_file = new UploadedFile(
nlog($file_url); $file_path,
nlog($file_name); $file_name,
nlog($file_path); $file_info,
nlog($file_info); filesize($file_path),
nlog(filesize($file_path)); 0,
false
$uploaded_file = new UploadedFile( );
$file_path,
$file_name,
$file_info,
filesize($file_path),
0,
false
);
$this->saveDocument($uploaded_file, $entity, $is_public = true); $this->saveDocument($uploaded_file, $entity, $is_public = true);
$uploaded_file = null;
$finfo = null;
$file_url = null;
$file_name = null;
$file_path = null;
$file_info = null;
} }
} }
private function processPaymentTerms(array $data) :void private function processPaymentTerms(array $data) :void
@ -1380,4 +1373,27 @@ $uploaded_file = new UploadedFile(
info(print_r($exception->getMessage(), 1)); info(print_r($exception->getMessage(), 1));
} }
public function curlGet($url, $headers = false)
{
return $this->exec('GET', $url, null);
}
public function exec($method, $url, $data)
{
nlog($this->token);
$client = new \GuzzleHttp\Client(['headers' =>
[
'X-Ninja-Token' => $this->token,
]
]);
$response = $client->request('GET', $url);
return $response->getBody();
}
} }