bucket(); if ( empty( $bucket ) ) { return new WP_Error( 'exception', 'Could not get bucket for item.' ); } $region = $as3cf_item->region(); if ( is_wp_error( $region ) ) { return new WP_Error( 'exception', 'Could not get region for bucket: ' . $region->get_error_message() ); } elseif ( ! is_string( $region ) ) { return new WP_Error( 'exception', "Could not get region for item's bucket." ); } try { $provider_client = $this->as3cf->get_provider_client( $region ); } catch ( Exception $e ) { return new WP_Error( 'exception', 'Could not get provider client: ' . $e->getMessage() ); } $paths = AS3CF_Utils::get_attachment_file_paths( $as3cf_item->source_id(), false ); if ( empty( $paths ) ) { return new WP_Error( 'exception', 'Could not get paths for Media Library item with ID: ' . $as3cf_item->source_id() ); } $fullsize_paths = AS3CF_Utils::fullsize_paths( $paths ); if ( empty( $fullsize_paths ) ) { return new WP_Error( 'exception', 'Could not get full size paths for Media Library item with ID: ' . $as3cf_item->source_id() ); } $fullsize_exists = false; $fullsize_missing = false; foreach ( $fullsize_paths as $path ) { $key = $as3cf_item->key( wp_basename( $path ) ); if ( $provider_client->does_object_exist( $bucket, $key ) ) { $fullsize_exists = true; } else { $fullsize_missing = true; } } // A full sized file has not been found, remove metadata. if ( ! $fullsize_exists ) { $as3cf_item->delete(); return false; } // At least one full sized file has been found, set as verified. $as3cf_item->set_is_verified( true ); $as3cf_item->save(); // Need to log that sizes need regeneration? // NOTE: As we currently do not have a means of setting individual thumbnails sizes as verified, we can shortcut out here. // NOTE: In the future we should record whether each size is verified and/or remove details record. if ( $fullsize_missing ) { return new WP_Error( 'exception', 'Thumbnails need regenerating for Media Library item with ID: ' . $as3cf_item->source_id() ); } // If item has sizes, check them too. $size_paths = array_diff( $paths, $fullsize_paths ); if ( empty( $size_paths ) ) { return true; } foreach ( $size_paths as $path ) { $key = $as3cf_item->key( wp_basename( $path ) ); if ( ! $provider_client->does_object_exist( $bucket, $key ) ) { return new WP_Error( 'exception', 'Thumbnails need regenerating for Media Library item with ID: ' . $as3cf_item->source_id() ); } } return true; } /** * Get complete notice message. * * @return string */ protected function get_complete_message() { return __( 'Finished checking or removing items previously created with the Add Metadata tool.', 'amazon-s3-and-cloudfront' ); } /** * Called when background process has completed. */ protected function completed() { $this->as3cf->update_media_library_total(); } }