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
|
|
|
use TechDivision\Import\Utils\RegistryKeys; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The subject implementation to move the files to their target directory. |
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 MoveFilesSubject extends AbstractSubject |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Clean up the global data after importing the variants. |
39
|
|
|
* |
40
|
|
|
* @param string $serial The serial of the actual import |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function tearDown($serial) |
45
|
|
|
{ |
46
|
|
|
|
47
|
|
|
// load the registry processor |
48
|
|
|
$registryProcessor = $this->getRegistryProcessor(); |
49
|
|
|
|
50
|
|
|
// update target and source directory for the next subject |
51
|
|
|
$registryProcessor->mergeAttributesRecursive( |
52
|
|
|
RegistryKeys::STATUS, |
53
|
|
|
array( |
54
|
|
|
RegistryKeys::TARGET_DIRECTORY => $newSourceDir = $this->getNewSourceDir($serial), |
55
|
|
|
RegistryKeys::SOURCE_DIRECTORY => $newSourceDir |
56
|
|
|
) |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
// log a debug message with the new source directory |
60
|
|
|
$this->getSystemLogger()->debug( |
61
|
|
|
sprintf('Subject %s successfully updated source directory to %s', get_class($this), $newSourceDir) |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
// invoke the parent method |
65
|
|
|
parent::tearDown($serial); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Return's the header mappings for the actual entity. |
70
|
|
|
* |
71
|
|
|
* @return array The header mappings |
72
|
|
|
*/ |
73
|
1 |
|
public function getHeaderMappings() |
74
|
|
|
{ |
75
|
1 |
|
return array(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Return's the default callback frontend input mappings for the user defined attributes. |
80
|
|
|
* |
81
|
|
|
* @return array The default frontend input callback mappings |
82
|
|
|
*/ |
83
|
1 |
|
public function getDefaultFrontendInputCallbackMappings() |
84
|
|
|
{ |
85
|
1 |
|
return array(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Return's the next source directory, which will be the target directory |
90
|
|
|
* of this subject, in most cases. |
91
|
|
|
* |
92
|
|
|
* @param string $serial The serial of the actual import |
93
|
|
|
* |
94
|
|
|
* @return string The new source directory |
95
|
|
|
*/ |
96
|
3 |
|
public function getNewSourceDir($serial) |
97
|
|
|
{ |
98
|
3 |
|
return sprintf('%s/%s', $this->getConfiguration()->getSourceDir(), $serial); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Imports the content of the file with the passed filename. |
103
|
|
|
* |
104
|
|
|
* @param string $serial The serial of the actual import |
105
|
|
|
* @param string $filename The filename to process |
106
|
|
|
* |
107
|
|
|
* @return void |
108
|
|
|
* @throws \Exception Is thrown, if the import can't be processed |
109
|
|
|
*/ |
110
|
3 |
|
public function import($serial, $filename) |
111
|
|
|
{ |
112
|
|
|
|
113
|
|
|
// initialize the serial/filename |
114
|
3 |
|
$this->setSerial($serial); |
115
|
3 |
|
$this->setFilename($filename); |
116
|
|
|
|
117
|
|
|
// query whether the new source directory has to be created or not |
118
|
3 |
|
if (!$this->isDir($newSourceDir = $this->getNewSourceDir($serial))) { |
119
|
2 |
|
$this->mkdir($newSourceDir); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
// move the file to the new source directory |
123
|
3 |
|
$this->rename($filename, sprintf('%s/%s', $newSourceDir, basename($filename))); |
124
|
|
|
|
125
|
|
|
// update the status |
126
|
3 |
|
$this->mergeStatus( |
127
|
|
|
array( |
128
|
|
|
RegistryKeys::STATUS => array( |
129
|
|
|
RegistryKeys::FILES => array( |
130
|
|
|
$filename => array( |
131
|
3 |
|
$this->getUniqueId() => array( |
132
|
3 |
|
RegistryKeys::STATUS => 1, |
133
|
3 |
|
RegistryKeys::SKIPPED_ROWS => $this->getSkippedRows(), |
134
|
3 |
|
RegistryKeys::PROCESSED_ROWS => $this->getLineNumber() - 1 |
135
|
|
|
) |
136
|
|
|
) |
137
|
|
|
) |
138
|
|
|
) |
139
|
|
|
) |
140
|
|
|
); |
141
|
3 |
|
} |
142
|
|
|
} |
143
|
|
|
|