3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /* */ /* * ssi_update.php * * CRON Script to directly maintain SSI's DB containing list of our members and profile survey answers. * Makes use of SSI's Bulk Import API using RESTful model to perform updates. RESTful requests made using cURL connections. * Only deletions and additons are performed. Once member is created in SSI's DB, updates are not done. * * @dependencies BatchProcessLogging, SSI, SSI_db, SSI_api * Derives from cint_update.php * @author Dave Buchanan * @version 1.0 * @created 20150227 */ require_once '_variables.php'; require_once '_classes/class.MarsImportToSsi.php'; //SSI Class for API requests ini_set( 'memory_limit', '1024M' ); // initially added to try to fix Out of Memory error set_time_limit(0); $debug=1; // 0=no echo output, just batch logging, 1=batch and echo out, 2= only echo out ///Bulk is the flag needs to be passed in like --bulk $extra_options= getopt('P:L:',array('bulk','redo')); //Decide if we're doing bulk full export to csv OR api import calls $type = (isset($extra_options['bulk'])) ? 'bulk' : 'api'; ///Special flag to redo import run, doesn't drop/create/repopulate partner tables $redo = (isset($extra_options['redo'])) ? true : false; /* Init SSI class and start logging */ $ssi = new SSI(basename(__FILE__),$debug,$cli_options['L'], $cli_options['P'],$type); $ssi->startLog(); $ssi->logComment("Started"); if($redo) { $ssi->logComment("REDO RUN!!!!!!!!!!!!!!!!!!!!!!!!!!! NOT GOING TO DROP PREV AND RECREATE PARTNER TABLES!!"); $ssi->sendEmailAlert("REDO RUN STARTED!!!!!!!!!!!!!!!!!!!!!!!!!!! NOT GOING TO DROP PREV AND RECREATE PARTNER TABLES!!"); } $exec_results = $ssi->alreadyRunning(); if ( (int)$exec_results[0] > 1 ) { $ssi->logComment("Process already started. Existing."); $ssi->logFinish( 'Finished: ' . $batchProcessLogging->getElapsedBatchExecutionTime(true)); exit(); } /* Init SSI Database class, pass in main SSI */ $ssi_db = new SSI_db($ssi); if($redo===false) { /* Check 1: Make sure member_partner_integration table has rows */ $check1 = $ssi_db->checkMemberPartnerIntegration(); if($check1===false) exit(0); else $ssi->logComment('Completed 1st validation, member_partner_integration not empty'); /* If exists, drop ssi_member_list_prev table and recreate from ssi_member_list */ $result = $ssi_db->dropMemberListPrev(); $result = $ssi_db->createMemberListPrev(); /* Re-create ssi_member_list from member_partner_integration. */ $result = $ssi_db->populateMemberList(); $ssi->logComment('Completed table maintainence'); /* Check 2: If counts are the same then no new members were added, something is wrong */ $check2 = $ssi_db->compareMemberListCounts(); if($check2===false) exit(0); else $ssi->logComment('Completed 2nd validation, ssi_member_list and ssi_member_list_prev counts are NOT the same'); /* Remove duplicates from Sendearnings, don't allow member email to receive surveys from both sites, inboxdollars and sendearnings */ if ($ssi->getSite() == 'sendearnings') { $ssi->logComment('Deleting duplicate members for sendearings'); $ssi_db->deleteDuplicateSEMembers(); } } else { $ssi->logComment("Redo run set, reimporting the same members! Not doing any table maintainence for ssi_member_list, ssi_member_list_prev"); } /* Get FEATURES matched in survey_partner_xref */ $result = $ssi_db->getQuestionFromSurveyPartnerXref(); ///Default 4 labels to INTEGER type question that won't exist in survey_partner_xref ///They come from survey_result_dob and member_status table $int_feature_lbls = array('postalcode','monthdob','daydob','yeardob'); $feature_lbls = array(); while( $row = mysql_fetch_assoc($result) ) { if ( !empty($row['survey_partner_question_desc']) ) array_push($feature_lbls,$row['survey_partner_question_desc']); } if($ssi->getType() == 'bulk') { $ssi->logComment("Preparing to add members to bulk csv."); $result = $ssi_db->getSurveyMembers($feature_lbls,false); ///EXPORT CSV PATH $file_name = './'.$ssi->getSite().'_export.csv'; $header = 'id,'; $header .= implode(',',$int_feature_lbls); $header .= ','.implode(',',$feature_lbls); ///Write header $z = file_put_contents($file_name,$header.PHP_EOL); } else { $ssi->logComment("Preparing to use SSI API to send members in batches"); $result = $ssi_db->getSurveyMembers($feature_lbls,true); $members = array(); $ssi_api = new SSI_api($ssi); } $total_required_features = count($feature_lbls) + count($int_feature_lbls)+1; ///Some counters to track stuff $members_skipped=0; $members_added=0; $number_of_batches=0; while( $row = mysql_fetch_assoc($result) ) { //Dont send to partner if not equal to features expected if(count($row) !== $total_required_features) { $ssi->logComment("Member ".$row['respondentid'].") doesn't have enough required features...Has ".count($row)." needs to have ".$total_required_features."."); $members_skipped++; } else { //IF bulk then append to csv, otherwise add to array and determine if ready to send a batch if($ssi->getType() == 'bulk') { $z = file_put_contents($file_name,implode(',',$row).PHP_EOL, FILE_APPEND); } else { ///Assemble json for members, member_code (respondentID) is first value while the rest should match the $feature_lbls array_push($members,array( 'respondentID'=>array_shift($row), 'values'=>array_values($row))); if(($members_added+1) % $ssi_api->getBatchCount() === 0) { $batch_result = $ssi_api->sendBatch($members,array_merge($int_feature_lbls,$feature_lbls)); ///If batch result isn't false add failed submissions to members skipped, else add current count of members $members_skipped = ($batch_result!=false) ? $members_skipped + $batch_result : $members_skipped+count($members); $number_of_batches++; ///Reset array for next batch $members = array(); } } $members_added++; } } /* END loop through members */ $ssi_db->freeResult($result); $total_sent = $members_added-$members_skipped; if($ssi->getType()!='bulk') { $ssi->logComment("Ran ".$number_of_batches." batches. Total of $members_added members to $type export. $members_skipped members skipped, total sent=$total_sent"); } else { $ssi->logComment("Added $members_added members to $type export. $members_skipped members skipped, total sent=$total_sent"); } $ssi->sendEmailFinish("Completed! $type...$members_added members added. $members_skipped members skipped, total sent=$total_sent"); $ssi->endLog("Finished $type import."); // END ASSEMBLING JSON TO SEND TO SSI // ***************************************************************************///
based on K2fjU
Output for 5.4.0 - 7.2.0
Warning: require_once(_variables.php): failed to open stream: No such file or directory in /in/b2W0Z on line 18 Fatal error: require_once(): Failed opening required '_variables.php' (include_path='.:') in /in/b2W0Z on line 18
Process exited with code 255.