mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 22:47:32 -05:00 
			
		
		
		
	Refactor for Zipping backups
This commit is contained in:
		
							parent
							
								
									63725ea743
								
							
						
					
					
						commit
						8df0f6bb27
					
				@ -431,30 +431,20 @@ class CompanyExport implements ShouldQueue
 | 
				
			|||||||
    private function zipAndSend()
 | 
					    private function zipAndSend()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $tempStream = fopen('php://memory', 'w+');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $options = new Archive();
 | 
					 | 
				
			||||||
        $options->setOutputStream($tempStream);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $file_name = date('Y-m-d').'_'.str_replace(' ', '_', $this->company->present()->name() . '_' . $this->company->company_key .'.zip');
 | 
					        $file_name = date('Y-m-d').'_'.str_replace(' ', '_', $this->company->present()->name() . '_' . $this->company->company_key .'.zip');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $zip = new ZipStream($file_name, $options);
 | 
					        $zip_path = public_path('storage/backups/'.$file_name);
 | 
				
			||||||
 | 
					        $zip = new \ZipArchive();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $fp = tmpfile();
 | 
					        if ($zip->open($zip_path, \ZipArchive::CREATE)!==TRUE) {
 | 
				
			||||||
        fwrite($fp, json_encode($this->export_data));
 | 
					            nlog("cannot open {$zip_path}");
 | 
				
			||||||
        rewind($fp);
 | 
					        }
 | 
				
			||||||
        $zip->addFileFromStream('backup.json', $fp);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $zip->finish();
 | 
					        $zip->addFromString("backup.json", json_encode($this->export_data));
 | 
				
			||||||
 | 
					        $zip->close();
 | 
				
			||||||
        $path = 'backups/';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Storage::disk(config('filesystems.default'))->put($path.$file_name, $tempStream);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        fclose($tempStream);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $nmo = new NinjaMailerObject;
 | 
					        $nmo = new NinjaMailerObject;
 | 
				
			||||||
        $nmo->mailable = new DownloadBackup(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company);
 | 
					        $nmo->mailable = new DownloadBackup(Storage::disk(config('filesystems.default'))->url('backups/'.$file_name), $this->company);
 | 
				
			||||||
        $nmo->to_user = $this->user;
 | 
					        $nmo->to_user = $this->user;
 | 
				
			||||||
        $nmo->company = $this->company;
 | 
					        $nmo->company = $this->company;
 | 
				
			||||||
        $nmo->settings = $this->company->settings;
 | 
					        $nmo->settings = $this->company->settings;
 | 
				
			||||||
 | 
				
			|||||||
@ -298,8 +298,11 @@ class Import implements ShouldQueue
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $data = $this->transformCompanyData($data);
 | 
					        $data = $this->transformCompanyData($data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(Ninja::isHosted())
 | 
					        if(Ninja::isHosted() && strlen($data['subdomain']) > 1) {
 | 
				
			||||||
            $data['subdomain'] = MultiDB::randomSubdomainGenerator();
 | 
					
 | 
				
			||||||
 | 
					            if(!MultiDB::checkDomainAvailable($data['subdomain']))
 | 
				
			||||||
 | 
					                $data['subdomain'] = MultiDB::randomSubdomainGenerator();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $rules = (new UpdateCompanyRequest())->rules();
 | 
					        $rules = (new UpdateCompanyRequest())->rules();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user