Skip to content

Commit 06f50f8

Browse files
committed
Merge branch 'feature/cache_clear'
* feature/cache_clear: ReadMe updatet with oxrun-light. small stuff Now describes what oxrun-light is and has cache-clear added. Make cache:clear runable without to load oxid bootstrap.php
2 parents 48fe43e + a59392d commit 06f50f8

File tree

6 files changed

+138
-59
lines changed

6 files changed

+138
-59
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
## [v5.1.0] 2021-09-07
9+
### Changed
10+
- `oxrun-light` is now officially documented.
11+
- Command cache:clear works without bootstrap.php so can now used in `oxrun-light`.
812

913
## [v5.0.1] 2021-09-06
1014
### Fixed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ Oxrun provides a cli toolset for the OXID eShop Community Edition.
1919
- PHP >=7.1 is required.
2020
- OXID eShop >= CE v6.5 is required.
2121

22-
After installation manually clear the cache via `rm -rf source/tmp/*` to make all oxrun commands available.
22+
After installation manually clear the cache via `./vendor/bin/oxrun-light cache:clear` to make all oxrun commands available.
2323

2424
# Usage
2525

26-
In your Installation Direction `./vendor/bin/oe-console`
26+
`./vendor/bin/oe-console` is standard call.
27+
28+
* `./vendor/bin/oxrun-light` is a light version of tools that are not need an active OXID eSale database connection.
29+
* `./vendor/bin/oxrun` is a alias from `oe-console`
2730

2831
---
2932

src/Oxrun/Application/oxrun-light.php

+28-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,34 @@
99

1010
declare(strict_types=1);
1111

12-
$application = new \Symfony\Component\Console\Application('oxrun-light', '0.2');
12+
namespace Oxrun\Application;
13+
14+
/**
15+
* Class OxrunLight
16+
* @package Oxrun\Application
17+
*/
18+
class OxrunLight extends \Symfony\Component\Console\Application
19+
{
20+
/**
21+
* @inheritDoc
22+
*/
23+
public function getHelp()
24+
{
25+
$version = parent::getHelp();
26+
return <<<TAG
27+
$version
28+
29+
-----------------------------------------------------------------------
30+
<comment> Is a light console line tool for OXID eSale.
31+
These commands don't need an active OXID eSale database connection.</comment>
32+
-----------------------------------------------------------------------
33+
TAG;
34+
}
35+
36+
}
37+
38+
$application = new OxrunLight('oxrun-light', '0.3');
39+
$application->add(new \Oxrun\Command\Cache\ClearCommand());
1340
$application->add(new \Oxrun\Command\Misc\RegisterCommand());
1441
$application->add(new \Oxrun\Command\Misc\PhpstormMetadataCommand());
1542
$application->add(new \Oxrun\Command\Misc\GenerateDocumentationCommand());

src/Oxrun/Command/Cache/ClearCommand.php

+77-12
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
namespace Oxrun\Command\Cache;
44

5-
use OxidEsales\Eshop\Core\Registry;
5+
use OxidEsales\Facts\Facts;
66
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputInterface;
88
use Symfony\Component\Console\Input\InputOption;
99
use Symfony\Component\Console\Output\OutputInterface;
1010
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
11+
use Webmozart\PathUtil\Path;
1112

1213
/**
1314
* Class ClearCommand
@@ -16,7 +17,39 @@
1617
class ClearCommand extends Command
1718
{
1819

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+
2053

2154
/**
2255
* Configures the current command.
@@ -62,11 +95,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
6295
*/
6396
protected function getCompileDir()
6497
{
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');
67100

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);
70103
return $oxConfigFile->getVar('sCompileDir');
71104
}
72105

@@ -123,7 +156,11 @@ protected function checkSameOwner($compileDir)
123156
if ($current_owner != $owner) {
124157
global $argv;
125158
$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+
);
127164
}
128165
}
129166

@@ -132,23 +169,51 @@ protected function checkSameOwner($compileDir)
132169
*/
133170
protected function enterpriseCache(OutputInterface $output)
134171
{
135-
if (class_exists('\OxidEsales\Facts\Facts') == false) {
172+
if ($this->facts->isEnterprise() == false) {
136173
return;
137174
}
138175

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+
);
140182
return;
141183
}
142184

143185
try {
144-
Registry::get('OxidEsales\Eshop\Core\Cache\Generic\Cache')->flush();
186+
$this->getGenericCache()->flush();
145187
$output->writeln('<info>Generic\Cache is cleared</info>');
146188

147-
Registry::get('OxidEsales\Eshop\Core\Cache\DynamicContent\ContentCache')->reset(true);
189+
$this->getDynamicContentCache()->reset(true);
148190
$output->writeln('<info>DynamicContent\Cache is cleared</info>');
149191

150192
} 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>');
152194
}
153195
}
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+
}
154219
}

tests/Oxrun/Command/Cache/ClearCommandTest.php

+24-43
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
use Prophecy\PhpUnit\ProphecyTrait;
99
use Symfony\Component\Console\Tester\CommandTester;
1010

11+
/**
12+
* Class ClearCommandTest
13+
* @package Oxrun\Command\Cache
14+
*/
1115
class ClearCommandTest extends TestCase
1216
{
13-
use ProphecyTrait;
14-
1517
public function testExecute()
1618
{
1719
$app = new Application();
@@ -62,14 +64,12 @@ public function testDontClearCompileFolderIfIsNotSameOwner()
6264

6365
public function testItClearCacheOnEnterpriseEdtion()
6466
{
67+
[$facts, $genericCache, $dynamicContentCache] = $this->mockEEClasses();
68+
6569
$app = new Application();
66-
$app->add(new ClearCommand());
70+
$app->add(new ClearCommand($facts, $genericCache, $dynamicContentCache));
6771
$command = $app->find('cache:clear');
6872

69-
if ((new \OxidEsales\Facts\Facts)->isEnterprise() == false) {
70-
$this->mockEEGenericCacheAndDynamicContentClass();
71-
}
72-
7373

7474
$commandTester = new CommandTester($command);
7575
$commandTester->execute(
@@ -86,13 +86,15 @@ public function testItClearCacheOnEnterpriseEdtion()
8686

8787
public function testCatchExcetionByEE()
8888
{
89+
[$facts, $genericCache, $dynamicContentCache] = $this->mockEEClasses();
90+
8991
$app = new Application();
90-
$app->add(new ClearCommand());
92+
$app->add(new ClearCommand($facts, $genericCache, $dynamicContentCache));
9193
$command = $app->find('cache:clear');
9294

93-
list($facts, $genericCache) = $this->mockEEGenericCacheClass();
94-
$genericCache->flush()->willThrow(new \Exception('PHPUnit Tests'));
95-
95+
$genericCache
96+
->method('flush')
97+
->will($this->returnCallback(function () { throw new \Exception('PHPUnit Tests'); }));
9698

9799
$commandTester = new CommandTester($command);
98100
$commandTester->execute(
@@ -106,40 +108,19 @@ public function testCatchExcetionByEE()
106108
$this->assertStringContainsString('Only enterprise cache could', $display);
107109
}
108110

109-
protected function tearDown(): void
110-
{
111-
Registry::set(\OxidEsales\Facts\Facts::class, null);
112-
Registry::set('\OxidEsales\Eshop\Core\Cache\Generic\Cache', null);
113-
Registry::set('\OxidEsales\Eshop\Core\Cache\DynamicContent\ContentCache', null);
114-
}
115-
116-
117-
/**
118-
* @return array
119-
*/
120-
protected function mockEEGenericCacheClass()
121-
{
122-
$facts = $this->prophesize(\OxidEsales\Facts\Facts::class);
123-
$facts->isEnterprise()->willReturn(true);
124-
$genericCache = $this->prophesize(GenericCache::class);
125111

126-
Registry::set(\OxidEsales\Facts\Facts::class, $facts->reveal());
127-
Registry::set('OxidEsales\Eshop\Core\Cache\Generic\Cache', $genericCache->reveal());
128-
129-
return [$facts, $genericCache];
130-
}
131-
132-
/**
133-
* @return array
134-
*/
135-
protected function mockEEGenericCacheAndDynamicContentClass()
112+
protected function mockEEClasses(): array
136113
{
137-
list($facts, $genericCache) = $this->mockEEGenericCacheClass();
138-
139-
$dynamicContentCache = $this->prophesize(DynamicContentCache::class);
140-
Registry::set('OxidEsales\Eshop\Core\Cache\DynamicContent\ContentCache', $dynamicContentCache->reveal());
141-
142-
return [$facts, $genericCache, $dynamicContentCache];
114+
$facts = $this->createMock(\OxidEsales\Facts\Facts::class);
115+
$facts
116+
->method('isEnterprise')
117+
->willReturn($this->returnValue(true));
118+
119+
return [
120+
$facts,
121+
$this->createMock(GenericCache::class),
122+
$this->createMock(DynamicContentCache::class),
123+
];
143124
}
144125
}
145126

tests/Oxrun/Command/Misc/RegisterCommandTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
/**
1818
* Class RegisterCommandTest
1919
* @package Oxrun\Command\Misc
20-
* @group active
2120
*/
2221
class RegisterCommandTest extends TestCase
2322
{

0 commit comments

Comments
 (0)