|
@@ -2,20 +2,47 @@
|
|
|
|
|
|
namespace Drupal\reinstall\EventSubscriber;
|
|
|
|
|
|
-
|
|
|
-use Drupal\reinstall\Dumper;
|
|
|
+use Drupal\Component\Utility\Unicode;
|
|
|
+use Drupal\Core\File\FileSystem;
|
|
|
+use Drupal\Core\File\FileSystemInterface;
|
|
|
+use Drupal\file\Entity\File;
|
|
|
use Drupal\reinstall\DumperEvent;
|
|
|
use Drupal\reinstall\DumperEvents;
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|
|
|
|
|
+
|
|
|
+ * Class FilePostDump performs physical file copy on file dump.
|
|
|
+ */
|
|
|
class FilePostDump implements EventSubscriberInterface {
|
|
|
|
|
|
- protected $importPath = Dumper::IMPORT_PATH;
|
|
|
+
|
|
|
+ * The file_system service.
|
|
|
+ *
|
|
|
+ * @var \Drupal\Core\File\FileSystemInterface
|
|
|
+ */
|
|
|
+ protected $fileSystem;
|
|
|
|
|
|
- public function __construct(string $importPath) {
|
|
|
+
|
|
|
+ * The export/import path.
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $importPath;
|
|
|
+
|
|
|
+
|
|
|
+ * FilePostDump constructor.
|
|
|
+ *
|
|
|
+ * @param string $importPath
|
|
|
+ * The reinstall.path parameter.
|
|
|
+ */
|
|
|
+ public function __construct(FileSystemInterface $fileSystem, string $importPath) {
|
|
|
+ $this->fileSystem = $fileSystem;
|
|
|
$this->importPath = $importPath;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * {@inheritdoc}
|
|
|
+ */
|
|
|
public static function getSubscribedEvents() {
|
|
|
return [
|
|
|
DumperEvents::POST_DUMP => 'onDumpPost',
|
|
@@ -23,18 +50,16 @@ class FilePostDump implements EventSubscriberInterface {
|
|
|
}
|
|
|
|
|
|
public function onDumpPost(DumperEvent $event) {
|
|
|
- $args = func_get_args();
|
|
|
if ($event->storage->getEntityTypeId() !== 'file') {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- echo "coucou" . $event->bundleName . "\n";
|
|
|
- static::dumpFiles($event->bundleName, $event->entities);
|
|
|
+ $this->dumpFiles($event->bundleName, $event->entities);
|
|
|
}
|
|
|
|
|
|
- public function dumpFiles(string $bundle, array $files) {
|
|
|
+ public function dumpFiles(string $bundleName, array $files) {
|
|
|
$importPath = $this->importPath;
|
|
|
- $dir = "$importPath/file";
|
|
|
+ $dir = "$importPath/$bundleName";
|
|
|
$usedNamespaces = array_keys(array_reduce($files, [__CLASS__, 'namespacesReducer'], []));
|
|
|
$lists = [];
|
|
|
|
|
@@ -62,6 +87,7 @@ class FilePostDump implements EventSubscriberInterface {
|
|
|
foreach ($files as $fid => $file) {
|
|
|
$uri = $file->getFileUri();
|
|
|
$target = file_uri_target($uri);
|
|
|
+ $ns = $this->fileSystem->uriScheme($uri);
|
|
|
fputs($lists[$ns]['handle'], $target . "\n");
|
|
|
$dest = $lists[$ns]['dir'] . '/' . $target;
|
|
|
|