Giter VIP home page Giter VIP logo

c3-cloudfront-clear-cache's Introduction

C3 Cloudfront Cache Controller

This is simple plugin that clear all cloudfront cache if you publish posts.

How to install

$ cd /path/to/wordpress/wp-content/plugins
$ git clone [email protected]:amimoto-ami/c3-cloudfront-clear-cache.git
$ cd c3-cloudfront-clear-cache

Adding your configuration through env vars

The plugin can be configured by defining the following environment variables:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • C3_DISTRIBUTION_ID

Filters

Change Invalidation interval

Default interval is 1 minutes.

add_filter('c3_invalidation_interval', function( $interval_minutes ) {
    $custom_interval = 1;
    return $custom_interval;
} );

Change Invalidation retry interval

Default interval is 1 minutes.

add_filter('c3_invalidation_cron_interval', function( $interval_minutes ) {
    $custom_interval = 1;
    return $custom_interval;
} );

Change Invalidation items limit

Default limit is 100.

add_filter( 'c3_invalidation_item_limits', function( $limits ) {
    $custom_limit = 300;
    return $custom_limit;
} );

Customize/Overwrite the invalidation path

Using the c3_invalidation_items filter, we can update the invalidation path.

add_filter( 'c3_invalidation_items', function($items){  
        return array('/*'); 
});
add_filter( 'c3_invalidation_items', function( $items, $post ) {
    if ( 'should-overwritten' === $post->post_name) {
        return ['/slug-overwritten'];
    }
    return $items;
}, 10, 2 );

Change or Stop loading bundled AWS SDK (Since v6.0.0)

Use c3_aws_sdk_path filter, to relace the AWS SDK library path.

add_filter( 'c3_aws_sdk_path', function () {
	return 'YOUR/CUSTOM/AWS/SDK/ENTRY/POINT.php';
} );

If return null, the plugin will not load bundled AWS SDK.

add_filter( 'c3_aws_sdk_path', function () {
	return null;
} );

Logging cron job history(Since v6.0.0)

add_filter( 'c3_log_cron_invalidation_task', '__return_true' );

Local testing

wp-env

Unit test

$ yarn dev
$ yarn test

GitHub Action(WIP)

Using act to execute the workflow in your local.

$ act -P ubuntu-latest=shivammathur/node:latest

c3-cloudfront-clear-cache's People

Contributors

atoutant avatar dependabot[bot] avatar hideokamoto avatar hinaloe avatar jepser avatar johnbillion avatar miya0001 avatar mt8 avatar renovate-bot avatar wokamoto avatar yahiru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

c3-cloudfront-clear-cache's Issues

Using EC2 Roles Fails

I noticed in your release notes it says roles were added in 2.2.0. That said, If I try to just add the distro ID and then click the button to perform an invalidation, it just errors saying secret key not set. Can you provide more insight on how to use this with roles? We have added the roles for the machines to support invalidations but it's not working.

Doesn't work on AWS SDK v3

If update SDK, can not submit "flush all cache" button.

Display Error Message

! ) Fatal error: Class 'Aws\Common\Credentials\Credentials' not found in /var/www/wordpress/wp-content/plugins/c3-cloudfront-clear-cache/c3-cloudfront-clear-cache.php on line 101
Call Stack

Time Memory Function Location

1 0.0008 129840 {main}( ) .../admin.php:0
2 0.2736 4466128 do_action( ) .../admin.php:168
3 0.2786 4511816 call_user_func_array:{/var/www/wordpress/wp-includes/plugin.php:525} ( ) .../plugin.php:525
4 0.2786 4511892 CloudFront_Clear_Cache_Admin->c3_admin_init( ) .../plugin.php:525
5 0.2786 4512896 CloudFront_Clear_Cache->c3_invalidation( ) .../c3-admin.php:131
6 0.2856 4519628 apply_filters( ) .../c3-cloudfront-clear-cache.php:118
7 0.2856 4520348 call_user_func_array:{/var/www/wordpress/wp-includes/plugin.php:235} ( ) .../plugin.php:235
8 0.2856 4520388 CloudFront_Clear_Cache->create_credentials( ) .../plugin.php:235

SameSite Cookie Policy change will be required

Just wanted to notify that there are recently SameSite Cookie Policy changes, that apply to this plugin

Cookies with SameSite=None must now also specify the Secure attribute (they require a secure context/HTTPS).
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite

Feel free to look at the patch for my fork.

You might have to adapt the patch to use the older setcookie() argument definition as this patch is based on a fork that drops support for PHP7.2 and older.

Issues encountered with C3 Cloudfront Cache Controller

Can you please help me with the following queries that I encountered while trying to work with C3 Cloudfront Cache Controller

  1. Is WordPress 5.4 compatible to C3 Cloudfront Cache Controller plugin?

  2. If we are updating multiple post from wordpress admin panel, how many invalidation request will be created in CloudFront?

  3. Can we customise c3 Cloudfront Cache controller plugin ? Can make the post update reload happen only once the invalidation request gets its response.

option 設定されていない時に Fatal Error が発生します

$query = $this->invalidation_batch->create_batch_by_post( $home_url, $options['distribution_id'], $post );

$query = $this->invalidation_batch->create_batch_by_posts( $home_url, $options['distribution_id'], $posts );

$query = $this->invalidation_batch->create_batch_by_posts( $home_url, $options['distribution_id'], $posts );

$options['distribution_id'] が null の場合の考慮が抜けてます。
$options['distribution_id'] が null だったら、後続処理しないとかの対応してください。

PHP Fatal error: Cannot redeclare Aws\constantly()

他のプラグインで aws SDK をインクルードしていると以下のエラーが出ます。

PHP Fatal error:  Cannot redeclare Aws\constantly() (previously declared in /var/www/html/wp-content/plugins/amazon-polly/vendor/aws/Aws/functions.php:19) in phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.v3.phar/Aws/functions.php on line 22

Error when clearing a post type without archive

Hello,

When clearing a post_Type without archive, here is the error

This appears on a page clear, since get_post_type_archive_link returns false, the parse_url is not possible.

Nicolas,

I get a fatal error when running "Flush All CDN Cache".

I get a fatal error when running "Flush All CDN Cache".

Fatal error: Uncaught Error: Class 'C3_Invalidation' not found in /var/www/vhosts/www.hwtest.dev/wp-content/plugins/c3-cloudfront-clear-cache/c3-cloudfront-clear-cache.php:222

  | Stack trace:
  | #0 /var/www/vhosts/www.hwtest.dev/wp-content/plugins/amimoto-dashboard/module/model/c3.php(153): CloudFront_Clear_Cache->c3_invalidation()
  | #1 /var/www/vhosts/www.hwtest.dev/wp-content/plugins/amimoto-dashboard/amimoto-plugin-dashboard.php(141): Amimoto_C3->invalidation('all')
  | #2 /var/www/vhosts/www.hwtest.dev/wp-includes/class-wp-hook.php(287): Amimoto_Dash->update_settings('')
  | #3 /var/www/vhosts/www.hwtest.dev/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)
  | #4 /var/www/vhosts/www.hwtest.dev/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
  | #5 /var/www/vhosts/www.hwtest.dev/wp-admin/admin.php(175): do_action('admin_init')
  | #6 {main}
  | thrown in /var/www/vhosts/www.hwtest.dev/wp-content/plugins/c3-cloudfront-clear-cache/c3-cloudfront-clear-cache.php on line 222

PHP 8.2 Deprecations

I was getting the following in my debug logs, and so tried to clean it up a bit:

PHP Deprecated:  Creation of dynamic property C3_CloudFront_Cache_Controller\Invalidation_Service::$cf_service is deprecated in .../c3-cloudfront-clear-cache/classes/Invalidation_Service.php on line 68
PHP Deprecated:  Creation of dynamic property C3_CloudFront_Cache_Controller\Invalidation_Service::$notice is deprecated in .../c3-cloudfront-clear-cache/classes/Invalidation_Service.php on line 69
PHP Deprecated:  Creation of dynamic property C3_CloudFront_Cache_Controller\Cron_Service::$cf_service is deprecated in .../c3-cloudfront-clear-cache/classes/Cron_Service.php on line 51

Undefined array key "scheme" and "host"

Fresh install... Flush All Cache worked fine but on page/post update couldn't see invalidation request submitting successfully to CloudFront. Error in log:

2023/04/13 17:47:52 [error] 378720#378720: *1341 FastCGI sent in stderr: "PHP message: PHP Warning:  Undefined array key "scheme" in /var/www/example.com/html/wp-content/plugins/c3-cloudfront-clear-cache/classes/WP/Post.php on line 57
PHP message: PHP Warning:  Undefined array key "host" in /var/www/example.com/html/wp-content/plugins/c3-cloudfront-clear-cache/classes/WP/Post.php on line 57

PHP message: exception 'Aws\CloudFront\Exception\CloudFrontException' with message 'Error executing "CreateInvalidation" on "https://cloudfront.amazonaws.com/2020-05-31/distribution/<DIST_ID>/invalidation"; AWS HTTP error: Client error: `POST https://cloudfront.amazonaws.com/2020-05-31/distribution/<DIST_ID>/invalidation` resulted in a `400 Bad Request` response:
<?xml version="1.0"?>
<ErrorResponse xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/"><Error><Type>Sender</Type>< (truncated...)
 InvalidArgument (client): Your request contains one or more invalid invalidation paths. - <?xml version="1.0"?>
<ErrorResponse xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/"><Error><Type>Sender</Type><Code>InvalidArgument</Code><Message>Your request contains one or more invalid invalidation paths.</Message></Error><RequestId><REQ_ID></RequestId></ErrorResponse>'
GuzzleHttp\Exception\ClientException: Client error: `POST https://cloudfront.amazonaws.com/2020-05" while reading response header from upstream, client: <Client_IP>, server: example.com, request: "POST /wp-json/wp/v2/pages/378?_locale=user HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.1-fpm.sock"

In /wp-content/plugins/c3-cloudfront-clear-cache/classes/WP/Post.php I modified this function from:

/**
	 * Parse the url
	 *
	 * @param string $url Target URL.
	 */
	public function parse_url( string $url ) {
		$parsed_url = parse_url( $url );
		$url        = $parsed_url['scheme'] . '://' . $parsed_url['host'];
		if ( isset( $parsed_url['path'] ) ) {
			$url .= $parsed_url['path'];
		}
		return $url;
	}

Updated to:

/**
 * Parse the url
 *
 * @param string $url Target URL.
 */
public function parse_url( string $url ) {
    if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
        return false;
    }

    $parsed_url = parse_url( $url );
    $url        = $parsed_url['scheme'] . '://' . $parsed_url['host'];
    if ( isset( $parsed_url['path'] ) ) {
        $url .= $parsed_url['path'];
    }
    return $url;
}

Which has allowed me to temporarily workaround this issue.

Purge doesn't work

Plugin used to work perfectly. Has stopped working sometime in the last month. Error below.

C3 Invalidation Error : Error executing "CreateInvalidation" on "https://cloudfront.amazonaws.com/2017-10-30/distribution/EQSV3SDRMJ1TT/invalidation"; AWS HTTP error: Client error: POST https://cloudfront.amazonaws.com/2017-10-30/distribution/EQSV3SDRMJ1TT/invalidation resulted in a 403 Forbidden response: Sender< (truncated...) SignatureDoesNotMatch (client): Signature expired: 20190929T171351Z is now earlier than 20190929T171436Z (20190929T171936Z - 5 min.) - SenderSignatureDoesNotMatchSignature expired: 20190929T171351Z is now earlier than 20190929T171436Z (20190929T171936Z - 5 min.)4fea0fbe-e2dd-11e9-b6f8-1d511a8a52fe

AutoScale Stack(Only AutoScaling) issue

[14-Dec-2016 09:02:18 UTC] PHP Fatal error:  Uncaught exception 'Guzzle\Http\Exception\CurlException' with message '[curl] 6: Could not resolve host: wp-content [url] https://wp-content/uploads/2016/12/shifter_-20161214090211.png' in phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/aws.phar/Guzzle/Http/Curl/CurlMulti.php:359
Stack trace:
#0 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/aws.phar/Guzzle/Http/Curl/CurlMulti.php(292): Guzzle\Http\Curl\CurlMulti->isCurlException(Object(Guzzle\Http\Message\Request), Object(Guzzle\Http\Curl\CurlHandle), Array)
#1 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/aws.phar/Guzzle/Http/Curl/CurlMulti.php(257): Guzzle\Http\Curl\CurlMulti->processResponse(Object(Guzzle\Http\Message\Request), Object(Guzzle\Http\Curl\CurlHandle), Array)
#2 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/aws.phar/Guzzle/Http/Curl/CurlMulti.php(240): Guzzle\Http\Curl\CurlMulti->processMessages()
#3 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/aw in phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/aws.phar/Aws/Common/Client/AbstractClient.php on line 258

Unable to use c3_aws_sdk_path filter

In #46 it was stated that we can use the c3_aws_sdk_path filter to prevent this plugin from loading the AWS SDK. I'm attempting to do that to resolve conflicts with this plugin redeclaring guzzle classes, since another plugin I use also includes guzzle and the two conflict.

This could be my lack of understanding, but I'm unable to make use of the c3_aws_sdk_path filter because the code in c3-cloudfront-clear-cache.php that calls apply_filters is executed before I can call add_filter in either my functions.php or in my custom plugin.

Please advise if the solution shown in #46 works as stated?

C3_Client_V3::create_credentials() が EC2 Role を使わない

C3_Client_V3::create_credentials() で、c3_settings を読み込んで credentials を組み立ててるけど c3_settings に access_key, secret_key が入っていることを前提にしているため、EC2 Role を使用したい時に distribution_id のみ入ってる場合に正常に credential が生成されません。

$credentials = array(
	'credentials' => array(
		'key'    => esc_attr( $c3_settings['access_key'] ),
		'secret' => esc_attr( $c3_settings['secret_key'] ),
	),
);

こんな感じで isset() されてて empty() じゃなければ $credentials array を作るようにしたほうがいいんじゃないかな?

$credentials = array();
if ( isset($c3_settings['access_key']) && isset($c3_settings['secret_key']) && ! empty($c3_settings['access_key']) && ! empty($c3_settings['secret_key']) ) {
	$credentials = array(
		'credentials' => array(
			'key'    => esc_attr( $c3_settings['access_key'] ),
			'secret' => esc_attr( $c3_settings['secret_key'] ),
		),
	);
}

個別URLのキャッシュ削除機能

Feature Requestさせてください

キャッシュを削除したいURLを指定してc3-cloudfront-clear-cache経由でCloudFrontのキャッシュを削除できる機能がありますと、AWS マネジメントコンソールにログインさせずにWordpressのアカウントを持つ人間がキャッシュ削除を行うことができるため大変助かります。

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Detected empty commit - aborting git push

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • Update dependency aws/aws-sdk-php to v3.288.1 [SECURITY]
  • Update dependency phpcompatibility/phpcompatibility-wp to v2.1.5
  • Update dependency squizlabs/php_codesniffer to v3.10.1
  • Update dependency yoast/phpunit-polyfills to v1.1.1
  • Update actions/cache action to v4
  • Update dependency dealerdirect/phpcodesniffer-composer-installer to v1
  • Update dependency wp-coding-standards/wpcs to v3
  • Update mysql Docker tag to v9

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

composer
composer.json
  • php >=7.4
  • aws/aws-sdk-php ^3.261
  • dealerdirect/phpcodesniffer-composer-installer *
  • phpcompatibility/phpcompatibility-wp *
  • squizlabs/php_codesniffer *
  • wp-coding-standards/wpcs *
  • wp-phpunit/wp-phpunit 5.7.2
  • phpunit/phpunit 7.5.20
  • yoast/phpunit-polyfills ^1.0
github-actions
.github/workflows/test.yml
  • shivammathur/setup-php v2
  • actions/cache v2
  • mysql 5.7
npm
package.json
  • @wordpress/env 4.0.5

  • Check this box to trigger a request for Renovate to run again on this repository

Remove top-level admin menu

Hi folks,

The top-level CloudFront Settings menu in the WordPress admin area is unnecessary, especially as the settings are typically set once and then never changed again.

Please can you move this menu into its correct place, which is as a submenu of the Settings menu.

Thanks!

Cloudfront returns a 502 error when page or post is created/updated in Wordpress in version 6.1.4

Hello,

It looks like in version 6.1.4, when a new post is made or page updated, the request that we are sending to Cloudfront to clear the cache is being reported as malformed and results in 502. The below is an extract from the php logs for when I make a post for a new page.

127.0.0.1 - journey 01/Dec/2022:12:09:31 +0000 "POST /index.php" 200
127.0.0.1 - journey 01/Dec/2022:12:09:35 +0000 "POST /wp/wp-admin/admin-ajax.php" 200
127.0.0.1 - journey 01/Dec/2022:12:09:35 +0000 "POST /wp/wp-admin/admin-ajax.php" 200
127.0.0.1 - journey 01/Dec/2022:12:09:39 +0000 "POST /wp/wp-admin/admin-ajax.php" 200
127.0.0.1 - journey 01/Dec/2022:12:09:39 +0000 "POST /wp/wp-admin/admin-ajax.php" 200
127.0.0.1 - journey 01/Dec/2022:12:09:43 +0000 "POST /wp/wp-admin/admin-ajax.php" 200
NOTICE: PHP message: exception 'Aws\CloudFront\Exception\CloudFrontException' with message 'Error executing "CreateInvalidation" on "https://cloudfront.amazonaws.com/2020-05-31/distribution/<REDACTED_CLOUDFRONT_DISTRO>/invalidation"; AWS HTTP error: Client error: `POST https://cloudfront.amazonaws.com/2020-05-31/distribution/<REDACTED_CLOUDFRONT_DISTRO>/invalidation` resulted in a `400 Bad Request` response:
<?xml version="1.0"?>
<ErrorResponse xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/"><Error><Type>Sender</Type>< (truncated...)
 InvalidArgument (client): Your request contains one or more invalid invalidation paths. - <?xml version="1.0"?>
<ErrorResponse xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/"><Error><Type>Sender</Type><Code>InvalidArgument</Code><Message>Your request contains one or more invalid invalidation paths.</Message></Error><RequestId>38f205fa-a2d6-48f0-a1fd-c843bc8b813e</RequestId></ErrorResponse>'
GuzzleHttp\Exception\ClientException: Client error: `POST https://cloudfront.amazonaws.com/2020-05-31/distribution/<REDACTED_CLOUDFRONT_DISTRO>/invalidation` resulted in a `400 Bad Request` response:
<?xml version="1.0"?>
<ErrorResponse xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/"><Error><Type>Sender</Type>< (truncated...)
 in phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Exception/RequestException.php:113
Stack trace:
#0 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(153): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL)
#3 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Handler/CurlMultiHandler.php(118): GuzzleHttp\Promise\TaskQueue->run()
#5 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Handler/CurlMultiHandler.php(145): GuzzleHttp\Handler\CurlMultiHandler->tick()
#6 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(248): GuzzleHttp\Handler\CurlMultiHandler->execute(true)
#7 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(224): GuzzleHttp\Promise\Promise->invokeWaitFn()
#8 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
#9 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
#10 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
#11 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
#12 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#13 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/AwsClientTrait.php(58): GuzzleHttp\Promise\Promise->wait()
#14 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/AwsClientTrait.php(86): Aws\AwsClient->execute(Object(Aws\Command))
#15 /var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/classes/AWS/CloudFront_Service.php(210): Aws\AwsClient->__call('createInvalidat...', Array)
#16 /var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/classes/Invalidation_Service.php(250): C3_CloudFront_Cache_Controller\AWS\CloudFront_Service->create_invalidation(Array)
#17 /var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/classes/Invalidation_Service.php(299): C3_CloudFront_Cache_Controller\Invalidation_Service->invalidate_by_query(Array, false)
#18 /var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/classes/Invalidation_Service.php(222): C3_CloudFront_Cache_Controller\Invalidation_Service->invalidate_post_cache(Object(WP_Post))
#19 /var/www/html/wp/wp-includes/class-wp-hook.php(308): C3_CloudFront_Cache_Controller\Invalidation_Service->invalidate_by_changing_post_status('publish', 'draft', Object(WP_Post))
#20 /var/www/html/wp/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
#21 /var/www/html/wp/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#22 /var/www/html/wp/wp-includes/post.php(5347): do_action('transition_post...', 'publish', 'draft', Object(WP_Post))
#23 /var/www/html/wp/wp-includes/post.php(4607): wp_transition_post_status('publish', 'draft', Object(WP_Post))
#24 /var/www/html/wp/wp-includes/post.php(4819): wp_insert_post(Array, false, true)
#25 /var/www/html/wp/wp-admin/includes/post.php(426): wp_update_post(Array)
#26 /var/www/html/wp/wp-admin/post.php(227): edit_post()
#27 {main}
Next Aws\CloudFront\Exception\CloudFrontException: Error executing "CreateInvalidation" on "https://cloudfront.amazonaws.com/2020-05-31/distribution/<REDACTED_CLOUDFRONT_DISTRO>/invalidation"; AWS HTTP error: Client error: `POST https://cloudfront.amazonaws.com/2020-05-31/distribution/<REDACTED_CLOUDFRONT_DISTRO>/invalidation` resulted in a `400 Bad Request` response:
<?xml version="1.0"?>
<ErrorResponse xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/"><Error><Type>Sender</Type>< (truncated...)
 InvalidArgument (client): Your request contains one or more invalid invalidation paths. - <?xml version="1.0"?>
<ErrorResponse xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/"><Error><Type>Sender</Type><Code>InvalidArgument</Code><Message>Your request contains one or more invalid invalidation paths.</Message></Error><RequestId>38f205fa-a2d6-48f0-a1fd-c843bc8b813e</RequestId></ErrorResponse> in phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/WrappedHttpHandler.php:195
Stack trace:
#0 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/WrappedHttpHandler.php(97): Aws\WrappedHttpHandler->parseError(Array, Object(GuzzleHttp\Psr7\Request), Object(Aws\Command), Array)
#1 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(204): Aws\WrappedHttpHandler->Aws\{closure}(Array)
#2 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(169): GuzzleHttp\Promise\Promise::callHandler(2, Array, NULL)
#3 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/RejectedPromise.php(42): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}(Array)
#4 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/TaskQueue.php(48): GuzzleHttp\Promise\RejectedPromise::GuzzleHttp\Promise\{closure}()
#5 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Handler/CurlMultiHandler.php(118): GuzzleHttp\Promise\TaskQueue->run()
#6 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Handler/CurlMultiHandler.php(145): GuzzleHttp\Handler\CurlMultiHandler->tick()
#7 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(248): GuzzleHttp\Handler\CurlMultiHandler->execute(true)
#8 phar:///var/www/html/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/GuzzleHttp/Promise/Promise.php(224): GuzzleHttp\Promise\Promise->invokeWaitFn()
#9 phar:///var/www/html/wp-content/plugins

If the plugin is disabled in Wordpress, I do not have this problem and the page is updated successfully. If I roll back a website to a version from last week which has version 6.1.3 baked into the docker image that we use, I also do not have the problem. I've been able to reproduce this on a couple of sites where the plugin is used. We use PHP version 7.4.

As a side note, it looks like the tag of 6.1.3 has gone missing from this repo. Was that intentional?

Missing parameters

Receiving some errors when the plugin tries to invalidate the cache. Sometimes this works and we can see the status in the list of log entries as "Completed".

Values are configured in wp-config.

Error in question:

[Wed Jun 10 23:34:53.703629 2020] [php7:notice] [pid 22502] [client -] Array\n(\n    [0] => Found 2 errors while validating the input provided for the CreateInvalidation operation:\n[DistributionId] is missing and is a required parameter\n[InvalidationBatch] is missing and is a required parameter\n)\n, referer: https://redacted.com/wp-cron.php?doing_wp_cron=1591846493.5165441036224365234375
[Wed Jun 10 23:34:53.703645 2020] [php7:notice] [pid 22502] [client -] WP_Error Object\n(\n    [errors] => Array\n        (\n            [C3 Invalidation Error] => Array\n                (\n                    [0] => Found 2 errors while validating the input provided for the CreateInvalidation operation:\n[DistributionId] is missing and is a required parameter\n[InvalidationBatch] is missing and is a required parameter\n                )\n\n        )\n\n    [error_data] => Array\n        (\n        )\n\n)\n, referer: https://redacted.com/wp-cron.php?doing_wp_cron=1591846493.5165441036224365234375```

Issues encountered with C3 Cloudfront Cache Controller

Can you please help me with the following queries that I encountered while trying to work with C3 Cloudfront Cache Controller

  1. Is WordPress 5.4 compatible to C3 Cloudfront Cache Controller plugin?

  2. If we are updating multiple post from wordpress admin panel, how many invalidation request will be created in CloudFront?

  3. Can we customise c3 Cloudfront Cache controller plugin ? Can make the post update reload happen only once the invalidation request gets its response.

Deprecates and stops old versions of CloudFront API.

CloudFrontのAPIの古いバージョンが停止されるようなのですが、ライブラリへの影響はありますか?

https://forums.aws.amazon.com/ann.jspa?annID=6697

Full list of versions to be deprecated on 6/6/2019:
2008-06-30, 2009-04-02, 2009-09-09, 2009-12-01, 2010-03-01, 2010-05-01, 2010-06-01, 2010-07-15, 2010-08-01, 2010-11-01, 2012-03-15, 2012-05-05, 2012-07-01, 2013-05-12, 2013-08-26, 2013-09-27, 2013-11-11, 2013-11-22, 2014-01-31, 2014-05-31, 2014-08-31, 2014-10-21, 2014-11-06, 2015-04-17, 2015-07-27, 2015-09-17, 2015-12-22

array check をしよう

$query_items = $query['Paths']['Items'];
$current_items = $current_transient['Paths']['Items'];

$query['Paths']['Items']$current_transient['Paths']['Items'] の存在チェックとなかった場合は初期化したほうがいいです。

こんな感じかな

private function query_normalyze( $query ) {
    // デフォルトの query 配列
    $default_query_paths = array(
        'Paths' => array(
            'Quantity' => 0,
	    'Items' => array(),
        )
    );

    if ( isset($query['Paths']) ) {
        if ( isset($query['Paths']) && isset($query['Paths']['Items']) && is_array($query['Paths']['Items']) ) {
            $query['Paths']['Quantity'] = count($query['Paths']['Items']);
        } else if ( is_array($query['Paths']) ) {
            $query['Paths'] = $default_query_paths;
        } else {
            $query = array('Paths' => $default_query_paths);
        }
    } else if ( is_array($query) ) {
        $query['Paths'] = $default_query_paths;
    } else {
        $query = array('Paths' => $default_query_paths);
    }
    return $query;
}

private function _merge_transient_invalidation_query( $query ) {
    $query = $this->query_normalyze($query);
    $current_transient = get_transient( self::C3_CRON_INDALITATION_TARGET );
    if ( $current_transient ) {
        $current_query = $this->query_normalyze($current_transient);
        $query_items = $query['Paths']['Items'];
        $current_items = $current_query['Paths']['Items']; 

6.1.5 error opening aws.phar

When updating to the latest version, causes a fatal error:

PHP Warning:  include(phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/Api/../data/s3/2006-03-01/paginators-1.json.php): failed to open stream: phar error: Cannot open phar archive "/home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar" for reading in phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/functions.php on line 151
Warning: include(phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/Api/../data/s3/2006-03-01/paginators-1.json.php): failed to open stream: phar error: Cannot open phar archive "/home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar" for reading in phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/functions.php on line 151
PHP Warning:  include(): Failed opening 'phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/Api/../data/s3/2006-03-01/paginators-1.json.php' for inclusion (include_path='.:/usr/share/php') in phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/functions.php on line 151
Warning: include(): Failed opening 'phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/Api/../data/s3/2006-03-01/paginators-1.json.php' for inclusion (include_path='.:/usr/share/php') in phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/functions.php on line 151
PHP Fatal error:  Uncaught UnexpectedValueException: There is no ListObjects paginator defined for the s3 service. in phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/Api/Service.php:400
Stack trace:
#0 phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/AwsClientTrait.php(15): Aws\Api\Service->getPaginatorConfig()
#1 /home/example/www/wp-content/plugins/S3-Uploads/inc/class-s3-uploads-stream-wrapper.php(509): Aws\AwsClient->getPaginator()
#2 [internal function]: S3_Uploads_Stream_Wrapper->dir_opendir()
#3 /home/example/www/wp-content/plugins/contact-form-7/includes/file.php(359): opendir()
#4 /home/example/www/wp-includes/class-wp-hook.php(306): wpcf7_cleanup_upload_files()
#5 /home/example/www/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#6 /home/example/www/wp-includes/plugin.php(517): WP_Hook->do_action()
#7 /home/example/www/wp-includes/load.php( in phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/Api/Service.php on line 400
Fatal error: Uncaught UnexpectedValueException: There is no ListObjects paginator defined for the s3 service. in phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/Api/Service.php:400
Stack trace:
#0 phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/AwsClientTrait.php(15): Aws\Api\Service->getPaginatorConfig()
#1 /home/example/www/wp-content/plugins/S3-Uploads/inc/class-s3-uploads-stream-wrapper.php(509): Aws\AwsClient->getPaginator()
#2 [internal function]: S3_Uploads_Stream_Wrapper->dir_opendir()
#3 /home/example/www/wp-content/plugins/contact-form-7/includes/file.php(359): opendir()
#4 /home/example/www/wp-includes/class-wp-hook.php(306): wpcf7_cleanup_upload_files()
#5 /home/example/www/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#6 /home/example/www/wp-includes/plugin.php(517): WP_Hook->do_action()
#7 /home/example/www/wp-includes/load.php( in phar:///home/example/www/wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.phar/Aws/Api/Service.php on line 400

PHP 7.4
WP 6.1.1

GuzzleHttpのコンフリクト

失礼いたします。

内部でGuzzleHttpを使用する別プラグインとコンフリクトする問題があるようです。

Fatal error: Cannot redeclare GuzzleHttp\uri_template() (previously declared in /Users/.../.../composer/vendor/guzzlehttp/guzzle/src/functions.php:17) in phar:///Users/.../.../wp-content/plugins/c3-cloudfront-clear-cache/libs/aws.v3.phar/GuzzleHttp/functions.php on line 31

.phar ファイルの使用を避け、composerですべての依存関係をインストールする形で回避可能のようですが、いかがでしょうか?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.