|
21 | 21 |
|
22 | 22 | class SyncFileList |
23 | 23 | { |
24 | | - static function load() |
| 24 | + static function load( ?string $lang = null , array $filterFiles = [] ) |
25 | 25 | { |
26 | | - $file = __DIR__ . "/../../../temp/lang"; |
27 | | - if ( ! file_exists( $file ) ) |
| 26 | + if ( $lang === null ) |
28 | 27 | { |
29 | | - fwrite( STDERR , "Language file not found, run 'doc-base/configure.php'.\n" ); |
30 | | - exit(); |
| 28 | + $file = __DIR__ . "/../../../temp/lang"; |
| 29 | + if ( ! file_exists( $file ) ) |
| 30 | + { |
| 31 | + fwrite( STDERR , "Language not found, run 'doc-base/configure.php' or use '--lang='.\n" ); |
| 32 | + exit(); |
| 33 | + } |
| 34 | + $lang = trim( file_get_contents( $file ) ); |
| 35 | + } |
| 36 | + |
| 37 | + $sourceDir = 'en'; |
| 38 | + $targetDir = $lang; |
| 39 | + |
| 40 | + if ( count( $filterFiles ) > 0 ) |
| 41 | + { |
| 42 | + $ret = []; |
| 43 | + |
| 44 | + foreach ( $filterFiles as $file ) |
| 45 | + { |
| 46 | + if ( ! file_exists( "$sourceDir/$file" ) ) |
| 47 | + { |
| 48 | + fwrite( STDERR , "File not found in source: $sourceDir/$file\n" ); |
| 49 | + continue; |
| 50 | + } |
| 51 | + if ( ! file_exists( "$targetDir/$file" ) ) |
| 52 | + continue; |
| 53 | + |
| 54 | + $item = new SyncFileItem(); |
| 55 | + $item->sourceDir = $sourceDir; |
| 56 | + $item->targetDir = $targetDir; |
| 57 | + $item->file = $file; |
| 58 | + $ret[] = $item; |
| 59 | + } |
| 60 | + |
| 61 | + if ( $ret === [] ) |
| 62 | + throw new Exception( "No matching files found." ); |
| 63 | + |
| 64 | + return $ret; |
31 | 65 | } |
32 | 66 |
|
33 | | - $lang = trim( file_get_contents( $file ) ); |
34 | 67 | $cacheFilename = __DIR__ . "/../../../temp/qaxml.files.$lang"; |
35 | 68 |
|
36 | 69 | if ( file_exists( $cacheFilename ) ) |
37 | 70 | { |
38 | 71 | return unserialize( gzdecode( file_get_contents( $cacheFilename ) ) ); |
39 | 72 | } |
40 | 73 |
|
41 | | - $sourceDir = 'en'; |
42 | | - $targetDir = $lang; |
43 | | - |
44 | 74 | require_once __DIR__ . '/../lib/all.php'; |
45 | 75 |
|
46 | | - $files = new RevcheckFileList( $sourceDir ); |
| 76 | + $revFiles = new RevcheckFileList( $sourceDir ); |
47 | 77 | $ret = []; |
48 | 78 |
|
49 | | - foreach( $files->iterator() as $file ) |
| 79 | + foreach( $revFiles->iterator() as $file ) |
50 | 80 | { |
51 | 81 | if ( ! file_exists( "$targetDir/{$file->file}" ) ) |
52 | 82 | continue; |
|
0 commit comments