Plugin Directory

Changeset 1859904


Ignore:
Timestamp:
04/17/2018 05:32:12 PM (8 years ago)
Author:
octify
Message:

Fix timeout. Bump version.

Location:
octify/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • octify/trunk/Libs/OctifyApi.php

    r1859060 r1859904  
    220220
    221221            $imageMeta             = wp_get_attachment_metadata( $id );
    222             $imageUrl              = $uploadDirs['baseurl'] . '/' . $imageMeta['file'];
     222            $imageUrl              = wp_get_attachment_image_url( $id, 'full' );
    223223            $imagePath             = $uploadDirs['basedir'] . '/' . $imageMeta['file'];
    224224            $imageToProcess[ $id ] = array(
     
    237237        $imageToProcess = array_filter( $imageToProcess );
    238238        if ( count( $imageToProcess ) ) {
    239             $request = wp_remote_post( self::API_ENDPOINT . 'v1/image/bulk_compress2', array(
    240                 'body'    => array(
    241                     'images' => json_encode( $imageToProcess )
    242                 ),
    243                 'timeout' => 30
    244             ) );
    245             if ( is_wp_error( $request ) ) {
    246                 return $request;
    247             }
    248             $body = wp_remote_retrieve_body( $request );
    249             $body = json_decode( $body, true );
    250             if ( ! is_array( $body ) ) {
    251                 return new \WP_Error( 'invalid_response', 'Please try again' );
    252             }
    253             if ( $body['status'] == 1 ) {
    254                 return array(
    255                     'success' => array_keys( $imageToProcess ),
    256                     'fail'    => array()
    257                 );
    258             } else {
    259                 //get the error and success
    260                 $success = array_keys( $imageToProcess );
    261                 $fail    = array();
    262                 foreach ( $body['error'] as $error ) {
    263                     unset( $success[ $error['meta'] ] );
    264                     $fail[] = array(
    265                         'id'    => $error['meta'],
    266                         'error' => $error['error'],
    267                         'code'  => $error['errorCode']
    268                     );
    269                     if ( $error['errorCode'] == 'expired' ) {
    270                         $license              = get_option( self::LICENSE_NAME, false );
    271                         $license['isExpired'] = true;
    272                         update_option( self::LICENSE_NAME, $license );
     239            $chunks = array_chunk( $imageToProcess, 10 );
     240            $data   = array(
     241                'success' => array(),
     242                'fail'    => array()
     243            );
     244            foreach ( $chunks as $chunk ) {
     245                $request = wp_remote_post( self::API_ENDPOINT . 'v1/image/bulk_compress2', array(
     246                    'body'    => array(
     247                        'images' => json_encode( $chunk )
     248                    ),
     249                    'timeout' => 60
     250                ) );
     251
     252                if ( is_wp_error( $request ) ) {
     253                    return $request;
     254                }
     255                $body = wp_remote_retrieve_body( $request );
     256                $body = json_decode( $body, true );
     257                if ( ! is_array( $body ) ) {
     258
     259                    return new \WP_Error( 'invalid_response', 'Please try again' );
     260                }
     261                if ( $body['status'] == 1 ) {
     262                    $data['success'] = array_merge( $data['success'], array_keys( $imageToProcess ) );
     263                } else {
     264                    //get the error and success
     265                    $success = array_keys( $imageToProcess );
     266                    $fail    = array();
     267                    foreach ( $body['error'] as $error ) {
     268                        unset( $success[ $error['meta'] ] );
     269                        $fail[] = array(
     270                            'id'    => $error['meta'],
     271                            'error' => $error['error'],
     272                            'code'  => $error['errorCode']
     273                        );
     274                        if ( $error['errorCode'] == 'expired' ) {
     275                            $license              = get_option( self::LICENSE_NAME, false );
     276                            $license['isExpired'] = true;
     277                            update_option( self::LICENSE_NAME, $license );
     278                        }
    273279                    }
     280                    $data['success'] = array_merge( $data['success'], $success );
     281                    $data['fail']    = array_merge( $data['fail'], $fail );
    274282                }
    275 
    276                 return array(
    277                     'success' => $success,
    278                     'fail'    => $fail
    279                 );
    280             }
     283            }
     284
     285            return $data;
    281286        } else {
    282287            return false;
     
    313318            return;
    314319        }
    315         file_put_contents( __DIR__ . '/test', var_export( $data, true ) . PHP_EOL, FILE_APPEND );
    316320        $comparedHmac = $data['hmac'];
    317321        unset( $data['hmac'] );
     
    347351            }
    348352            $tmp = download_url( $data['image_url'] );
    349 
    350353            if ( is_wp_error( $tmp ) ) {
    351354                update_post_meta( $attachmentId, self::META_STATUS, 'error' );
  • octify/trunk/Octify.php

    r1859162 r1859904  
    44 * Plugin URI: https://octify.io
    55 * Description: Octify Image Compression for WordPress.
    6  * Version: 1.1.2
     6 * Version: 1.1.3
    77 * Author: Octify
    88 * Author URI: https://octify.io
  • octify/trunk/readme.txt

    r1859162 r1859904  
    11=== WordPress Image Compression Plugin - Octify ===
    22Plugin Name: Octify
    3 Version: 1.1.1
     3Version: 1.1.3
    44Author: Octify
    55Author URI: https://octify.io/
     
    77Tags: Image Compression, Image Optimisation, resize, optimise, performance, optimize, compress images, optimize images, optimise images, image optimization.
    88Tested up to: 4.9.5
    9 Stable tag: 1.1.2
     9Stable tag: 1.1.3
    1010Requires PHP: 5.2.4
    1111License: GPLv2
     
    141141== Changelog ==
    142142
     143== 1.1.3 ==
     144
     145* Fix issue with sending images to API timing out
     146* Improve chunked data
     147
     148== 1.1.2 ==
     149
     150* Small fixes
     151
    143152== 1.1.1 ==
    144153* Add top level menu link
Note: See TracChangeset for help on using the changeset viewer.