modxcms/xpdo — pull request #38 by exside (2014-05-10 20:33:29+00:00)
Title: Enhancement xpdoarchive

First attempt to create a dedicated archive class for xpdo (which would replace the function unpack in MODX/modFileHandler). What I have so far seems to work quite well, also for other archive types than rar (tested with .tar, .tar.gz, tgz, .bz2, .tbz2).

Usage is quite simple:

```
if ($modx->getService('archive', 'compression.xPDOArchive', XPDO_CORE_PATH)) {
$results = $modx->archive->unpack($to, array('file' => $from)); // to let the class determine which extraction method to use
$results = $modx->archive->zipExtract($to, array('file' => $from)); // to directly extract a .zip file
$results = $modx->archive->tarExtract($to, array('file' => $from)); // to directly extract another archive format
}
```

with this the unpack() method on line 707 of xpdo/transport/xpdotransport.class.php could look like that (when _unpack() would be removed):

```
/**
* Unpack the package to prepare for installation and return a manifest.
*
* @param xPDO &$xpdo A reference to an xPDO instance.
* @param string $from Filename of the archive containing the transport package.
* @param string $to The root path where the contents of the archive should be extracted. This
* path must be writable by the user executing the PHP process on the server.
* @param integer $state The current state of the package, i.e. packed or unpacked.
* @return array The manifest which is included after successful extraction.
*/
public static function unpack(& $xpdo, $from, $to, $state = xPDOTransport::STATE_PACKED) {
$manifest= null;
if ($state !== xPDOTransport::STATE_UNPACKED) {
$xpdo->getService('archive', 'compression.xPDOArchive', XPDO_CORE_PATH);
// $resources = xPDOTransport::_unpack($xpdo, $from, $to); // old version
$resources = $xpdo->archive->unpack($to, array('file' => $from));
} else {
$resources = true;
}
if ($resources) {
$manifestFilename = $to . basename($from, '.transport.zip') . '/manifest.php';
if (file_exists($manifestFilename)) {
$manifest= @include ($manifestFilename);
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not find package manifest at {$manifestFilename}");
}
}
return $manifest;
}
```

@opengeek: is this approach more of what could be helpful somehow?