Completed
Push — 0.4.27 ( ec6131...b6e9cb )
by Peter
03:39
created

ScanExecutor::export()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\CatalogBundle\Service\Storage;
10
11
use Symfony\Component\Filesystem\Filesystem;
12
use AnimeDb\Bundle\AppBundle\Service\CommandExecutor;
13
use AnimeDb\Bundle\CatalogBundle\Entity\Storage as StorageEntity;
14
15
/**
16
 * Storage scanner service.
17
 *
18
 * @author  Peter Gribanov <[email protected]>
19
 */
20
class ScanExecutor
21
{
22
    /**
23
     * @var CommandExecutor
24
     */
25
    protected $command;
26
27
    /**
28
     * @var Filesystem
29
     */
30
    protected $fs;
31
32
    /**
33
     * @var string
34
     */
35
    protected $output = '';
36
37
    /**
38
     * @var string
39
     */
40
    protected $progress = '';
41
42
    /**
43
     * @param CommandExecutor $command
44
     * @param Filesystem $fs
45
     * @param string $output
46
     * @param string $progress
47
     */
48 1
    public function __construct(CommandExecutor $command, Filesystem $fs, $output, $progress)
49
    {
50 1
        $this->progress = $progress;
51 1
        $this->command = $command;
52 1
        $this->output = $output;
53 1
        $this->fs = $fs;
54 1
    }
55
56
    /**
57
     * Scan storage in background and export progress and output.
58
     *
59
     * @param StorageEntity $storage
60
     */
61 1
    public function export(StorageEntity $storage)
62
    {
63 1
        $output = sprintf($this->output, $storage->getId());
64 1
        $progress = sprintf($this->progress, $storage->getId());
65
66 1
        $this->fs->mkdir([dirname($output), dirname($progress)], 0755);
67
68 1
        $this->command->send(sprintf(
69 1
            'php app/console animedb:scan-storage --no-ansi --export=%s %s >%s 2>&1',
70 1
            $progress,
71 1
            $storage->getId(),
72
            $output
73 1
        ));
74 1
    }
75
}
76