From 2e0d2d38885bb2b447f7b9a5aeff2ff801e70f74 Mon Sep 17 00:00:00 2001 From: Siarhei Karavai Date: Sun, 31 Mar 2019 17:46:33 +0300 Subject: [PATCH] Allow subdirectories in migration file names (#4225) Credit to @GinoPane. Fixes #4224. --- modules/system/classes/VersionManager.php | 2 +- tests/unit/system/classes/VersionManagerTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/system/classes/VersionManager.php b/modules/system/classes/VersionManager.php index bd18f82da..98f21a830 100644 --- a/modules/system/classes/VersionManager.php +++ b/modules/system/classes/VersionManager.php @@ -530,7 +530,7 @@ class VersionManager protected function extractScriptsAndComments($details) { if (is_array($details)) { - $fileNamePattern = '/^[a-z_\-0-9\.]*\.php$/i'; + $fileNamePattern = "/^[a-z0-9\_\-\.\/\\\]+\.php$/i"; $comments = array_values(array_filter($details, function ($detail) use ($fileNamePattern) { return !preg_match($fileNamePattern, $detail); diff --git a/tests/unit/system/classes/VersionManagerTest.php b/tests/unit/system/classes/VersionManagerTest.php index 7cf87a338..b9934d3e5 100644 --- a/tests/unit/system/classes/VersionManagerTest.php +++ b/tests/unit/system/classes/VersionManagerTest.php @@ -186,6 +186,22 @@ class VersionManagerTest extends TestCase 'file.name.with.dots.php', '1.0.2.scripts_can_go_anywhere.php' ] + ], + [ + [ + 'subdirectory/file.name.with.dots.php', + 'The first update comment', + 'subdirectory\1.0.2.scripts_can_go_anywhere.php', + 'The second update comment', + ], + [ + 'The first update comment', + 'The second update comment' + ], + [ + 'subdirectory/file.name.with.dots.php', + 'subdirectory\1.0.2.scripts_can_go_anywhere.php' + ] ] ]; }