2
2
3
3
namespace Oxrun \Command \Cache ;
4
4
5
- use OxidEsales \Eshop \ Core \ Registry ;
5
+ use OxidEsales \Facts \ Facts ;
6
6
use Symfony \Component \Console \Command \Command ;
7
7
use Symfony \Component \Console \Input \InputInterface ;
8
8
use Symfony \Component \Console \Input \InputOption ;
9
9
use Symfony \Component \Console \Output \OutputInterface ;
10
10
use Symfony \Component \Filesystem \Exception \FileNotFoundException ;
11
+ use Webmozart \PathUtil \Path ;
11
12
12
13
/**
13
14
* Class ClearCommand
16
17
class ClearCommand extends Command
17
18
{
18
19
19
- // use NoNeedDatabase;
20
+ /**
21
+ * @var Facts
22
+ */
23
+ private $ facts ;
24
+
25
+ /**
26
+ * @var ?\OxidEsales\Eshop\Core\Cache\Generic\Cache
27
+ */
28
+ private $ genericCache = null ;
29
+
30
+ /**
31
+ * @var ?\OxidEsales\Eshop\Core\Cache\DynamicContent\ContentCache
32
+ */
33
+ private $ dynamicContentCache = null ;
34
+
35
+ /**
36
+ * ClearCommand constructor.
37
+ * @param Facts|null $facts
38
+ * @param \OxidEsales\Eshop\Core\Cache\Generic\Cache|null $genericCache
39
+ * @param \OxidEsales\Eshop\Core\Cache\DynamicContent\ContentCache|null $dynamicContentCache
40
+ */
41
+ public function __construct (
42
+ Facts $ facts = null ,
43
+ $ genericCache = null ,
44
+ $ dynamicContentCache = null
45
+ ) {
46
+ $ this ->facts = $ facts ?? new Facts ();
47
+ $ this ->genericCache = $ genericCache ;
48
+ $ this ->dynamicContentCache = $ dynamicContentCache ;
49
+
50
+ parent ::__construct ();
51
+ }
52
+
20
53
21
54
/**
22
55
* Configures the current command.
@@ -62,11 +95,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
62
95
*/
63
96
protected function getCompileDir ()
64
97
{
65
- $ oxidPath = OX_BASE_PATH ;
66
- $ configfile = $ oxidPath . DIRECTORY_SEPARATOR . 'config.inc.php ' ;
98
+ $ sourcePath = ( new \ OxidEsales \ Facts \ Facts ())-> getSourcePath () ;
99
+ $ configfile = Path:: join ( $ sourcePath , 'config.inc.php ' ) ;
67
100
68
- if ($ oxidPath && file_exists ($ configfile )) {
69
- $ oxConfigFile = new \OxConfigFile ($ configfile );
101
+ if ($ sourcePath && file_exists ($ configfile )) {
102
+ $ oxConfigFile = new \OxidEsales \ Eshop \ Core \ ConfigFile ($ configfile );
70
103
return $ oxConfigFile ->getVar ('sCompileDir ' );
71
104
}
72
105
@@ -123,7 +156,11 @@ protected function checkSameOwner($compileDir)
123
156
if ($ current_owner != $ owner ) {
124
157
global $ argv ;
125
158
$ owner = posix_getpwuid ($ owner );
126
- throw new \Exception ("Please run command as ` $ {owner['name ' ]}` user. " . PHP_EOL . " sudo -u $ {owner['name ' ]} " . join (' ' , $ argv ));
159
+ throw new \Exception (
160
+ "Please run command as ` $ {owner['name ' ]}` user. " . PHP_EOL .
161
+ " sudo -u $ {owner['name ' ]} " .
162
+ join (' ' , $ argv )
163
+ );
127
164
}
128
165
}
129
166
@@ -132,23 +169,51 @@ protected function checkSameOwner($compileDir)
132
169
*/
133
170
protected function enterpriseCache (OutputInterface $ output )
134
171
{
135
- if (class_exists ( ' \OxidEsales\Facts\Facts ' ) == false ) {
172
+ if ($ this -> facts -> isEnterprise ( ) == false ) {
136
173
return ;
137
174
}
138
175
139
- if ((Registry::get (\OxidEsales \Facts \Facts::class))->isEnterprise () == false ) {
176
+ if ($ this ->getApplication () instanceof \Oxrun \Application \OxrunLight) {
177
+ $ output ->writeln (
178
+ '<comment>[Info] The enterprise cache could not be cleared. ' .
179
+ 'Goes only via the command `oe-console cache:clear`.</comment> ' ,
180
+ OutputInterface::VERBOSITY_NORMAL
181
+ );
140
182
return ;
141
183
}
142
184
143
185
try {
144
- Registry:: get ( ' OxidEsales\Eshop\Core\Cache\Generic\Cache ' )->flush ();
186
+ $ this -> getGenericCache ( )->flush ();
145
187
$ output ->writeln ('<info>Generic\Cache is cleared</info> ' );
146
188
147
- Registry:: get ( ' OxidEsales\Eshop\Core\Cache\DynamicContent\ContentCache ' )->reset (true );
189
+ $ this -> getDynamicContentCache ( )->reset (true );
148
190
$ output ->writeln ('<info>DynamicContent\Cache is cleared</info> ' );
149
191
150
192
} catch (\Exception $ e ) {
151
- $ output ->writeln ('<error>Only enterprise cache could \'t be cleared: ' . $ e ->getMessage (). '</error> ' );
193
+ $ output ->writeln ('<error>Only enterprise cache could \'t be cleared: ' . $ e ->getMessage () . '</error> ' );
152
194
}
153
195
}
196
+
197
+ /**
198
+ * @return \OxidEsales\Eshop\Core\Cache\Generic\Cache
199
+ */
200
+ private function getGenericCache ()
201
+ {
202
+ if ($ this ->genericCache === null ) {
203
+ $ this ->genericCache = new \OxidEsales \Eshop \Core \Cache \Generic \Cache ();
204
+ }
205
+ return $ this ->genericCache ;
206
+ }
207
+
208
+ /**
209
+ * @return \OxidEsales\Eshop\Core\Cache\DynamicContent\ContentCache
210
+ */
211
+ private function getDynamicContentCache ()
212
+ {
213
+ if ($ this ->dynamicContentCache === null ) {
214
+ $ this ->dynamicContentCache = new \OxidEsales \Eshop \Core \Cache \DynamicContent \ContentCache ();
215
+ }
216
+
217
+ return $ this ->dynamicContentCache ;
218
+ }
154
219
}
0 commit comments