Fixes for company export paths

This commit is contained in:
David Bomba 2024-02-19 16:10:14 +11:00
parent 881ae75e5d
commit 4d4e3745f1

View File

@ -69,10 +69,9 @@ class CompanyExport implements ShouldQueue
{ {
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
$this->file_name = date('Y-m-d') . '_' . str_replace([" ", "/"], ["_",""], $this->company->present()->name() . '_' . $this->company->company_key . '.json'); $this->file_name = date('Y-m-d') . '_' . str_replace([" ", "/"], ["_",""], $this->company->present()->name() . '_' . $this->company->company_key . '.json');
$this->writer = new File($this->file_name); $this->writer = new File(sys_get_temp_dir().'/'.$this->file_name);
set_time_limit(0); set_time_limit(0);
@ -114,8 +113,6 @@ class CompanyExport implements ShouldQueue
return $user; return $user;
})->all(); })->all();
$x = $this->writer->collection('users'); $x = $this->writer->collection('users');
$x->addItems($this->export_data['users']); $x->addItems($this->export_data['users']);
$this->export_data = null; $this->export_data = null;
@ -667,7 +664,7 @@ class CompanyExport implements ShouldQueue
private function zipAndSend() private function zipAndSend()
{ {
$zip_path = \Illuminate\Support\Str::ascii(str_replace(".json", ".zip", $this->file_name)); $zip_path = sys_get_temp_dir().'/'.\Illuminate\Support\Str::ascii(str_replace(".json", ".zip", $this->file_name));
$zip = new \ZipArchive(); $zip = new \ZipArchive();
@ -675,8 +672,8 @@ class CompanyExport implements ShouldQueue
nlog("cannot open {$zip_path}"); nlog("cannot open {$zip_path}");
} }
$zip->addFile($this->file_name); $zip->addFile(sys_get_temp_dir().'/'.$this->file_name, 'backup.json');
$zip->renameName($this->file_name, 'backup.json'); // $zip->renameName($this->file_name, 'backup.json');
$zip->close(); $zip->close();
@ -686,8 +683,8 @@ class CompanyExport implements ShouldQueue
unlink($zip_path); unlink($zip_path);
} }
if(file_exists($this->file_name)) { if(file_exists(sys_get_temp_dir().'/'.$this->file_name)) {
unlink($this->file_name); unlink(sys_get_temp_dir().'/'.$this->file_name);
} }
if(Ninja::isSelfHost()) { if(Ninja::isSelfHost()) {
@ -717,8 +714,8 @@ class CompanyExport implements ShouldQueue
if (Ninja::isHosted()) { if (Ninja::isHosted()) {
sleep(3); sleep(3);
if(file_exists($zip_path)) { if(file_exists(sys_get_temp_dir().'/'.$zip_path)) {
unlink($zip_path); unlink(sys_get_temp_dir().'/'.$zip_path);
} }
} }
} }