forked from science-ation/science-ation
- Use the prize name, rather than the external_identifier to identify the prize. It only has to be unique within each award, which it will be (all prizes should have a name).
This commit is contained in:
parent
6a3eacaf9a
commit
347d2d5a86
@ -153,59 +153,61 @@
|
|||||||
|
|
||||||
//update the prizes
|
//update the prizes
|
||||||
$prizes = $award['prizes'];
|
$prizes = $award['prizes'];
|
||||||
if(is_array($prizes) && count($prizes) > 0) {
|
if(!is_array($prizes)) {
|
||||||
echo i18n("Number of prizes: %1",array(count($prizes)))."<br />";
|
continue;
|
||||||
$pq=mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$award_id'");
|
}
|
||||||
//get a list of all the existing prizes
|
|
||||||
$existingprizes=array();
|
echo i18n("Number of prizes: %1",array(count($prizes)))."<br />";
|
||||||
while($pr=mysql_fetch_object($pq)) {
|
/* Get existing prizes */
|
||||||
$existingprizes[$pr->external_identifier]=$pr;
|
$pq=mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$award_id'");
|
||||||
|
$existingprizes=array();
|
||||||
|
while($pr=mysql_fetch_assoc($pq))
|
||||||
|
$existingprizes[$pr['prize']]=$pr;
|
||||||
|
|
||||||
|
|
||||||
|
/* Iterate over the downloaded pizes */
|
||||||
|
foreach($prizes AS $prize) {
|
||||||
|
//if it doesn't exist, add it
|
||||||
|
if(!array_key_exists($prize['prize_en'],$existingprizes)) {
|
||||||
|
/* Add a base entry, then update it below, yes it's two sql queries,
|
||||||
|
* but it's much shorter code, and means changing things in only
|
||||||
|
* one spot */
|
||||||
|
echo " ".i18n("Adding prize %1",array($prize['prize_en']))."<br />";
|
||||||
|
$p = mysql_escape_string(stripslashes($prize['prize_en']));
|
||||||
|
mysql_query("INSERT INTO award_prizes (award_awards_id,prize,year,external_identifier)
|
||||||
|
VALUES ('$award_id','$p','$year','$p')");
|
||||||
|
$prize_id = mysql_insert_id();
|
||||||
|
} else {
|
||||||
|
$ep=$existingprizes[$prize['prize_en']];
|
||||||
|
echo " ".i18n("Updating prize %1",array($ep['prize']))."<br />";
|
||||||
|
$prize_id = $ep['id'];
|
||||||
|
//remove it from the list
|
||||||
|
unset($existingprizes[$ep['prize']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($prizes AS $prize) {
|
mysql_query("UPDATE award_prizes SET
|
||||||
//if it doesn't exist, add it
|
cash='".intval($prize['cash'])."',
|
||||||
if(!array_key_exists($prize['identifier'],$existingprizes)) {
|
scholarship='".intval($prize['scholarship'])."',
|
||||||
/* Add a base entry, then update it below, yes it's two sql queries,
|
value='".intval($prize['value'])."',
|
||||||
* but it's much shorter code, and means changing things in only
|
prize='".mysql_escape_string($prize['prize_en'])."',
|
||||||
* one spot */
|
number='".intval($prize['number'])."',
|
||||||
echo " ".i18n("Adding prize %1",array($prize['identifier']))."<br />";
|
`order`='".intval($prize['ord'])."'
|
||||||
mysql_query("INSERT INTO award_prizes (award_awards_id,year,externa_identifier)
|
WHERE
|
||||||
VALUES ('$award_id','$year',".mysql_escape_string($prize['identifier'])."')");
|
id='$prize_id'");
|
||||||
} else {
|
|
||||||
$ep=$existingprizes[$prize['identifier']];
|
|
||||||
echo " ".i18n("Updating prize %1",array($ep->external_identifier))."<br />";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!array_key_exists($prize['identifier'],$existingprizes)) {
|
|
||||||
$ep=$existingprizes[$prize['identifier']];
|
|
||||||
|
|
||||||
mysql_query("UPDATE award_prizes SET
|
|
||||||
cash='".intval($prize['cash'])."',
|
|
||||||
scholarship='".intval($prize['scholarship'])."',
|
|
||||||
value='".intval($prize['value'])."',
|
|
||||||
prize='".mysql_escape_string($prize['prize_en'])."',
|
|
||||||
number='".intval($prize['number'])."',
|
|
||||||
`order`='".intval($prize['ord'])."'
|
|
||||||
WHERE
|
|
||||||
id='$ep->id'");
|
|
||||||
|
|
||||||
//remove it from the list
|
|
||||||
unset($existingprizes[$ep->external_identifier]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//if an entry exists thats not in the xml -> delete it
|
|
||||||
foreach($existingprizes AS $ep) {
|
|
||||||
echo " ".i18n("Removing prize %1",array($ep->external_identifier))."<br />";
|
|
||||||
mysql_query("DELETE FROM award_prizes WHERE id='$ep->id'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//FIXME: update the translations
|
//FIXME: update the translations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Delete local entries that weren't downloaded */
|
||||||
|
foreach($existingprizes AS $ep) {
|
||||||
|
echo " ".i18n("Removing prize %1",array($ep['prize']))."<br />";
|
||||||
|
mysql_query("DELETE FROM award_prizes WHERE id='{$ep['id']}'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
echo "<br />";
|
echo "<br />";
|
||||||
|
|
||||||
|
|
||||||
//remove any awards that are left in the $existingawards array, they must have been removed from the source
|
//remove any awards that are left in the $existingawards array, they must have been removed from the source
|
||||||
foreach($existingawards AS $aid) {
|
foreach($existingawards AS $aid) {
|
||||||
echo i18n("Removing award id %1 that was removed from external source",array($aid))."<br />";
|
echo i18n("Removing award id %1 that was removed from external source",array($aid))."<br />";
|
||||||
mysql_query("DELETE FROM award_prizes WHERE award_awards_id='$aid'");
|
mysql_query("DELETE FROM award_prizes WHERE award_awards_id='$aid'");
|
||||||
|
Loading…
Reference in New Issue
Block a user