Skip to content
Open
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
49 changes: 49 additions & 0 deletions src/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down