-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] [Command] Clean bundle directory, fixes #23177 #23195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -132,7 +133,19 @@ protected function execute(InputInterface $input, OutputInterface $output) | |||
$this->hardCopy($originDir, $targetDir); | |||
} | |||
} | |||
if (is_dir($targetDir)) { | |||
array_push($validAssetDir, $targetDir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use $validAssetDir[] = $targetDir
instead.
@@ -132,7 +133,19 @@ protected function execute(InputInterface $input, OutputInterface $output) | |||
$this->hardCopy($originDir, $targetDir); | |||
} | |||
} | |||
if (is_dir($targetDir)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of adding this condition, move this inside the previous if
. There are 2 reasons for this:
- the variable is not assigned if the previous condition was false, which means it will either reuse the value from the previous iteration or fail with an undefined variable notice. Both are bad behaviors
- if we decided to install some assets for the bundle (which is what the previous condition is about), we know that the director us valid
} | ||
} | ||
// Check in $bundlesDir, if all links/folder still have an existing Bundle | ||
if ($dir = opendir($bundlesDir)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a DirectoryIterator
. The code will be simpler:
- no need to skip
.
and..
(you can configure the iterator to skip them for you) - no need to close the directory at the end (btw, you don't properly close it if
$filesystem->remove
throws an exception) - you can just do a
foreach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opendir() 😆 it's at least 10 years ago since a last used that function (you make me feel old 😢😉).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx @stof ,
i have used FilesystemIterator which is skipping dots by default
} | ||
} | ||
// Check in $bundlesDir, if all links/folder still have an existing Bundle | ||
foreach (new \FilesystemIterator($bundlesDir) as $file) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI it's actually a dir not a file 😉 other parts looks good 👍
@@ -89,6 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |||
$output->writeln('Installing assets as <comment>hard copies</comment>.'); | |||
} | |||
|
|||
$validAssetDir = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name should be a plural. It is not a directory, but a list of directories.
$validAssetDirs[] = $targetDir; | ||
} | ||
} | ||
// Check in $bundlesDir, if all links/folder still have an existing Bundle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment explains "how it does" something, but I'd recommend to explain "what it does" instead. Something like this:
// remove the assets of the bundles that no longer exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok @javiereguiluz 👍
Thank you @NicolasPion. |
…23177 (NicolasPion) This PR was squashed before being merged into the 2.7 branch (closes #23195). Discussion ---------- [FrameworkBundle] [Command] Clean bundle directory, fixes #23177 | Q | A | ------------- | --- | Branch? | 2.7 <!-- see comment below --> | Bug fix? | yes | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | no | Fixed tickets | #23177 | License | MIT This PR fix #23177 when running an assets:install, it will remove directorys who do not have anymore a valid Bundle Commits ------- 180f178 [FrameworkBundle] [Command] Clean bundle directory, fixes #23177
This PR was merged into the 2.7 branch. Discussion ---------- [FrameworkBundle] Do not remove files from assets dir | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - The patch introduced in #23195 removes files from `web/bundles` (eg. `.gitignore`) which is unintentional I think. Commits ------- 6ed9c8d [FrameworkBundle] Do not remove files from assets dir
This PR fix #23177
when running an assets:install, it will remove directorys who do not have anymore a valid Bundle