From 71ef4bf1dd1812212bad1f42c6a10745c9a27c5c Mon Sep 17 00:00:00 2001 From: Aina Sitraka <35221835+aynsix@users.noreply.github.com> Date: Mon, 22 Jan 2024 12:34:13 +0300 Subject: [PATCH] PHRAS-4011 : Moving cmd from console to setup - system:clear-cache system:clear-session (#4460) * cmd clear cache in bin/setup * Change maintenance state wording --- bin/setup | 5 ++ docker/phraseanet/setup/entrypoint.sh | 14 ++--- .../Command/Setup/SystemClearCacheCommand.php | 51 +++++++++++++++++++ .../Setup/SystemClearSessionCacheCommand.php | 37 ++++++++++++++ .../module/console/systemClearCache.php | 2 +- .../console/systemClearSessionCache.php | 2 +- 6 files changed, 102 insertions(+), 9 deletions(-) create mode 100644 lib/Alchemy/Phrasea/Command/Setup/SystemClearCacheCommand.php create mode 100644 lib/Alchemy/Phrasea/Command/Setup/SystemClearSessionCacheCommand.php diff --git a/bin/setup b/bin/setup index fa8296b1d4..e59327b938 100755 --- a/bin/setup +++ b/bin/setup @@ -14,6 +14,8 @@ namespace KonsoleKommander; use Alchemy\Phrasea\Command\Setup\ConfigurationEditor; use Alchemy\Phrasea\Command\Setup\FixAutoincrements; use Alchemy\Phrasea\Command\Setup\FixLogCollId; +use Alchemy\Phrasea\Command\Setup\SystemClearCacheCommand; +use Alchemy\Phrasea\Command\Setup\SystemClearSessionCacheCommand; use Alchemy\Phrasea\Core\Version; use Alchemy\Phrasea\Command\UpgradeDBDatas; use Alchemy\Phrasea\Command\Setup\Install; @@ -83,6 +85,9 @@ $app->command(new CrossDomainGenerator()); $app->command(new FixAutoincrements('system:fix-autoincrements')); $app->command(new FixLogCollId()); +$app->command(new SystemClearCacheCommand()); +$app->command(new SystemClearSessionCacheCommand()); + $app['phraseanet.setup_mode'] = true; $app->run(); diff --git a/docker/phraseanet/setup/entrypoint.sh b/docker/phraseanet/setup/entrypoint.sh index b49bd8609f..628f20ffaa 100755 --- a/docker/phraseanet/setup/entrypoint.sh +++ b/docker/phraseanet/setup/entrypoint.sh @@ -16,11 +16,11 @@ fi maintenance_manager() { if [[ $1 = "off" || $1 = "0" ]];then - echo `date +"%Y-%m-%d %H:%M:%S"` " - Phraseanet No Maintenance Mode Activated" + echo `date +"%Y-%m-%d %H:%M:%S"` " - Phraseanet Maintenance disabled" rm -rf /var/alchemy/Phraseanet/datas/nginx/maintenance.html elif [[ $1 = "on" || $1 = "1" ]];then - echo `date +"%Y-%m-%d %H:%M:%S"` " - Phraseanet Activating Maintenance Mode" + echo `date +"%Y-%m-%d %H:%M:%S"` " - Phraseanet Maintenance enabled" mkdir -p /var/alchemy/Phraseanet/datas/nginx if [[ ! -n "$PHRASEANET_MAINTENANCE_MESSAGE" ]];then echo "No custom maintenance message" @@ -28,7 +28,7 @@ maintenance_manager() fi envsubst < "/usr/local/etc/maintenance.html" > /var/alchemy/Phraseanet/datas/nginx/maintenance.html if [[ $2 != "noexit" ]];then - echo `date +"%Y-%m-%d %H:%M:%S"` " - Phraseanet Maintenance in persitent Mode" + echo `date +"%Y-%m-%d %H:%M:%S"` " - Phraseanet Maintenance in persistent Mode" exit 0 else echo `date +"%Y-%m-%d %H:%M:%S"` " - Phraseanet Maintenance in temporary Mode" @@ -79,15 +79,15 @@ fi if [[ -f "$FILE" && $PHRASEANET_UPGRADE = 1 ]];then maintenance_manager 1 noexit - echo `date +"%Y-%m-%d %H:%M:%S"` " - preparing config backup, check connection to db " - bin/console system:clear-cache - bin/console system:clear-session + echo `date +"%Y-%m-%d %H:%M:%S"` " - preparing Phraseanet configuration backup" + bin/setup system:clear-cache + bin/setup system:clear-session timestamp=$(date +'%Y-%m-%d_%H-%M-%S') timestamp_dir="backup/pre-upgrade/$timestamp" mkdir -p "$timestamp_dir" archive_name="$PHRASEANET_HOSTNAME-config.tgz" tar -zcf "$timestamp_dir/$archive_name" -C "config" . - echo `date +"%Y-%m-%d %H:%M:%S"` " - Pre-upgrade backup done for config $timestamp_dir/$archive_name" + echo `date +"%Y-%m-%d %H:%M:%S"` " - Pre-upgrade backup done for configuration $timestamp_dir/$archive_name" echo `date +"%Y-%m-%d %H:%M:%S"` " - Start Phraseanet upgrade datas" bin/setup system:upgrade -y echo `date +"%Y-%m-%d %H:%M:%S"` " - End Phraseanet upgrade datas" diff --git a/lib/Alchemy/Phrasea/Command/Setup/SystemClearCacheCommand.php b/lib/Alchemy/Phrasea/Command/Setup/SystemClearCacheCommand.php new file mode 100644 index 0000000000..b1b4d0b895 --- /dev/null +++ b/lib/Alchemy/Phrasea/Command/Setup/SystemClearCacheCommand.php @@ -0,0 +1,51 @@ +setDescription('Empties cache directories and cache-server data'); + + return $this; + } + + protected function doExecute(InputInterface $input, OutputInterface $output) + { + $finder = new Finder(); + + $in = $this->container['cache.paths']->getArrayCopy(); + $finder + ->exclude('.git') + ->exclude('.svn') + ->in($in); + + $this->container['filesystem']->remove($finder); + + if ($this->container['phraseanet.configuration-tester']->isInstalled()) { + $this->getService('phraseanet.cache-service')->flushAll(); + } + + $output->write('Finished !', true); + + return 0; + } +} diff --git a/lib/Alchemy/Phrasea/Command/Setup/SystemClearSessionCacheCommand.php b/lib/Alchemy/Phrasea/Command/Setup/SystemClearSessionCacheCommand.php new file mode 100644 index 0000000000..77af100fe9 --- /dev/null +++ b/lib/Alchemy/Phrasea/Command/Setup/SystemClearSessionCacheCommand.php @@ -0,0 +1,37 @@ +setDescription('Empties session cache in redis, ends sessions for all users'); + + return $this; + } + + protected function doExecute(InputInterface $input, OutputInterface $output) + { + /** @var Factory $cacheFactory */ + $cacheFactory = $this->container['phraseanet.cache-factory']; + $cache = $cacheFactory->create('redis', ['host' => 'redis-session', 'port' => '6379']); + + $flushOK = $cache->removeByPattern('PHPREDIS_SESSION*'); + + if ($flushOK) { + $output->writeln('session cache in redis successfully flushed!'); + } else { + $output->writeln('flush failed!'); + } + + return 0; + } +} diff --git a/lib/classes/module/console/systemClearCache.php b/lib/classes/module/console/systemClearCache.php index d52d522fb2..1c8c53a7d9 100644 --- a/lib/classes/module/console/systemClearCache.php +++ b/lib/classes/module/console/systemClearCache.php @@ -21,7 +21,7 @@ class module_console_systemClearCache extends Command { parent::__construct($name); - $this->setDescription('Empties cache directories and cache-server data'); + $this->setDescription('Empties cache directories and cache-server data (Deprecated use bin/setup system:clear-cache instead)'); return $this; } diff --git a/lib/classes/module/console/systemClearSessionCache.php b/lib/classes/module/console/systemClearSessionCache.php index 963be58892..e21bbcb3ce 100644 --- a/lib/classes/module/console/systemClearSessionCache.php +++ b/lib/classes/module/console/systemClearSessionCache.php @@ -11,7 +11,7 @@ class module_console_systemClearSessionCache extends Command { parent::__construct($name); - $this->setDescription('Empties session cache in redis'); + $this->setDescription('Empties session cache in redis (Deprecated use bin/setup system:clear-session-cache instead)'); return $this; }