8000 Restore config files after warmup (#32) · symfony-tools/code-block-checker@fc9ae78 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc9ae78

Browse files
authored
Restore config files after warmup (#32)
* Restore config files * cs
1 parent 22f0669 commit fc9ae78

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/Service/CodeNodeRunner.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,30 @@ private function processNode(CodeNode $node, IssueCollection $issues, string $ap
3535
return;
3636
}
3737

38+
$fullPath = $applicationDirectory.'/'.$file;
39+
$filesystem = new Filesystem();
40+
$replacedOriginal = false;
3841
try {
39-
file_put_contents($applicationDirectory.'/'.$file, $this->getNodeContents($node));
42+
if (is_file($fullPath)) {
43+
$filesystem->copy($fullPath, $fullPath.'.backup');
44+
$replacedOriginal = true;
45+
}
46+
47+
// Write config
48+
file_put_contents($fullPath, $this->getNodeContents($node));
49+
4050
// Clear cache
41-
(new Filesystem())->remove($applicationDirectory.'/var/cache');
51+
$filesystem->remove($applicationDirectory.'/var/cache');
52+
53+
// Warmup and log errors
4254
$this->warmupCache($node, $issues, $applicationDirectory);
4355
} finally {
44-
// Remove the file we added
45-
(new Filesystem())->remove($applicationDirectory.'/'.$file);
56+
// Remove added file and restore original
57+
$filesystem->remove($fullPath);
58+
if ($replacedOriginal) {
59+
$filesystem->copy($fullPath.'.backup', $fullPath);
60+
$filesystem->remove($fullPath.'.backup');
61+
}
4662
}
4763
}
4864

0 commit comments

Comments
 (0)
0