|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Subjects\FileResolver\OkFileAwareFileResolver |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/techdivision/import |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Subjects\FileResolver; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Exceptions\MissingOkFileException; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Plugin that processes the subjects. |
|
27
|
|
|
* |
|
28
|
|
|
* @author Tim Wagner <[email protected]> |
|
29
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
31
|
|
|
* @link https://github.com/techdivision/import |
|
32
|
|
|
* @link http://www.techdivision.com |
|
33
|
|
|
*/ |
|
34
|
|
|
class OkFileAwareFileResolver extends AbstractFileResolver |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Loads the files from the source directory and return's them sorted. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $serial The unique identifier of the actual import process |
|
41
|
|
|
* |
|
42
|
|
|
* @return array The array with the files matching the subjects suffix |
|
43
|
|
|
* @throws \Exception Is thrown, when the source directory is NOT available |
|
44
|
|
|
* @throws \TechDivision\Import\Exceptions\MissingOkFileException Is thrown, if files to be processed are available but the mandatory OK file is missing |
|
45
|
|
|
*/ |
|
46
|
|
|
public function loadFiles(string $serial) : array |
|
47
|
|
|
{ |
|
48
|
|
|
|
|
49
|
|
|
// initialize the array with the files that has to be handled |
|
50
|
|
|
$filesToHandle = parent::loadFiles($serial); |
|
51
|
|
|
|
|
52
|
|
|
// load the size of the files before the filters have been applied |
|
53
|
|
|
$sizeBeforeFiltersHaveBeenApplied = $this->getFilesystemLoader()->getSizeBeforeFiltersHaveBeenApplied(); |
|
54
|
|
|
|
|
55
|
|
|
// stop processing, if files ARE available, an OK file IS mandatory, but |
|
56
|
|
|
// NO file will be processed (because of a missing/not matching OK file) |
|
57
|
|
|
if ($this->getSubjectConfiguration()->isOkFileNeeded() && $sizeBeforeFiltersHaveBeenApplied > 0 && sizeof($filesToHandle) === 0) { |
|
58
|
|
|
throw new MissingOkFileException( |
|
59
|
|
|
sprintf( |
|
60
|
|
|
'Stop processing, because can\'t find the mandatory OK file to process at least one of %d files', |
|
61
|
|
|
$sizeBeforeFiltersHaveBeenApplied |
|
62
|
|
|
) |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
// return the array with the files that has to be handled |
|
67
|
|
|
return $filesToHandle; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|