Skip to content

Commit c4f3cd7

Browse files
authored
Merge pull request #1 from flownative/feature/file-import
FEATURE: File import command
2 parents ea9ee67 + ca1765a commit c4f3cd7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Classes/Command/ResourceToolsCommandController.php

+19
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,23 @@ public function matchCommand(string $sourcePath, string $collection = 'persisten
9999
}
100100
}
101101
}
102+
103+
/**
104+
* Import the given file as resource in Neos.
105+
*
106+
* @param string $source Can be anything PHP can open (filepath, URL, data string, etc.)
107+
* @param string $filename The filename (if empty string it will try to fetch from stream or leave empty)
108+
* @param string $collection
109+
* @throws \Neos\Flow\ResourceManagement\Exception
110+
*/
111+
public function importFileCommand(string $source, string $filename, string $collection = 'persistent')
112+
{
113+
$fileHandler = fopen($source, 'r');
114+
$resource = $this->resourceManager->importResource($fileHandler, $collection);
115+
if ($filename !== '') {
116+
$resource->setFilename($filename);
117+
}
118+
119+
$this->outputLine('Imported file as resource "%s"', [$resource->getSha1()]);
120+
}
102121
}

0 commit comments

Comments
 (0)