|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kaliop\eZMigrationBundle\Core\Loader; |
|
4
|
|
|
|
|
5
|
|
|
use Kaliop\eZMigrationBundle\API\Exception\MigrationBundleException; |
|
6
|
|
|
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Similar to parent, except that, given a folder, we scan all of its subfolders |
|
10
|
|
|
* |
|
11
|
|
|
* @todo allow to specify specific subfolders not to scan, eg: where the media files are stored |
|
12
|
|
|
*/ |
|
13
|
|
|
class FilesystemRecursive extends Filesystem |
|
14
|
|
|
{ |
|
15
|
|
|
protected function getDefinitions(array $paths = array(), $returnFilename = false) |
|
16
|
|
|
{ |
|
17
|
|
|
// if no paths defined, we look in all bundles |
|
18
|
|
|
if (empty($paths)) { |
|
19
|
|
|
/** @var $bundle \Symfony\Component\HttpKernel\Bundle\BundleInterface */ |
|
20
|
|
|
foreach ($this->kernel->getBundles() as $bundle) |
|
21
|
|
|
{ |
|
22
|
|
|
$path = $bundle->getPath() . "/" . $this->versionDirectory; |
|
23
|
|
|
if (is_dir($path)) { |
|
24
|
|
|
$paths[] = $path; |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$definitions = array(); |
|
30
|
|
|
foreach ($paths as $path) { |
|
31
|
|
|
if (is_file($path)) { |
|
32
|
|
|
$definitions[basename($path)] = $returnFilename ? $path : new MigrationDefinition( |
|
33
|
|
|
basename($path), |
|
34
|
|
|
$path, |
|
35
|
|
|
file_get_contents($path) |
|
36
|
|
|
); |
|
37
|
|
|
} elseif (is_dir($path)) { |
|
38
|
|
|
|
|
39
|
|
|
// seems like sorting of recursive dirs scan is though... |
|
40
|
|
|
|
|
41
|
|
|
$dirs = array(); |
|
42
|
|
|
$DI = new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO); |
|
43
|
|
|
foreach (new \RecursiveIteratorIterator($DI) as $file) { |
|
44
|
|
|
if ($file->isFile()) { |
|
45
|
|
|
$dirs[dirname($file->getRealpath())] = true; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
$dirs = array_keys($dirs); |
|
49
|
|
|
asort($dirs); |
|
50
|
|
|
|
|
51
|
|
|
foreach ($dirs as $dir) { |
|
52
|
|
|
foreach (glob("$dir/*") as $filename) { |
|
53
|
|
|
if (is_file($filename)) { |
|
54
|
|
|
$definitions[basename($filename)] = |
|
55
|
|
|
$returnFilename ? realpath($filename) : new MigrationDefinition( |
|
56
|
|
|
basename($filename), |
|
57
|
|
|
realpath($filename), |
|
58
|
|
|
file_get_contents($filename) |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
else { |
|
65
|
|
|
throw new MigrationBundleException("Path '$path' is neither a file nor directory"); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
ksort($definitions); |
|
69
|
|
|
|
|
70
|
|
|
return $definitions; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|