Image_Resizer::run()

Summary

No summary available.

Source

File: src/BigCommerce/Import/Processors/Image_Resizer.php

	public function run() {
		/** @var \wpdb $wpdb */
		global $wpdb;

		$status = new Status();
		$status->set_status( Status::RESIZING_IMAGES );

		$sql = "SELECT SQL_CALC_FOUND_ROWS p.ID FROM {$wpdb->posts} p
		        INNER JOIN {$wpdb->postmeta} bcid ON p.ID=bcid.post_id AND bcid.meta_key='bigcommerce_id'
		        LEFT JOIN {$wpdb->postmeta} version ON p.ID=version.post_id AND version.meta_key=%s
		        WHERE p.post_type='attachment' AND ( version.meta_value != %s OR version.meta_value IS NULL )
		        LIMIT %d";

		$query = $wpdb->prepare( $sql, Image_Sizes::STATE_META, Image_Sizes::VERSION, $this->limit );

		$image_ids = $wpdb->get_col( $query );

		$total_remaining = (int) $wpdb->get_var( "SELECT FOUND_ROWS()" );

		if ( empty( $image_ids ) ) {
			do_action( 'bigcommerce/log', Error_Log::DEBUG, __( 'No images found requiring regeneration', 'bigcommerce' ), [] );
		} else {
			do_action( 'bigcommerce/log', Error_Log::DEBUG, __( 'Found images to regenerate', 'bigcommerce' ), [
				'batch' => $image_ids,
				'total' => $total_remaining,
			] );
			foreach ( $image_ids as $post_id ) {
				$this->regenerate_image( $post_id );
			}
		}

		if ( empty( $image_ids ) || $total_remaining <= $this->limit ) {
			$status->set_status( Status::RESIZED_IMAGES );
		}
	}


User Contributed Notes

You must log in before being able to contribute a note or feedback.