| 1 |
<?php |
| 2 |
|
| 3 |
defined('ABSPATH') or die; |
| 4 |
|
| 5 |
use FluentSupport\Framework\Foundation\Application; |
| 6 |
use FluentSupport\App\Hooks\Handlers\ActivationHandler; |
| 7 |
use FluentSupport\App\Hooks\Handlers\DeactivationHandler; |
| 8 |
|
| 9 |
return function ($file) { |
| 10 |
|
| 11 |
require_once FLUENT_SUPPORT_PLUGIN_PATH . 'vendor/woocommerce/action-scheduler/action-scheduler.php'; |
| 12 |
|
| 13 |
register_activation_hook($file, function () { |
| 14 |
(new ActivationHandler)->handle(); |
| 15 |
}); |
| 16 |
|
| 17 |
register_deactivation_hook($file, function () { |
| 18 |
(new DeactivationHandler)->handle(); |
| 19 |
}); |
| 20 |
|
| 21 |
add_action('plugins_loaded', function () use ($file) { |
| 22 |
$application = new Application($file); |
| 23 |
|
| 24 |
$currentDbVersion = get_option('fluent_support_db_version'); |
| 25 |
if (!$currentDbVersion || version_compare($currentDbVersion, FLUENT_SUPPORT_DB_VERSION, '<')) { |
| 26 |
\FluentSupport\Database\DBMigrator::run(); |
| 27 |
update_option('fluent_support_db_version', FLUENT_SUPPORT_DB_VERSION, 'no'); |
| 28 |
} |
| 29 |
|
| 30 |
do_action('fluent_support_loaded', $application); |
| 31 |
do_action('fluent_support_addons_loaded', $application); |
| 32 |
|
| 33 |
// add_action('init', function () { |
| 34 |
// load_plugin_textdomain('fluent-support', false, 'fluent-support/language/'); |
| 35 |
// }); |
| 36 |
|
| 37 |
add_action('fluent_support/admin_app_loaded', function () { |
| 38 |
if (!wp_next_scheduled('fluent_support_hourly_tasks')) { |
| 39 |
wp_schedule_event(time(), 'hourly', 'fluent_support_hourly_tasks'); |
| 40 |
} |
| 41 |
|
| 42 |
if (!wp_next_scheduled('fluent_support_daily_tasks')) { |
| 43 |
wp_schedule_event(time(), 'daily', 'fluent_support_daily_tasks'); |
| 44 |
} |
| 45 |
|
| 46 |
if (!wp_next_scheduled('fluent_support_weekly_tasks')) { |
| 47 |
wp_schedule_event(time(), 'weekly', 'fluent_support_weekly_tasks'); |
| 48 |
} |
| 49 |
|
| 50 |
global $wpdb; |
| 51 |
$table = esc_sql($wpdb->prefix . 'fs_tickets'); |
| 52 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $table is sanitized via esc_sql(); no user input. |
| 53 |
$column_exists = $wpdb->get_var("SHOW COLUMNS FROM `{$table}` LIKE 'serial_number'"); |
| 54 |
if ($column_exists) { |
| 55 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 56 |
$has_null = $wpdb->get_var("SELECT id FROM `{$table}` WHERE `serial_number` IS NULL LIMIT 1"); |
| 57 |
if ($has_null) { |
| 58 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 59 |
$wpdb->query("UPDATE `{$table}` SET `serial_number` = `id` WHERE `serial_number` IS NULL"); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
/* |
| 64 |
* The below schedule is powered by Action Scheduler by WooCommerce |
| 65 |
* It will run every 30 minutes. |
| 66 |
*/ |
| 67 |
if (false === as_next_scheduled_action('fluent_support_half_hourly')) { |
| 68 |
as_schedule_recurring_action(time(), 1800, 'fluent_support_half_hourly', [], 'fluent-support', true); |
| 69 |
} |
| 70 |
|
| 71 |
}); |
| 72 |
|
| 73 |
}); |
| 74 |
}; |
| 75 |
|