--- a/admin/importdatagov.php +++ b/admin/importdatagov.php @@ -1,7 +1,7 @@ prepare($contractNoticeInsertQ); +$contractNoticeUpdateQ = 'UPDATE contractnotice SET ("' . implode('" , "', $contractNoticeFields) . '") = ( '; +foreach ($contractNoticeFields as $key => $f) { + $contractNoticeUpdateQ.= ($key == 0 ? "" : ", ") . "?"; +} +$contractNoticeUpdateQ.= ') where "CNID" = ?;'; +$contractNoticeUpdateQ = $conn->prepare($contractNoticeUpdateQ); + function processFile($fpath) { - global $conn, $contractNoticeFields, $contractNoticeInsertQ; + global $conn, $contractNoticeFields, $contractNoticeInsertQ, $contractNoticeUpdateQ; $row = 1; $success = 0; ini_set('auto_detect_line_endings',TRUE); @@ -59,6 +67,7 @@ //"t" mode string translates windows line breaks to unix $datamapping0712 = array( +// "_id" => "", "Agency Name" => "agencyName", "Parent Contract ID" => "parentCN", "Contract ID" => "CNID", @@ -70,10 +79,11 @@ "Description" => "description", "Agency Ref ID" => "agencyID", "UNSPSC Code" => "categoryUNSPSC", - "Title" => "category", + "UNSPSC Title" => "category", "Procurement Method" => "procurementMethod", "ATM ID" => "atmID", "SON ID" => "SONID", + "Panel Arrangement" => "SONPanelArrangement", "Confidentiality Contract Flag" => "confidentialityContract", "Confidentiality Contract Reason" => "confidentialityContractReason", "Confidentiality Outputs Flag" => "confidentialityOutputs", @@ -87,7 +97,7 @@ "Supplier Postcode" => "supplierPostcode", "Supplier Country" => "supplierCountry", "Supplier ABN Exempt" => "supplierABNExempt", - "ABN" => "supplierABN", + "Supplier ABN" => "supplierABN", "Contact Name" => "", "Contact Phone" => "", "Branch" => "contactBranch", @@ -102,7 +112,7 @@ $num = count($data); if ($row == 1) { $headers = $data; - } elseif ($row > 1) { + } elseif ($row >30000 && $row < 59000) { if ($num > count($datamapping0712)) { die("Error in data import; data mapping fields out of bounds or changed $num > ".count($datamapping0712)."
" . $fpath . print_r($data)); } @@ -129,7 +139,8 @@ $contractNoticeInsert[] = null; } } elseif (($datamapping0712[$headers[$c]]) == "amendDate" || ($datamapping0712[$headers[$c]]) == "publishDate" || ($datamapping0712[$headers[$c]]) == "contractStart" || ($datamapping0712[$headers[$c]]) == "contractEnd") { - $contractNoticeInsert[] = date('Y-m-d H:i:s', strtotime($data[$c])); +//echo $datamapping0712[$headers[$c]]." ".$data[$c]." ".date('Y-m-d H:i:s', strtotime(str_replace('/','-',$data[$c])))."\n"; + $contractNoticeInsert[] = date('Y-m-d H:i:s', strtotime(str_replace('/','-',$data[$c]))); } else { if (strstr("\" =", $data[$c] > 0)) { die("Invalid Description field" . $contractNoticeInsert); @@ -141,12 +152,14 @@ } } flush(); - //print_r($contractNoticeInsert); - $contractNoticeInsertQ->execute($contractNoticeInsert); +// print_r($contractNoticeInsert); + /* $contractNoticeInsertQ->execute($contractNoticeInsert); $errors = $conn->errorInfo(); if ($errors[1] == 7 && strpos($errors[2], "duplicate key")) { - // echo "dupe
"; - } elseif ($errors[1] == 0) { + echo "dupe {$data[2]} row $row
\n"; + } else { + if ($errors[1] == 0) { + echo "success insert {$data[2]} row $row
\n"; $success++; } else { foreach ($contractNoticeFields as $key => $cnf) { @@ -154,8 +167,32 @@ } echo $data[2] . " failed CN insert.
" . print_r($errors, true) . "
row $row

\n"; } +}*/ + + + $contractNoticeUpdate = $contractNoticeInsert; + $contractNoticeUpdate[] = $data[2]; +#var_dump($contractNoticeUpdate); + /*$i =0; + while($i < 35) { + echo "{$contractNoticeFields[$i]} : {$contractNoticeUpdate[$i]}
"; + $i++; + }*/ + $contractNoticeUpdateQ->execute($contractNoticeUpdate); + $errors = $conn->errorInfo(); + + if ($errors[1] == 0) { + // echo "success update {$data[2]} row $row
\n"; + $success++; + } else { + foreach ($contractNoticeFields as $key => $cnf) { + echo var_dump($contractNoticeUpdate[$key]) . $cnf . "
"; + } + echo $data[2] . " failed CN update.
" . print_r($errors, true) . "
row $row

\n"; + } flush(); + //die('endlol'); //echo "
\n"; } $row++; @@ -200,10 +237,10 @@ // if ($success > 0) { $conn->exec("update datasets set \"lastUpdated\" = NOW() where title = 'Contract Notices'"); - echo "link amend
"; + /*echo "link amend
"; include ("linkAmendments.php"); echo "update UNSPSC
"; - include ("updateUNSPSC.php"); + include ("updateUNSPSC.php");*/ } // cn