Only save logs that have duplicate areas.

This commit is contained in:
paul121 2020-10-28 09:28:20 -07:00 committed by Michael Stenta
parent 25ecd4faf1
commit 50494b16da
1 changed files with 6 additions and 4 deletions

View File

@ -545,15 +545,17 @@ function farm_livestock_update_7008(&$sandbox) {
$log_wrapper = entity_metadata_wrapper('log', $log);
$areas = $log_wrapper->field_farm_area->value();
// Only update areas if some exist.
if (!empty($areas)) {
// Only update areas if more than 1 exists.
if (!empty($areas) && count($areas) > 1) {
// Get the unique areas.
$new_areas = array_unique($areas, SORT_REGULAR);
// Update the log.
$log_wrapper->field_farm_area->set($new_areas);
$log_wrapper->save();
if (count($areas) > count($new_areas)) {
$log_wrapper->field_farm_area->set($new_areas);
$log_wrapper->save();
}
}
$sandbox['progress']++;