Skip to content

Commit

Permalink
Merge pull request #9 from wallabag/fix-cacheclearcommand
Browse files Browse the repository at this point in the history
Fix CacheClearCommand
  • Loading branch information
yguedidi authored Dec 24, 2023
2 parents 52256d9 + 8ffa6d4 commit 08dcddd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
31 changes: 20 additions & 11 deletions Command/CacheClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,29 @@

namespace KPhoen\RulerZBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

/**
* Clear the cache.
*
* @author Kévin Gomez <[email protected]>
*/
class CacheClearCommand extends ContainerAwareCommand
class CacheClearCommand extends Command
{
private $cacheDir;
private Filesystem $filesystem;

public function __construct($cacheDir, Filesystem $filesystem)
{
$this->cacheDir = $cacheDir;
$this->filesystem = $filesystem;

parent::__construct();
}

/**
* {@inheritdoc}
*/
Expand All @@ -29,18 +41,15 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$cacheDir = $this->getContainer()->getParameter('rulerz.cache_directory');
$filesystem = $this->getContainer()->get('filesystem');

if (!is_writable($cacheDir)) {
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $cacheDir));
if (!is_writable($this->cacheDir)) {
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $this->cacheDir));
}

if ($filesystem->exists($cacheDir)) {
$filesystem->remove($cacheDir);
$filesystem->mkdir($cacheDir);
if ($this->filesystem->exists($this->cacheDir)) {
$this->filesystem->remove($this->cacheDir);
$this->filesystem->mkdir($this->cacheDir);
}
}
}
1 change: 1 addition & 0 deletions Resources/config/rulerz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ services:
rulerz.command.cache_clear:
class: KPhoen\RulerZBundle\Command\CacheClearCommand
public: true
arguments: ["%rulerz.cache_directory%", "@filesystem"]
tags:
- {name: console.command }

0 comments on commit 08dcddd

Please sign in to comment.