File: /var/www/innodrive/cron/reminder.php
<?php
define('CRON_ROOT', __DIR__ . '/');
define('SHORTINIT', true);
define( 'BASE_PATH', realpath(CRON_ROOT . '../public/') . '/' );
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');
}
define('WP_USE_THEMES', false);
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header, $wpdb, $phpmailer;
require(BASE_PATH . 'wp-load.php');
require(CRON_ROOT . 'wp-mock.php');
require(CRON_ROOT . 'wp-mailer.php');
require(BASE_PATH . 'wp-content/plugins/smtp-mailer/main.php');
require(BASE_PATH . 'wp-content/plugins/e-mailer/e-mailer.php');
require(BASE_PATH . 'wp-content/plugins/import/import.php');
require(BASE_PATH . 'api/v1/class/Reminder.php');
if (APPLICATION_ENV == 'production') {
$running = exec( "ps aux|grep " . basename( __FILE__ ) . "|grep -v grep|grep -v '/bin/sh'|wc -l" );
if ( $running > 1 ) {
Output::log( 'Another instance running. Exit!' );
exit;
}
}
$reminders = $wpdb->get_results('SELECT * FROM reminders WHERE status = 0 AND DATE_SUB(payment_date, INTERVAL 5 DAY) = \'' . date('Y-m-d') . '\' ORDER BY id ASC');
if (!empty($reminders)) {
foreach($reminders as $reminder) {
echo 'Reminder id: ' . $reminder->id . PHP_EOL;
Reminder::create( $reminder );
echo PHP_EOL;
}
} else {
echo 'No reminders' . PHP_EOL . PHP_EOL;
}