From 3b2bfb383d057b212d637f031b10c018d6e79a91 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Wed, 14 Jul 2021 16:22:26 +0530 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=EF=B8=8F=20Add=20cache=20update?= =?UTF-8?q?=20feature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helper/class-ee-site.php | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/helper/class-ee-site.php b/src/helper/class-ee-site.php index a882171a..0d6bfd9a 100644 --- a/src/helper/class-ee-site.php +++ b/src/helper/class-ee-site.php @@ -363,6 +363,17 @@ protected function delete_site( $level, $site_url, $site_fs_path, $db_data = [] * [--wildcard] * : Enable wildcard SSL on site. * + * [--cache[=]] + * : Enable / Disable cache on site. + * --- + * options: + * - "on" + * - "off" + * --- + * + * [--with-local-redis] + * : Enable cache with local redis container. + * * [--php=] * : PHP version for site. Currently only supports PHP 5.6, 7.0, 7.2, 7.3, 7.4, 8.0 and latest. * --- @@ -431,6 +442,7 @@ public function update( $args, $assoc_args ) { $args = auto_site_name( $args, 'site', __FUNCTION__ ); $this->site_data = get_site_info( $args, true, true, false ); $ssl = get_flag_value( $assoc_args, 'ssl', false ); + $cache = get_flag_value( $assoc_args, 'cache', false ); $php = get_flag_value( $assoc_args, 'php', false ); $proxy_cache = get_flag_value( $assoc_args, 'proxy-cache', false ); $add_domains = get_flag_value( $assoc_args, 'add-alias-domains', false ); @@ -440,6 +452,10 @@ public function update( $args, $assoc_args ) { $this->update_ssl( $assoc_args ); } + if ( $cache ) { + $this->update_cache( $assoc_args ); + } + if ( $php ) { $this->update_php( $args, $assoc_args ); } @@ -453,6 +469,36 @@ public function update( $args, $assoc_args ) { } } + /** + * Update cache of a site + * + * @param array|bool $assoc_args Associate arguments passed to update command + */ + protected function update_cache( $assoc_args ) { + + $cache = get_flag_value( $assoc_args, 'cache', false ); + $local_cache = get_flag_value( $assoc_args, 'with-local-redis', false ); + $already_local_cache = $this->site_data->cache_host === 'redis'; + + if ( $cache === 'on' ) { + $cache = true; + } elseif( $cache === 'off') { + $cache = false; + } + + if ( $cache && $this->site_data->cache_host && $local_cache === $already_local_cache ) { + $local_cache_message = $local_cache ? ' with local cache' : ''; + EE::error( 'Cache is already enabled on ' . $this->site_data['site_url'] . $local_cache_message ); + } elseif ( ! $cache && ! $this->site_data->cache_host ) { + EE::error( 'Cache is already disabled on ' . $this->site_data['site_url'] ); + } + + $action = $cache ? 'Enabling' : 'Disabling' ; + $local_cache_message = $local_cache ? ' with local cache' : ''; + + EE::log( $action . ' cache on ' . $this->site_data->site_url . $local_cache_message ); + + } /** * Function to update alias domains of a site. From 12f4e6b8d234b432fd36b51f291f86e7fa163595 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Thu, 15 Jul 2021 18:03:21 +0530 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Make=20changesin=20get=5Fsit?= =?UTF-8?q?e=5Finfo=20for=20ArrayObject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helper/site-utils.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/helper/site-utils.php b/src/helper/site-utils.php index f98cd8d3..279406f2 100644 --- a/src/helper/site-utils.php +++ b/src/helper/site-utils.php @@ -95,8 +95,7 @@ function get_site_info( $args, $site_enabled_check = true, $exit_if_not_found = $site_url = \EE\Utils\remove_trailing_slash( $args[0] ); $data = Site::find( $site_url ); - $array_data = ( array ) $data; - $site_data = $return_array ? reset( $array_data ) : $data; + $array_data = $data; if ( ! $data ) { if ( $exit_if_not_found ) { @@ -106,6 +105,8 @@ function get_site_info( $args, $site_enabled_check = true, $exit_if_not_found = return false; } + $site_data = $return_array ? reset( $array_data ) : $data; + if ( ! $data->site_enabled && $site_enabled_check ) { \EE::error( sprintf( 'Site %1$s is not enabled. Use `ee site enable %1$s` to enable it.', $data->site_url ) ); }