From f41a41d3830de671e24c3d8538a4fe5307902db3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 19 Jul 2020 00:18:21 +0000 Subject: [PATCH 1/2] Bump lodash Bumps [lodash](https://github.com/lodash/lodash) from 4.17.11 to 4.17.19. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](https://github.com/lodash/lodash/compare/4.17.11...4.17.19) Signed-off-by: dependabot[bot] --- .../package-lock.json | 6 +++--- .../package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/package-lock.json b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/package-lock.json index 704cd7df0..20b1209d5 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/package-lock.json +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/package-lock.json @@ -11924,9 +11924,9 @@ } }, "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "version": "4.17.19", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", + "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==", "dev": true }, "lodash._reinterpolate": { diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/package.json b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/package.json index 4511bf188..5f69bd582 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/package.json +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/package.json @@ -59,7 +59,7 @@ "grunt-contrib-copy": "1.0.0", "grunt-shell": "3.0.1", "grunt-wp-deploy": "2.0.0", - "lodash": "4.17.11", + "lodash": "4.17.19", "mini-css-extract-plugin": "0.7.0", "moment": "2.24.0", "npm-run-all": "4.1.5", From b0c00e4f2d14dbb3305d85e15fad96428f691a60 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 23 Jul 2020 11:29:39 +0100 Subject: [PATCH 2/2] Make the assets upgrade mechanism more resilient --- .../php/media/class-upgrade.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-upgrade.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-upgrade.php index 0733bf599..29430a9c4 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-upgrade.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-upgrade.php @@ -34,6 +34,20 @@ class Upgrade { */ private $sync; + /** + * The cron frequency to ensure that the queue is progressing. + * + * @var int + */ + protected $cron_frequency; + + /** + * The cron offset since the last update. + * + * @var int + */ + protected $cron_start_offset; + /** * Filter constructor. * @@ -42,6 +56,10 @@ class Upgrade { public function __construct( \Cloudinary\Media $media ) { $this->media = $media; $this->sync = $media->plugin->components['sync']; + + $this->cron_frequency = apply_filters( 'cloudinary_cron_frequency', 600 ); + $this->cron_start_offset = apply_filters( 'cloudinary_cron_start_offset', 60 ); + $this->setup_hooks(); } @@ -167,6 +185,10 @@ function ( $val ) use ( $media ) { update_post_meta( $attachment_id, Sync::META_KEYS['downloading'], true ); delete_post_meta( $attachment_id, Sync::META_KEYS['syncing'] ); + if ( ! wp_next_scheduled( 'cloudinary_resume_upgrade' ) ) { + wp_schedule_single_event( time() + $this->cron_frequency, 'cloudinary_resume_upgrade' ); + } + if ( ! defined( 'DOING_BULK_SYNC' ) ) { $this->sync->managers['upload']->add_to_sync( $attachment_id ); // Auto sync if upgrading outside of bulk sync. } @@ -174,6 +196,33 @@ function ( $val ) use ( $media ) { return $public_id; } + /** + * Maybe resume the upgrading assets. + * This is a fallback mechanism to resume the upgrade when it stops unexpectedly. + * + * @return void + */ + public function maybe_resume_upgrade() { + global $wpdb; + + $assets = $wpdb->get_col( // phpcs:ignore WordPress.DB.DirectDatabaseQuery + $wpdb->prepare( + "SELECT post_id + FROM $wpdb->postmeta + WHERE meta_key = %s", + Sync::META_KEYS['downloading'] + ) + ); + + if ( ! empty( $assets ) ) { + wp_schedule_single_event( time() + $this->cron_frequency, 'cloudinary_resume_upgrade' ); + + foreach ( $assets as $asset ) { + $this->sync->managers['upload']->add_to_sync( $asset ); + } + } + } + /** * Setup hooks for the filters. */ @@ -193,5 +242,7 @@ public function setup_hooks() { } } ); } + + add_action( 'cloudinary_resume_upgrade', array( $this, 'maybe_resume_upgrade' ) ); } }