forked from nyuhsl/data-catalog
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9acae1f
commit f064243
Showing
47 changed files
with
1,987 additions
and
263 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
#$db_output_url = '<BASE URL OF YOUR DATA CATALOG INSTALLATION>/api/dataset/all.json'; | ||
#$solr_output_url = '<BASE URL OF YOUR SOLR INSTALLATION>/solr/collection1/select/?q=*:*&wt=json'; | ||
#$solr_submit_url = '<BASE URL OF YOUR SOLR INSTALLATION>/solr/data_catalog/update/json?commit=true&overwrite=true'; | ||
#$solr_remove_url = '<BASE URL OF YOUR SOLR INSTALLATION>/solr/data_catalog/update/?commit=true'; | ||
|
||
$db_output_url = 'http://testbox1.hsls.pitt.edu/data/api/dataset/all.json'; | ||
$solr_output_url = 'http://testbox1.hsls.pitt.edu:8983/solr/collection1/select/?q=*:*&wt=json'; | ||
$solr_submit_url = 'http://testbox1.hsls.pitt.edu:8983/solr/collection1/update/json?commit=true&overwrite=true'; | ||
$solr_remove_url = 'http://testbox1.hsls.pitt.edu:8983/solr/collection1/update/?commit=true'; | ||
|
||
|
||
if (! $fh = fopen($db_output_url, 'r')) { | ||
exit("Could not open '{$db_output_url}'\n"); | ||
} | ||
|
||
$db_json = stream_get_contents($fh); | ||
$db_json_parsed = json_decode($db_json); | ||
|
||
fclose($fh); | ||
|
||
# | ||
# Find items to remove | ||
|
||
if (! $fh = fopen($solr_output_url, 'r')) { | ||
exit("Could not open '{$solr_output_url}'\n"); | ||
} | ||
|
||
$solr_json = stream_get_contents($fh); | ||
|
||
fclose($fh); | ||
|
||
foreach (json_decode($solr_json)->response->docs as $row) { | ||
|
||
$found=0; | ||
foreach($db_json_parsed as $db_row) { | ||
|
||
if ($row->id == $db_row->id) { | ||
$found=1; | ||
break; | ||
} | ||
|
||
} | ||
if ($found!=1) { | ||
|
||
$to_solr = "{'delete': {'id': ".$row->id."}}"; | ||
$context = stream_context_create([ | ||
'http' => [ | ||
'method' => 'POST', | ||
'header' => 'Content-Type: application/json' . "\r\n" | ||
. 'Content-Length: ' . strlen($to_solr) . "\r\n", | ||
'content' => $to_solr, | ||
] | ||
]); | ||
|
||
file_get_contents($solr_remove_url, null, $context); | ||
print "delete ".$row->id."\n"; | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
# | ||
# Find new/added items | ||
|
||
foreach ($db_json_parsed as $row) { | ||
if ($row->dataset_end_date && $row->dataset_start_date) { | ||
$end_date = $row->dataset_end_date; | ||
if ('Present' == $row->dataset_end_date) { | ||
$end_date = (int) (date('Y') + 1); | ||
} | ||
|
||
if ($row->dataset_start_date == $end_date) { | ||
$row->dataset_years = ["{$row->dataset_start_date}-01-01T00:00:00Z","{$end_date}-01-01T00:00:00Z"]; | ||
} | ||
else { | ||
$row->dataset_years = []; | ||
for ($i = $row->dataset_start_date; $i <= $end_date; $i++) { | ||
$row->dataset_years[] = "{$i}-01-01T00:00:00Z"; | ||
} | ||
} | ||
} | ||
|
||
foreach ($row as $k => $v) { | ||
if (! $v) { | ||
$row->{$k} = ''; | ||
} | ||
} | ||
if ($row->date_added) { | ||
$from_symfony = $row->date_added->date; | ||
$row->date_added = trim(explode(' ', $from_symfony)[0]) . 'T00:00:00Z'; | ||
} | ||
|
||
$to_solr = json_encode([$row]); | ||
echo $to_solr; | ||
|
||
$context = stream_context_create([ | ||
'http' => [ | ||
'method' => 'POST', | ||
'header' => 'Content-Type: application/json' . "\r\n" | ||
. 'Content-Length: ' . strlen($to_solr) . "\r\n", | ||
'content' => $to_solr, | ||
] | ||
]); | ||
|
||
file_get_contents($solr_submit_url, null, $context); | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.