File: //var/www/innodrive/cron/import.php
<?php
define('CRON_ROOT', __DIR__ . '/');
define('SHORTINIT', true);
define( 'BASE_PATH', realpath(CRON_ROOT . '../public/') . '/' );
define('WP_USE_THEMES', false);
if( php_sapi_name() !== 'cli' ) {
die("Meant to be run from command line");
}
if (!empty($argv[1])) {
define('APPLICATION_ENV', $argv[1]);
} else {
define('APPLICATION_ENV', 'production');
}
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header, $wpdb;
require(BASE_PATH . 'wp-load.php');
require(BASE_PATH . 'wp-content/plugins/import/import.php');
$task = $wpdb->get_row('SELECT * FROM import WHERE status = 0 ORDER BY created_at ASC');
if (!empty($task)) {
echo 'Import task: ' . $task->id . PHP_EOL;
$wpdb->update('import', [
'status' => 1,
'updated_at' => date('Y-m-d H:i:s')
], [
'id' => $task->id
]);
parseFile($task);
$wpdb->update('import', [
'status' => 2,
'updated_at' => date('Y-m-d H:i:s')
], [
'id' => $task->id
]);
} else {
echo 'No tasks' . PHP_EOL . PHP_EOL;
}