示例#1
0
 /**
  * Retrieve list of packages available to download.
  *
  * Example of return value:
  * array(
  *  'packages' => array(
  *                      '<package_name1>' => array( "name" =>... , "version" =>... , "summary" => ... "url" =>... ),
  *                      '<package_name2>' => array( "name" =>... , "version" =>... , "summary" => ... "url" =>... )
  *                     )
  *      );
  *
  */
 function retrieveRemotePackagesList($onlySitePackages = false)
 {
     // Download index file.
     $idxFileName = $this->downloadFile($this->XMLIndexURL, eZStepSiteTypes::tempDir(), 'index.xml');
     if ($idxFileName === false) {
         // Searching for a local index.xml file to use for offline installation
         $destIndexPath = eZStepSiteTypes::tempDir() . DIRECTORY_SEPARATOR . 'index.xml';
         $repo = eZPackage::systemRepositoryInformation();
         if ($repo) {
             $sourceIndexPath = $repo['path'] . DIRECTORY_SEPARATOR . 'index.xml';
             if (file_exists($sourceIndexPath)) {
                 eZFileHandler::copy($sourceIndexPath, $destIndexPath);
                 $idxFileName = $destIndexPath;
                 // Removing error message from downloadFile
                 $this->ErrorMsg = false;
             }
         }
     }
     if ($idxFileName === false) {
         $this->ErrorMsg = ezpI18n::tr('design/standard/setup/init', 'Retrieving remote site packages list failed. ' . 'You may upload packages manually.');
         eZDebug::writeNotice("Cannot download remote packages index file from '{$this->XMLIndexURL}'.");
         return false;
     }
     // Parse it.
     $dom = new DOMDocument('1.0', 'utf-8');
     $dom->preserveWhiteSpace = false;
     $success = $dom->load(realpath($idxFileName));
     @unlink($idxFileName);
     if (!$success) {
         eZDebug::writeError("Unable to open index file.");
         return false;
     }
     $root = $dom->documentElement;
     if ($root->localName != 'packages') {
         eZDebug::writeError("Malformed index file.");
         return false;
     }
     $packageList = array();
     foreach ($root->childNodes as $packageNode) {
         if ($packageNode->localName != 'package') {
             // skip unwanted chilren
             continue;
         }
         if ($onlySitePackages && $packageNode->getAttribute('type') != 'site') {
             // skip non-site packages
             continue;
         }
         $packageAttributes = array();
         foreach ($packageNode->attributes as $attributeNode) {
             $packageAttributes[$attributeNode->localName] = $attributeNode->value;
         }
         $packageList[$packageAttributes['name']] = $packageAttributes;
     }
     return $packageList;
 }
示例#2
0
function downloadPackages($packageList, $packageURL, $packageDir, $packageRepository)
{
    global $cli;
    showMessage2("Configuring...");
    if (!is_array($packageList) || count($packageList) == 0) {
        showError("Package list is empty. Aborting...");
    }
    // 1. check if packages specified in $packageList exist in $packageRepository(means already downloaded and imported).
    //    if yes - ask user to do download or not. If not - go out
    foreach (array_keys($packageList) as $k) {
        $packageName = $packageList[$k];
        $package = eZPackage::fetch($packageName);
        if (is_object($package)) {
            global $autoMode;
            if ($autoMode == 'on') {
                $action = 'y';
            } else {
                $action = getUserInput("Package '{$packageName}' already imported. Import it anyway? [y/n]: ");
            }
            if (strpos($action, 'n') === 0) {
                unset($packageList[$k]);
            } else {
                eZDir::recursiveDelete(eZPackage::repositoryPath() . "/{$packageRepository}/{$packageName}");
            }
        }
    }
    if (count($packageList) == 0) {
        // all packages are imported.
        return true;
    }
    // 2. check $packgesList exists in $packageDir(means packages downloaded but not imported)
    //    if yes - ask user to import or not. If not - go out
    if (!checkDir($packageDir)) {
        return false;
    }
    $downloadPackageList = array();
    foreach ($packageList as $packageName) {
        if (file_exists("{$packageDir}/{$packageName}.ezpkg")) {
            global $autoMode;
            if ($autoMode == 'on') {
                $action = 'y';
            } else {
                $action = getUserInput("Package '{$packageName}' already downloaded. Download it anyway? [y/n]: ");
            }
            if (strpos($action, 'n') === 0) {
                continue;
            }
        }
        $downloadPackageList[] = $packageName;
    }
    //
    // download
    //
    showMessage2("Downloading...");
    if (count($downloadPackageList) > 0) {
        // TODO: using 'eZStepSiteTypes' is hack.
        //       need to exclude 'downloadFile' from that class.
        $tpl = false;
        $http = false;
        $ini = false;
        $persistenceList = false;
        $downloader = new eZStepSiteTypes($tpl, $http, $ini, $persistenceList);
        foreach ($downloadPackageList as $packageName) {
            showMessage("{$packageName}");
            $archiveName = $downloader->downloadFile("{$packageURL}/{$packageName}.ezpkg", $packageDir);
            if ($archiveName === false) {
                showError("download error - " . $downloader->ErrorMsg);
            }
        }
    }
    //
    // import
    //
    showMessage2("Importing...");
    foreach ($packageList as $packageName) {
        showMessage("{$packageName}");
        $package = eZPackage::import("{$packageDir}/{$packageName}.ezpkg", $packageName, false, $packageRepository);
        if (!is_object($package)) {
            showError("Faild to import '{$packageName}' package: err = {$package}");
        }
    }
    return true;
}
 /**
  * Retrieve list of packages available to download.
  *
  * Example of return value:
  * array(
  *  'packages' => array(
  *                      '<package_name1>' => array( "name" =>... , "version" =>... , "summary" => ... "url" =>... ),
  *                      '<package_name2>' => array( "name" =>... , "version" =>... , "summary" => ... "url" =>... )
  *                     )
  *      );
  *
  */
 function retrieveRemotePackagesList($onlySitePackages = false)
 {
     // Download index file.
     $idxFileName = $this->downloadFile($this->XMLIndexURL, eZStepSiteTypes::tempDir(), 'index.xml');
     if ($idxFileName === false) {
         $this->ErrorMsg = ezpI18n::tr('design/standard/setup/init', 'Retrieving remote site packages list failed. ' . 'You may upload packages manually.');
         eZDebug::writeNotice("Cannot download remote packages index file from '{$this->XMLIndexURL}'.");
         return false;
     }
     // Parse it.
     $dom = new DOMDocument('1.0', 'utf-8');
     $dom->preserveWhiteSpace = false;
     $success = $dom->load(realpath($idxFileName));
     @unlink($idxFileName);
     if (!$success) {
         eZDebug::writeError("Unable to open index file.");
         return false;
     }
     $root = $dom->documentElement;
     if ($root->localName != 'packages') {
         eZDebug::writeError("Malformed index file.");
         return false;
     }
     $packageList = array();
     foreach ($root->childNodes as $packageNode) {
         if ($packageNode->localName != 'package') {
             // skip unwanted chilren
             continue;
         }
         if ($onlySitePackages && $packageNode->getAttribute('type') != 'site') {
             // skip non-site packages
             continue;
         }
         $packageAttributes = array();
         foreach ($packageNode->attributes as $attributeNode) {
             $packageAttributes[$attributeNode->localName] = $attributeNode->value;
         }
         $packageList[$packageAttributes['name']] = $packageAttributes;
     }
     return $packageList;
 }