Просмотр исходного кода

fix: Ignore non-PHP files in migrations/ folder (#4163)

Some NAS create folders named `@eaDir` in the FreshRSS tree, including
the `migrations/` folder. This broke the migration system which expected
only valid PHP files to be present in this folder. Now, it ignores
non-PHP files.

Reference: https://github.com/FreshRSS/FreshRSS/issues/4044
berumuron 4 лет назад
Родитель
Сommit
bc5271b0eb
2 измененных файлов с 4 добавлено и 2 удалено
  1. 4 2
      lib/Minz/Migrator.php
  2. 0 0
      tests/fixtures/migrations/2022_01_17_IgnoredFile

+ 4 - 2
lib/Minz/Migrator.php

@@ -39,7 +39,8 @@ class Minz_Migrator
 
 		$migration_files = scandir($migrations_path);
 		$migration_files = array_filter($migration_files, function ($filename) {
-			return $filename[0] !== '.';
+			$file_extension = pathinfo($filename, PATHINFO_EXTENSION);
+			return $file_extension === 'php';
 		});
 		$migration_versions = array_map(function ($filename) {
 			return basename($filename, '.php');
@@ -134,7 +135,8 @@ class Minz_Migrator
 		}
 
 		foreach (scandir($directory) as $filename) {
-			if ($filename[0] === '.') {
+			$file_extension = pathinfo($filename, PATHINFO_EXTENSION);
+			if ($file_extension !== 'php') {
 				continue;
 			}
 

+ 0 - 0
tests/fixtures/migrations/2022_01_17_IgnoredFile