Skip to content

Commit

Permalink
Fix cache constant update for only wp site type
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarnasit committed Dec 27, 2018
1 parent c788766 commit d44bda1
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ public function up() {
/**
* Sites wp-config changes for global-cache.
*/
$cache_sites = EE\Model\Site::where( 'cache_host', 'global-redis' );
$cache_sites = EE::db()
->table( 'sites' )
->where( [ [ 'site_type', '==', 'wp' ], [ 'cache_host', '==', 'global-redis' ] ] )
->all();

foreach ( $cache_sites as $site ) {

self::$rsp->add_step(
sprintf( 'update-cache-host-%s', $site->site_url ),
sprintf( 'update-cache-host-%s', $site['site_url'] ),
'EE\Migration\ChangeGlobalServiceContainerNames::update_cache_host',
null,
[ $site ],
Expand Down Expand Up @@ -277,26 +281,26 @@ public static function start_global_service_containers( $containers ) {
/**
* Update redis cache host name.
*
* @param $site_info EE\Model\Site site information.
* @param $site_info array of site information.
*
* @throws \Exception
*/
public static function update_cache_host( $site_info ) {
$update_hostname_constant = "docker-compose exec --user='www-data' php wp config set RT_WP_NGINX_HELPER_REDIS_HOSTNAME global-redis --add=true --type=constant";
$redis_plugin_constant = 'docker-compose exec --user=\'www-data\' php wp config set --type=variable redis_server "array(\'host\'=> \'global-redis\',\'port\'=> 6379,)" --raw';

if ( ! chdir( $site_info->site_fs_path ) ) {
throw new \Exception( sprintf( '%s path not exists', $site_info->site_fs_path ) );
if ( ! chdir( $site_info['site_fs_path'] ) ) {
throw new \Exception( sprintf( '%s path not exists', $site_info['site_fs_path'] ) );
}

if ( ! EE::exec( $update_hostname_constant ) ) {
throw new \Exception( sprintf( 'Unable to update cache host of %s', $site_info->site_url ) );
throw new \Exception( sprintf( 'Unable to update cache host of %s', $site_info['site_url'] ) );
}

if ( ! EE::exec( $redis_plugin_constant ) ) {
throw new \Exception( sprintf( 'Unable to update plugin constant %s', $site_info->site_url ) );
throw new \Exception( sprintf( 'Unable to update plugin constant %s', $site_info['site_url'] ) );
}
EE::log( sprintf( '%s Updated cache-host successfully', $site_info->site_url ) );
EE::log( sprintf( '%s Updated cache-host successfully', $site_info['site_url'] ) );
}

}

0 comments on commit d44bda1

Please # to comment.