/**
  * {@inheritdoc}
  */
 public function expired()
 {
     if (null !== $this->package && $this->package->isInitial()) {
         return false;
     }
     return null === $this->expiresAt || $this->expiresAt < new \DateTime();
 }
 /**
  * {@inheritdoc}
  */
 public function isCurrent(PackageInterface $currentPackage = null)
 {
     return null !== $currentPackage && $this->getAlias() === $currentPackage->getAlias();
 }
Example #3
0
 /**
  * Install a fully downloaded package
  *
  * Using \PEAR2\Pyrus\FileTransactions and the PEAR2\Pyrus\Installer\Role* to
  * group files in appropriate locations, the install() method then passes
  * on the registration of installation to \PEAR2\Pyrus\Registry.  If necessary,
  * Config will update the install-time snapshots of configuration
  * @param \PEAR2\Pyrus\Package $package
  */
 function install(PackageInterface $package)
 {
     $this->_options = array();
     $lastversion = Config::current()->registry->info($package->name, $package->channel, 'version');
     $globalreplace = array('attribs' => array('from' => '@' . 'PACKAGE_VERSION@', 'to' => 'version', 'type' => 'package-info'));
     foreach ($package->installcontents as $file) {
         $channel = $package->channel;
         // {{{ assemble the destination paths
         $roles = Installer\Role::getValidRoles($package->getPackageType());
         if (!in_array($file->role, $roles)) {
             throw new Installer\Exception('Invalid role `' . $file->role . "' for file " . $file->name);
         }
         $role = Installer\Role::factory($package->getPackageType(), $file->role);
         $role->setup($this, $package, $file['attribs'], $file->name);
         if (!$role->isInstallable()) {
             continue;
         }
         $transact = AtomicFileTransaction::getTransactionObject($role);
         $info = $role->getRelativeLocation($package, $file, true);
         $dir = $info[0];
         $dest_file = $info[1];
         // }}}
         // pretty much nothing happens if we are only registering the install
         if (isset($this->_options['register-only'])) {
             continue;
         }
         try {
             $transact->mkdir($dir, 0755);
         } catch (AtomicFileTransaction\Exception $e) {
             throw new Installer\Exception("failed to mkdir {$dir}", $e);
         }
         Logger::log(3, "+ mkdir {$dir}");
         if ($file->md5sum) {
             $md5sum = md5_file($package->getFilePath($file->packagedname));
             if (strtolower($md5sum) == strtolower($file->md5sum)) {
                 Logger::log(2, "md5sum ok: {$dest_file}");
             } else {
                 if (!isset(Main::$options['force'])) {
                     throw new Installer\Exception("bad md5sum for file " . $file->name);
                 }
                 Logger::log(0, "warning : bad md5sum for file " . $file->name);
             }
         } else {
             // installing from package.xml in source control, save the md5 of the current file
             $file->md5sum = md5_file($package->getFilePath($file->packagedname));
         }
         if (strpos(PHP_OS, 'WIN') === false) {
             if ($role->isExecutable()) {
                 $mode = ~octdec(Config::current()->umask) & 0777;
                 Logger::log(3, "+ chmod +x {$dest_file}");
             } else {
                 $mode = ~octdec(Config::current()->umask) & 0666;
             }
         } else {
             $mode = null;
         }
         try {
             $transact->createOrOpenPath($dest_file, $package->getFileContents($file->packagedname, true), $mode);
         } catch (AtomicFileTransaction\Exception $e) {
             throw new Installer\Exception("failed writing to {$dest_file}", $e);
         }
         $tasks = $file->tasks;
         // only add the global replace task if it is not preprocessed
         if ($package->isNewPackage() && !$package->isPreProcessed()) {
             if (isset($tasks['tasks:replace'])) {
                 if (isset($tasks['tasks:replace'][0])) {
                     $tasks['tasks:replace'][] = $globalreplace;
                 } else {
                     $tasks['tasks:replace'] = array($tasks['tasks:replace'], $globalreplace);
                 }
             } else {
                 $tasks['tasks:replace'] = $globalreplace;
             }
         }
         $fp = false;
         foreach (new Package\Creator\TaskIterator($tasks, $package, Task\Common::INSTALL, $lastversion) as $name => $task) {
             if (!$fp) {
                 $fp = $transact->openPath($dest_file);
             }
             $task->startSession($fp, $dest_file);
             if (!rewind($fp)) {
                 throw new Installer\Exception('task ' . $name . ' closed the file pointer, invalid task');
             }
         }
         if ($fp) {
             fclose($fp);
         }
     }
 }
Example #4
0
 /**
  * Execute After Packages are installed
  * @param PackageInterface $initPackage
  * @param PackageInterface $targetPackage
  * @return boolean
  */
 protected function execPostPackageUpdate($initPackage, $targetPackage)
 {
     if ($initPackage->getType() != 'horisen-cms_mod') {
         return true;
     }
     //$this->io->write("Updating version from: " . $initPackage->getVersion() . ", to: " . $targetPackage->getVersion());
     //$this->io->write("Updating version from: " . $initPackage->getPrettyVersion() . ", to: " . $targetPackage->getPrettyVersion());
     $extras = $initPackage->getExtra();
     if (!isset($extras['installer-name'])) {
         return true;
     }
     $updatesDir = $this->dir . '/application/modules/' . $extras['installer-name'] . '/db_updates';
     //$updatesDir = __DIR__ . '/test_updates';
     $this->processUpdates($updatesDir, $initPackage->getPrettyVersion(), $targetPackage->getPrettyVersion(), $extras['installer-name']);
 }
Example #5
0
 /**
  * Generate archive filename for a particular version of a package.
  *
  * @param PackageInterface $package The package to get a name for
  *
  * @return string A filename without an extension
  */
 public function getPackageFilename($package)
 {
     $nameParts = array(preg_replace('#[^a-z0-9-_/]#i', '-', $package->getName()));
     if (preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) {
         $nameParts = array_merge($nameParts, array($package->getDistReference()));
     } else {
         $nameParts = array_merge($nameParts, array($package->getPrettyVersion(), $package->getDistReference()));
     }
     return implode('-', array_filter($nameParts, function ($p) {
         return !empty($p);
     }));
 }
 public function getInstallPath(PackageInterface $package)
 {
     $this->initializeVendorDir();
     $targetDir = $package->getTargetDir();
     return ($this->vendorDir ? $this->vendorDir . '/' : '') . ($targetDir ? '/' . $targetDir : '');
 }
Example #7
0
 /**
  * Get the cache file path (without cache-files-dir prefix).
  *
  * @param PackageInterface $p
  * @return type
  */
 public function getCacheKey($p)
 {
     $distRef = $p->getDistReference();
     if (preg_match('{^[a-f0-9]{40}$}', $distRef)) {
         return $p->getName() . '/' . $distRef . '.' . $p->getDistType();
     }
     // Composer builds the key like this, but it doesn't work:
     //return $p->getName().'/'.$p->getVersion().'-'.$distRef.'.'.$p->getDistType();
     // we need to apply the SHA1 fix from
     // https://github.com/krispypen/composer/commit/d8fa9ab57efdac94cd7135d96c2523932ac30f8b
     return $p->getName() . '/' . $p->getVersion() . '-' . $distRef . '-' . $p->getDistSha1Checksum() . '.' . $p->getDistType();
 }