Forum Moderators: coopster
$duplicateRemoved = false;
$dup_record = null;
while (!$recordSet->EOF) {
$dup_record = $recordSet->fields['listingsdb_id'];
$dupWhere = " WHERE listingsdb_id = '" . $dup_record . "'";
$BATCH_RESULT->addDuplicatedItem();
if ($EXTRACT_CONTEXT->refresh) {
if (!$EXTRACT_CONTEXT->mls_only) {
// retain non-MLS data
$sql = 'SELECT * FROM ' . $TARGET_CONTEXT->data_table . $dupWhere;
$recordSet2 = $conn->Execute($sql);
if ($recordSet2 === false) {
//$BATCH_RESULT->addError("user data bypass ERROR " . $sql);
} else {
if ($recordSet2 != null) {
while (!$recordSet2->EOF) {
$temp = $recordSet2->fields['listingsdbelements_field_name'];
if (!array_key_exists($temp, $data)) {
print('<br/>Saving value for field [' . $temp . '] from record ' . $dup_record . '<br/>');
$userSuppliedData[$temp] = $recordSet2->fields['listingsdbelements_field_value'];
}
$recordSet2->MoveNext();
}
}
}
}
// delete all data for this listing
$sql = 'DELETE FROM ' . $TARGET_CONTEXT->data_table . $dupWhere;
$recordSet2 = $conn->Execute($sql);
if ($recordSet2 === false) {
$BATCH_RESULT->addError('delete data ERROR ' . $sql);
}
if (!$EXTRACT_CONTEXT->mls_only) {
// delete only MLS images for this listing
$imagesPrior = 0;
$sql = 'select * FROM ' . $TARGET_CONTEXT->image_table . $dupWhere;
$recordSet2 = $conn->Execute($sql);
if ($recordSet2 === false) {
$BATCH_RESULT->addError('select count from image ERROR ' . $sql);
}
if ($recordSet2 != null) {
$imagesPrior = $recordSet2->NumRows();
}
$imagesDeleted = 0;
for ($i = 0; $i < ($EXTRACT_CONTEXT->max_images + 1); ++$i) {
$image_name = $dup_record . '_' . $i . '.jpg';
$image_path = $TARGET_CONTEXT->image_upload_path . '/' . $image_name;
if (file_exists($image_path)) {
unlink($image_path);
$thumb_path = $TARGET_CONTEXT->image_upload_path . '/' .
EXP_THUMB_PREFIX . $image_name;
if (file_exists($thumb_path)) {
unlink($thumb_path);
}
$imagesDeleted++;
$sql = 'DELETE FROM ' . $TARGET_CONTEXT->image_table . $dupWhere . " AND listingsimages_file_name = '" . $image_name . "'";
$recordSet2 = $conn->Execute($sql);
if ($recordSet2 === false) {
$BATCH_RESULT->addError('delete from image ERROR ' . $sql);
}
}
}
$userSuppliedImages = $imagesPrior - $imagesDeleted;
} else {
// delete all images for this listing
$sql = 'DELETE FROM ' . $TARGET_CONTEXT->image_table . $dupWhere;
$recordSet2 = $conn->Execute($sql);
if ($recordSet2 === false) {
$BATCH_RESULT->addError('delete from image ERROR ' . $sql);
}
for ($i = 0; $i < ($EXTRACT_CONTEXT->max_images + 1); ++$i) {
$image_name = $dup_record . '_' . $i . '.jpg';
$image_path = $TARGET_CONTEXT->image_upload_path . '/' . $image_name;
if (file_exists($image_path)) {
unlink($image_path);
$thumb_path = $TARGET_CONTEXT->image_upload_path . '/' .
EXP_THUMB_PREFIX . $image_name;
if (file_exists($thumb_path)) {
unlink($thumb_path);
}
}
}
}
$duplicateRemoved = true;
} else {
$clearToInsert = false;
}
$recordSet->MoveNext();
}