Advertisement
iamdangavin

Cron

Sep 7th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.78 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * LSCU FACU DATA NIGHTLY MIGRATION BY CUSG
  5.  * SCRIPT SHOULD RUN NIGHTLY AT 2 AM EST AS CRON JOB
  6.  *
  7.  * CRON TIME OPTION:  0 2 * * *
  8.  *
  9.  * CRON COMMAND OPTIONS:
  10.  * php /path/to/script/cu_finder_cron.php
  11.  * OR
  12.  * wget -q -O /dev/null http://siteURL.org/path_to_script_from_doc_root/cu_finder_cron.php
  13.  *
  14.  * PLEASE CONTACT SUPPORT@CUSOLUTIONSGROUP.COM WITH ISSUES - SUBJECT "LSCU CRON ISSUES"
  15.  *
  16.  */
  17.  
  18. // SET MySQL Parameters - DEFINED BY LSCU in CU-SOLUTIONS-DATA/CU-BRANCHES.PHP
  19. $dbhost = "localhost";
  20. $dbuser = "scoutbra";
  21. $dbpass = "J0S#n1Bo0";
  22. $dbname = "scoutbra_wrd1";
  23.  
  24. // EMAIL ERRORS - PLEASE LEAVE THE TDB@MCUL.ORG/GZD@MCUL.ORG ADDRESSES IN THERE FOR TRACKING ON OUR END.  ADD ADDITONAL ADDRESSES, SEPARATED BY COMMAS
  25. $errorto = 'tdb@mcul.org,gzd@mcul.org, dan@scoutbrand.com';
  26. $errorsub = 'LSCU FACU DATA MIGRATION ERROR';
  27. $successsub = 'LSCU FACU DATA MIGRATION COMPLETED';
  28. $errormess = '';
  29. $errorfrom = 'noreply@cu-village.com';
  30.  
  31. /*
  32.  * PLEASE DO NOT EDIT ANYTHING BELOW THIS LINE!!!!
  33.  */
  34.  
  35. // VARS
  36. $buffer = '';
  37. $sqlstatements = array();
  38. $sqldata = '';
  39.  
  40. // TOKENIZED HASH TO PASS
  41. $TOKEN = 'CC56534uydR3w00-23DDf4Izzpl-09345';
  42. $hashtok = md5($TOKEN);
  43.  
  44. // CALL TO FIND A CU SCRIPT
  45.  
  46. $fields ="hashtok=".urlencode($hashtok);
  47.  
  48.         $ch=curl_init("https://natcufinder.secure.cu-village.com/client/lscu_finder/index.php");
  49.         curl_setopt($ch, CURLOPT_HEADER, 0);
  50.         curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); // set the fields to post
  51.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  52.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // make sure we get the response back
  53.  
  54.         $buffer = curl_exec($ch); // execute the post
  55.  
  56.         curl_close($ch); // close our session
  57.        
  58.        
  59. if(empty($buffer) || $buffer == '-1'){
  60.     // FAILED
  61.     $errormess = 'Failed to communicated correctly with CUSG API';
  62.     mail($errorto,$errorsub,$errormess,'From:'.$errorfrom);
  63. }else{
  64.     // EXECUTE SQL CALLS
  65.     $dblink = mysql_connect($dbhost,$dbuser,$dbpass);
  66.     if (!$dblink) {
  67.         $errormess = 'Failed to login correctly to MySQL service: '. mysql_error();
  68.         mail($errorto,$errorsub,$errormess,'From:'.$errorfrom);
  69.         die('Could not connect: ' . mysql_error());
  70.     }
  71.    
  72.     $db_selected = mysql_select_db($dbname,$dblink);
  73.     if (!$db_selected) {
  74.         $errormess = 'Failed to communicated correctly with local DB: '. mysql_error();
  75.         mail($errorto,$errorsub,$errormess,'From:'.$errorfrom);
  76.         die ('Can\'t use WordPress DB: ' . mysql_error());
  77.     }
  78.    
  79.     $sqlstatements = explode("\n",$buffer);
  80.     foreach($sqlstatements as $query){
  81.         $query = trim($query);
  82.         if($query != ''){
  83.             $res = mysql_query($query,$dblink);        
  84.         }
  85.     }
  86.    
  87.     $errormess = 'Nightly data migration completed';
  88.     mail($errorto,$successsub,$errormess,'From:'.$errorfrom);
  89.    
  90. }
  91.  
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement