Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a430ccb

Browse filesBrowse files
committed
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 ------- ab92e9f Backport: Improve link script with rollback when using symlink
2 parents b98f2af + ab92e9f commit a430ccb
Copy full SHA for a430ccb

File tree

Expand file treeCollapse file tree

1 file changed

+19
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-5
lines changed

‎link

Copy file name to clipboardExpand all lines: link
+19-5Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ require __DIR__.'/src/Symfony/Component/Filesystem/Filesystem.php';
1818
use Symfony\Component\Filesystem\Filesystem;
1919

2020
/**
21-
* Links dependencies to components to a local clone of the main symfony/symfony GitHub repository.
21+
* Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository.
2222
*
2323
* @author Kévin Dunglas <dunglas@gmail.com>
2424
*/
2525

2626
$copy = false !== $k = array_search('--copy', $argv, true);
2727
$copy && array_splice($argv, $k, 1);
28+
$rollback = false !== $k = array_search('--rollback', $argv, true);
29+
$rollback && array_splice($argv, $k, 1);
2830
$pathToProject = $argv[1] ?? getcwd();
2931

3032
if (!is_dir("$pathToProject/vendor/symfony")) {
31-
echo 'Link (or copy) dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
33+
echo 'Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
3234
echo "Usage: $argv[0] /path/to/the/project".PHP_EOL;
3335
echo ' Use `--copy` to copy dependencies instead of symlink'.PHP_EOL.PHP_EOL;
36+
echo ' Use `--rollback` to rollback'.PHP_EOL.PHP_EOL;
3437
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;
3538
exit(1);
3639
}
@@ -51,12 +54,19 @@ foreach ($directories as $dir) {
5154

5255
foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
5356
$package = 'symfony/'.basename($dir);
54-
if (!$copy && is_link($dir)) {
55-
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
57+
58+
if (!isset($sfPackages[$package])) {
5659
continue;
5760
}
5861

59-
if (!isset($sfPackages[$package])) {
62+
if ($rollback) {
63+
$filesystem->remove($dir);
64+
echo "\"$package\" has been rollback from \"$sfPackages[$package]\".".PHP_EOL;
65+
continue;
66+
}
67+
68+
if (!$copy && is_link($dir)) {
69+
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
6070
continue;
6171
}
6272

@@ -76,3 +86,7 @@ foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as
7686
foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) {
7787
$filesystem->remove($cacheDir);
7888
}
89+
90+
if ($rollback) {
91+
echo PHP_EOL."Rollback done, do not forget to run \"composer install\" in your project \"$pathToProject\".".PHP_EOL;
92+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.