-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
migrations/container/20230207100940_site-command_nginx_add_webp_to_cache.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace EE\Migration; | ||
|
||
use EE; | ||
use EE\Migration\Base; | ||
use EE\Migration\SiteContainers; | ||
use EE\RevertableStepProcessor; | ||
use EE\Model\Site; | ||
|
||
class NginxAddWebpToCache extends Base { | ||
|
||
private $sites; | ||
/** @var RevertableStepProcessor $rsp Keeps track of migration state. Reverts on error */ | ||
private static $rsp; | ||
|
||
public function __construct() { | ||
|
||
parent::__construct(); | ||
$this->sites = Site::all(); | ||
if ( $this->is_first_execution || ! $this->sites ) { | ||
$this->skip_this_migration = true; | ||
} | ||
} | ||
|
||
/** | ||
* Execute nginx config updates. | ||
* | ||
* @throws EE\ExitException | ||
*/ | ||
public function up() { | ||
|
||
if ( $this->skip_this_migration ) { | ||
EE::debug( 'Skipping nginx-config update migration as it is not needed.' ); | ||
|
||
return; | ||
} | ||
|
||
foreach ( $this->sites as $site ) { | ||
$main_conf_file = $site->site_fs_path . '/config/nginx/conf.d/main.conf'; | ||
|
||
if ( file_exists( $main_conf_file ) ) { | ||
|
||
$search = '|swf'; | ||
$replace = '|swf|webp'; | ||
|
||
$file_contents = file_get_contents( $main_conf_file ); | ||
|
||
if ( strpos( $file_contents, $search ) !== false && strpos( $file_contents, 'webp' ) === false ) { | ||
$file_contents = str_replace( $search, $replace, $file_contents ); | ||
} | ||
|
||
file_put_contents( $main_conf_file, $file_contents ); | ||
} | ||
|
||
} | ||
} | ||
|
||
/** | ||
* Bring back the existing old nginx config. | ||
* | ||
* @throws EE\ExitException | ||
*/ | ||
public function down() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters