Created
September 30, 2013 19:37
-
-
Save gmilby/6768976 to your computer and use it in GitHub Desktop.
replacing perl scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/sw/php/bin/php | |
| <?php | |
| $file = __FILE__; | |
| $filename = basename($file); | |
| $instances = `ps -Af | grep 'php .*$filename' | grep -v 'grep' | wc -l`; | |
| $instances = intval(trim($instances)); | |
| if($instances > 1) | |
| { | |
| print "$filename is already running! ($instances)\n##ScriptDashStatus=-2\n"; | |
| return; | |
| } | |
| $opts = getopt('dvthqm::'); | |
| if(isset($opts['h'])) | |
| { | |
| print <<<USAGE | |
| $file [-dvmthr] | |
| -h : Show help output | |
| -d : Show Debug Statements | |
| -v : Verbose Output | |
| -t : Use testing DB/Paths | |
| -n : Use to specify a division | |
| -q : Show query times | |
| USAGE; | |
| return; | |
| } | |
| $verbose = isset($opts['v']); | |
| $debug = isset($opts['d']); | |
| $query = isset($opts['q']); | |
| $test = isset($opts['t']); | |
| $division = isset($opts['n']) ? $opts['n'] : false; | |
| $hostname = gethostname(); | |
| ini_set('include_path', ini_get('include_path').':/data/web/phpexcel/Classes:/data/web/php-inc'); | |
| require_once("constants.inc"); | |
| require_once("DAO/Schema.inc"); | |
| require_once("DAO/DataObject.inc"); | |
| require_once("DAO/DBFactory.inc"); | |
| require_once(MODULES."eng/lib/DAO/System.inc"); | |
| $_SESSION['DEBUG'] = PHP_ERRORS | DB; error_reporting(E_ALL); | |
| $DB = DBFactory::create(DBFactory::CON_REP); | |
| $DB_WEB = DBFactory::create(DBFactory::CON_WEB); | |
| $env = $test ? 'Development' : 'Production'; | |
| for($fkM=3; $fkM<=7; $fkM++){ | |
| for($dom=11;$dom<=26;$dom++){ | |
| $doIt = false; | |
| $calls = array(); | |
| $toDelete = array(); | |
| echo "fkMarket:$fkM DOM:$dom\nSelecting...\n"; | |
| $partition = "p".$fkM."_".$dom; | |
| $selector = "SELECT * FROM workOrder.customerCalls PARTITION($partition)"; | |
| $result = $DB->select($selector); | |
| foreach($result as $row){ | |
| if(isset($calls[$row->account."_".$row->datetime])){ | |
| $toDelete[$row->account."_".$row->datetime] = $row; | |
| $doIt = true; | |
| }else{ | |
| $calls[$row->account."_".$row->datetime] = true; | |
| } | |
| } | |
| if($doIt){ | |
| echo "Total to delete:".count($toDelete)."\n"; | |
| $count = 0; | |
| foreach($toDelete as $acctDate=>$row){ | |
| list($account, $datetime) = explode("_", $acctDate); | |
| $deleter = "DELETE FROM workOrder.customerCalls WHERE fkMarket={$row->fkMarket} AND DOM={$row->DOM} AND account=$account and `datetime`='$datetime'"; | |
| if(++$count%10===0) echo "."; | |
| $DB->execute($deleter); | |
| } | |
| echo "Done deleting!\nInserting..."; | |
| $inserter = "INSERT INTO workOrder.customerCalls (fkMarket, DOM, fkSystem, Hub, Node, account, datetime, cable, data, phone, wireless, security, tzOffset) VALUES "; | |
| $chunks = array_chunk($toDelete, 500); | |
| foreach($chunks as $chunk){ | |
| $i = array(); | |
| foreach($chunk as $call){ | |
| $i[] = "($call->fkMarket, $call->DOM, $call->fkSystem, '$call->Hub', '$call->Node', $call->account, '$call->datetime', $call->cable, $call->data, $call->phone, $call->wireless, $call->security, $call->tzOffset)"; | |
| } | |
| #echo $inserter.implode(",",$i); | |
| $DB->execute($inserter.implode(",",$i)); | |
| } | |
| echo "Done Inserting!\n"; | |
| echo "Sleeping..."; | |
| sleep(180); | |
| } | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment