4
4
5
5
use Countable ;
6
6
use Exception ;
7
+ use Jh \Import \Archiver \Archiver ;
7
8
use Jh \Import \Archiver \Factory as ArchiverFactory ;
8
9
use Jh \Import \Config ;
9
10
use Jh \Import \Locker \ImportLockedException ;
@@ -107,10 +108,13 @@ public function transform(callable $transform): void
107
108
$ this ->transformers [] = $ transform ;
108
109
}
109
110
110
- private function canImport (string $ importName , Report $ report ): bool
111
+ private function canImport (Config $ config , Report $ report, Archiver $ archiver ): bool
111
112
{
112
113
if ($ this ->history ->isImported ($ this ->source )) {
113
114
$ report ->addError ('This import source has already been imported. ' );
115
+ if ($ config ->get ('archive_already_imported_files ' )) {
116
+ $ archiver ->failed ();
117
+ }
114
118
return false ;
115
119
}
116
120
@@ -121,7 +125,7 @@ private function canImport(string $importName, Report $report): bool
121
125
122
126
try {
123
127
//check if an import by this name is already running
124
- $ this ->locker ->lock ($ importName );
128
+ $ this ->locker ->lock ($ config -> getImportName () );
125
129
} catch (ImportLockedException $ e ) {
126
130
$ report ->addError ($ e ->getMessage ());
127
131
return false ;
@@ -133,9 +137,11 @@ private function canImport(string $importName, Report $report): bool
133
137
public function process (Config $ config ): void
134
138
{
135
139
$ report = $ this ->reportFactory ->createFromSourceAndConfig ($ this ->source , $ config );
140
+ $ archiver = $ this ->archiverFactory ->getArchiverForSource ($ this ->source , $ config );
141
+
136
142
$ report ->start ();
137
143
138
- if (!$ this ->canImport ($ config-> getImportName () , $ report )) {
144
+ if (!$ this ->canImport ($ config , $ report, $ archiver )) {
139
145
$ this ->endReport ($ report );
140
146
return ;
141
147
}
@@ -158,7 +164,6 @@ public function process(Config $config): void
158
164
}
159
165
160
166
try {
161
- $ archiver = $ this ->archiverFactory ->getArchiverForSource ($ this ->source , $ config );
162
167
$ report ->isSuccessful () ? $ archiver ->successful () : $ archiver ->failed ();
163
168
} catch (Exception $ e ) {
164
169
$ report ->addError (sprintf (
@@ -172,6 +177,12 @@ public function process(Config $config): void
172
177
$ this ->endReport ($ report );
173
178
}
174
179
180
+ public function skip (Config $ config )
181
+ {
182
+ $ archiver = $ this ->archiverFactory ->getArchiverForSource ($ this ->source , $ config );
183
+ $ archiver ->failed ();
184
+ }
185
+
175
186
private function endReport (Report $ report ): void
176
187
{
177
188
$ report ->finish (new \DateTime (), memory_get_usage (true ));
0 commit comments