|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Cli\Subjects\MoveFilesSubject |
|
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; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The subject implementation to move the files to their target directory. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Tim Wagner <[email protected]> |
|
27
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
29
|
|
|
* @link https://github.com/techdivision/import |
|
30
|
|
|
* @link http://www.techdivision.com |
|
31
|
|
|
*/ |
|
32
|
|
|
class MoveFilesSubject extends AbstractSubject |
|
33
|
|
|
{ |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Imports the content of the file with the passed filename. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $serial The unique process serial |
|
39
|
|
|
* @param string $filename The filename to process |
|
40
|
|
|
* |
|
41
|
|
|
* @return void |
|
42
|
|
|
* @throws \Exception Is thrown, if the import can't be processed |
|
43
|
|
|
*/ |
|
44
|
|
|
public function import($serial, $filename) |
|
45
|
|
|
{ |
|
46
|
|
|
|
|
47
|
|
|
// initialize the global global data to import a bunch |
|
48
|
|
|
$this->setUp(); |
|
49
|
|
|
|
|
50
|
|
|
// initialize serial and filename |
|
51
|
|
|
$this->setSerial($serial); |
|
52
|
|
|
$this->setFilename($filename); |
|
53
|
|
|
|
|
54
|
|
|
// query whether the new source directory has to be created or not |
|
55
|
|
|
if (!is_dir($newSourceDir = $this->getNewSourceDir())) { |
|
56
|
|
|
mkdir($newSourceDir); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// move the file to the new source directory |
|
60
|
|
|
rename($filename, sprintf('%s/%s', $newSourceDir, basename($filename))); |
|
61
|
|
|
|
|
62
|
|
|
// clean up the data after importing the bunch |
|
63
|
|
|
$this->tearDown(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|