beginning of export merge
[disclosr.git] / admin / importContractDashboardAgencies.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
 
require_once '../include/common.inc.php';
try {
    $server->create_db('disclosr-agencies');
} catch (SetteeRestClientException $e) {
    setteErrorHandler($e);
}
$db = $server->get_db('disclosr-agencies');
createAgencyDesignDoc();
$conn = new PDO("pgsql:dbname=contractDashboard;user=postgres;password=snmc;host=localhost");
$namesQ = 'select agency.abn, string_agg("agencyName",\'|\') as names from agency inner join agency_nametoabn on agency.abn::text = agency_nametoabn.abn group by agency.abn;';
$abntonames = Array();
foreach ($conn->query($namesQ) as $row) {
    $abntonames[$row['abn']] = explode("|", $row['names']);
}
$result = $conn->query("select * from agency");
while ($agency = $result->fetch(PDO::FETCH_ASSOC)) {
    $agency['_id'] = md5($agency['abn']);
    $agency['otherNames'] = $abntonames[$agency['abn']];
    if (sizeof($abntonames[$agency['abn']]) == 1)
        $agency['name'] = $abntonames[$agency['abn']][0];
    $agency["lastScraped"] = "1/1/1970";
    $agency["scrapeDepth"] = 1;
    try {
        $doc = $db->save($agency);
        //print_r($doc);
        echo $agency['abn'] . " imported \n<br>";
    } catch (SetteeRestClientException $e) {
        setteErrorHandler($e);
    }
}
?>