/**
  * Unpack the zip file using the xPDOZip class
  * 
  * @return bool|string
  */
 public function unpack()
 {
     if (!$this->modx->loadClass('compression.xPDOZip', $this->modx->getOption('core_path') . 'xpdo/', true, true)) {
         return $this->modx->lexicon('gallery.xpdozip_err_nf');
     }
     /* unpack zip file */
     $archive = new xPDOZip($this->modx, $this->source['tmp_name']);
     if (!$archive) {
         return $this->modx->lexicon('gallery.zip_err_unpack');
     }
     $archive->unpack($this->target);
     $archive->close();
     return true;
 }
 /**
  * Unpack a zip archive to a specified location.
  *
  * @uses compression.xPDOZip OR compression.PclZip
  * @todo Refactor this to be implemented in a service class external to xPDOTransport.
  *
  * @param xPDO &$xpdo A reference to an xPDO instance.
  * @param string $from An absolute file system location to a valid zip archive.
  * @param string $to A file system location to extract the contents of the archive to.
  * @return array|boolean An array of unpacked resources or false on failure.
  */
 public static function _unpack(&$xpdo, $from, $to)
 {
     $resources = false;
     if ($xpdo->getOption(xPDOTransport::ARCHIVE_WITH, null, 0) != xPDOTransport::ARCHIVE_WITH_PCLZIP && class_exists('ZipArchive', true) && $xpdo->loadClass('compression.xPDOZip', XPDO_CORE_PATH, true, true)) {
         $archive = new xPDOZip($xpdo, $from);
         if ($archive) {
             $resources = $archive->unpack($to);
             $archive->close();
         }
     } elseif (class_exists('PclZip') || (include XPDO_CORE_PATH . 'compression/pclzip.lib.php')) {
         $archive = new PclZip($from);
         if ($archive) {
             $resources = $archive->extract(PCLZIP_OPT_PATH, $to);
         }
     }
     return $resources;
 }
Exemple #3
0
 /**
  * Test unpacking files/dirs from a ZipArchive
  *
  * @dataProvider providerUnpackArchive
  * @depends testPackArchive
  * @param $target
  * @param $archive
  * @param $options
  * @param $unpackOptions
  * @param $expected
  */
 public function testUnpackArchive($target, $archive, $options, $unpackOptions, $expected)
 {
     if (!empty(xPDOTestHarness::$debug)) {
         print "\n" . __METHOD__ . " = ";
     }
     $result = false;
     $targetPath = xPDOTestHarness::$properties['xpdo_test_path'] . "fs/unzip/{$target}";
     $archivePath = xPDOTestHarness::$properties['xpdo_test_path'] . "fs/{$archive}";
     try {
         $this->xpdo->loadClass('compression.xPDOZip', XPDO_CORE_PATH, true, true);
         $archive = new xPDOZip($this->xpdo, $archivePath, $options);
         $result = $archive->unpack($targetPath, $unpackOptions);
         $this->xpdo->log(xPDO::LOG_LEVEL_INFO, "Unpack results for {$archivePath}: " . print_r($result, true));
     } catch (Exception $e) {
         $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $e->getMessage(), '', __METHOD__, __FILE__, __LINE__);
     }
     $this->assertEquals($expected, $result, "Error unpacking xPDOZip archive {$archivePath} to target {$targetPath}");
 }