gnucash stable: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Fri Apr 28 20:08:17 EDT 2023
Updated via https://github.com/Gnucash/gnucash/commit/8481f062 (commit)
via https://github.com/Gnucash/gnucash/commit/0d175dce (commit)
via https://github.com/Gnucash/gnucash/commit/e8c80f2f (commit)
from https://github.com/Gnucash/gnucash/commit/9ff2362b (commit)
commit 8481f062d45d99c506f77f920e4ae1a859b19c35
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Apr 28 16:58:44 2023 -0700
Create obsolete features list with first member book_currency.
Obsolete features set in the book will be removed from the book's
KVP and ignored. Note the warning in the comment!
diff --git a/libgnucash/engine/gnc-features.cpp b/libgnucash/engine/gnc-features.cpp
index 109b2dd3c8..859cc413c0 100644
--- a/libgnucash/engine/gnc-features.cpp
+++ b/libgnucash/engine/gnc-features.cpp
@@ -27,6 +27,7 @@
#include <glib.h>
#include <glib/gi18n.h>
+#include "qofbook.h"
#include "qofbook.hpp"
#include "gnc-features.h"
@@ -36,7 +37,6 @@ static const FeaturesTable features_table
{ GNC_FEATURE_CREDIT_NOTES, "Customer and vendor credit notes (requires at least GnuCash 2.5.0)" },
{ GNC_FEATURE_NUM_FIELD_SOURCE, "User specifies source of 'num' field'; either transaction number or split action (requires at least GnuCash 2.5.0)" },
{ GNC_FEATURE_KVP_EXTRA_DATA, "Extra data for addresses, jobs or invoice entries (requires at least GnuCash 2.6.4)" },
- { GNC_FEATURE_BOOK_CURRENCY, "User-specified book currency stored in KVP. Never implemented but some user managed to get it set anyway. (requires at least GnuCash 2.7.0)" },
{ GNC_FEATURE_GUID_BAYESIAN, "Use account GUID as key for Bayesian data (requires at least GnuCash 2.6.12)" },
{ GNC_FEATURE_GUID_FLAT_BAYESIAN, "Use account GUID as key for bayesian data and store KVP flat (requires at least Gnucash 2.6.19)" },
{ GNC_FEATURE_SQLITE3_ISO_DATES, "Use ISO formatted date-time strings in SQLite3 databases (requires at least GnuCash 2.6.20)"},
@@ -46,6 +46,21 @@ static const FeaturesTable features_table
{ GNC_FEATURE_EQUITY_TYPE_OPENING_BALANCE, GNC_FEATURE_EQUITY_TYPE_OPENING_BALANCE " (requires at least Gnucash 4.3)" },
};
+/* To obsolete a feature leave the #define in gnc-features.h and move the
+ * feature from features_table to obsolete_features after removing all of the
+ * code that depends on the feature. The feature will be removed from the book's
+ * KVP, allowing the book to be opened with GnuCash versions that don't support
+ * the feature.
+ *
+ * Do this only if the book's data is restored to compatibility with older
+ * GnuCash versions lacking the feature. In general this can be used only in
+ * cases where a feature was created but never implemented in a way that affects
+ * the book's data.
+ */
+static const FeaturesTable obsolete_features{
+ {GNC_FEATURE_BOOK_CURRENCY, "User-specified book currency stored in KVP. Never implemented but some user managed to get it set anyway. (requires at least GnuCash 2.7.0)"},
+};
+
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = G_LOG_DOMAIN;
@@ -66,6 +81,19 @@ header = N_("This Dataset contains features not supported "
gchar *gnc_features_test_unknown (QofBook *book)
{
auto unknowns {qof_book_get_unknown_features (book, features_table)};
+ if (unknowns.empty())
+ return nullptr;
+
+ auto obsolete = std::remove_if(unknowns.begin(), unknowns.end(),
+ [](auto& unknown){
+ return obsolete_features.find(unknown.first) != obsolete_features.end();
+ });
+ while (obsolete != unknowns.end())
+ {
+ qof_book_unset_feature(book, obsolete->first.data());
+ obsolete = unknowns.erase(obsolete);
+ }
+
if (unknowns.empty())
return nullptr;
diff --git a/libgnucash/engine/test/test-qofbook.c b/libgnucash/engine/test/test-qofbook.c
index c33d7a0ad9..ecabf85a7a 100644
--- a/libgnucash/engine/test/test-qofbook.c
+++ b/libgnucash/engine/test/test-qofbook.c
@@ -784,6 +784,11 @@ test_book_features (Fixture *fixture, gconstpointer pData)
g_assert_null (gnc_features_test_unknown (fixture->book));
g_assert_false (gnc_features_check_used (fixture->book, "Credit Notes"));
+ qof_book_set_feature(fixture->book, "Use a Book-Currency", "Random string, doesn't matter");
+ g_assert_null (gnc_features_test_unknown (fixture->book));
+ g_assert_false (gnc_features_check_used (fixture->book, "Use a Book-Currency"));
+
+
/* cannot use gnc_features_set_used to set an unknown feature: it bails out.
* use qof_book_set_feature instead. */
qof_book_set_feature (fixture->book, "Nanotech", "With Quantum Computing");
commit 0d175dce12239eda4db54e3d93c3cb6ebbdfe0f9
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Apr 28 16:31:07 2023 -0700
Refactor gnc-features.
* type aliases to gnc-features.h
* string_views to avoid copying (all of the strings are static)
* qof_book_get_unknown_features returns a FeatureSet
diff --git a/libgnucash/engine/gnc-features.cpp b/libgnucash/engine/gnc-features.cpp
index 8af413dd89..109b2dd3c8 100644
--- a/libgnucash/engine/gnc-features.cpp
+++ b/libgnucash/engine/gnc-features.cpp
@@ -69,7 +69,7 @@ gchar *gnc_features_test_unknown (QofBook *book)
if (unknowns.empty())
return nullptr;
- auto accum = [](const auto& a, const auto& b){ return a + "\n* " + b; };
+ auto accum = [](const auto& a, const auto& b){ return a + "\n* " + b.second.data(); };
auto msg {std::accumulate (unknowns.begin(), unknowns.end(),
std::string (_(header)), accum)};
return g_strdup (msg.c_str());
@@ -88,7 +88,7 @@ void gnc_features_set_used (QofBook *book, const gchar *feature)
return;
}
- qof_book_set_feature (book, feature, iter->second.c_str());
+ qof_book_set_feature (book, feature, iter->second.data());
}
diff --git a/libgnucash/engine/gnc-features.h b/libgnucash/engine/gnc-features.h
index b5960ac7ad..b82aad762b 100644
--- a/libgnucash/engine/gnc-features.h
+++ b/libgnucash/engine/gnc-features.h
@@ -36,9 +36,15 @@
#ifndef GNC_FEATURES_H
#define GNC_FEATURES_H
-#include "qof.h"
-
#ifdef __cplusplus
+#include <string_view>
+#include <unordered_map>
+#include <vector>
+
+using Feature = std::pair<std::string_view, std::string_view>;
+using FeaturesTable = std::unordered_map<std::string_view, std::string_view>;
+using FeatureSet = std::vector<Feature>;
+
extern "C" {
#endif
diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp
index be5cc46916..aae4cc6cf8 100644
--- a/libgnucash/engine/qofbook.cpp
+++ b/libgnucash/engine/qofbook.cpp
@@ -1267,14 +1267,14 @@ qof_book_set_feature (QofBook *book, const gchar *key, const gchar *descr)
}
}
-std::vector<std::string>
+FeatureSet
qof_book_get_unknown_features (QofBook *book, const FeaturesTable& features)
{
- std::vector<std::string> rv;
+ FeatureSet rv;
auto test_feature = [&](const KvpFrameImpl::map_type::value_type& feature)
{
if (features.find (feature.first) == features.end ())
- rv.push_back (feature.second->get<const char*>());
+ rv.emplace_back (feature.first, feature.second->get<const char*>());
};
auto frame = qof_instance_get_slots (QOF_INSTANCE (book));
auto slot = frame->get_slot({GNC_FEATURES});
diff --git a/libgnucash/engine/qofbook.hpp b/libgnucash/engine/qofbook.hpp
index 402de17119..3727f96ad4 100644
--- a/libgnucash/engine/qofbook.hpp
+++ b/libgnucash/engine/qofbook.hpp
@@ -26,10 +26,9 @@
#include <string>
#include "qof.h"
+#include "gnc-features.h"
-using FeaturesTable = std::unordered_map<std::string,std::string>;
-
-std::vector<std::string>
+FeatureSet
qof_book_get_unknown_features (QofBook *book, const FeaturesTable& features);
bool qof_book_test_feature (QofBook*, const char*);
commit e8c80f2f5cca6e16abea87740d59b5b52c9ab69f
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Apr 28 14:15:59 2023 -0700
Restore existence, but not implementation, of GNC_FEATURE_BOOK_CURRENCY.
At least one user has managed to get it set on their book so even
though it was supposed to be unimplemented it got through somehow.
Restoring it allows books with it set to load.
diff --git a/libgnucash/engine/gnc-features.cpp b/libgnucash/engine/gnc-features.cpp
index 2204f5ea34..8af413dd89 100644
--- a/libgnucash/engine/gnc-features.cpp
+++ b/libgnucash/engine/gnc-features.cpp
@@ -36,6 +36,7 @@ static const FeaturesTable features_table
{ GNC_FEATURE_CREDIT_NOTES, "Customer and vendor credit notes (requires at least GnuCash 2.5.0)" },
{ GNC_FEATURE_NUM_FIELD_SOURCE, "User specifies source of 'num' field'; either transaction number or split action (requires at least GnuCash 2.5.0)" },
{ GNC_FEATURE_KVP_EXTRA_DATA, "Extra data for addresses, jobs or invoice entries (requires at least GnuCash 2.6.4)" },
+ { GNC_FEATURE_BOOK_CURRENCY, "User-specified book currency stored in KVP. Never implemented but some user managed to get it set anyway. (requires at least GnuCash 2.7.0)" },
{ GNC_FEATURE_GUID_BAYESIAN, "Use account GUID as key for Bayesian data (requires at least GnuCash 2.6.12)" },
{ GNC_FEATURE_GUID_FLAT_BAYESIAN, "Use account GUID as key for bayesian data and store KVP flat (requires at least Gnucash 2.6.19)" },
{ GNC_FEATURE_SQLITE3_ISO_DATES, "Use ISO formatted date-time strings in SQLite3 databases (requires at least GnuCash 2.6.20)"},
diff --git a/libgnucash/engine/gnc-features.h b/libgnucash/engine/gnc-features.h
index 9702177b1a..b5960ac7ad 100644
--- a/libgnucash/engine/gnc-features.h
+++ b/libgnucash/engine/gnc-features.h
@@ -48,6 +48,7 @@ extern "C" {
#define GNC_FEATURE_CREDIT_NOTES "Credit Notes"
#define GNC_FEATURE_NUM_FIELD_SOURCE "Number Field Source"
#define GNC_FEATURE_KVP_EXTRA_DATA "Extra data in addresses, jobs or invoice entries"
+#define GNC_FEATURE_BOOK_CURRENCY "Use a Book-Currency"
#define GNC_FEATURE_GUID_BAYESIAN "Account GUID based Bayesian data"
#define GNC_FEATURE_GUID_FLAT_BAYESIAN "Account GUID based bayesian with flat KVP"
#define GNC_FEATURE_SQLITE3_ISO_DATES "ISO-8601 formatted date strings in SQLite3 databases."
Summary of changes:
libgnucash/engine/gnc-features.cpp | 33 +++++++++++++++++++++++++++++++--
libgnucash/engine/gnc-features.h | 11 +++++++++--
libgnucash/engine/qofbook.cpp | 6 +++---
libgnucash/engine/qofbook.hpp | 5 ++---
libgnucash/engine/test/test-qofbook.c | 5 +++++
5 files changed, 50 insertions(+), 10 deletions(-)
More information about the gnucash-changes
mailing list