public function getGuid() { if (null !== $this->_targetPackage) { return $this->_targetPackage->getGuid(); } else { return $this->_currentPackage->getGuid(); } }
public function extractAction() { $this->_helper->contextSwitch->initContext(); $package = $this->_getParam('package'); // Setup try { $archiveDir = $this->_packageManager->getTemporaryPath(Engine_Package_Manager::PATH_ARCHIVES); $extractDir = $this->_packageManager->getTemporaryPath(Engine_Package_Manager::PATH_PACKAGES); } catch (Exception $e) { $this->view->error = $e->getMessage(); return; } // Check if archive is a tar file $targetFile = $archiveDir . DIRECTORY_SEPARATOR . $package; if (strtolower(substr($targetFile, -4, 4)) != '.tar') { $this->view->error = 'Package is not a TAR archive.'; return; } // Check if archive exists if (!file_exists($targetFile)) { $this->view->error = 'Package does not exist.'; return; } // Try to deflate archive? $extractFiles = array($targetFile); $packagesInfo = array(); @set_time_limit(300); $toRemove = array(); try { while (count($extractFiles) > 0) { $current = array_shift($extractFiles); $hadPackage = false; $hadArchive = false; // Try to extract $outputPath = Engine_Package_Archive::inflate($current, $extractDir); // Check for tar files or package files foreach (scandir($outputPath) as $child) { // Package file if (strtolower($child) == 'package.json') { $packageFile = new Engine_Package_Manifest($outputPath . DIRECTORY_SEPARATOR . $child); $packagesInfo[] = array('key' => $packageFile->getKey(), 'data' => $packageFile->toArray(), 'html' => $this->view->packageSelect($packageFile)); $hadPackage = true; } else { if (strtolower(substr($child, -4)) === '.tar') { $extractFiles[] = $outputPath . DIRECTORY_SEPARATOR . $child; $hadArchive = true; } } } // Add to remove after extraction $toRemove[] = $current; if (!$hadPackage) { $toRemove[] = $outputPath; } } } catch (Exception $e) { $this->view->error = $e->getMessage(); return; } if (empty($packagesInfo)) { $this->view->error = 'No packages found in archive'; return; } // Remove to remove foreach ($toRemove as $removeFile) { if (is_dir($removeFile)) { try { Engine_Package_Utilities::fsRmdirRecursive($removeFile, true); } catch (Exception $e) { } } else { if (is_file($removeFile)) { @unlink($removeFile); } } } $this->view->status = 1; $this->view->packagesInfo = $packagesInfo; }
protected static function _addPackageToArchive(Engine_Package_Manifest $package, Archive_Tar $archive, $basePath) { $rval = null; foreach ($package->getStructure() as $name => $contents) { if (!$contents instanceof Engine_Package_Manifest_Entity_Abstract) { continue; } switch ($contents->getType()) { case 'package': $subPackageObject = new Engine_Package_Manifest($basePath . DIRECTORY_SEPARATOR . $contents['path'] . DIRECTORY_SEPARATOR . $contents['packageFile']); $subPackageObject->setBasePath($basePath); self::_addPackageToArchive($subPackageObject, $archive, $basePath); break; case 'directory': // Add directory $rval = $archive->addModify($basePath . DIRECTORY_SEPARATOR . $contents['path'], null, $basePath); if ($archive->isError($rval)) { throw new Engine_Package_Exception(sprintf('Unable to add path "%s" to archive', $contents['path'])); } break; case 'file': // Add file $rval = $archive->addModify($basePath . DIRECTORY_SEPARATOR . $contents['path'], null, $basePath); if ($archive->isError($rval)) { throw new Engine_Package_Exception(sprintf('Unable to add path "%s" to archive', $contents['path'])); } break; default: throw new Engine_Package_Exception('unknown contents type'); break; } } // Throw error if failed if ($archive->isError($rval)) { throw new Engine_Package_Exception('Error in archive: ' . $rval->getMessage()); } }
public function manageAction() { require_once 'PEAR.php'; require_once 'Archive/Tar.php'; // Get built packages $builtPackages = array(); $builtPackageFiles = array(); foreach (scandir($this->_outputPath) as $file) { $path = $this->_outputPath . '/' . $file; if (!is_file($path)) { continue; } if (substr($file, -4) !== '.tar') { continue; } // Read package.json $archive = new Archive_Tar($path); $string = $archive->extractInString('package.json'); if ($string) { $package = new Engine_Package_Manifest(); $parser = Engine_Package_Manifest_Parser::factory('package.json'); $package->fromArray($parser->fromString($string)); } else { $package = null; } $builtPackages[] = $package; $builtPackageFiles[] = $path; } $this->view->packages = $builtPackages; $this->view->packageFiles = $builtPackageFiles; }
/** * @param array $options * @return Engine_Package_Manager_PackageCollection */ public function listInstalledPackages($options = array()) { if (null !== $this->_installedPackages) { return $this->_installedPackages; } // Generate $installedPackages = new Engine_Package_Manager_PackageCollection($this, array(), $options); $it = new DirectoryIterator($this->getAbsPath(self::PATH_INSTALLED)); // List installed packages foreach ($it as $file) { if ($file->isDot() || $file->isDir() || $file->getFilename() === 'index.html') { continue; } try { $packageFile = new Engine_Package_Manifest($file->getPathname()); // Reset base path $packageFile->setBasePath($this->_basePath); // Check for package files for two versions of the package $guid = $packageFile->getGuid(); if ($installedPackages->hasGuid($guid)) { /* $otherPackageKey = $installedPackages->getKeyByGuid($guid); $otherPackageVersion = trim(str_replace($guid, '', $otherPackageKey), '.:-'); if( version_compare($packageFile->getVersion(), $otherPackageVersion, '>') ) { $installedPackages->append($packageFile); } * */ $otherPackage = $installedPackages->offsetGet($packageFile->getGuid()); if (version_compare($packageFile->getVersion(), $otherPackage->getVersion(), '>')) { $installedPackages->append($packageFile); } } else { $installedPackages->append($packageFile); } unset($packageFile); } catch (Exception $e) { // Silence? if (APPLICATION_ENV == 'development') { throw $e; } } } // Order? -- @todo probably should switch to priority later $installedPackages->ksort(); return $this->_installedPackages = $installedPackages; }