@@ -28,6 +28,13 @@ class ExtensionUpgraderSkin extends UpgraderSkin {
2828 */
2929 private $ track_files = false ;
3030
31+ /**
32+ * Whether file tracking hooks have been set up.
33+ *
34+ * @var bool
35+ */
36+ private $ hooks_setup = false ;
37+
3138 /**
3239 * Enable file tracking for opcache invalidation.
3340 */
@@ -49,6 +56,13 @@ public function get_changed_files() {
4956 * Setup hooks to track file changes during upgrade.
5057 */
5158 private function setup_file_tracking_hooks () {
59+ // Prevent duplicate hook registrations.
60+ if ( $ this ->hooks_setup ) {
61+ return ;
62+ }
63+
64+ $ this ->hooks_setup = true ;
65+
5266 // Hook into upgrader_post_install to capture the destination directory
5367 add_filter (
5468 'upgrader_post_install ' ,
@@ -73,16 +87,22 @@ private function scan_directory_for_files( $dir ) {
7387 return ;
7488 }
7589
76- $ iterator = new \RecursiveIteratorIterator (
77- new \RecursiveDirectoryIterator ( $ dir , \RecursiveDirectoryIterator::SKIP_DOTS ),
78- \RecursiveIteratorIterator::SELF_FIRST
79- );
90+ try {
91+ $ iterator = new \RecursiveIteratorIterator (
92+ new \RecursiveDirectoryIterator ( $ dir , \RecursiveDirectoryIterator::SKIP_DOTS ),
93+ \RecursiveIteratorIterator::SELF_FIRST
94+ );
8095
81- foreach ( $ iterator as $ file ) {
82- /** @var \SplFileInfo $file */
83- if ( $ file ->isFile () && 'php ' === $ file ->getExtension () ) {
84- $ this ->changed_files [] = $ file ->getPathname ();
96+ foreach ( $ iterator as $ file ) {
97+ /** @var \SplFileInfo $file */
98+ if ( $ file ->isFile () && 'php ' === $ file ->getExtension () ) {
99+ $ this ->changed_files [] = $ file ->getPathname ();
100+ }
85101 }
102+ // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch -- Intentionally ignoring errors to prevent update failure.
103+ } catch ( \Exception $ e ) {
104+ // Silently handle filesystem errors to prevent update process from failing.
105+ // The changed files list may be incomplete, but the update should still succeed.
86106 }
87107 }
88108
0 commit comments