65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
|
|
|
class WPI_Logger
|
|
{
|
|
|
|
public static function log($message)
|
|
{
|
|
$dir = WP_CONTENT_DIR . '/uploads/wpi-import';
|
|
if (!file_exists($dir)) {
|
|
wp_mkdir_p($dir);
|
|
}
|
|
|
|
$file = $dir . '/wpi-cron.log';
|
|
$time = current_time('Y-m-d H:i:s');
|
|
|
|
file_put_contents(
|
|
$file,
|
|
"[{$time}] {$message}\n",
|
|
FILE_APPEND
|
|
);
|
|
}
|
|
|
|
|
|
|
|
public static function log_product_item($item)
|
|
{
|
|
$log_file = WP_CONTENT_DIR . '/uploads/wpi-import/api-product-preview.log';
|
|
|
|
if (!file_exists(dirname($log_file))) {
|
|
wp_mkdir_p(dirname($log_file));
|
|
}
|
|
|
|
$time = current_time('Y-m-d H:i:s');
|
|
|
|
file_put_contents(
|
|
$log_file,
|
|
"================ ITEM {$item['sku']} | {$time} ================\n" .
|
|
print_r($item, true) . "\n\n",
|
|
FILE_APPEND
|
|
);
|
|
}
|
|
|
|
public static function log_category_item(array $category)
|
|
{
|
|
$log_file = WP_CONTENT_DIR . '/uploads/wpi-import/api-category-preview.log';
|
|
|
|
if (!file_exists(dirname($log_file))) {
|
|
wp_mkdir_p(dirname($log_file));
|
|
}
|
|
|
|
$time = current_time('Y-m-d H:i:s');
|
|
|
|
$id = $category['id'] ?? 'N/A';
|
|
$name = $category['name'] ?? 'N/A';
|
|
$parent_id = $category['parent_id'] ?? 0;
|
|
|
|
file_put_contents(
|
|
$log_file,
|
|
"================ CATEGORY {$id} | {$name} | {$time} ================\n" .
|
|
print_r($category, true) . "\n\n",
|
|
FILE_APPEND
|
|
);
|
|
}
|
|
}
|