public function testListFiles() { // testing empty file $this->file->shouldReceive('isFile')->with('foo.file')->andReturn(true); $this->file->shouldReceive('isFile')->with('bar.file')->andReturn(true); $this->assertEquals(array(), $this->archive->listFiles()); // testing not empty file $this->archive->add('foo.file'); $this->archive->add('bar.file'); $this->assertEquals(array('foo.file', 'bar.file'), $this->archive->listFiles()); // testing with a empty sub dir $this->file->shouldReceive('isFile')->with('/path/to/subDirEmpty')->andReturn(false); $this->file->shouldReceive('files')->with('/path/to/subDirEmpty')->andReturn(array()); $this->file->shouldReceive('directories')->with('/path/to/subDirEmpty')->andReturn(array()); $this->archive->folder('subDirEmpty')->add('/path/to/subDirEmpty'); $this->assertEquals(array('foo.file', 'bar.file'), $this->archive->listFiles()); // testing with a not empty sub dir $this->file->shouldReceive('isFile')->with('/path/to/subDir')->andReturn(false); $this->file->shouldReceive('isFile')->with('sub.file')->andReturn(true); $this->file->shouldReceive('files')->with('/path/to/subDir')->andReturn(array('sub.file')); $this->file->shouldReceive('directories')->with('/path/to/subDir')->andReturn(array()); $this->archive->folder('subDir')->add('/path/to/subDir'); $this->assertEquals(array('foo.file', 'bar.file', 'subDir/sub.file'), $this->archive->listFiles()); }
/** * Sets the internal folder to the given path.<br/> * Useful for extracting only a segment of a zip file. * * @param $path * @return $this * @static */ public static function folder($path) { return \Chumper\Zipper\Zipper::folder($path); }
/** * Adds database dump to the package * * @param Zipper $zipper * @return Zipper */ protected function addDbdumpToPackage(Zipper $zipper) { $fileName = sys_get_temp_dir() . '/' . date('Y-m-d_His') . '-mysqldump.sql'; MySql::create()->setDbName(env('DB_DATABASE'))->setUserName(env('DB_USERNAME'))->setPassword(env('DB_PASSWORD'))->dumpToFile($fileName); $zipper->folder('database')->add($fileName); return $zipper; }
public function getJust($idCarga) { $carga = Cargas::find($idCarga); if ($carga) { //obtener cargas $empresa = $carga->empresa()->orderBy('tipo_receptor')->get(); $sat = $carga->sat()->orderBy('tipo_receptor')->get(); $diff = new DiferenciasCFID($sat, $empresa, $carga->rfc); $just_emitidos = $diff->get_justificados_emitidos(); $just_recibidos = $diff->get_justificados_recibidos(); $array = ['rfc' => $carga->rfc, 'nombre' => $carga->contribuyente->nombre, 'justEm' => $just_emitidos, 'justRec' => $just_recibidos]; $namePdf = $carga->rfc . "_" . time() . ".pdf"; \PDF::loadView('descargas.reporte-justificados', $array)->save(storage_path('temp') . "/{$namePdf}"); $nameZip = "just_" . time() . ".zip"; $zipper = new Zipper(); $zipper->make(storage_path("temp/{$nameZip}"))->add(storage_path('temp') . "/{$namePdf}"); $anexos = $diff->getAnexos(); foreach ($anexos as $anexo) { $zipper->folder($anexo['uuid']); foreach ($anexo['anexos'] as $file) { $zipper->add($file->file); } } $zipper->close(); return response()->download(storage_path("temp/{$nameZip}"), $nameZip); } }
public function getJust(Request $request) { try { $contr = $request->cont; $desde = Carbon::createFromFormat('Y-m-d', $request->desde)->startOfDay(); $hasta = Carbon::createFromFormat('Y-m-d', $request->hasta)->endOfDay(); } catch (\Exception $e) { return view('vacio'); } $sat = ArchivoSat::whereBetween('fecha', array($desde, $hasta))->where(function ($q) use($contr) { $q->where('rfc_emisor', '=', $contr)->orWhere('rfc_receptor', '=', $contr); })->get(); $empresa = ArchivoEmpresa::whereBetween('fecha', array($desde, $hasta))->where(function ($q) use($contr) { $q->where('rfc_emisor', '=', $contr)->orWhere('rfc_receptor', '=', $contr); })->get(); $todos = $sat->count() + $empresa->count(); if ($todos == 0) { return view('vacio'); } $diff = new DiferenciasCFID($sat, $empresa, $contr); $just_emitidos = $diff->get_justificados_emitidos(); $just_recibidos = $diff->get_justificados_recibidos(); $contr = Contribuyente::where('rfc', '=', $contr)->first(); $array = ['nombre' => $contr->nombre, 'rfc' => $contr->rfc, 'justEm' => $just_emitidos, 'justRec' => $just_recibidos]; $namePdf = $contr->rfc . "_" . time() . ".pdf"; \PDF::loadView('descargas.reporte-justificados', $array)->save(storage_path('temp') . "/{$namePdf}"); $nameZip = "just_" . time() . ".zip"; $zipper = new Zipper(); $zipper->make(storage_path("temp/{$nameZip}"))->add(storage_path('temp') . "/{$namePdf}"); $anexos = $diff->getAnexos(); foreach ($anexos as $anexo) { $zipper->folder($anexo['uuid']); foreach ($anexo['anexos'] as $file) { $zipper->add($file->file); } } $zipper->close(); return response()->download(storage_path("temp/{$nameZip}"), $nameZip); }