PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Modules / WooCommerceMigrator / WooCommerceMigratorHelper.php

WooCommerceMigratorHelper.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Modules/WooCommerceMigrator/WooCommerceMigratorHelper.php

69 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Modules\WooCommerceMigrator;
4
5 class WooCommerceMigratorHelper
6 {
7 public static function doBulkInsert($table, $data)
8 {
9 if (empty($data)) {
10 return false;
11 }
12
13 global $wpdb;
14 $firstRow = reset($data);
15 $columns = array_keys($firstRow);
16 $values = [];
17 $placeHolders = [];
18
19 foreach ($data as $row) {
20 $rowPlaceholders = [];
21 foreach ($columns as $column) {
22 $values[] = $row[$column];
23 $rowPlaceholders[] = is_numeric($row[$column]) ? '%d' : '%s';
24 }
25 $placeHolders[] = '(' . implode(',', $rowPlaceholders) . ')';
26 }
27
28 $query = "INSERT INTO {$wpdb->prefix}{$table} (`" . implode('`,`', $columns) . "`) VALUES " . implode(',', $placeHolders);
29
30 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared -- Query is prepared on this line with values
31 return $wpdb->query($wpdb->prepare($query, $values));
32 }
33
34 public static function logMigrationError($productId, $error)
35 {
36 $failedLogs = get_option('_fluent_wc_failed_migration_logs', []);
37 $failedLogs[$productId] = is_wp_error($error) ? $error->get_error_message() : $error;
38 update_option('_fluent_wc_failed_migration_logs', $failedLogs);
39 }
40
41 public static function updateMigrationStatus($step, $status)
42 {
43 $migrationSteps = get_option('__fluent_cart_wc_migration_steps', []);
44 $migrationSteps[$step] = $status;
45 update_option('__fluent_cart_wc_migration_steps', $migrationSteps);
46 }
47
48 public static function checkRequiredTables()
49 {
50 global $wpdb;
51 $requiredTables = [
52 'fct_product_details',
53 'fct_product_variations',
54 'fct_product_downloads'
55 ];
56
57 foreach ($requiredTables as $table) {
58 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
59 if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}{$table}'") != $wpdb->prefix . $table) {
60 return new \WP_Error('wc_migrator_error', "Required table {$table} does not exist.");
61 }
62 }
63
64 return true;
65 }
66
67
68 }
69