Announcement Regarding Support

Hello everyone, Charles here. Please read my post on changes to Media Cloud support and updates regarding Media Cloud in general.


Dev/Test/Prod - Different GCS Buckets for each environment

  • Hello-


    1. We run on pantheon with dev, test, live environments, and also have local docker (lando) based environments for devs.
    2. We have 4 GCS buckets and 4 Imgix Sources. dev-local, dev, test, and live.
    3. We use gsutils rsync to sync data across the buckets as needed.
    4. For each environment we are programmatically setting the Bucket and ImgIx Sources in wp-config via define's.

    What works:
    Within each environment the Public Urls for media reflect the appropriate imgix source based on the MCLOUD_IMGIX_DOMAINS setting.

    Undesired Behavior:
    Within each environment the Bucket and Storage url reflect the environment in which the media was created, not based on the value of the MCLOUD_STORAGE_GOOGLE_BUCKET.

    Desired Behavior:
    Within each environment the Bucket and Storage url reflect the appropriate bucket based on the MCLOUD_STORAGE_GOOGLE_BUCKET setting.

    Is it possible to get the desired behavior dynamically?
    Or is this a search and replace situation?


  • @wholesalesolar

    It's a search and a replace situation.

    In the attachment metadata for each attachment is a field called s3 which contains all the cloud metadata for the image. Each size in the sizes field of the metadata also has the s3 field with metadata for that particular image size.

    You'd have to update the bucket field and probably the url field as well.

    If I were you, I'd write a WP-CLI command to handle it. If you have the premium version of Media Cloud, look at the StorageCommands.php class for an example on how to do a WP_Query for attachments that have cloud metadata. I'd perform a query and then loop through those ids and use get_post_meta($id, '_attachment_metadata') and update_post_meta(). I would NOT use wp_get_attachment_meta() or update_attachment_meta() as those will trigger plugins and it could be a mess.

    Even on a huge library, it should be pretty fast.

  • Hey @jong -

    I'm just doing a "wp search-replace old-bucket-name new-bucket-name".
    That seems to working just fine.

    Lemme know if you see any issues with that.


  • @wholesalesolar

    I've never tried it so if it's working then 👍

Log in to reply