Add update command, fixes #28
parent
7493cf7654
commit
1feebcafe2
|
@ -33,7 +33,7 @@ class DebugPackagesCommand extends Command
|
|||
->setName('debug:packages')
|
||||
->setDescription('Lists all existing packages and their version')
|
||||
->setHelp(<<<EOT
|
||||
<info>php composer debug:packages</info>
|
||||
<info>php composer.phar debug:packages</info>
|
||||
|
||||
EOT
|
||||
)
|
||||
|
|
|
@ -43,7 +43,7 @@ The <info>install</info> command reads the composer.json file from the
|
|||
current directory, processes it, and downloads and installs all the
|
||||
libraries and dependencies outlined in that file.
|
||||
|
||||
<info>php composer install</info>
|
||||
<info>php composer.phar install</info>
|
||||
|
||||
EOT
|
||||
)
|
||||
|
@ -51,10 +51,15 @@ EOT
|
|||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
return $this->install($output, $input->getOption('dev'));
|
||||
}
|
||||
|
||||
public function install(OutputInterface $output, $preferSource, $update = false)
|
||||
{
|
||||
$composer = $this->getComposer();
|
||||
|
||||
if ($input->getOption('dev')) {
|
||||
if ($preferSource) {
|
||||
$composer->getDownloadManager()->setPreferSource(true);
|
||||
}
|
||||
|
||||
|
@ -72,7 +77,30 @@ EOT
|
|||
|
||||
// creating requirements request
|
||||
$request = new Request($pool);
|
||||
if ($composer->getLocker()->isLocked()) {
|
||||
if ($update) {
|
||||
$output->writeln('> Updating dependencies.');
|
||||
$listedPackages = array();
|
||||
$installedPackages = $installedRepo->getPackages();
|
||||
|
||||
foreach ($composer->getPackage()->getRequires() as $link) {
|
||||
$listedPackages[] = $link->getTarget();
|
||||
|
||||
foreach ($installedPackages as $package) {
|
||||
if ($package->getName() === $link->getTarget()) {
|
||||
$request->update($link->getTarget(), $link->getConstraint());
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$request->install($link->getTarget(), $link->getConstraint());
|
||||
}
|
||||
|
||||
foreach ($localRepo->getPackages() as $package) {
|
||||
if (!in_array($package->getName(), $listedPackages)) {
|
||||
$request->remove($package->getName());
|
||||
}
|
||||
}
|
||||
} elseif ($composer->getLocker()->isLocked()) {
|
||||
$output->writeln('> Found lockfile. Reading.');
|
||||
|
||||
foreach ($composer->getLocker()->getLockedPackages() as $package) {
|
||||
|
@ -80,6 +108,7 @@ EOT
|
|||
$request->install($package->getName(), $constraint);
|
||||
}
|
||||
} else {
|
||||
$output->writeln('> Installing dependencies.');
|
||||
foreach ($composer->getPackage()->getRequires() as $link) {
|
||||
$request->install($link->getTarget(), $link->getConstraint());
|
||||
}
|
||||
|
@ -116,7 +145,7 @@ EOT
|
|||
$installationManager->execute($operation);
|
||||
}
|
||||
|
||||
if (!$composer->getLocker()->isLocked()) {
|
||||
if ($update || !$composer->getLocker()->isLocked()) {
|
||||
$composer->getLocker()->lockPackages($localRepo->getPackages());
|
||||
$output->writeln('> Locked');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Command;
|
||||
|
||||
use Composer\Autoload\AutoloadGenerator;
|
||||
use Composer\DependencyResolver;
|
||||
use Composer\DependencyResolver\Pool;
|
||||
use Composer\DependencyResolver\Request;
|
||||
use Composer\DependencyResolver\Operation;
|
||||
use Composer\Package\LinkConstraint\VersionConstraint;
|
||||
use Composer\Repository\PlatformRepository;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class UpdateCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('update')
|
||||
->setDescription('Updates your dependencies to the latest version, and updates the composer.lock file.')
|
||||
->setDefinition(array(
|
||||
new InputOption('dev', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
|
||||
))
|
||||
->setHelp(<<<EOT
|
||||
The <info>update</info> command reads the composer.json file from the
|
||||
current directory, processes it, and updates, removes or installs all the
|
||||
dependencies.
|
||||
|
||||
<info>php composer.phar update</info>
|
||||
|
||||
EOT
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$composer = $this->getComposer();
|
||||
|
||||
$installCommand = $this->getApplication()->find('install');
|
||||
return $installCommand->install($output, $input->getOption('dev'), true);
|
||||
}
|
||||
}
|
|
@ -64,6 +64,7 @@ class Application extends BaseApplication
|
|||
protected function registerCommands()
|
||||
{
|
||||
$this->add(new Command\InstallCommand());
|
||||
$this->add(new Command\UpdateCommand());
|
||||
$this->add(new Command\DebugPackagesCommand());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue