|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by Adam Jakab. |
|
4
|
|
|
* Date: 07/10/15 |
|
5
|
|
|
* Time: 14.26 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SuiteCrm\Command; |
|
9
|
|
|
|
|
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
14
|
|
|
|
|
15
|
|
|
class CacheClearCommand extends Command implements CommandInterface { |
|
16
|
|
|
const COMMAND_NAME = 'cache:clear'; |
|
17
|
|
|
const COMMAND_DESCRIPTION = 'Empty the cache folder by removing all files.'; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct() { |
|
20
|
|
|
$this->enableConsoleLogging(true); |
|
21
|
|
|
parent::__construct(NULL); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Configure command |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function configure() { |
|
28
|
|
|
$this->setName(static::COMMAND_NAME); |
|
29
|
|
|
$this->setDescription(static::COMMAND_DESCRIPTION); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param InputInterface $input |
|
34
|
|
|
* @param OutputInterface $output |
|
35
|
|
|
* @return bool |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
|
38
|
|
|
parent::_execute($input, $output); |
|
|
|
|
|
|
39
|
|
|
$this->log("Starting command " . static::COMMAND_NAME . "..."); |
|
40
|
|
|
$this->executeCommand(); |
|
41
|
|
|
$this->log("Command " . static::COMMAND_NAME . " done."); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Execute Command |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function executeCommand() { |
|
48
|
|
|
$cachePath = realpath(PROJECT_ROOT . '/cache'); |
|
49
|
|
|
$this->log("Emptying cache folder: " . $cachePath); |
|
50
|
|
|
$this->deleteDirectory($cachePath); |
|
51
|
|
|
$this->recreateCacheFolder($cachePath); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Recursively delete directory content and the directory itself |
|
56
|
|
|
* @param string $dir |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function deleteDirectory($dir) { |
|
59
|
|
|
if (is_dir($dir)) { |
|
60
|
|
|
$elements = scandir($dir); |
|
61
|
|
|
foreach ($elements as $element) { |
|
62
|
|
|
if (!in_array($element, ['.','..'])) { |
|
63
|
|
|
$elementFullPath = $dir . "/" . $element; |
|
64
|
|
|
if (is_dir($elementFullPath)) { |
|
65
|
|
|
$this->deleteDirectory($elementFullPath); |
|
66
|
|
|
} else { |
|
67
|
|
|
unlink($dir."/".$element); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
rmdir($dir); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param string $dir |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function recreateCacheFolder($dir) { |
|
79
|
|
|
mkdir($dir); |
|
80
|
|
|
} |
|
81
|
|
|
} |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.