|
@@ -32,6 +32,8 @@ class FilePostDump implements EventSubscriberInterface {
|
|
|
|
|
|
* FilePostDump constructor.
|
|
|
*
|
|
|
+ * @param \Drupal\Core\File\FileSystemInterface $fileSystem
|
|
|
+ * The file_system service.
|
|
|
* @param string $importPath
|
|
|
* The reinstall.path parameter.
|
|
|
*/
|
|
@@ -49,6 +51,12 @@ class FilePostDump implements EventSubscriberInterface {
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Callback for POST_DUMP event.
|
|
|
+ *
|
|
|
+ * @param \Drupal\reinstall\DumperEvent $event
|
|
|
+ * The post-dump event.
|
|
|
+ */
|
|
|
public function onDumpPost(DumperEvent $event) {
|
|
|
if ($event->storage->getEntityTypeId() !== 'file') {
|
|
|
return;
|
|
@@ -57,6 +65,14 @@ class FilePostDump implements EventSubscriberInterface {
|
|
|
$this->dumpFiles($event->bundleName, $event->entities);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Dump the actual files for a file entity bundle.
|
|
|
+ *
|
|
|
+ * @param string $bundleName
|
|
|
+ * The bundle name.
|
|
|
+ * @param array $files
|
|
|
+ * The file URLs.
|
|
|
+ */
|
|
|
public function dumpFiles(string $bundleName, array $files) {
|
|
|
$importPath = $this->importPath;
|
|
|
$dir = "$importPath/$bundleName";
|
|
@@ -80,15 +96,12 @@ class FilePostDump implements EventSubscriberInterface {
|
|
|
];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * @var int $fid
|
|
|
- * @var \Drupal\file\Entity\File $file
|
|
|
- */
|
|
|
- foreach ($files as $fid => $file) {
|
|
|
+
|
|
|
+ foreach ($files as $file) {
|
|
|
$uri = $file->getFileUri();
|
|
|
$target = file_uri_target($uri);
|
|
|
$ns = $this->fileSystem->uriScheme($uri);
|
|
|
- fputs($lists[$ns]['handle'], $target . "\n");
|
|
|
+ fwrite($lists[$ns]['handle'], $target . "\n");
|
|
|
$dest = $lists[$ns]['dir'] . '/' . $target;
|
|
|
|
|
|
$dir = dirname($dest);
|
|
@@ -103,14 +116,16 @@ class FilePostDump implements EventSubscriberInterface {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
- * array_reduce() callback to collect namespaces from file entities.
|
|
|
+ * An array_reduce() callback to collect namespaces from file entities.
|
|
|
*
|
|
|
* @param string[] $accu
|
|
|
+ * The namespaces accumulator.
|
|
|
* @param \Drupal\file\Entity\File $fileItem
|
|
|
+ * A file description.
|
|
|
*
|
|
|
* @return string[]
|
|
|
+ * An array of namespaces used on the site.
|
|
|
*
|
|
|
* @see \Drupal\reinstall\Dumper::dumpFiles()
|
|
|
*/
|
|
@@ -125,4 +140,5 @@ class FilePostDump implements EventSubscriberInterface {
|
|
|
$accu[$namespace] = TRUE;
|
|
|
return $accu;
|
|
|
}
|
|
|
+
|
|
|
}
|