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());
     }
 }
Beispiel #2
0
 /**
  * @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;
 }