コード例 #1
0
 protected function _buildPackage($manifest, $date = null)
 {
     if (null === $date) {
         $date = time();
     }
     // Get manifest data
     if (is_string($manifest)) {
         $manifestData = (require $manifest);
         if (empty($manifestData['package'])) {
             throw new Exception(sprintf('Missing package data for package in path: %s', $manifestPath));
         }
         $manifestData = $manifestData['package'];
     } else {
         if (is_array($manifest)) {
             $manifestData = $manifest;
         } else {
             throw new Exception('Invalid manifest data type');
         }
     }
     // Override date (for now at least)
     $manifestData['date'] = $date;
     // Build package file
     $package = new Engine_Package_Manifest($manifestData);
     // Build archive
     $archiveFile = Engine_Package_Archive::deflate($package, $this->_outputPath);
     // Verify archive for integrity
     $extractedPath = Engine_Package_Archive::inflate($archiveFile, $this->_outputPath);
     $loaded = new Engine_Package_Manifest($extractedPath);
     // Remove verified archive
     Engine_Package_Utilities::fsRmdirRecursive($extractedPath, true);
     return $archiveFile;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: Manager.php プロジェクト: robeendey/ce
 /**
  * @param array $options
  * @return Engine_Package_Manager_PackageCollection
  */
 public function listAvailablePackages()
 {
     if (null !== $this->_availablePackages) {
         return $this->_availablePackages;
     }
     // Generate
     $availablePackages = new Engine_Package_Manager_PackageCollection($this);
     $extractedPath = $this->getAbsPath(self::PATH_PACKAGES);
     $archivesPath = $this->getAbsPath(self::PATH_ARCHIVES);
     if (!is_dir($archivesPath)) {
         return $availablePackages;
     }
     $it = new DirectoryIterator();
     foreach ($it as $file) {
         if ($file->isDot() || $file->isDir() || $file->getFilename() === 'index.html') {
             continue;
         }
         // Already extracted
         if (is_dir($extractedPath . DIRECTORY_SEPARATOR . substr($file->getFilename(), 0, strrpos($file->getFilename(), '.')))) {
             continue;
         }
         try {
             $packageFile = Engine_Package_Archive::readPackageFile($file->getPathname());
             $availablePackages->append($packageFile);
             unset($packageFile);
         } catch (Exception $e) {
             // Silence?
             //if( APPLICATION_ENV == 'development' ) {
             //  throw $e;
             //}
         }
     }
     // Order? -- @todo probably should switch to priority later
     $availablePackages->ksort();
     return $this->_availablePackages = $availablePackages;
 }