/**
  * Ajoute un paquet a la liste des paquets installes.
  * @param Package $package Le paquet a ajouter.
  */
 public function addPackage(Package $package)
 {
     //Si le paquet est deja installe, on enleve l'ancien
     if ($this->isPackage($package->getName())) {
         $oldPackage = $this->getPackage($package->getName());
         $oldPackage->remove();
     }
     $xml = new \DOMDocument('1.0');
     if ($this->webos->managers()->get('File')->exists($this->source . '/packages.xml')) {
         $xml->loadXML($this->webos->managers()->get('File')->get($this->source . '/packages.xml')->contents());
         $root = $xml->getElementsByTagName('packages')->item(0);
     } else {
         $root = $xml->createElement('packages');
         $xml->appendChild($root);
     }
     $element = $xml->createElement('package');
     $root->appendChild($element);
     $name = $xml->createAttribute('name');
     $name->appendChild($xml->createTextNode($package->getName()));
     $element->appendChild($name);
     $version = $xml->createAttribute('version');
     $version->appendChild($xml->createTextNode($package->getVersion()->getVersion()));
     $element->appendChild($version);
     $this->webos->managers()->get('File')->get($this->source . '/packages.xml')->setContents($xml->saveXML());
     $xml = new \DOMDocument('1.0');
     $root = $xml->createElement('package');
     $xml->appendChild($root);
     $xml_attributes = $xml->createElement('attributes');
     $root->appendChild($xml_attributes);
     $attributes = $package->getAttributes();
     $attributes['installed_time'] = time();
     $attributes['source'] = $package->getRepositorySource();
     foreach ($attributes as $attribute => $value) {
         $node = $xml->createElement('attribute');
         $xml_attributes->appendChild($node);
         $name = $xml->createAttribute('name');
         $name->appendChild($xml->createTextNode($attribute));
         $node->appendChild($name);
         $val = $xml->createAttribute('value');
         $val->appendChild($xml->createTextNode($value));
         $node->appendChild($val);
     }
     $files = $package->getFiles();
     $xml_files = $xml->createElement('files');
     $root->appendChild($xml_files);
     foreach ($files as $file) {
         $node = $xml->createElement('file');
         $xml_files->appendChild($node);
         $path = $xml->createAttribute('path');
         $path->appendChild($xml->createTextNode($file));
         $node->appendChild($path);
     }
     $this->webos->managers()->get('File')->createFile($this->source . '/packages/' . $package->getName() . '.xml')->setContents($xml->saveXML());
     $newPackage = new InstalledPackage($this->webos, $this, $package->getName());
     $this->packages[$package->getName()] = $newPackage;
 }
 /**
  * Checks if the new package is compatible with
  * the package that is about to be updated.
  *
  * @return 	boolean 	isValidUpdate
  */
 public function isValidUpdate()
 {
     // Check name of the installed package against the name of the update. Both must be identical.
     if ($this->packageInfo['name'] != $this->package->getPackage()) {
         return false;
     }
     // Check if the version number of the installed package is lower than the version number to which
     // it's about to be updated.
     if (Package::compareVersion($this->packageInfo['version'], $this->package->getVersion()) != 1) {
         return false;
     }
     // Check if the package provides an instructions block for the update from the installed package version
     if ($this->update === null) {
         return false;
     }
     return true;
 }
 /**
  * Updates an existing package.
  * 
  * @param	integer		$packageID
  * @param	string		$version	new package version
  */
 protected function updatePackage($packageID, $version)
 {
     // get package info
     $package = new Package($packageID);
     // get current package version
     $packageVersion = $package->getVersion();
     if (isset($this->virtualPackageVersions[$packageID])) {
         $packageVersion = $this->virtualPackageVersions[$packageID];
         // check virtual package version
         if (Package::compareVersion($packageVersion, $version, '>=')) {
             // virtual package version is greater than requested version
             // skip package update
             return;
         }
     }
     // get highest version of the required major release
     if (preg_match('/(\\d+\\.\\d+\\.)/', $version, $match)) {
         $packageVersions = array();
         $sql = "SELECT\tDISTINCT packageVersion\n\t\t\t\tFROM\twcf" . WCF_N . "_package_update_version\n\t\t\t\tWHERE\tpackageUpdateID IN (\n\t\t\t\t\t\tSELECT\tpackageUpdateID\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package_update\n\t\t\t\t\t\tWHERE\tpackage = '" . escapeString($package->getPackage()) . "'\n\t\t\t\t\t)\n\t\t\t\t\tAND packageVersion LIKE '" . escapeString($match[1]) . "%'";
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $packageVersions[] = $row['packageVersion'];
         }
         if (count($packageVersions) > 1) {
             // sort by version number
             usort($packageVersions, array('Package', 'compareVersion'));
             // get highest version
             $version = array_pop($packageVersions);
         }
     }
     // get all fromversion
     $fromversions = array();
     $sql = "SELECT\t\tpuv.packageVersion, puf.fromversion\n\t\t\tFROM\t\twcf" . WCF_N . "_package_update_fromversion puf\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package_update_version puv\n\t\t\tON\t\t(puv.packageUpdateVersionID = puf.packageUpdateVersionID)\n\t\t\tWHERE\t\tpuf.packageUpdateVersionID IN (\n\t\t\t\t\t\tSELECT\tpackageUpdateVersionID\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package_update_version\n\t\t\t\t\t\tWHERE \tpackageUpdateID IN (\n\t\t\t\t\t\t\tSELECT\tpackageUpdateID\n\t\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package_update\n\t\t\t\t\t\t\tWHERE\tpackage = '" . escapeString($package->getPackage()) . "'\n\t\t\t\t\t\t)\n\t\t\t\t\t)";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if (!isset($fromversions[$row['packageVersion']])) {
             $fromversions[$row['packageVersion']] = array();
         }
         $fromversions[$row['packageVersion']][$row['fromversion']] = $row['fromversion'];
     }
     // sort by version number
     uksort($fromversions, array('Package', 'compareVersion'));
     // find shortest update thread
     $updateThread = self::findShortestUpdateThread($package->getPackage(), $fromversions, $packageVersion, $version);
     // process update thread
     foreach ($updateThread as $fromversion => $toVersion) {
         $packageUpdateVersions = self::getPackageUpdateVersions($package->getPackage(), $toVersion);
         // resolve requirements
         $this->resolveRequirements($packageUpdateVersions[0]['packageUpdateVersionID']);
         // download package
         $download = '';
         if ($this->download) {
             $download = $this->downloadPackage($package->getPackage(), $packageUpdateVersions);
         }
         // add to stack
         $this->packageInstallationStack[] = array('packageName' => $package->getName(), 'instanceNo' => $package->getInstanceNo(), 'fromversion' => $fromversion, 'toVersion' => $toVersion, 'package' => $package->getPackage(), 'packageID' => $packageID, 'archive' => $download, 'action' => 'update');
         // update virtual versions
         $this->virtualPackageVersions[$packageID] = $toVersion;
     }
 }
Example #4
0
 /**
  * Add package
  *
  * @param Package $package
  * @return void
  */
 public function addPackage($package)
 {
     $channel = $this->chanName($package->getChannel());
     $name = $package->getName();
     $record = array(self::K_VER => $package->getVersion(), self::K_STATE => $package->getStability(), self::K_XML => $package->getPackageXml(), self::K_NAME => $name, self::K_DEPS => array(), self::K_PACK_DEPS => array());
     $this->setPackageRecord($channel, $name, $record);
     $this->setPackageDependencies($channel, $name, $package->getDependencyPackages());
     $this->save();
 }
Example #5
0
 /**
  * Writes the config.inc.php for a standalone application.
  * 
  * @param	integer		$packageID
  */
 public static function writeConfigFile($packageID)
 {
     $package = new Package($packageID);
     $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $package->getDir()));
     $file = new File($packageDir . PackageInstallation::CONFIG_FILE);
     $file->write("<?php\n");
     $currentPrefix = strtoupper($package->getAbbreviation());
     // get dependencies (only standalones)
     $sql = "SELECT\t\tpackage.*, IF(package.packageID = " . $packageID . ", 1, 0) AS sortOrder\n\t\t\tFROM\t\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = package_dependency.dependency)\n\t\t\tWHERE\t\tpackage_dependency.packageID = " . $packageID . "\n\t\t\t\t\tAND package.standalone = 1\n\t\t\t\t\tAND package.packageDir <> ''\n\t\t\tORDER BY\tsortOrder DESC,\n\t\t\t\t\tpackage_dependency.priority DESC";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $dependency = new Package(null, $row);
         $dependencyDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $dependency->getDir()));
         $prefix = strtoupper($dependency->getAbbreviation());
         $file->write("// " . $dependency->getPackage() . " vars\n");
         $file->write("// " . strtolower($prefix) . "\n");
         $file->write("if (!defined('" . $prefix . "_DIR')) define('" . $prefix . "_DIR', " . ($dependency->getPackageID() == $package->getPackageID() ? "dirname(__FILE__).'/'" : "'" . $dependencyDir . "'") . ");\n");
         $file->write("if (!defined('RELATIVE_" . $prefix . "_DIR')) define('RELATIVE_" . $prefix . "_DIR', " . ($dependency->getPackageID() == $package->getPackageID() ? "''" : "RELATIVE_" . $currentPrefix . "_DIR.'" . FileUtil::getRelativePath($packageDir, $dependencyDir) . "'") . ");\n");
         $file->write("if (!defined('" . $prefix . "_N')) define('" . $prefix . "_N', '" . WCF_N . "_" . $dependency->getInstanceNo() . "');\n");
         $file->write("\$packageDirs[] = " . $prefix . "_DIR;\n");
         $file->write("\n");
     }
     // write general information
     $file->write("// general info\n");
     $file->write("if (!defined('RELATIVE_WCF_DIR'))\tdefine('RELATIVE_WCF_DIR', RELATIVE_" . $currentPrefix . "_DIR.'" . FileUtil::getRelativePath($packageDir, WCF_DIR) . "');\n");
     $file->write("if (!defined('PACKAGE_ID')) define('PACKAGE_ID', " . $package->getPackageID() . ");\n");
     $file->write("if (!defined('PACKAGE_NAME')) define('PACKAGE_NAME', '" . str_replace("'", "\\'", $package->getName()) . "');\n");
     $file->write("if (!defined('PACKAGE_VERSION')) define('PACKAGE_VERSION', '" . $package->getVersion() . "');\n");
     // write end
     $file->write("?>");
     $file->close();
 }