Upgrades/downgrades a plugin to a specific version.

@param PluginBundleInterface $plugin
@param string                $currentVersion
@param string                $targetVersion
439960
public function update(PluginBundleInterface $plugin, $currentVersion, $targetVersion)
    {
        $this->checkInstallationStatus($plugin, true);

        $this->baseInstaller->update($plugin, $currentVersion, $targetVersion);

        // updates plugin version
        $this->versionManager->setLogger($this->logger);
        $version = $this->versionManager->register($plugin);
        $this->versionManager->execute($version);
    }
208685
public function downgradeBundle(Bundle $bundle, $version)
    {
        $this->doMigrate($bundle, $version, Migrator::DIRECTION_DOWN);
    }
640290
public function setVersion($version)
    {
        if (Version::isKnown($version) === true) {
            $this->version = Version::appendPatchVersion($version);
        } else {
            $msg = "Version '{$version}' is not a known QTI version. Known versions are '" . implode(', ', Version::knownVersions()) . "'";
            throw new InvalidArgumentException($msg);
        }
    }
1029910
public function listNewVersions($plugin)
    {
        $code = is_string($plugin) ? $plugin : $this->pluginManager->getIdentifier($plugin);

        if (!$this->hasVersionFile($code)) {
            return [];
        }

        $databaseVersion = $this->getDatabaseVersion($code);
        return $this->getNewFileVersions($code, $databaseVersion);
    }
1052830
protected function setVersion($version) {
		$this->version = $version;

		$numbers = explode('.', $version);

		// Update Mayor and Minor-Version-Numbers
		$this->setMayor((int) $numbers[0]);
		$this->setMinor((int) $numbers[1]);
	}
628773
public function update(\Composer\Repository\InstalledRepositoryInterface $repo, \Composer\Package\PackageInterface $initial,
			\Composer\Package\PackageInterface $target) {
				
		$this->moveBackResources($initial);
		
		parent::update($repo, $initial, $target);
		
		$this->removeResources($target);
		$this->installResources($target);
	}
819687
public function removePlugin($plugin, $stopOnVersion = null)
    {
        $code = is_string($plugin) ? $plugin : $this->pluginManager->getIdentifier($plugin);

        if (!$this->hasVersionFile($code)) {
            return false;
        }

        $pluginHistory = $this->getDatabaseHistory($code);
        $pluginHistory = array_reverse($pluginHistory);

        $stopOnNextVersion = false;
        $newPluginVersion = null;

        foreach ($pluginHistory as $history) {
            if ($stopOnNextVersion && $history->version !== $stopOnVersion) {
                // Stop if the $stopOnVersion value was found and
                // this is a new version. The history could contain
                // multiple items for a single version (comments and scripts).
                $newPluginVersion = $history->version;
                break;
            }

            if ($history->type == self::HISTORY_TYPE_COMMENT) {
                $this->removeDatabaseComment($code, $history->version);
            }
            elseif ($history->type == self::HISTORY_TYPE_SCRIPT) {
                $this->removeDatabaseScript($code, $history->version, $history->detail);
            }

            if ($stopOnVersion === $history->version) {
                $stopOnNextVersion = true;
            }
        }

        $this->setDatabaseVersion($code, $newPluginVersion);

        if (isset($this->fileVersions[$code])) {
            unset($this->fileVersions[$code]);
        }
        if (isset($this->databaseVersions[$code])) {
            unset($this->databaseVersions[$code]);
        }
        if (isset($this->databaseHistory[$code])) {
            unset($this->databaseHistory[$code]);
        }
        return true;
    }
101950
public function update_plugin( $plugin_slug, $tag = 'master' ) {
		$plugin           = null;
		$is_plugin_active = false;

		foreach ( (array) Singleton::get_instance( 'Plugin', $this )->get_plugin_configs() as $config_entry ) {
			if ( $config_entry->slug === $plugin_slug ) {
				$plugin = $config_entry;
				break;
			}
		}

		if ( ! $plugin ) {
			throw new \UnexpectedValueException( 'Plugin not found or not updatable with GitHub Updater: ' . $plugin_slug );
		}

		if ( is_plugin_active( $plugin->file ) ) {
			$is_plugin_active = true;
		}

		$this->get_remote_repo_meta( $plugin );
		$repo_api = Singleton::get_instance( 'API', $this )->get_repo_api( $plugin->git, $plugin );

		$update = [
			'slug'        => $plugin->slug,
			'plugin'      => $plugin->file,
			'new_version' => null,
			'url'         => $plugin->uri,
			'package'     => $repo_api->construct_download_link( $tag ),
		];

		add_filter(
			'site_transient_update_plugins',
			function ( $current ) use ( $plugin, $update ) {
				$current->response[ $plugin->file ] = (object) $update;

				return $current;
			}
		);

		$upgrader = new \Plugin_Upgrader( $this->upgrader_skin );
		$upgrader->upgrade( $plugin->file );

		if ( $is_plugin_active ) {
			$activate = is_multisite() ? activate_plugin( $plugin->file, null, true ) : activate_plugin( $plugin->file );
			if ( ! $activate ) {
				$this->upgrader_skin->messages[] = 'Plugin reactivated successfully.';
			}
		}
	}
1250526
public function updateExistingPlugin(
        $pluginData,
        SiteEntity $site,
        string $modifiedByUserId,
        string $modifiedReason = Tracking::UNKNOWN_REASON,
        $forceSave = false,
        $doFlush = true
    ) {
        if (empty($pluginData['pluginInstanceId'])) {
            throw new InvalidArgumentException(
                'Plugin instance Id required to update.'
            );
        }

        /** @var PluginInstanceEntity $pluginInstance */
        $pluginInstance = $this->findOneBy(
            ['pluginInstanceId' => $pluginData['pluginInstanceId']]
        );

        if (empty($pluginInstance)) {
            throw new InvalidArgumentException(
                'No plugin found for instance Id: '
                . $pluginData['pluginInstanceId']
            );
        }

        $pluginData['plugin'] = $pluginInstance->getPlugin();

        $pluginData = $this->prepareData($pluginData);

        if (!$forceSave
            && $pluginInstance->getMd5() == md5(serialize($pluginData['saveData']))
            // @deprecated <deprecated-site-wide-plugin>
            && $pluginInstance->isSiteWide() == (bool)$pluginData['siteWide']
        ) {
            return $pluginInstance;
        }

        $newPluginInstance = $this->createPluginInstance(
            $pluginData,
            $site,
            $modifiedByUserId,
            $modifiedReason,
            $pluginInstance,
            $doFlush
        );

        return $newPluginInstance;
    }
49618
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
    {
        new Textpattern();
        parent::update($repo, $initial, $target);
        $plugin = new $this->textpatternPackager($this->getInstallPath($target), $target);
        $plugin->update();
    }
1123051
public function install(PluginBundleInterface $plugin)
    {
        $this->baseInstaller->install($plugin);

        $pluginEntity = $this->pluginManager->getPluginByShortName(
            $plugin->getName()
        );

        if (!$this->pluginManager->isReady($pluginEntity) || !$this->pluginManager->isActivatedByDefault($pluginEntity)) {
            $errors = $this->pluginManager->getMissingRequirements($pluginEntity);

            foreach ($errors['extensions'] as $extension) {
                $this->log(sprintf('<fg=red>Extension %s missing for %s !</fg=red>', $extension, $plugin->getName()));
            }

            foreach ($errors['plugins'] as $bundle) {
                $this->log(sprintf('<fg=red>The plugin %s is required for %s ! You must enable it first to use %s.</fg=red>', $bundle, $plugin->getName(), $plugin->getName()));
            }

            foreach ($errors['extras'] as $extra) {
                $this->log(sprintf('<fg=red>The plugin %s has extra requirements ! %s.</fg=red>', $plugin->getName(), $this->translator->trans($extra, [], 'error')));
            }

            $this->log(sprintf('<fg=red>Disabling %s...</fg=red>', $plugin->getName()));
            $this->pluginManager->disable($pluginEntity);
        }

        $this->versionManager->setLogger($this->logger);
        $version = $this->versionManager->register($plugin);
        $this->versionManager->execute($version);
    }
727099
protected function setVersion($version)
    {
        try {
            // Prepare
            $currentVersion = $this->config['version'];
            // Replace in config file
            $this->replaceInFile($currentVersion, $version, $this->configFilename);
            // Replace in package.json
            $packageJson = json_decode(file_get_contents($this->rootPath.'/package.json'));
            $this->replaceInFile(
                '"version": "'.$packageJson->version.'"',
                '"version": "'.$version.'"',
                $this->rootPath.'/package.json'
            );
            // Replace in project
            $filename = $this->config['type'] === 'theme'
                ? $this->rootPath.'/style.css'
                : $this->rootPath.'/plugin.php';
            preg_match(
                '/[Vv]ersion\:[|\s][0-9\.vV]+/',
                file_get_contents($filename),
                $matches
            );
            if (count($matches) > 0)
                $this->replaceInFile(
                    $matches[0],
                    'Version: '.$version,
                    $filename
                );
            // Print end
            $this->_print('Version updated!');
            $this->_lineBreak();
        } catch (Exception $e) {
            file_put_contents(
                $this->rootPath.'/error_log',
                $e->getMessage()
            );
            throw new NoticeException('Command "'.$this->key.'": Fatal error ocurred.');
        }
    }
385027
public function can_upgrade($type, $version) {
        if ($type == 'offline' && $version >= 2011112900) {
            return true;
        }
        foreach ($this->submissionplugins as $plugin) {
            if ($plugin->can_upgrade($type, $version)) {
                return true;
            }
        }
        foreach ($this->feedbackplugins as $plugin) {
            if ($plugin->can_upgrade($type, $version)) {
                return true;
            }
        }
        return false;
    }
1056648
private function updateCurrentVersion(
        Manager $manager,
        $version,
        $allowMajor,
        $allowPreRelease,
        OutputInterface $output
    ) {
        if ($manager->update($version, $allowMajor, $allowPreRelease)) {
            $output->writeln('<info>Updated to latest version.</info>');
        } else {
            $output->writeln('<comment>Already up-to-date.</comment>');
        }
    }
93733
public function validatePlugin($plugin)
    {
        if ($plugin instanceof ObjectManagerInterface) {
            return;
        }

        throw new Exception\RuntimeException(sprintf(
            'Plugin of type %s is invalid; must implement %s',
            (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
            DoctrineObjectManager::class
        ));
    }
852226
protected function setDatabaseVersion($code, $version = null)
    {
        $currentVersion = $this->getDatabaseVersion($code);

        if ($version && !$currentVersion) {
            Db::table('system_plugin_versions')->insert([
                'code' => $code,
                'version' => $version,
                'created_at' => new Carbon
            ]);
        }
        elseif ($version && $currentVersion) {
            Db::table('system_plugin_versions')->where('code', $code)->update([
                'version' => $version,
                'created_at' => new Carbon
            ]);
        }
        elseif ($currentVersion) {
            Db::table('system_plugin_versions')->where('code', $code)->delete();
        }

        $this->databaseVersions[$code] = $version;
    }
1366328
protected function setReleaseVersion()
    {
        try {
            $currentVersion = Context::get('version-persister')->getCurrentVersion();
        } catch (\Exception $e) {
            $currentVersion = Context::get('version-generator')->getInitialVersion();
        }

        $this->releaseVersion = Context::get('version-generator')->generateNextVersion($currentVersion);
    }