Plugin Directory

Changeset 3240028


Ignore:
Timestamp:
02/13/2025 11:33:52 AM (12 months ago)
Author:
visidea
Message:

2.1.14

Location:
visidea
Files:
215 added
3 edited

Legend:

Unmodified
Added
Removed
  • visidea/trunk/admin/class-visidea-admin.php

    r3224275 r3240028  
    217217      // Close the file and rename it
    218218      fclose($fp);
     219     
    219220      $old_filename = 'items_' . $options['private_token'] . '.csv';
    220221      $hash_filename = 'items_' . $options['private_token'] . '.hash';
    221222      unlink(plugin_dir_path(__FILE__) . $old_filename);
    222223      rename($file_path, plugin_dir_path(__FILE__) . $old_filename);
    223       file_put_contents(plugin_dir_path(__FILE__) . $hash_filename, hash_file('md5', plugin_dir_path(__FILE__) . $old_filename));
     224      file_put_contents(plugin_dir_path(__FILE__) . $hash_filename, hash_file('sha256', plugin_dir_path(__FILE__) . $old_filename));
    224225
    225226    } catch (Exception $e) {
     
    227228    }
    228229
    229     error_log('Visidea - cron_items_dump job finished at ' . date(DATE_RFC2822)); // Log start
     230    error_log('Visidea - cron_items_dump job finished at ' . date(DATE_RFC2822)); // Log end
    230231
    231232  }
     
    353354
    354355  public function cron_users_dump() {
    355     // error_log( 'fired cron_users_dump at ' . date( DATE_RFC2822 ) );
     356
     357    error_log('Visidea - cron_users_dump job started at ' . date(DATE_RFC2822)); // Log start
    356358
    357359    // Re-initialize items dump file
     
    400402    $file = plugin_dir_path(__FILE__) . $option_filename;
    401403    rename(plugin_dir_path(__FILE__) . $option_filename, plugin_dir_path(__FILE__) . $old_filename);
    402     file_put_contents(plugin_dir_path(__FILE__) . $hash_filename, hash_file('md5', plugin_dir_path(__FILE__) . $old_filename));
     404    file_put_contents(plugin_dir_path(__FILE__) . $hash_filename, hash_file('sha256', plugin_dir_path(__FILE__) . $old_filename));
     405
     406    error_log('Visidea - cron_users_dump job finished at ' . date(DATE_RFC2822)); // Log end
    403407
    404408  }
     
    425429
    426430  public function cron_interactions_dump() {
    427       // error_log( 'fired cron_interactions_dump at ' . date( DATE_RFC2822 ) );
    428 
    429       // Initialize interactions file
     431      error_log('Visidea - cron_interactions_dump job started at ' . date(DATE_RFC2822)); // Log start
     432
     433      // Initialize file and options
    430434      $options = get_option('visidea_plugin_options');
    431       $option_filename = 'interactions_'.$options['private_token'].'.tmp';
     435      $option_filename = 'interactions_' . $options['private_token'] . '.tmp';
    432436      $file = plugin_dir_path(__FILE__) . $option_filename;
    433       $fp = fopen($file, 'w');
    434 
    435       // Write header
    436       $interactions_columns = "item_id;action;user_id;price;quantity;timestamp\n";
    437       fwrite($fp, $interactions_columns);
    438 
    439       for ($i=0; $i<356; $i++) {
    440         // Get all previous orders
    441         $start   = 356 - $i;
    442         $one_day = 24 * 60 * 60;
    443         $today   = strtotime( date('Y-m-d') );
    444 
    445         $query = new WC_Order_Query( array(
    446           'limit' => -1,
    447           'date_created' => ( $today - ( $start * $one_day ) ).'...'.( $today - ( $start * $one_day ) + $one_day ),
    448         ) );
    449         $orders = $query->get_orders();
    450  
    451         foreach ($orders as $order) {
    452 
    453           // Get customer ID
    454           $user_id = $order->get_user_id();
    455  
    456           // Loop through order items and write them in the opened file
    457           foreach ($order->get_items() as $item_id => $item) {
    458  
    459             // Get product handle
    460             $product = $item->get_product();
    461  
    462             // Get the product ID
    463             if (is_object($product))
    464               $product_id = $product->get_id();
    465             else
    466               $product_id = 0;
    467      
    468             // Get item price and quantity
    469             $item_price = $item->get_total(); // Total price for this item (quantity * unit price)
    470             $item_quantity = $item->get_quantity(); // Quantity of the item in the order
    471 
    472             // If all is set create the buffer
    473             if ($product_id > 0 && !empty($user_id)) {
    474  
    475               $buffer = $product_id .
    476                         ';"purchase";' .
    477                         $user_id . ';' .
    478                         round($item_price, 2). ';' .
    479                         round($item_quantity) . ';' .
    480                         '"' . $order->get_date_created()->format(DateTime::ATOM) . '"' . "\n";
    481  
    482               // Write to file
    483               fwrite($fp, $buffer);
    484 
    485             }
    486  
     437      $fp = fopen($file, 'a'); // Open in append mode
     438
     439      // Write header only if the file is empty
     440      if (filesize($file) === 0) {
     441          $interactions_columns = "item_id;action;user_id;price;quantity;timestamp\n";
     442          fwrite($fp, $interactions_columns);
     443      }
     444
     445      // Page marker file
     446      $page_marker_file = plugin_dir_path(__FILE__) . 'interactions_page_marker_' . $options['private_token'] . '.txt';
     447      $start_page = 0;
     448
     449      // Load page marker if it exists
     450      if (file_exists($page_marker_file)) {
     451          $start_page = (int)file_get_contents($page_marker_file);
     452      }
     453
     454      $one_day = 24 * 60 * 60;
     455      $today = strtotime(date('Y-m-d'));
     456
     457      for ($i = $start_page; $i < 356 * 10; $i++) {
     458          $start = 356 * 10 - $i;
     459
     460          // Fetch orders for the specific day
     461          $query = new WC_Order_Query(array(
     462              'limit' => -1,
     463              'date_created' => ($today - ($start * $one_day)) . '...' . ($today - ($start * $one_day) + $one_day),
     464          ));
     465          $orders = $query->get_orders();
     466
     467          error_log('Visidea - cron_interactions_dump processing day # ' . $i . ' with orders: ' . count($orders)); // Log progress
     468
     469          foreach ($orders as $order) {
     470              // Get customer ID
     471              $user_id = $order->get_user_id();
     472
     473              foreach ($order->get_items() as $item_id => $item) {
     474                  // Get product
     475                  $product = $item->get_product();
     476
     477                  $product_id = is_object($product) ? $product->get_id() : 0;
     478                  $item_price = $item->get_total(); // Total price
     479                  $item_quantity = $item->get_quantity(); // Quantity
     480
     481                  if ($product_id > 0 && !empty($user_id)) {
     482                      $buffer = $product_id .
     483                          ';"purchase";' .
     484                          $user_id . ';' .
     485                          round($item_price, 2) . ';' .
     486                          round($item_quantity) . ';' .
     487                          '"' . $order->get_date_created()->format(DateTime::ATOM) . '"' . "\n";
     488
     489                      fwrite($fp, $buffer);
     490                  }
     491              }
    487492          }
    488  
    489         }
    490  
     493
     494          // Save progress and log memory usage
     495          file_put_contents($page_marker_file, $i);
     496          error_log('Visidea - cron_interactions_dump saved page # ' . $i);
     497          error_log('Visidea - cron_interactions_dump memory usage: ' . memory_get_usage(true));
    491498      }
    492499
    493500      fclose($fp);
    494501
    495       $old_filename = 'interactions_'.$options['private_token'].'.csv';
    496       $hash_filename = 'interactions_'.$options['private_token'].'.hash';
    497       unlink(plugin_dir_path(__FILE__) . $old_filename);
    498       $file = plugin_dir_path(__FILE__) . $option_filename;
    499       rename(plugin_dir_path(__FILE__) . $option_filename, plugin_dir_path(__FILE__) . $old_filename);
    500       file_put_contents(plugin_dir_path(__FILE__) . $hash_filename, hash_file('md5', plugin_dir_path(__FILE__) . $old_filename));
    501 
    502     }
     502      // Rename and hash the completed file
     503      $old_filename = 'interactions_' . $options['private_token'] . '.csv';
     504      $hash_filename = 'interactions_' . $options['private_token'] . '.hash';
     505      if (file_exists(plugin_dir_path(__FILE__) . $old_filename)) {
     506          unlink(plugin_dir_path(__FILE__) . $old_filename);
     507      }
     508      rename($file, plugin_dir_path(__FILE__) . $old_filename);
     509      file_put_contents(plugin_dir_path(__FILE__) . $hash_filename, hash_file('sha256', plugin_dir_path(__FILE__) . $old_filename));
     510
     511      // Cleanup page marker
     512      unlink($page_marker_file);
     513
     514      error_log('Visidea - cron_interactions_dump job finished at ' . date(DATE_RFC2822)); // Log end
     515  }
     516
    503517
    504518  function check_crons() {
  • visidea/trunk/readme.txt

    r3224275 r3240028  
    66Tested up to: 6.6
    77Requires PHP: 7.0
    8 Stable tag: 2.1.13
     8Stable tag: 2.1.14
    99License: GPLv3
    1010License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    9696
    9797== Changelog ==
     98
     99= 2.1.14 2025-02-13 =
     100Changed the hashing algorithm to sha256
    98101
    99102= 2.1.13 2025-01-17 =
  • visidea/trunk/visidea.php

    r3224275 r3240028  
    55 * Plugin URI: https://visidea.ai
    66 * Description: Visidea is the search and recommendations plugin for WooCommerce. Visidea improves UX and increases the revenues of your website.
    7  * Version: 2.1.13
     7 * Version: 2.1.14
    88 * Author: Inferendo
    99 * Author URI: https://visidea.ai
     
    2727 * Current Visidea version.
    2828 */
    29 define('VISIDEA_VERSION', '2.1.13');
     29define('VISIDEA_VERSION', '2.1.14');
    3030
    3131/**
Note: See TracChangeset for help on using the changeset viewer.