1
0
Fork 0

Allow disabling execution of operations and lock writing independently from dryRun, closes #5787

pull/5873/merge
Jordi Boggiano 2016-12-06 22:40:47 +01:00
parent cd21d7e7d4
commit 3c1300bcaf
1 changed files with 87 additions and 47 deletions

View File

@ -115,6 +115,9 @@ class Installer
protected $preferStable = false; protected $preferStable = false;
protected $preferLowest = false; protected $preferLowest = false;
protected $skipSuggest = false; protected $skipSuggest = false;
protected $writeLock = true;
protected $executeOperations = true;
/** /**
* Array of package names/globs flagged for update * Array of package names/globs flagged for update
* *
@ -182,6 +185,9 @@ class Installer
if ($this->dryRun) { if ($this->dryRun) {
$this->verbose = true; $this->verbose = true;
$this->runScripts = false; $this->runScripts = false;
$this->executeOperations = false;
$this->writeLock = false;
$this->dumpAutoloader = false;
$this->installationManager->addInstaller(new NoopInstaller); $this->installationManager->addInstaller(new NoopInstaller);
$this->mockLocalRepositories($this->repositoryManager); $this->mockLocalRepositories($this->repositoryManager);
} }
@ -218,13 +224,13 @@ class Installer
return $res; return $res;
} }
} catch (\Exception $e) { } catch (\Exception $e) {
if (!$this->dryRun) { if ($this->executeOperations) {
$this->installationManager->notifyInstalls($this->io); $this->installationManager->notifyInstalls($this->io);
} }
throw $e; throw $e;
} }
if (!$this->dryRun) { if ($this->executeOperations) {
$this->installationManager->notifyInstalls($this->io); $this->installationManager->notifyInstalls($this->io);
} }
@ -252,9 +258,8 @@ class Installer
); );
} }
if (!$this->dryRun) {
// write lock // write lock
if ($this->update) { if ($this->update && $this->writeLock) {
$localRepo->reload(); $localRepo->reload();
$platformReqs = $this->extractPlatformRequirements($this->package->getRequires()); $platformReqs = $this->extractPlatformRequirements($this->package->getRequires());
@ -300,6 +305,7 @@ class Installer
$this->eventDispatcher->dispatchScript($eventName, $this->devMode); $this->eventDispatcher->dispatchScript($eventName, $this->devMode);
} }
if ($this->executeOperations) {
// force binaries re-generation in case they are missing // force binaries re-generation in case they are missing
foreach ($localRepo->getPackages() as $package) { foreach ($localRepo->getPackages() as $package) {
$this->installationManager->ensureBinariesPresence($package); $this->installationManager->ensureBinariesPresence($package);
@ -566,8 +572,8 @@ class Installer
$this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation); $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
} }
// output non-alias ops in dry run, output alias ops in debug verbosity // output non-alias ops when not executing operations (i.e. dry run), output alias ops in debug verbosity
if ($this->dryRun && false === strpos($operation->getJobType(), 'Alias')) { if (!$this->executeOperations && false === strpos($operation->getJobType(), 'Alias')) {
$this->io->writeError(' - ' . $operation); $this->io->writeError(' - ' . $operation);
$this->io->writeError(''); $this->io->writeError('');
} elseif ($this->io->isDebug() && false !== strpos($operation->getJobType(), 'Alias')) { } elseif ($this->io->isDebug() && false !== strpos($operation->getJobType(), 'Alias')) {
@ -599,12 +605,12 @@ class Installer
$this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation); $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
} }
if (!$this->dryRun) { if ($this->executeOperations) {
$localRepo->write(); $localRepo->write();
} }
} }
if (!$this->dryRun) { if ($this->executeOperations) {
// force source/dist urls to be updated for all packages // force source/dist urls to be updated for all packages
$this->processPackageUrls($pool, $policy, $localRepo, $repositories); $this->processPackageUrls($pool, $policy, $localRepo, $repositories);
$localRepo->write(); $localRepo->write();
@ -1521,6 +1527,8 @@ class Installer
/** /**
* set whether to run autoloader or not * set whether to run autoloader or not
* *
* This is disabled implicitly when enabling dryRun
*
* @param bool $dumpAutoloader * @param bool $dumpAutoloader
* @return Installer * @return Installer
*/ */
@ -1534,6 +1542,8 @@ class Installer
/** /**
* set whether to run scripts or not * set whether to run scripts or not
* *
* This is disabled implicitly when enabling dryRun
*
* @param bool $runScripts * @param bool $runScripts
* @return Installer * @return Installer
*/ */
@ -1646,6 +1656,36 @@ class Installer
return $this; return $this;
} }
/**
* Should the lock file be updated when updating?
*
* This is disabled implicitly when enabling dryRun
*
* @param bool $writeLock
* @return Installer
*/
public function setWriteLock($writeLock = true)
{
$this->writeLock = (boolean) $writeLock;
return $this;
}
/**
* Should the operations (packge install, update and removal) be executed on disk?
*
* This is disabled implicitly when enabling dryRun
*
* @param bool $executeOperations
* @return Installer
*/
public function setExecuteOperations($executeOperations = true)
{
$this->executeOperations = (boolean) $executeOperations;
return $this;
}
/** /**
* Should suggestions be skipped? * Should suggestions be skipped?
* *