file_put_contents($my_data_dir . "/paypal_ds.log", print_r($ret, true) . " \n cdata:" . print_r($cdata, true) . "\n reply:" . print_r($host_reply, true) . "\n pgerr:" . pg_errormessage() . "\n", FILE_APPEND); $resp = "system error, unable update client in database. Please contact support."; file_put_contents($my_data_dir . "/" . $hash . ".prc", "100"); file_put_contents($my_data_dir . "/" . $hash . ".resp", $resp); die; } } else { if (1 != pg_affected_rows(@pg_query("insert into client (iname, ikey, ihash, ieml, cname, sftplogin, sftppwd,idate, todo, iparent, active, app ) values ('{$company_name}',{$ikey},'{$hash}','{$eml}','{$contact_name}','{$sftplog}','{$sftppwd}',CURRENT_TIMESTAMP,1,{$parent_key}, 1, {$capsidea_appid})"))) { file_put_contents($my_data_dir . "/paypal_ds.log", date(DATE_ATOM) . " ERR CPS ERR: client {$eml} [{$company_name}] {$contact_name} l: {$sftplog} p: {$sftppwd} \n", FILE_APPEND); file_put_contents($my_data_dir . "/paypal_ds.log", print_r($ret, true) . " \n cdata:" . print_r($cdata, true) . "\n reply:" . print_r($host_reply, true) . "\n pgerr:" . pg_errormessage() . "\n", FILE_APPEND); $resp = "system error, unable to insert client into database. Please contact support."; file_put_contents($my_data_dir . "/" . $hash . ".prc", "100"); file_put_contents($my_data_dir . "/" . $hash . ".resp", $resp); die; } } // all ok, proceed to cps // create json for DB if (0 == $parent_key) { $source_id = $ikey; } else { $source_id = $parent_key; } $resp = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<script type=\"text/javascript\" src=\"http://beta.capsidea.com/api.js\"></script><script>CI.updateSource({$ikey});CI.closeApp();</script>\n<title>Success</title><link rel=\"stylesheet\" type=\"text/css\" href=\"view.css\" media=\"all\"></head><body id=\"main_body\"\n<img id=\"top\" src=\"top.png\" alt=\"\"><div id=\"form_container\"><h1><b>Source {$ikey} created</b></h1><br>\n<div id=\"footer\"></div></div><img id=\"bottom\" src=\"bottom.png\" alt=\"\"></body></html>"; // report time and mem $mem = floor(memory_get_peak_usage(true) / (1024 * 1024)); $full_time = get_timer() - $stime1; mystat("signup [{$ikey}] mem: {$mem} MB list: {$list_time} upload: {$cps_time} size: {$fsize} MB full: {$full_time}"); file_put_contents($my_data_dir . "/" . $hash . ".resp", $resp); file_put_contents($my_data_dir . "/" . $hash . ".prc", "100"); die;
function link_merchant_data($merchant_cube_id, $dbconn) { global $dbg; $merchant = array(); $txn = array(); $dbg = $dbg . "linking client data {$merchant_cube_id} \n"; //die(); $dbg = $dbg . "\nloading merchant data ..."; $pgres = pg_query($dbconn, "select mid from merchant where mid<>'' and idate is null and ikey={$merchant_cube_id};"); $mcount = pg_num_rows($pgres); while ($row2 = @pg_fetch_assoc($pgres)) { $merchant[$row2["mid"]] = 0; } pg_free_result($pgres); $dbg = $dbg . "({$mcount}) done"; $dbg = $dbg . "\nloading txn data ..."; $qry = "select mid, stop_ts from txn where ikey={$merchant_cube_id} and mid<>'';"; $res = @pg_query($qry); if (false === $res) { $qr = pg_errormessage($dbconn); log_fatal("ERR error {$qr} \n count=" . count($merchant)); } $tcount = pg_num_rows($res); while ($row2 = @pg_fetch_assoc($res)) { if (isset($merchant[$row2["mid"]])) { $merchant[$row2["mid"]] = $row2["stop_ts"]; } } pg_free_result($res); $dbg = $dbg . "({$tcount}) done"; $i = 0; $lines = 0; foreach ($merchant as $key => $value) { if (0 == $value) { continue; } // empty data $qry = "update merchant set idate='" . $value . "' where ikey={$merchant_cube_id} and mid='{$key}'"; $res = pg_query($qry); if (false === $res) { $qr = pg_errormessage($dbconn); log_fatal("ERR error in {$qry} \n{$qr}"); } $lines++; $i++; if ($i > 10000) { @pg_query("commit;"); //echo "*"; @pg_query("begin;"); $i = 0; } } @pg_query("commit;"); unset($txn); unset($merchant); $mem = floor(memory_get_peak_usage(true) / (1024 * 1024)); mystat("link merchant stat {$merchant_cube_id} lines: {$mcount} rlines: {$lines} txn: {$tcount} mem: {$mem} MB\n"); return $lines; }