4
4
5
5
use Neos \Flow \Annotations as Flow ;
6
6
use Neos \Flow \Cli \CommandController ;
7
+ use Neos \Flow \ResourceManagement \Exception ;
7
8
use Neos \Flow \ResourceManagement \ResourceManager ;
8
9
use Neos \Flow \ResourceManagement \Storage \StorageObject ;
10
+ use Neos \Utility \Exception \FilesException ;
9
11
use Neos \Utility \Files ;
10
12
11
13
final class ResourceToolsCommandController extends CommandController
@@ -25,12 +27,13 @@ final class ResourceToolsCommandController extends CommandController
25
27
* @param string $targetPath The path where the resource files should be exported to.
26
28
* @param bool $emptyTargetPath If set, all files in the target path will be deleted before the export runs
27
29
* @param string $collection Name of the resource collection to export. Default: "persistent"
30
+ * @throws FilesException
28
31
*/
29
- public function exportCommand (string $ targetPath , bool $ emptyTargetPath = false , $ collection = 'persistent ' )
32
+ public function exportCommand (string $ targetPath , bool $ emptyTargetPath = false , $ collection = 'persistent ' ): void
30
33
{
31
34
if (!is_dir ($ targetPath )) {
32
35
$ this ->outputLine ('The target path does not exist. ' );
33
- $ this -> quit (1 );
36
+ exit (1 );
34
37
}
35
38
$ targetPath = realpath ($ targetPath ) . '/ ' ;
36
39
@@ -70,11 +73,11 @@ public function exportCommand(string $targetPath, bool $emptyTargetPath = false,
70
73
* @param string $sourcePath The path where the resource files are located
71
74
* @param string $collection Name of the resource collection to match with. Default: "persistent"
72
75
*/
73
- public function matchCommand (string $ sourcePath , string $ collection = 'persistent ' )
76
+ public function matchCommand (string $ sourcePath , string $ collection = 'persistent ' ): void
74
77
{
75
78
if (!is_dir ($ sourcePath )) {
76
79
$ this ->outputLine ('The source path does not exist. ' );
77
- $ this -> quit (1 );
80
+ exit (1 );
78
81
}
79
82
80
83
$ sourcePath = rtrim ($ sourcePath ,'/ ' ) . '/ ' ;
@@ -89,8 +92,12 @@ public function matchCommand(string $sourcePath, string $collection = 'persisten
89
92
if ($ stream === false ) {
90
93
if (file_exists ($ sourcePath . $ object ->getSha1 ())) {
91
94
sha1_file ($ sourcePath . $ object ->getSha1 ());
92
- $ persistentCollection ->importResource (fopen ($ sourcePath . $ object ->getSha1 (), 'r ' ));
93
- $ this ->outputLine ('<success>imported</success> %s %s ' , [$ object ->getSha1 (), $ object ->getFilename ()]);
95
+ try {
96
+ $ persistentCollection ->importResource (fopen ($ sourcePath . $ object ->getSha1 (), 'r ' ));
97
+ $ this ->outputLine ('<success>imported</success> %s %s ' , [$ object ->getSha1 (), $ object ->getFilename ()]);
98
+ } catch (Exception $ e ) {
99
+ $ this ->outputLine ('<error>failed</error> %s %s %s ' , [$ object ->getSha1 (), $ object ->getFilename (), $ e ->getMessage ()]);
100
+ }
94
101
} else {
95
102
$ this ->outputLine ('<error>missing </error> %s %s ' , [$ object ->getSha1 (), $ object ->getFilename ()]);
96
103
}
@@ -106,16 +113,20 @@ public function matchCommand(string $sourcePath, string $collection = 'persisten
106
113
* @param string $source Can be anything PHP can open (filepath, URL, data string, etc.)
107
114
* @param string $filename The filename (if empty string it will try to fetch from stream or leave empty)
108
115
* @param string $collection
109
- * @throws \Neos\Flow\ResourceManagement\Exception
110
116
*/
111
- public function importFileCommand (string $ source , string $ filename , string $ collection = 'persistent ' )
117
+ public function importFileCommand (string $ source , string $ filename , string $ collection = 'persistent ' ): void
112
118
{
113
- $ fileHandler = fopen ($ source , 'r ' );
114
- $ resource = $ this ->resourceManager ->importResource ($ fileHandler , $ collection );
115
- if ($ filename !== '' ) {
116
- $ resource ->setFilename ($ filename );
117
- }
119
+ $ fileHandler = fopen ($ source , 'rb ' );
120
+ try {
121
+ $ resource = $ this ->resourceManager ->importResource ($ fileHandler , $ collection );
122
+ if ($ filename !== '' ) {
123
+ $ resource ->setFilename ($ filename );
124
+ }
118
125
119
- $ this ->outputLine ('Imported file as resource "%s" ' , [$ resource ->getSha1 ()]);
126
+ $ this ->outputLine ('Imported file as resource "%s" ' , [$ resource ->getSha1 ()]);
127
+ } catch (Exception $ e ) {
128
+ $ this ->outputLine ('<error>Failed importing file</error> %s ' , [$ e ->getMessage ()]);
129
+ exit (1 );
130
+ }
120
131
}
121
132
}
0 commit comments