forked from Islandora-Devops/migrate_7x_claw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectory.php
47 lines (38 loc) · 1.3 KB
/
Directory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Drupal\migrate_7x_claw\Plugin\migrate\source;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_plus\Plugin\migrate\source\Url;
/**
* Source plugin for retrieving files from directories.
*
* @MigrateSource(
* id = "directory"
* )
*/
class Directory extends Url {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
$files = [];
foreach ($configuration['urls'] as $url) {
$dir_iterator = new \RecursiveDirectoryIterator($url, \FilesystemIterator::SKIP_DOTS);
$file_iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($file_iterator as $file_info) {
if ($file_info->isFile()) {
if (isset($configuration['extensions']) && !empty($configuration['extensions'])) {
$ext = $file_info->getExtension();
if (in_array($ext, $configuration['extensions'])) {
$files[] = $file_info->getPathname();
}
}
else {
$files[] = $file_info->getPathname();
}
}
}
}
$configuration['urls'] = $files;
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
}
}