Skip to content

Commit

Permalink
Merge pull request #608 from tynanbe/try_parallel_pull
Browse files Browse the repository at this point in the history
Fix an issue where images won't be pulled with older versions of WordPress
  • Loading branch information
hi-hai committed Jan 8, 2024
2 parents c3c7bba + 4d95f08 commit cdb75b0
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/img-optm.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,17 @@ public function pull($manual = false)
} else {
// handle error
$image_url = $server_info['server'] . '/' . $server_info[$row_type];
self::debug('❌ failed to pull image (' . $row_type . '): ' . (!empty($response->status_code) ? $response->status_code : '') . ' [Local: ' . $row_img->src . '] / [remote: ' . $image_url . ']');
self::debug(
'❌ failed to pull image (' .
$row_type .
'): ' .
(!empty($response->status_code) ? $response->status_code : '') .
' [Local: ' .
$row_img->src .
'] / [remote: ' .
$image_url .
']'
);
return;
}
}
Expand Down Expand Up @@ -1134,7 +1144,7 @@ public function pull($manual = false)
$total_pulled_ori++;
};

if (class_exists('Requests')) {
if (class_exists('\WpOrg\Requests\Requests') && class_exists('\WpOrg\Requests\Autoload') && version_compare(PHP_VERSION, '5.6.0', '>=')) {
// Make sure Requests can load internal classes.
Autoload::register();

Expand Down Expand Up @@ -1172,9 +1182,9 @@ public function pull($manual = false)
// Notify IAPI images taken
foreach ($server_list as $server => $img_list) {
$data = array(
'action' => self::CLOUD_ACTION_TAKEN,
'list' => $img_list,
'server' => $server,
'action' => self::CLOUD_ACTION_TAKEN,
'list' => $img_list,
'server' => $server,
);
// TODO: improve this so we do not call once per server, but just once and then filter on the server side
Cloud::post(Cloud::SVC_IMG_OPTM, $data);
Expand Down Expand Up @@ -2063,10 +2073,10 @@ public function handler()
self::start_async();
break;

/**
* Batch switch
* @since 1.6.3
*/
/**
* Batch switch
* @since 1.6.3
*/
case self::TYPE_BATCH_SWITCH_ORI:
case self::TYPE_BATCH_SWITCH_OPTM:
$this->_batch_switch($type);
Expand Down

0 comments on commit cdb75b0

Please sign in to comment.