From bb355d6ea86716ccc440fd94d12bfde26cede614 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 21 Apr 2021 22:55:40 +0200 Subject: [PATCH 1/2] Restore config files --- src/Service/CodeNodeRunner.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Service/CodeNodeRunner.php b/src/Service/CodeNodeRunner.php index 8292488..b4830d2 100644 --- a/src/Service/CodeNodeRunner.php +++ b/src/Service/CodeNodeRunner.php @@ -35,14 +35,30 @@ private function processNode(CodeNode $node, IssueCollection $issues, string $ap return; } + $fullPath = $applicationDirectory . '/' . $file; + $filesystem = new Filesystem(); + $replacedOriginal = false; try { - file_put_contents($applicationDirectory.'/'.$file, $this->getNodeContents($node)); + if (is_file($fullPath)) { + $filesystem->copy($fullPath, $fullPath.'.backup'); + $replacedOriginal = true; + } + + // Write config + file_put_contents($fullPath, $this->getNodeContents($node)); + // Clear cache - (new Filesystem())->remove($applicationDirectory.'/var/cache'); + $filesystem->remove($applicationDirectory.'/var/cache'); + + // Warmup and log errors $this->warmupCache($node, $issues, $applicationDirectory); } finally { - // Remove the file we added - (new Filesystem())->remove($applicationDirectory.'/'.$file); + // Remove added file and restore original + $filesystem->remove($fullPath); + if ($replacedOriginal) { + $filesystem->copy($fullPath.'.backup', $fullPath); + $filesystem->remove($fullPath.'.backup'); + } } } From a7445cb7ae769883d6e62e7b71043ab93eedf2bf Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 21 Apr 2021 22:57:40 +0200 Subject: [PATCH 2/2] cs --- src/Service/CodeNodeRunner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/CodeNodeRunner.php b/src/Service/CodeNodeRunner.php index b4830d2..b69642c 100644 --- a/src/Service/CodeNodeRunner.php +++ b/src/Service/CodeNodeRunner.php @@ -35,7 +35,7 @@ private function processNode(CodeNode $node, IssueCollection $issues, string $ap return; } - $fullPath = $applicationDirectory . '/' . $file; + $fullPath = $applicationDirectory.'/'.$file; $filesystem = new Filesystem(); $replacedOriginal = false; try {