Skip to content

Commit

Permalink
[console] Remove site cache file. (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas authored Jul 7, 2017
1 parent b3a6161 commit ae2a766
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions src/Extender.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,29 @@ public function processPackages(Event $event)

if (file_exists($configFile)) {
unlink($configFile);
$this->io->write('<info>Removing config cache file:</info>' . $configFile);
$this->io->write('<info>Removing config cache file:</info>');
$this->io->write($configFile);
}

if (file_exists($servicesFile)) {
unlink($servicesFile);
$this->io->write('<info>Removing services cache file:</info>' . $servicesFile);
$this->io->write('<info>Removing packages services cache file:</info>');
$this->io->write($servicesFile);
}

if (file_exists($servicesUninstallFile)) {
unlink($servicesUninstallFile);
$this->io->write('<info>Removing services cache file:</info>' . $servicesUninstallFile);
$this->io->write('<info>Removing packages services cache file:</info>');
$this->io->write($servicesUninstallFile);
}

if ($configData = $extenderManager->getConfigData()) {
file_put_contents(
$configFile,
Yaml::dump($configData, 6, 2)
);
$this->io->write('<info>Creating config cache file:</info>' . $configFile);
$this->io->write('<info>Creating packages config cache file:</info>');
$this->io->write($configFile);
}

$servicesData = $extenderManager->getServicesData();
Expand All @@ -116,7 +120,8 @@ public function processPackages(Event $event)
$servicesFile,
Yaml::dump($servicesData['install'], 4, 2)
);
$this->io->write('<info>Creating services cache file: </info>' . $servicesFile);
$this->io->write('<info>Creating packages services cache file: </info>');
$this->io->write($servicesFile);
}

$servicesData = $extenderManager->getServicesData();
Expand All @@ -125,36 +130,29 @@ public function processPackages(Event $event)
$servicesUninstallFile,
Yaml::dump($servicesData['uninstall'], 4, 2)
);
$this->io->write('<info>Creating services cache file: </info>' . $servicesUninstallFile);
$this->io->write('<info>Creating packages services cache file: </info>');
$this->io->write($servicesUninstallFile);
}

$this->removeCacheFiles();
$this->removeCacheFiles($directory);
}

protected function removeCacheFiles()
protected function removeCacheFiles($directory)
{
if (is_dir(getcwd().'/console/cache/')) {
try {
$finder = new Finder();
$finder->files()
->in(getcwd() . '/console/cache/')
->ignoreUnreadableDirs();

foreach ($finder as $file) {
unlink($file->getPathName());
}

$finder->directories()
->in(getcwd() . '/console/cache/')
->ignoreUnreadableDirs();

foreach ($finder as $directory) {
rmdir($directory);
}

} catch (\InvalidArgumentException $argumentException) {
$this->io->write('<info>Cache files can not be deleted</info>');
try {
$finder = new Finder();
$finder->files()
->in($directory)
->name('*-console.services.yml')
->ignoreUnreadableDirs();

foreach ($finder as $file) {
$this->io->write('<info>Removing site services cache file:</info>');
$this->io->write($file->getPathName());
unlink($file->getPathName());
}
} catch (\InvalidArgumentException $argumentException) {
$this->io->write('<info>Cache file can not be deleted</info>');
}
}
}

0 comments on commit ae2a766

Please sign in to comment.