minor #37952 Backport: Improve link script with rollback when using symlink (noniagriconomie)
This PR was merged into the 3.4 branch.
Discussion
----------
Backport: Improve link script with rollback when using symlink
| Q | A
| ------------- | ---
| Branch? | 3.4 <!-- see below -->
| Bug fix? | no
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets | N/A <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License | MIT
| Doc PR | N/A
Backports #37915 to 3.4.
Even if it's a new feature, it's a contributors tool that can be used for any version to try out.
Commits
-------
ab92e9f4c3
Backport: Improve link script with rollback when using symlink
This commit is contained in:
commit
a430ccbcf1
24
link
24
link
@ -18,19 +18,22 @@ require __DIR__.'/src/Symfony/Component/Filesystem/Filesystem.php';
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
/**
|
||||
* Links dependencies to components to a local clone of the main symfony/symfony GitHub repository.
|
||||
* Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
|
||||
$copy = false !== $k = array_search('--copy', $argv, true);
|
||||
$copy && array_splice($argv, $k, 1);
|
||||
$rollback = false !== $k = array_search('--rollback', $argv, true);
|
||||
$rollback && array_splice($argv, $k, 1);
|
||||
$pathToProject = $argv[1] ?? getcwd();
|
||||
|
||||
if (!is_dir("$pathToProject/vendor/symfony")) {
|
||||
echo 'Link (or copy) dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
|
||||
echo 'Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
|
||||
echo "Usage: $argv[0] /path/to/the/project".PHP_EOL;
|
||||
echo ' Use `--copy` to copy dependencies instead of symlink'.PHP_EOL.PHP_EOL;
|
||||
echo ' Use `--rollback` to rollback'.PHP_EOL.PHP_EOL;
|
||||
echo "The directory \"$pathToProject\" does not exist or the dependencies are not installed, did you forget to run \"composer install\" in your project?".PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
@ -51,12 +54,19 @@ foreach ($directories as $dir) {
|
||||
|
||||
foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
|
||||
$package = 'symfony/'.basename($dir);
|
||||
if (!$copy && is_link($dir)) {
|
||||
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
|
||||
|
||||
if (!isset($sfPackages[$package])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($sfPackages[$package])) {
|
||||
if ($rollback) {
|
||||
$filesystem->remove($dir);
|
||||
echo "\"$package\" has been rollback from \"$sfPackages[$package]\".".PHP_EOL;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$copy && is_link($dir)) {
|
||||
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -76,3 +86,7 @@ foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as
|
||||
foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) {
|
||||
$filesystem->remove($cacheDir);
|
||||
}
|
||||
|
||||
if ($rollback) {
|
||||
echo PHP_EOL."Rollback done, do not forget to run \"composer install\" in your project \"$pathToProject\".".PHP_EOL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user