<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
 * Plugin Name: SmartSync Lite - Offload media cloud storage using AWS S3, Digital Ocean Spaces
 * Description: Configure AWS S3 and CloudFront dynamically for your WordPress site with a wizard-based UI and advanced sync options.
 * Version: 1.4
 * Author: Infinitietech
 * Author URI: https://infinitietech.com/
 * Text Domain: smartsync-lite-media-offloader-and-assets-cdn
 * Domain Path: /languages/
 * License: GPL v2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 *
 * @package SmartSync
 * @company Infinitie Technologies <https://infinitietech.com/>
 *
 * This plugin simplifies the process of configuring AWS S3 and CloudFront for WordPress. It provides a wizard-based UI and advanced synchronization options.
 * Dependencies: Composer for autoLoading, Action Scheduler library for task scheduling.
 */


use SmartSyncS3\SMARL_SmartSync;

const SMARL_ASSET_VERSION_CODE = "1.1";

require_once __DIR__ . '/vendor/autoload.php';
require_once plugin_dir_path( __FILE__ ) . '/vendor/woocommerce/action-scheduler/action-scheduler.php' ;


$smartSync = new SMARL_SmartSync(plugin_root: __FILE__);
$smartSync->registerAutoload();
$smartSync->initializeActions();
$smartSync->initializeFilters();
$smartSync->initializeViews();

register_activation_hook(__FILE__, 'smarl_file_sync_queue_create_table');

function allow_json_uploads($mimes) {
    $mimes['json'] = 'application/json';
    return $mimes;
}
add_filter('upload_mimes', 'allow_json_uploads');

function smarl_file_sync_queue_create_table() {
    global $wpdb;

    $table_name = $wpdb->prefix . 'smarl_file_sync_queue';
    $charset_collate = $wpdb->get_charset_collate();

    $sql = "CREATE TABLE $table_name (
        id INT AUTO_INCREMENT PRIMARY KEY,
        path VARCHAR(255) NOT NULL,
        relative_path VARCHAR(255) NOT NULL,
        status ENUM('pending', 'in_progress', 'completed', 'failed') DEFAULT 'pending',
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    ) $charset_collate;";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta($sql);
}

