Completed
Push — master ( 03e582...b12e79 )
by Tim
11s
created

MoveFilesSubject::needsOkFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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
        // only process the file, if the filename match
48
        if ($this->match($filename)) {
49
            // initialize the global global data to import a bunch
50
            $this->setUp();
51
52
            // initialize serial and filename
53
            $this->setSerial($serial);
54
            $this->setFilename($filename);
55
56
            // query whether the new source directory has to be created or not
57
            if (!is_dir($newSourceDir = $this->getNewSourceDir())) {
58
                mkdir($newSourceDir);
59
            }
60
61
            // move the file to the new source directory
62
            rename($filename, sprintf('%s/%s', $newSourceDir, basename($filename)));
63
64
            // clean up the data after importing the bunch
65
            $this->tearDown();
66
        }
67
    }
68
69
    /**
70
     * Return's TRUE if an OK file is needed for the subject to be processed, else FALSE.
71
     *
72
     * @return boolean TRUE if the subject needs an OK file to be executed, else FALSE
73
     */
74
    public function needsOkFile()
75
    {
76
        return true;
77
    }
78
}
79