Exemple #1
0
 public function testMergeZipArchives()
 {
     $zip_1 = Zip::create(__DIR__ . '/../tmp/test_manager_5.zip');
     $zip_1->add(__DIR__ . '/../resources/lorem.txt')->close();
     $zip_2 = Zip::create(__DIR__ . '/../tmp/test_manager_6.zip');
     $zip_2->add(__DIR__ . '/../resources/keepcalm.png')->close();
     $manager = new ZipManager();
     $addZip = $manager->addZip(Zip::open(__DIR__ . '/../tmp/test_manager_5.zip'))->addZip(Zip::open(__DIR__ . '/../tmp/test_manager_6.zip'));
     $merge = $manager->merge(__DIR__ . '/../tmp/test_manager_merge.zip');
     $this->assertTrue($merge);
     $manager->close();
 }
Exemple #2
0
 /**
  * @expectedException        Comodojo\Exception\ZipException
  */
 public function testInvalidSkipMode()
 {
     $zip = new Zip(__DIR__ . '/../tmp/test_2.zip');
     $zip->setSkipped("FOO");
 }
Exemple #3
0
 /**
  * Add files to zip
  *
  * @param $path string
  * @param $files array
  * @throws \Comodojo\Exception\ZipException
  */
 public function add($path, $files)
 {
     $zip = \Comodojo\Zip\Zip::open($path);
     $zip->add($files);
 }
 public function post()
 {
     // Init resources
     $collector = new Collector();
     $zip = new Zip();
     $cache = $this->getCacher();
     // Acquire attributes, parameters and logger
     $attributes = $this->getAttributes();
     $parameters = $this->getParameters();
     $logger = $this->getLogger();
     // get info from request
     $docId = $attributes['docId'];
     $payload = $parameters['payload'];
     $payloadHash = $this->getRequestHeader('X-Hub-Signature');
     $event = $this->getRequestHeader('X-Github-Event');
     // $logger->debug($event);
     // $logger->debug($payload);
     // get main configuration
     $config = file_get_contents(DISPATCHER_REAL_PATH . 'configs/gitdoc.json');
     if ($config === false) {
         throw new DispatcherException("Invalid configuration file", 500);
     }
     $config = $this->deserialize->fromJson($config);
     // start populating collector
     $collector->setConfiguration($config);
     if (!$collector->setProject($docId)) {
         throw new DispatcherException("Unknown project", 400);
     }
     if (!$collector->checkConsistence($payload, $payloadHash)) {
         throw new DispatcherException("Wrong payload signature", 400);
     }
     if (!$collector->setEvent($event)) {
         throw new DispatcherException("Event not supported", 400);
     }
     $collector->setPayload($payload);
     try {
         if ($collector->processDownload()) {
             // $logger->debug($collector->getDownloadUrl());
             $http = new Httprequest($collector->getDownloadUrl(), false);
             $zipball = $http->get();
             $download = file_put_contents($collector->getDownloadPath(), $zipball);
             if ($download === false) {
                 throw new DispatcherException("Download folder not writeable", 500);
             }
             $zip->setMask(0777)->open($collector->getDownloadPath())->extract($collector->getExtractPath());
             unlink($collector->getDownloadPath());
         }
         $collector->updateConfiguration();
         $cache->purge();
     } catch (HttpException $he) {
         throw new DispatcherException("Unable to get repository zipball", 500);
     } catch (ZipException $ze) {
         // $logger->error($ze->getMessage());
         throw new DispatcherException("Unable to unzip repository zipball", 500);
     } catch (DispatcherException $de) {
         throw $de;
     } catch (Exception $e) {
         throw $e;
     }
     return 'OK';
 }
 public function notesupload()
 {
     $chapterid = Input::get('chapteruuid');
     $file = Input::file('notes');
     $notes = Notes::where('chapter_id', $chapterid)->first();
     if (!$notes) {
         $notes = new Notes();
         $notes->id = Uuid::generate();
         $notes->chapter_id = $chapterid;
         $notes->file_path = public_path() . "/notes/";
     }
     $notes->file_name = $file->getClientOriginalName();
     $notes->save();
     if ($file->isValid()) {
         $fileName = $notes->chapter_id . ".zip";
         /* if(env('APP_ENV')==="production"){//give write permission
                chmod($notes->file_path, 0777);
            }*/
         $file->move($notes->file_path, $fileName);
         //\Storage::disk('notes')->put($fileName,File::get($file));
         //$filePath=storage_path()."/thinkmerit/notes/";
         $zip = \Comodojo\Zip\Zip::open($notes->file_path . $fileName);
         $zip->extract($notes->file_path . $chapterid);
         $notes->save();
         $zip->close();
         unlink($notes->file_path . $fileName);
         /*if(env('APP_ENV')==="production"){//exclude write permission
               chmod($notes->file_path, 0444);
           }*/
         //\Storage::disk('notes')->delete($fileName);
         return back()->withErrors(['success' => "File successfully uploaded!"]);
     }
     return back()->withErrors(['error' => "Error uploading file!"]);
 }
Exemple #6
0
 /**
  * Create a new zip archive
  *
  * @param   string  $zip_file   ZIP file name
  * @param   bool    $overwrite  overwrite existing file (if any)
  *
  * @return  \Comodojo\Zip\Zip
  * @throws  \Comodojo\Exception\ZipException
  */
 public static function create($zip_file, $overwrite = false)
 {
     $overwrite = filter_var($overwrite, FILTER_VALIDATE_BOOLEAN, array("options" => array("default" => false)));
     try {
         $zip = new Zip($zip_file);
         if ($overwrite) {
             $zip->setArchive(self::openZipFile($zip_file, ZipArchive::CREATE | ZipArchive::OVERWRITE));
         } else {
             $zip->setArchive(self::openZipFile($zip_file, ZipArchive::CREATE));
         }
     } catch (ZipException $ze) {
         throw $ze;
     }
     return $zip;
 }
 /**
  * Merge multiple Zips into one
  * 
  * @param   string  $output_zip_file    Destination zip
  * @param   bool    $separate           Specify if files should be placed in different directories
  *
  * @return  bool
  * @throws  \Comodojo\Exception\ZipException
  */
 public function merge($output_zip_file, $separate = true)
 {
     $pathinfo = pathinfo($output_zip_file);
     $temporary_folder = $pathinfo['dirname'] . "/" . self::getTemporaryFolder();
     try {
         $this->extract($temporary_folder, $separate, null);
         $zip = Zip::create($output_zip_file);
         $zip->add($temporary_folder, true)->close();
         self::recursiveUnlink($temporary_folder);
     } catch (ZipException $ze) {
         throw $ze;
     } catch (Exception $e) {
         throw $e;
     }
     return true;
 }