File: /var/www/content-sp/cron/new_sp_data_replace.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include 'new_sp_config.php';
$start_time = microtime(true);
echo " Start time: " . $start_time . " seconds ".date('Y-m-d H:i:s');
// $curDate = date('Y-m-d',strtotime('-1 days'));
$curDate = date('Y-m-d');
$SP_QUESTION = 'csp_sp_question';
$SP_QUESTION_MEDIUM_WISE = 'csp_sp_question_medium_wise';
echo "Query run on :".$curDate.PHP_EOL;
# get last updated questions
$getQuestions = $live->query("SELECT question_id,question_of FROM $SP_QUESTION where question_flag IN('1','2') and (date(add_date)='$curDate' OR date(last_update_on)='$curDate')");
$i = 1;
while ($q = $getQuestions->fetch_assoc()) {
$qID = $q['question_id'];
$quesOf = $q['question_of'];
$repo = json_decode($quesOf);
if ($quesOf != '' && $qID !='') {
if ((sizeof($repo) == '1') && (in_array('sarkari-pariksha', $repo))) {
# update to sarkari-pariksha
$updateToSp = $live->query("REPLACE into h7382406836182.wp_aat93akkcv_sp_question SELECT * FROM $SP_QUESTION where question_id='$qID'");
echo $i."-Ques :".$qID.'-'.$quesOf.PHP_EOL;
} else if ((sizeof($repo) == '1') && (in_array('csc-olympiad', $repo))) {
# update to csc-olympiad
$updateToOly = $live->query("REPLACE into cscolydb.wp_aat93akkcv_sp_question SELECT * FROM $SP_QUESTION where question_id='$qID'");
echo $i."-Ques :".$qID.'-'.$quesOf.PHP_EOL;
} else if ((sizeof($repo) == '2')) {
# update to both
$updateToSp = $live->query("REPLACE into h7382406836182.wp_aat93akkcv_sp_question SELECT * FROM $SP_QUESTION where question_id='$qID'");
$updateToOly = $live->query("REPLACE into cscolydb.wp_aat93akkcv_sp_question SELECT * FROM $SP_QUESTION where question_id='$qID'");
echo $i."-Ques :".$qID.'-'.$quesOf.PHP_EOL;
}
} else {
echo 'empty'.PHP_EOL;
}
$i++;
}
$end_time = microtime(true);
$execution_time = ($end_time - $start_time);
echo " Execution time: " . $execution_time . " seconds ".date('Y-m-d H:i:s');