Skip to content

Commit

Permalink
Simplify database::check
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Jun 16, 2024
1 parent cbbe9e4 commit 2141fb0
Show file tree
Hide file tree
Showing 23 changed files with 193 additions and 240 deletions.
4 changes: 2 additions & 2 deletions bb/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <database/books.h>
#include <database/config/bible.h>
#include <database/mappings.h>
#include <database/check.h>
#include <locale/translate.h>
#include <dialog/entry.h>
#include <dialog/yes.h>
Expand Down Expand Up @@ -295,8 +296,7 @@ std::string bible_settings (Webserver_Request& webserver_request)
database::config::bible::set_daily_checks_enabled (bible, checked);
if (!checked) {
// If checking is switched off, also remove any existing checking results for this Bible.
Database_Check database_check;
database_check.truncateOutput(bible);
database::check::truncateOutput(bible);
}
}
}
Expand Down
17 changes: 7 additions & 10 deletions checks/french.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
void checks_french::space_before_after_punctuation (const std::string& bible, int book, int chapter,
const std::map <int, std::string>& texts)
{
Database_Check database_check {};
const std::string nbsp = filter::strings::non_breaking_space_u00A0 ();
const std::string nnbsp = filter::strings::narrow_non_breaking_space_u202F ();
const std::vector <std::string> right_punctuation = { right_guillemet(), "!", "?", ":", ";" };
Expand All @@ -47,10 +46,10 @@ void checks_french::space_before_after_punctuation (const std::string& bible, in
bool nnbsp_follows = text.find (nnbsp) == 0;
if (space_follows) {
const std::string message = left_guillemet () + " - " + translate ("Should be followed by a no-break space rather than a plain space in French");
database_check.recordOutput (bible, book, chapter, verse, message);
database::check::recordOutput (bible, book, chapter, verse, message);
} else if (!nbsp_follows && !nnbsp_follows) {
const std::string message = left_guillemet () + " - " + translate ("Should be followed by a no-break space in French");
database_check.recordOutput (bible, book, chapter, verse, message);
database::check::recordOutput (bible, book, chapter, verse, message);
}
pos = text.find (left_guillemet ());
}
Expand All @@ -65,13 +64,13 @@ void checks_french::space_before_after_punctuation (const std::string& bible, in
const std::string preceding_character = filter::strings::unicode_string_substr (text, pos - 1, 1);
if (preceding_character == " ") {
const std::string message = punctuation + " - " + translate ("Should be preceded by a no-break space rather than a plain space in French");
database_check.recordOutput (bible, book, chapter, verse, message);
database::check::recordOutput (bible, book, chapter, verse, message);
}
else if (preceding_character == nbsp) { /* This is OK. */ }
else if (preceding_character == nnbsp) { /* This is OK. */ }
else {
const std::string message = punctuation + " - " + translate ("Should be preceded by a no-break space in French");
database_check.recordOutput (bible, book, chapter, verse, message);
database::check::recordOutput (bible, book, chapter, verse, message);
}
}
// Prepare for next iteration.
Expand All @@ -92,8 +91,6 @@ void checks_french::space_before_after_punctuation (const std::string& bible, in
void checks_french::citation_style (const std::string & bible, int book, int chapter,
const std::vector <std::map <int, std::string>>& verses_paragraphs)
{
Database_Check database_check {};

// Store the state of the previous paragraph.
// It indicates whether any citation was left open at the end of the paragraph.
bool previous_paragraph_open_citation {false};
Expand All @@ -118,7 +115,7 @@ void checks_french::citation_style (const std::string & bible, int book, int cha
const std::string character = filter::strings::unicode_string_substr (text, 0, 1);
if (character != left_guillemet ()) {
const std::string message = translate ("The previous paragraph contains a citation not closed with a » therefore the current paragraph is expected to start with a « to continue that citation in French");
database_check.recordOutput (bible, book, chapter, verse, message);
database::check::recordOutput (bible, book, chapter, verse, message);
}
}
}
Expand All @@ -142,13 +139,13 @@ void checks_french::citation_style (const std::string & bible, int book, int cha
// Whether there's too many left guillements.
if (opener_count > (closer_count + 1)) {
const std::string message = translate ("The paragraph contains more left guillements than needed");
database_check.recordOutput (bible, book, chapter, last_verse, message);
database::check::recordOutput (bible, book, chapter, last_verse, message);
}

// Whether there's too many right guillements.
if (closer_count > opener_count) {
const std::string message = translate ("The paragraph contains more right guillements than needed");
database_check.recordOutput (bible, book, chapter, last_verse, message);
database::check::recordOutput (bible, book, chapter, last_verse, message);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions checks/headers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void checks_headers::no_punctuation_at_end (const std::string& bible, int book,
const std::map <int, std::string>& headings,
const std::string& centermarks, const std::string& endmarks)
{
Database_Check database_check {};
for (const auto & element : headings) {
int verse = element.first;
const std::string heading = element.second;
Expand All @@ -40,7 +39,7 @@ void checks_headers::no_punctuation_at_end (const std::string& bible, int book,
if (centermarks.find (last_character) != std::string::npos) message = true;
if (endmarks.find (last_character) != std::string::npos) message = true;
if (message) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Punctuation at end of heading:") + " " + heading);
database::check::recordOutput (bible, book, chapter, verse, translate ("Punctuation at end of heading:") + " " + heading);
}
}
}
9 changes: 3 additions & 6 deletions checks/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ bool checks_index_acl (Webserver_Request& webserver_request)

std::string checks_index (Webserver_Request& webserver_request)
{
Database_Check database_check {};


std::string page {};
Assets_Header header = Assets_Header (translate("Checks"), webserver_request);
header.add_bread_crumb (menu_logic_tools_menu (), menu_logic_tools_text ());
Expand All @@ -62,14 +59,14 @@ std::string checks_index (Webserver_Request& webserver_request)

if (webserver_request.query.count ("approve")) {
const int approve = filter::strings::convert_to_int (webserver_request.query["approve"]);
database_check.approve (approve);
database::check::approve (approve);
view.set_variable ("success", translate("The entry was suppressed."));
}


if (webserver_request.query.count ("delete")) {
const int erase = filter::strings::convert_to_int (webserver_request.query["delete"]);
database_check.erase (erase);
database::check::erase (erase);
view.set_variable ("success", translate("The entry was deleted for just now."));
}

Expand All @@ -87,7 +84,7 @@ std::string checks_index (Webserver_Request& webserver_request)


std::stringstream resultblock {};
const std::vector <Database_Check_Hit>& hits = database_check.getHits ();
const std::vector <database::check::Hit>& hits = database::check::getHits ();
for (const auto& hit : hits) {
std::string bible = hit.bible;
if (find (bibles.begin(), bibles.end (), bible) != bibles.end ()) {
Expand Down
6 changes: 2 additions & 4 deletions checks/pairs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ void checks_pairs::run (const std::string& bible, int book, int chapter,
closers.push_back (closer);
}

Database_Check database_check {};

// Go through the verses with their texts.
for (const auto & element : texts) {
int verse = element.first;
Expand Down Expand Up @@ -82,7 +80,7 @@ void checks_pairs::run (const std::string& bible, int book, int chapter,
const std::string fragment2 = translate ("without its matching opening character");
std::stringstream message {};
message << fragment1 << " " << std::quoted(character) << " " << fragment2 << " " << std::quoted(opener);
database_check.recordOutput (bible, book, chapter, verse, message.str());
database::check::recordOutput (bible, book, chapter, verse, message.str());
}
}
}
Expand All @@ -97,7 +95,7 @@ void checks_pairs::run (const std::string& bible, int book, int chapter,
const std::string fragment2 = translate ("without its matching closing character");
std::stringstream message {};
message << fragment1 << " " << std::quoted(opener) << " " << fragment2 << " " << std::quoted(closer);
database_check.recordOutput (bible, book, chapter, verse, message.str());
database::check::recordOutput (bible, book, chapter, verse, message.str());
}
}

Expand Down
11 changes: 5 additions & 6 deletions checks/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
void checks_run (std::string bible)
{
Webserver_Request webserver_request {};
Database_Check database_check {};


if (bible.empty()) return;
Expand All @@ -60,7 +59,7 @@ void checks_run (std::string bible)
Database_Logs::log ("Check " + bible + ": Start", Filter_Roles::translator ());


database_check.truncateOutput (bible);
database::check::truncateOutput (bible);


const std::string stylesheet = database::config::bible::get_export_stylesheet (bible);
Expand Down Expand Up @@ -163,7 +162,7 @@ void checks_run (std::string bible)
if (check_valid_utf8_text) {
if (!filter::strings::unicode_string_is_valid (verseUsfm)) {
const std::string msg = "Invalid UTF-8 Unicode in verse text";
database_check.recordOutput (bible, book, chapter, verse, msg);
database::check::recordOutput (bible, book, chapter, verse, msg);
}
}
if (check_space_before_final_note_marker) {
Expand Down Expand Up @@ -199,7 +198,7 @@ void checks_run (std::string bible)
for (const auto& result : results) {
const int verse = result.first;
const std::string msg = result.second;
database_check.recordOutput (bible, book, chapter, verse, msg);
database::check::recordOutput (bible, book, chapter, verse, msg);
}
}

Expand All @@ -211,7 +210,7 @@ void checks_run (std::string bible)
for (const auto& element : results) {
const int verse = element.first;
const std::string msg = element.second;
database_check.recordOutput (bible, book, chapter, verse, msg);
database::check::recordOutput (bible, book, chapter, verse, msg);
}
}

Expand Down Expand Up @@ -246,7 +245,7 @@ void checks_run (std::string bible)

// Create an email with the checking results for this bible.
std::vector <std::string> emailBody;
std::vector <Database_Check_Hit> hits = database_check.getHits ();
std::vector <database::check::Hit> hits = database::check::getHits ();
for (const auto & hit : hits) {
if (hit.bible == bible) {
const std::string passage = filter_passage_display_inline ({Passage ("", hit.book, hit.chapter, std::to_string (hit.verse))});
Expand Down
26 changes: 11 additions & 15 deletions checks/space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,40 @@ void double_space_usfm (const std::string& bible, int book, int chapter, int ver
int start = static_cast<int>(pos) - 10;
if (start < 0) start = 0;
const std::string fragment = data.substr (static_cast <size_t> (start), 20);
Database_Check database_check {};
database_check.recordOutput (bible, book, chapter, verse, translate ("Double space:") + " ... " + fragment + " ...");
database::check::recordOutput (bible, book, chapter, verse, translate ("Double space:") + " ... " + fragment + " ...");
}
}


void space_before_punctuation (const std::string& bible, int book, int chapter, const std::map <int, std::string> & texts)
{
Database_Check database_check {};
for (const auto & element : texts) {
const int verse = element.first;
const std::string text = element.second;
if (text.find (" ,") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before a comma"));
database::check::recordOutput (bible, book, chapter, verse, translate ("Space before a comma"));
}
if (text.find (" ;") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before a semicolon"));
database::check::recordOutput (bible, book, chapter, verse, translate ("Space before a semicolon"));
}
if (text.find (" :") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before a colon"));
database::check::recordOutput (bible, book, chapter, verse, translate ("Space before a colon"));
}
if (text.find (" .") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before a full stop"));
database::check::recordOutput (bible, book, chapter, verse, translate ("Space before a full stop"));
}
if (text.find (" ?") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before a question mark"));
database::check::recordOutput (bible, book, chapter, verse, translate ("Space before a question mark"));
}
if (text.find (" !") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before an exclamation mark"));
database::check::recordOutput (bible, book, chapter, verse, translate ("Space before an exclamation mark"));
}
}
}


void space_end_verse (const std::string& bible, int book, int chapter, const std::string& usfm)
{
Database_Check database_check {};
std::vector <int> verses = filter::usfm::get_verse_numbers (usfm);
for (auto verse : verses) {
if (!verse) continue;
Expand All @@ -88,7 +85,7 @@ void space_end_verse (const std::string& bible, int book, int chapter, const std
const char lastchar = text.back ();
if (lastchar == ' ') hit = true;
}
if (hit) database_check.recordOutput (bible, book, chapter, verse, translate ("Space at the end of the verse"));
if (hit) database::check::recordOutput (bible, book, chapter, verse, translate ("Space at the end of the verse"));
}
}

Expand Down Expand Up @@ -119,15 +116,14 @@ bool transpose_note_space (std::string & usfm)

void space_before_final_note_markup (const std::string& bible, int book, int chapter, int verse, const std::string& data)
{
Database_Check database_check {};
if (data.find (R"( \f*)") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before final note markup"));
database::check::recordOutput (bible, book, chapter, verse, translate ("Space before final note markup"));
}
if (data.find (R"( \fe*)") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before final note markup"));
database::check::recordOutput (bible, book, chapter, verse, translate ("Space before final note markup"));
}
if (data.find (R"( \x*)") != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Space before final cross reference markup"));
database::check::recordOutput (bible, book, chapter, verse, translate ("Space before final cross reference markup"));
}
}

Expand Down
8 changes: 3 additions & 5 deletions checks/suppress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <webserver/request.h>
#include <locale/translate.h>
#include <database/config/general.h>
#include <database/check.h>
#include <client/logic.h>
#include <demo/logic.h>
#include <sendreceive/logic.h>
Expand All @@ -47,17 +48,14 @@ bool checks_suppress_acl (Webserver_Request& webserver_request)

std::string checks_suppress (Webserver_Request& webserver_request)
{
Database_Check database_check {};


std::string page {};
page = assets_page::header (translate ("Suppressed checking results"), webserver_request);
Assets_View view {};


if (webserver_request.query.count ("release")) {
int release = filter::strings::convert_to_int (webserver_request.query["release"]);
database_check.release (release);
database::check::release (release);
view.set_variable ("success", translate ("The check result is no longer suppressed."));
}

Expand All @@ -75,7 +73,7 @@ std::string checks_suppress (Webserver_Request& webserver_request)


std::string block {};
const std::vector <Database_Check_Hit> suppressions = database_check.getSuppressions ();
const std::vector <database::check::Hit> suppressions = database::check::getSuppressions ();
for (const auto & suppression : suppressions) {
std::string bible = suppression.bible;
// Only display entries for Bibles the user has write access to.
Expand Down
6 changes: 2 additions & 4 deletions checks/verses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ void checks_verses::missing_punctuation_at_end (const std::string& bible, int bo
const std::vector <std::string> centermarks = filter::strings::explode (center_marks, ' ');
const std::vector <std::string> endmarks = filter::strings::explode (end_marks, ' ');
const std::vector <std::string> ignores = filter::strings::explode (disregards, ' ');
Database_Check database_check {};
for (const auto & element : verses) {
int verse = element.first;
std::string text = element.second;
Expand All @@ -49,22 +48,21 @@ void checks_verses::missing_punctuation_at_end (const std::string& bible, int bo
const std::string lastCharacter = filter::strings::unicode_string_substr (text, text_length - 1, 1);
if (in_array (lastCharacter, centermarks)) continue;
if (in_array (lastCharacter, endmarks)) continue;
database_check.recordOutput (bible, book, chapter, verse, translate ("No punctuation at end of verse:") + " " + lastCharacter);
database::check::recordOutput (bible, book, chapter, verse, translate ("No punctuation at end of verse:") + " " + lastCharacter);
}
}


void checks_verses::patterns (const std::string& bible, int book, int chapter,
const std::map <int, std::string> & verses, const std::vector <std::string> & patterns)
{
Database_Check database_check {};
for (const auto & element : verses) {
const int verse = element.first;
const std::string text = element.second;
for (const auto & pattern : patterns) {
if (pattern.empty ()) continue;
if (text.find (pattern) != std::string::npos) {
database_check.recordOutput (bible, book, chapter, verse, translate ("Pattern found in text:") + " " + pattern);
database::check::recordOutput (bible, book, chapter, verse, translate ("Pattern found in text:") + " " + pattern);
}
}
}
Expand Down
Loading

0 comments on commit 2141fb0

Please sign in to comment.