Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨️ Add cache update feature #387

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/helper/class-ee-site.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,17 @@ protected function delete_site( $level, $site_url, $site_fs_path, $db_data = []
* [--wildcard]
* : Enable wildcard SSL on site.
*
* [--cache[=<cache>]]
* : Enable / Disable cache on site.
* ---
* options:
* - "on"
* - "off"
* ---
*
* [--with-local-redis]
* : Enable cache with local redis container.
*
* [--php=<php-version>]
* : PHP version for site. Currently only supports PHP 5.6, 7.0, 7.2, 7.3, 7.4, 8.0 and latest.
* ---
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
}
Expand All @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions src/helper/site-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 ) );
}
Expand Down