[editor] Automatically create/update check_date

Signed-off-by: matheusgomesms <matheusgomesms@noreply.codeberg.org>
This commit is contained in:
matheusgomesms
2026-01-20 14:56:31 -03:00
parent 54e2696830
commit 5509a7f5a3

View File

@@ -862,24 +862,8 @@ void EditableMapObject::LogDiffInJournal(EditableMapObject const & unedited_emo)
{
LOG(LDEBUG, ("Executing LogDiffInJournal"));
// Auto-fill check_date
if (ftypes::IsCheckDateChecker::Instance()(GetTypes()))
{
std::string const currentDate = GetCurrentDate();
// Always update check_date
SetMetadata(feature::Metadata::FMD_CHECK_DATE, currentDate);
// Update check_date:opening_hours if Opening Hours changed
std::string_view const newOH = GetMetadata(feature::Metadata::FMD_OPEN_HOURS);
std::string_view const oldOH = unedited_emo.GetMetadata(feature::Metadata::FMD_OPEN_HOURS);
// If new OH exists and is different from old (or old was empty), update the date.
if (!newOH.empty() && newOH != oldOH)
{
SetMetadata(feature::Metadata::FMD_CHECK_DATE_OPEN_HOURS, currentDate);
}
}
// Capture the initial size of the journal to detect if changes occur later
auto const initialJournalSize = m_journal.GetJournal().size();
// Name
for (StringUtf8Multilang::Lang language : StringUtf8Multilang::GetSupportedLanguages())
@@ -971,6 +955,39 @@ void EditableMapObject::LogDiffInJournal(EditableMapObject const & unedited_emo)
std::tie(key, old_value, new_value) = kvdiff;
m_journal.AddTagChange(key, old_value, new_value);
}
// check_date logic
// Check if any changes were detected (Journal grew)
if (m_journal.GetJournal().size() > initialJournalSize)
{
// Auto-fill check_date only if other changes exist
if (ftypes::IsCheckDateChecker::Instance()(GetTypes()))
{
std::string const currentDate = GetCurrentDate();
// Update check_date
std::string_view const oldCheckDate = unedited_emo.GetMetadata(feature::Metadata::FMD_CHECK_DATE);
if (oldCheckDate != currentDate)
{
SetMetadata(feature::Metadata::FMD_CHECK_DATE, currentDate);
m_journal.AddTagChange("check_date", std::string(oldCheckDate), currentDate);
}
// Update check_date:opening_hours if Opening Hours changed
std::string_view const newOH = GetMetadata(feature::Metadata::FMD_OPEN_HOURS);
std::string_view const oldOH = unedited_emo.GetMetadata(feature::Metadata::FMD_OPEN_HOURS);
if (!newOH.empty() && newOH != oldOH)
{
std::string_view const oldOHDate = unedited_emo.GetMetadata(feature::Metadata::FMD_CHECK_DATE_OPEN_HOURS);
if (oldOHDate != currentDate)
{
SetMetadata(feature::Metadata::FMD_CHECK_DATE_OPEN_HOURS, currentDate);
m_journal.AddTagChange("check_date:opening_hours", std::string(oldOHDate), currentDate);
}
}
}
}
}
void EditableMapObject::ApplyBusinessReplacement(uint32_t new_type)