Skip to content

Commit

Permalink
Merge branch 'develop' for v3.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrobot47 committed Nov 10, 2023
2 parents 13be7f0 + 724d594 commit f37e51e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
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() {
}

}
14 changes: 14 additions & 0 deletions src/helper/class-ee-site.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use AcmePhp\Ssl\Certificate;
use AcmePhp\Ssl\Parser\CertificateParser;
use EE;
use EE\Model\Cron;
use EE\Model\Site;
use EE\Model\Option;
use Symfony\Component\Filesystem\Filesystem;
Expand Down Expand Up @@ -323,6 +324,19 @@ protected function delete_site( $level, $site_url, $site_fs_path, $db_data = []
EE::exec( 'docker exec ' . EE_PROXY_TYPE . " bash -c 'rm -rf /var/cache/nginx/$site_url'" );
}

try {
$crons = Cron::where( [ 'site_url' => $site_url ] );
if ( ! empty( $crons ) ) {
\EE::log( 'Deleting cron entry' );
foreach ( $crons as $cron ) {
$cron->delete();
}
\EE\Cron\Utils\update_cron_config();
}
} catch ( \Exception $e ) {
\EE::debug( $e->getMessage() );
}

/**
* Execute before site db data cleanup and after site services cleanup.
* Note: This can be use to cleanup site data added by any package command.
Expand Down
2 changes: 1 addition & 1 deletion templates/config/nginx/main.conf.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ server {
}

# Cache static files
location ~* \.(ogg|ogv|svg|svgz|eot|otf|woff|woff2|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|swf)$ {
location ~* \.(ogg|ogv|svg|svgz|eot|otf|woff|woff2|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|swf|webp)$ {
add_header "Access-Control-Allow-Origin" "*";
access_log off;
log_not_found off;
Expand Down

0 comments on commit f37e51e

Please sign in to comment.