You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
987 B

2 years ago
  1. <?php namespace WpsMcloud\Actions\Convert;
  2. use WpsMcloud\Models\PostAttachment;
  3. class Attachment
  4. {
  5. public function getImagesWithoutS3MetaData(): array
  6. {
  7. global $wpdb;
  8. $query = <<<EOF
  9. SELECT $wpdb->posts.ID, $wpdb->posts.guid, $wpdb->posts.post_mime_type, $wpdb->postmeta.meta_id, $wpdb->postmeta.meta_value
  10. FROM $wpdb->posts
  11. JOIN $wpdb->postmeta ON $wpdb->posts.ID=$wpdb->postmeta.post_id
  12. LEFT JOIN $wpdb->postmeta pm2 ON $wpdb->posts.ID=pm2.post_id AND pm2.meta_key = %s
  13. WHERE
  14. $wpdb->posts.post_type = %s and
  15. $wpdb->postmeta.meta_key = %s and
  16. $wpdb->postmeta.meta_value not like %s and
  17. pm2.meta_id IS NULL
  18. EOF;
  19. return PostAttachment::get($wpdb->get_results($wpdb->prepare(
  20. $query,
  21. [
  22. PostAttachment::META_KEY_FLAGGED_AS_404,
  23. 'attachment',
  24. '_wp_attachment_metadata',
  25. '%' . $wpdb->esc_like('"s3"') . '%',
  26. ]
  27. )));
  28. }
  29. }