|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Cli\Command\ImportClearPidFileCommand |
|
5
|
|
|
* |
|
6
|
|
|
* PHP version 7 |
|
7
|
|
|
* |
|
8
|
|
|
* @author Tim Wagner <[email protected]> |
|
9
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
10
|
|
|
* @license https://opensource.org/licenses/MIT |
|
11
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
|
12
|
|
|
* @link http://www.techdivision.com |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace TechDivision\Import\Cli\Command; |
|
16
|
|
|
|
|
17
|
|
|
use TechDivision\Import\Utils\CommandNames; |
|
18
|
|
|
use TechDivision\Import\Configuration\ConfigurationInterface; |
|
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The remove PID command implementation. |
|
24
|
|
|
* |
|
25
|
|
|
* @author Tim Wagner <[email protected]> |
|
26
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
27
|
|
|
* @license https://opensource.org/licenses/MIT |
|
28
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
|
29
|
|
|
* @link http://www.techdivision.com |
|
30
|
|
|
*/ |
|
31
|
|
|
class ImportClearPidFileCommand extends AbstractSimpleImportCommand |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Configures the current command. |
|
36
|
|
|
* |
|
37
|
|
|
* @return void |
|
38
|
|
|
* @see \Symfony\Component\Console\Command\Command::configure() |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function configure() |
|
41
|
|
|
{ |
|
42
|
|
|
|
|
43
|
|
|
// initialize the command with the required/optional options |
|
44
|
|
|
$this->setName(CommandNames::IMPORT_CLEAR_PID_FILE) |
|
45
|
|
|
->setDescription('Clears the PID file from a previous import process, if it has not been cleaned up'); |
|
46
|
|
|
|
|
47
|
|
|
// invoke the parent method |
|
48
|
|
|
parent::configure(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Finally executes the simple command. |
|
53
|
|
|
* |
|
54
|
|
|
* @param \TechDivision\Import\Configuration\ConfigurationInterface $configuration The configuration instance |
|
55
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input An InputInterface instance |
|
56
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output An OutputInterface instance |
|
57
|
|
|
* |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function executeSimpleCommand( |
|
61
|
|
|
ConfigurationInterface $configuration, |
|
62
|
|
|
InputInterface $input, |
|
63
|
|
|
OutputInterface $output |
|
64
|
|
|
) { |
|
65
|
|
|
|
|
66
|
|
|
// query whether or not a PID file exists and delete it |
|
67
|
|
|
if (file_exists($pidFilename = $configuration->getPidFilename())) { |
|
68
|
|
|
if (!unlink($pidFilename)) { |
|
69
|
|
|
throw new \Exception(sprintf('Can\'t delete PID file %s', $pidFilename)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
// write a message to the console |
|
73
|
|
|
$output->writeln(sprintf('<info>Successfully deleted PID file %s</info>', $pidFilename)); |
|
74
|
|
|
} else { |
|
75
|
|
|
// write a message to the console |
|
76
|
|
|
$output->writeln(sprintf('<error>PID file %s not available</error>', $pidFilename)); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|