Plugin Directory

Changeset 2406067


Ignore:
Timestamp:
10/25/2020 04:08:30 AM (5 years ago)
Author:
frankspress
Message:

V2.1.0

Location:
in-stock-mailer-for-woocommerce/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • in-stock-mailer-for-woocommerce/trunk/in-stock-mailer-for-wc.php

    r2405747 r2406067  
    88 * Text Domain: in-stock-mailer-for-wc
    99 * Domain Path: /languages/
    10  * Version: 2.0.2
     10 * Version: 2.1.0
    1111 * WC requires at least: 3.5
    1212 * WC tested up to: 4.6.1
     
    2424}
    2525
    26 define( 'ISM_VERSION', '2.0.2' );
     26define( 'ISM_VERSION', '2.1.0' );
    2727define( 'ISM_DOMAIN', 'in-stock-mailer-for-wc' );
    2828define( 'ISM_FILE_PATH', __FILE__ );
  • in-stock-mailer-for-woocommerce/trunk/includes/api-manager.php

    r2405747 r2406067  
    233233
    234234  public function validate_email($email) {
    235     $getEmail = sanitize_email( $this->get_user_email($email) );
     235    $getEmail = strtolower(sanitize_email( $this->get_user_email($email)) );
    236236    if ( $getEmail &&
    237237           is_email( $getEmail ) &&
     
    248248    // Checks if email is valid and honeypot field was sent and it is empty
    249249    if ( $email && ( isset( $request['hname'] ) && empty( $request['hname'] ) ) ) {
    250         $request['email'] = strtolower( $email );
     250        $request['email'] =  $email;
    251251        return true;
    252252    }
     
    379379
    380380  public function add_alert_request( WP_REST_Request $data) {
    381       global $wpdb, $table_prefix;
     381
    382382      $product_id = intval($data['product_id']);
    383383      $email = $data['email'];
    384384      $consent = rest_sanitize_boolean($data['mchimp_consent']) ? 1 : 0;
    385385
    386       $tblname = self::table_name;
    387       $wp_table = $table_prefix . $tblname;
    388 
    389       $sql = "INSERT INTO $wp_table ( product_id, email, consent, sent_id ) VALUES ( %d, %s, %d, null ) ON DUPLICATE KEY UPDATE product_id = %d";
    390       $sql = $wpdb->prepare( $sql, $product_id, $email, $consent, $product_id );
    391       $wpdb->query($sql);
    392 
    393       return array('action'=> 'add' );
     386      if ( !self::has_user_request ($email, $product_id)) {
     387        self::add_user_request($email, $product_id, $consent);
     388      }
     389
     390      return array( 'action'=> 'add' );
    394391  }
    395392
  • in-stock-mailer-for-woocommerce/trunk/includes/in-stock-manager.php

    r2405747 r2406067  
    209209      }
    210210
     211      public static function has_user_request($email, $product_id) {
     212
     213        global $wpdb, $table_prefix;
     214        $tblname = self::table_name;
     215        $wp_table = $table_prefix . $tblname;
     216
     217        $sql = "SELECT id FROM $wp_table WHERE email = %s AND product_id = %d AND sent_id IS NULL";
     218        $sql = $wpdb->prepare( $sql, [ $email, $product_id ] );
     219        return $wpdb->get_var($sql) ? true : false;
     220
     221      }
     222
    211223      public static function remove_user_request($id) {
    212224          global $wpdb, $table_prefix;
     
    222234          $prepare_ph = rtrim($prepare_ph, ',');
    223235
    224           $sql = $wpdb->prepare(" DELETE FROM $wp_table WHERE email = %s AND product_id IN ( $prepare_ph ) ", $prepare_val );
     236          $sql = $wpdb->prepare(" DELETE FROM $wp_table WHERE email = %s AND product_id IN ( ". $prepare_ph ." ) ", $prepare_val );
    225237          return $wpdb->query($sql);
     238      }
     239
     240      public static function add_user_request($email, $product_id, $consent) {
     241
     242          global $wpdb, $table_prefix;
     243          $tblname = self::table_name;
     244          $wp_table = $table_prefix . $tblname;
     245
     246          $sql = "INSERT INTO $wp_table ( product_id, email, consent, sent_id ) VALUES ( %d, %s, %d, null ) ON DUPLICATE KEY UPDATE product_id = %d";
     247          $sql = $wpdb->prepare( $sql, $product_id, $email, $consent, $product_id );
     248          return $wpdb->query($sql);
     249
    226250      }
    227251
     
    231255        $wp_table = $table_prefix . $tblname;
    232256
    233         $placeholders ='';
     257        $placeholders = '';
    234258        $values = $request_ids;
    235259        foreach ( $request_ids as $value ) {
     
    238262        $placeholders = rtrim($placeholders, ',');
    239263        array_unshift( $values, $email_id );
    240         $sql = $wpdb->prepare(" UPDATE $wp_table SET sent_id = %d WHERE id IN ( $placeholders ) ", $values );
     264        $sql = $wpdb->prepare(" UPDATE $wp_table SET sent_id = %d WHERE id IN ( ". $placeholders ." ) ", $values );
    241265        return $wpdb->query($sql);
    242266      }
  • in-stock-mailer-for-woocommerce/trunk/includes/update-manager.php

    r2405747 r2406067  
    7070    }
    7171
    72     // Future versions check template
    73     // if ( $version < '2.0.2' ) {
     72    // Removes duplicates from table, fixed in 2.1.0
     73    if ( $version < '2.1.0' ) {
     74
     75      $tblname = self::table_name;
     76      $wp_table = $table_prefix . $tblname;
     77
     78      $sql = "SELECT email, product_id, COUNT(*) AS c FROM {$wp_table}  WHERE sent_id IS NULL GROUP BY email, product_id HAVING c > 1";
     79      $wpdb->suppress_errors( true );
     80      $duplicates = $wpdb->get_results( $sql );
     81
     82      if ( $duplicates ) {
     83        // Prevents system crash lock on failure
     84        update_option( 'ism_version', '2.1.0' );
     85
     86        foreach ( $duplicates as $duplicate ) {
     87          $sql =  "DELETE FROM {$wp_table} WHERE  email = %s AND product_id = %d LIMIT 1";
     88          $sql = $wpdb->prepare( $sql, [$duplicate->email, intval($duplicate->product_id)] );
     89          $wpdb->query( $sql );
     90        }
     91      }
     92
     93      $wpdb->suppress_errors( false );
     94    }
     95
     96    // // Updates from this version
     97    // if ( $version < '2.1.0' ) {
    7498    //
    7599    // }
    76100
     101
    77102    update_option( 'ism_version', ISM_VERSION );
    78 
    79103  }
    80104
  • in-stock-mailer-for-woocommerce/trunk/readme.txt

    r2405747 r2406067  
    55Requires at least: 4.9
    66Tested up to: 5.5.1
    7 Stable tag: 2.0.2
     7Stable tag: 2.1.0
    88Requires PHP: 5.6.4
    99License: GPLv2 or later
     
    7272
    7373== Changelog ==
     74
     75= 2.1.0 =
     76* Fixes a database bug.
     77* This update will fix a known issue for those pending emails that are not being sent automatically or manually.
    7478
    7579= 2.0.2 =
Note: See TracChangeset for help on using the changeset viewer.