Record an extension install.

@param string $package
@param string $version
165945
public function recordInstall($package, $version)
    {
        $url = sprintf($this->extendSite . $this->urls['install'], $package, $version);

        try {
            $this->client->head($url);
        } catch (RequestException $e) {
            $this->loggerSystem->critical($e->getMessage(), ['event' => 'exception', 'exception' => $e]);
        }
    }
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.');
        }
    }
1126580
public static function downloadReleaseArchive(string $releaseName, string $version): bool
    {
        $archiveName = $releaseName . '.tar.gz';
        $archivePath = sprintf('%s/%s', Utilities::getBasePath(), $archiveName);
        $releaseUrl = sprintf(
            'https://github.com/editorconfig-checker/editorconfig-checker/releases/download/%s/%s',
            $version,
            $archiveName
        );

        $result = file_put_contents($archivePath, fopen($releaseUrl, 'r'));
        return $result > 0 || $result;
    }
187668
protected function printMeta(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo)
    {
        $this->getIO()->write('<info>name</info>     : ' . $package->getPrettyName());
        $this->getIO()->write('<info>descrip.</info> : ' . $package->getDescription());
        $this->getIO()->write('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
        $this->printVersions($package, $versions, $installedRepo);
        $this->getIO()->write('<info>type</info>     : ' . $package->getType());
        $this->printLicenses($package);
        $this->getIO()->write('<info>source</info>   : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
        $this->getIO()->write('<info>dist</info>     : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
        $this->getIO()->write('<info>names</info>    : ' . implode(', ', $package->getNames()));

        if ($package->isAbandoned()) {
            $replacement = ($package->getReplacementPackage() !== null)
                ? ' The author suggests using the ' . $package->getReplacementPackage(). ' package instead.'
                : null;

            $this->getIO()->writeError(
                sprintf('<warning>Attention: This package is abandoned and no longer maintained.%s</warning>', $replacement)
            );
        }

        if ($package->getSupport()) {
            $this->getIO()->write("\n<info>support</info>");
            foreach ($package->getSupport() as $type => $value) {
                $this->getIO()->write('<comment>' . $type . '</comment> : '.$value);
            }
        }

        if ($package->getAutoload()) {
            $this->getIO()->write("\n<info>autoload</info>");
            foreach ($package->getAutoload() as $type => $autoloads) {
                $this->getIO()->write('<comment>' . $type . '</comment>');

                if ($type === 'psr-0') {
                    foreach ($autoloads as $name => $path) {
                        $this->getIO()->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
                    }
                } elseif ($type === 'psr-4') {
                    foreach ($autoloads as $name => $path) {
                        $this->getIO()->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
                    }
                } elseif ($type === 'classmap') {
                    $this->getIO()->write(implode(', ', $autoloads));
                }
            }
            if ($package->getIncludePaths()) {
                $this->getIO()->write('<comment>include-path</comment>');
                $this->getIO()->write(implode(', ', $package->getIncludePaths()));
            }
        }
    }
611549
public function installPackage(string $name, string $version, bool $dev = true)
    {
        $node = $dev ? 'require-dev' : 'require';

        if (array_key_exists($node, $this->definition)
            && array_key_exists($name, $this->definition[$node])
        ) {
            return;
        }

        $application = new Application();
        $command     = new RequireCommand();

        $definition = clone $application->getDefinition();
        $definition->addArguments($command->getDefinition()->getArguments());
        $definition->addOptions($command->getDefinition()->getOptions());

        $input = new ArrayInput(
            [
                'command' => 'require',
                'packages' => [$name . ':' . $version],
                '--dev' => $dev,
                '--no-scripts' => true,
                '--no-interaction' => true,
                '--no-plugins' => true,
                '--working-dir' => $this->workingDir
            ],
            $definition
        );

        $application->setAutoExit(false);
        $application->run($input, $this->output);
    }
1263079
public function installPackage($package) {
		
		$app = Application::getInstance();
		
		$ret = TRUE;
		
		$zip		= new \ZipArchive;
		$zipOpened	= $zip->open($package);
		
		// TODO managing all ZIP errors (ZipArchive::ER_EXISTS, ZipArchive::ER_INCONS, etc.)
		
		static::checkTemporaryFolder();
		
		if (TRUE !== $zipOpened) {
			trigger_error('ERROR_EXTRACTING_ZIP_CONTENT');
			return FALSE;
		}
		
		// make a random temporary folder
		$tempFolder = static::TEMP_FOLDER . '/' . substr(md5(time()),0,6);
		
		// extract all zip contents
		$zip->extractTo($tempFolder);
		
		// checks if all contents are in a subfolder
		$stat = $zip->statIndex(0);
		$subfolder = (0==$stat['size']  and '/'==substr($stat['name'],-1)) ? $stat['name'] : FALSE;
		
		// locates manifest file
		$manifestIndex = $zip->locateName('manifest.xml', \ZipArchive::FL_NOCASE|\ZipArchive::FL_NODIR);

		try {
			// get XML content of manifest from ZIP
			$manifest = simplexml_load_string($zip->getFromIndex($manifestIndex));
		} catch (\Exception $e) {
			$app->enqueueError('Manifest content is not valid: ' . $e->getMessage());
			return FALSE;
		}

		// check if manifest is valid
		if (!is_a($manifest, '\SimpleXMLElement')) {
			$app->enqueueError('Manifest file is not valid');
			return FALSE;
		}
		
		// get installation info by manifest file
		$plugin = static::createPluginByManifest($manifest);
		
		// error check
		if (is_null($plugin)) {
			$zip->close();
			Utilities::deleteFolder($package);
			return FALSE;
		}
		
		// set the plugin-type common folder
		$this->baseFolder = $plugin->getBaseFolder();
			
		// the temporary directory where extracted files reside
		$sourceFolder = APPLICATION_PATH . '/' . $tempFolder;
		
		// this is destination path for copy plugin files
		$pluginFolder = $this->baseFolder . '/' . strtolower($manifest->plugin->folder);

		// creates final plugin folder
		$old = umask(0);
		if (!mkdir($pluginFolder, 0777, TRUE)) {
			trigger_error('Directory creation on ' . $pluginFolder . ' failed');
			$ret = FALSE;
		}
		umask($old);

		// sets full permissions on final folder
		if (!chmod($pluginFolder, 0777)) {
			trigger_error('Set permissions on directory ' . $pluginFolder . ' failed');
			$ret = FALSE;
		}
		
		// TODO must notify all lost files when copying
		
		$files = $manifest->plugin->files->children();
		
		// copy all plugin files
		foreach ($files as $file) {
			
			$source = $sourceFolder . '/' . $file;
			$dest	= $pluginFolder . '/' . $file;
			
			try {
				
				if (!file_exists(dirname($dest))) {
					$old = umask(0);
					mkdir(dirname($dest), 0777, true);
					umask($old);
				}

				copy($source, $dest);
				
			} catch (\Exception $e) {
				trigger_error('Failed to copy file ' . $source . ' into path ' . $this->baseFolder);
				$ret = FALSE;
				
			}
			
		}
		
		$zip->close();
		
		// ZIP archive and temporary files deletion
		Utilities::deleteFolder($package);
		Utilities::deleteFolder($sourceFolder);
		
		return $ret;
		
	}
47170
public static function install( $directory, $package, $version = null, $dev = false ) {
		$command = 'composer require' .
			( $dev ? ' --dev' : '' ) .
			' "' . $package .( $version !== null ? ':' . $version : '' ) . '"';

		$output = App::execute( $command, $directory );

		return trim( $output );
	}
41632
public function specials($package, Version $version)
    {
        $specials = $this->searchProvides($package);
        if ($specials) {
            $this->providesJsonDetected = true;
        } else {
            $this->providesJsonDetected = false;
            $specials = $this->searchReflect($package, $version);
        }
        if (count($specials['providers']) === 0 && count($specials['aliases']) === 0) {
            return false;
        }
        return $specials;
    }
1023190
public function update($package = null, $version = null, $dryRun = false)
    {
        if ($dryRun) {
            $this->setDryRun(true);
        }

        $package = !empty($version) ? $package . ':' . $version : $package;

        return $this->runCommand(self::UPDATE, $package, self::ROOT_REQS . self::DEFAULT_ARGS);
    }
143025
public function download($package, $version = null, $noInstall = false)
    {
        $package = !empty($version) ? $package . ':' . $version : $package;

        $args = $noInstall === true ? self::NO_PROGRESS . self::NO_UPDATE . self::DEFAULT_ARGS : self::DEFAULT_ARGS;

        return $this->runCommand(self::DOWNLOAD, $package, $args);
    }
948707
public function addVersion( PhpVersion $version ) {
		$versionString = $version->getVersion();

		$this->phpVersions[$versionString] = $version;

		return $this;
	}
224923
public function update($package = null)
    {
        if (! is_null($package)) {
            $package = '"'.$package.'"';
        }
        $process = $this->getProcess();
        $process->setCommandLine(trim($this->findComposer().' update '.$package));
        $process->run($this->output);
    }
941048
private static function file_set_version($package, \Datetime $version) {
		self::get_version($package);

		if (file_exists(Config::$migration_directory . '/db_version')) {
			$version_file = trim(file_get_contents(Config::$migration_directory . '/db_version'));
			$versions = json_decode($version_file, true);
		} else {
			$versions = [];
		}

		$versions[$package] = $version->format('Ymd His');
		file_put_contents(Config::$migration_directory . '/db_version', json_encode($versions));
	}
321541
protected function getLoadPackagePathes($package, Version $version)
    {
        $packageName = $package instanceof Package ? $package->getName() : $package;
        $basePath = 'vendor' . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, explode('/', $packageName));
        $paths = array('directories' => array(), 'files' => array());
        foreach ($version->getAutoload() as $type => $map) {
            switch ($type) {
                case 'classmap':
                    $paths['directories'] = array_merge($paths['directories'], (array)$map);
                    break;
                case 'psr-0':
                    foreach ($map as $ns => $src) {
                        $nsPath = implode(DIRECTORY_SEPARATOR, explode('\\', str_replace('\\\\', '\\', $ns)));
                        foreach ((array)$src as $path) {
                            $paths['directories'][] = rtrim($path, '/') . DIRECTORY_SEPARATOR . $nsPath;
                        }
                    }
                    break;
                case 'psr-4':
                    foreach ($map as $ns => $src) {
                        foreach ((array)$src as $path) {
                            $paths['directories'][] = implode(DIRECTORY_SEPARATOR, explode('/', rtrim($path, '/')));
                        }
                    }
                    break;
                case 'files':
                    $paths['files'] = array_merge($paths['files'], (array)$map);
            }
        }

        $pathsToExclude = $this->excludeFilesInPath($basePath);
        $pathsToExclude = array_map(function ($p) use ($basePath) {
            return realpath($basePath . DIRECTORY_SEPARATOR . $p);
        }, $pathsToExclude);
        $pathsToExclude = array_filter($pathsToExclude, function ($p) {
            return $p !== false;
        });

        foreach ($paths as &$maps) {
            $maps = array_unique(array_values($maps));
            $maps = array_map(function ($p) use ($basePath) {
                return realpath($basePath . DIRECTORY_SEPARATOR . $p);
            }, $maps);
            foreach ($pathsToExclude as $p) {
                foreach ($maps as $index => $map) {
                    if (strpos($map, $p) === 0) {
                        unset($maps[$index]);
                    }
                }
            }
        }

        return $paths;
    }
80219
private function requireComposerPackage($package)
    {
        $composer = $this->findComposer();
        $process = new Process($composer.' require '.$package.''.$this->getDevOption(),
                       null, null, null, null);
        $this->output->writeln('<info>Running composer require '.$package.$this->getDevOption().'</info>');
        $process->run(function ($type, $line) {
            $this->output->write($line);
        });
    }
479
public function savePreviousVersion($version)
    {
        if (!is_numeric($version)) {
            return;
        }

        try {
            $this->setVersionNumber($version);
            $this->owner->write();
        } catch (Exception $e) {
            throw new ValidationException(new ValidationResult(
                false,
                "Could not replace file #{$this->owner->ID} with version #$version."
            ));
        }
    }
924174
protected function addMigrationHistory(string $version, ?string $namespace = null): void
    {
        $this->stdout(' > Adding migration history entry ...', Console::FG_YELLOW);

        $this->db->createCommand()->insert(
            $this->migrationTable,
            [
                'version' => ($namespace ? $namespace . '\\' : '') . $version,
                'apply_time' => time(),
            ]
        )->execute();

        $this->stdout("DONE.\n", Console::FG_GREEN);
    }