/** * Updates a given package. * * This is the wrong method if you are looking * for something like 'composer update'. Look * at the 'configurePackage' method instead. * * @throws ComposerException * @param $packageName * @return mixed */ public function updatePackage($packageName) { if (!$this->packageExists($packageName)) { return false; } $newPackageLocation = $this->resolvePackagePath($packageName); $oldPackageLocation = $this->normalizePath($newPackageLocation . '_{updating_in_progress}'); $installationInstructionsPath = $this->normalizePath($oldPackageLocation . DIRECTORY_SEPARATOR . '_newup_install_instructions'); if ($this->files->exists($oldPackageLocation)) { $this->files->deleteDirectory($oldPackageLocation, false); } $this->files->makeDirectory($oldPackageLocation, 0755, true); $this->files->copyDirectory($newPackageLocation, $oldPackageLocation); $this->files->deleteDirectory($newPackageLocation, false); // Retrieve the old installation instructions that were stored // when the package template was first installed. $installInstructions = $this->files->get($installationInstructionsPath); // Write updated initiated here in case of early failures. $this->writePackageUpdateInitiated($newPackageLocation, $installInstructions); try { $this->addPackage($installInstructions); // Write updated initiated here in case of failures during configuration. $this->writePackageUpdateInitiated($newPackageLocation, $installInstructions); $this->configurePackage($packageName); $this->files->deleteDirectory($oldPackageLocation, false); $this->log->info('Updated package template', ['package' => $packageName]); // If we are at this point of the update process, we can safely assume that // it is okay to remove the update initiated file. $this->removePackageUpdateInitiatedFile($newPackageLocation); return true; } catch (\Exception $e) { // There was an issue updating the package. We will rollback. $this->files->deleteDirectory($newPackageLocation, false); $this->files->makeDirectory($newPackageLocation, 0755, true); $this->files->copyDirectory($oldPackageLocation, $newPackageLocation); $this->files->deleteDirectory($oldPackageLocation, false); $this->log->debug('Package updated failed', ['package' => $packageName, 'message' => $e->getMessage(), 'exception' => $e]); throw new ComposerException('There was an unexpected failure during the package update process.', $e->getCode(), $e); } }