From 89945b8f1dd4c0dd1e3d0457629989bf84060442 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Wed, 14 Jul 2021 16:22:24 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=EF=B8=8F=20Add=20cache=20update=20fea?= =?UTF-8?q?ture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PHP.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/PHP.php b/src/PHP.php index 590a1a1..d1569fb 100644 --- a/src/PHP.php +++ b/src/PHP.php @@ -305,6 +305,55 @@ public function create( $args, $assoc_args ) { \EE\Utils\delem_log( 'site create end' ); } + /** + * Update cache of a site + * + * @param array|bool $assoc_args Associate arguments passed to update command + */ + protected function update_cache( $assoc_args ) + { + parent::update_cache( $assoc_args ); + + $cache = get_flag_value( $assoc_args, 'cache', false ); + $local_cache = get_flag_value( $assoc_args, 'with-local-redis' ); + + if ( $cache === 'on' ) { + $cache = true; + } elseif( $cache === 'off') { + $cache = false; + } + + $this->site_data->cache_host = $cache ? $local_cache ? 'redis' : 'global-redis' : ''; + $this->site_data->cache_nginx_browser = $cache; + $this->site_data->cache_nginx_fullpage = $cache; + $this->site_data->cache_mysql_query = $cache; + $this->cache_type = $cache; + + $site_conf_dir = $this->site_data->site_fs_path . '/config'; + $site_nginx_default_conf = $site_conf_dir . '/nginx/conf.d/main.conf'; + $server_name = implode( ' ', explode( ',', $this->site_data->alias_domains ) ); + $default_conf_content = $this->generate_default_conf( $this->cache_type, $server_name ); + $this->fs->dumpFile( $site_nginx_default_conf, $default_conf_content ); + + $this->dump_docker_compose_yml( [ 'nohttps' => ! $this->site_data->site_ssl ] ); + + $containers = ['nginx', 'php']; + + if ( $local_cache ) { + $containers[] = 'redis'; + } + + \EE\Site\Utils\stop_site_containers( $this->site_data->site_fs_path, [] ); + \EE\Site\Utils\start_site_containers( $this->site_data->site_fs_path, $containers ); + + $this->site_data->save(); + + $action = $cache ? 'Enabled' : 'Disabled'; + $local_cache_message = $local_cache ? ' with local cache' : ''; + + EE::success( $action . ' cache for ' . $this->site_data->site_url . $local_cache_message ); + } + /** * Creates database user for a site *