Skip to content

Commit

Permalink
Fixes #151: click delete on a language deletes the language.
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoFara committed Dec 28, 2023
1 parent 66401ac commit 05afb1b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 51 deletions.
4 changes: 3 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ and `click_faster` were declared two times in `src/js/audio_controller.js`.
* It was impossible to install the demo database if they was more or less than one instruction a line.
This is fixed, and the SQL file was made more readable.
* Changes `WoStatusChange` default value to '1970-01-01 01:00:01', it was impossible
to install the demo DB out of LWT (related to [#78](https://github.com/HugoFara/lwt/issues/78)).
to install the demo DB out of LWT (related to [#78](https://github.com/HugoFara/lwt/issues/78)).
* Deleting a language deletes the language ([#151](https://github.com/HugoFara/lwt/issues/151)).
Before it was setting the language to empty values.

### Deprecated

Expand Down
2 changes: 2 additions & 0 deletions docs/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -2222,6 +2222,8 @@ <h4>Fixed</h4>
This is fixed, and the SQL file was made more readable.</li>
<li>Changes <code>WoStatusChange</code> default value to '1970-01-01 01:00:01', it was impossible
to install the demo DB out of LWT (related to <a href="https://github.com/HugoFara/lwt/issues/78">#78</a>).</li>
<li>Deleting a language deletes the language (<a href="https://github.com/HugoFara/lwt/issues/151">#151</a>).
Before it was setting the language to empty values.</li>
</ul>
<h4>Deprecated</h4>
<ul>
Expand Down
95 changes: 45 additions & 50 deletions edit_languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ function edit_languages_refresh($lid): string
{
global $tbpref;
$message2 = runsql(
'delete from ' . $tbpref . 'sentences where SeLgID = ' . $lid,
"DELETE FROM {$tbpref}sentences where SeLgID = $lid",
"Sentences deleted"
);
$message3 = runsql(
'delete from ' . $tbpref . 'textitems2 where Ti2LgID = ' . $lid,
"DELETE FROM {$tbpref}textitems2 where Ti2LgID = $lid",
"Text items deleted"
);
adjust_autoincr('sentences', 'SeID');
Expand All @@ -97,14 +97,14 @@ function edit_languages_refresh($lid): string
$message = $message2 .
" / " . $message3 .
" / Sentences added: " . get_first_value(
'select count(*) as value
from ' . $tbpref . 'sentences
where SeLgID = ' . $lid
"SELECT count(*) as value
FROM {$tbpref}sentences
where SeLgID = $lid"
) .
" / Text items added: " . get_first_value(
'select count(*) as value
from ' . $tbpref . 'textitems2
where Ti2LgID = ' . $lid
"SELECT count(*) as value
FROM {$tbpref}textitems2
where Ti2LgID = $lid"
);
return $message;
}
Expand All @@ -124,36 +124,31 @@ function edit_languages_delete($lid): string
{
global $tbpref;
$anztexts = get_first_value(
'select count(TxID) as value
from ' . $tbpref . 'texts
where TxLgID = ' . $lid
"SELECT count(TxID) as value
FROM {$tbpref}texts
where TxLgID = $lid"
);
$anzarchtexts = get_first_value(
'select count(AtID) as value
from ' . $tbpref . 'archivedtexts
where AtLgID = ' . $lid
"SELECT count(AtID) as value
FROM {$tbpref}archivedtexts
where AtLgID = $lid"
);
$anzwords = get_first_value(
'select count(WoID) as value
from ' . $tbpref . 'words
where WoLgID = ' . $lid
"SELECT count(WoID) as value
FROM {$tbpref}words
where WoLgID = $lid"
);
$anzfeeds = get_first_value(
'select count(NfID) as value
from ' . $tbpref . 'newsfeeds
where NfLgID = ' . $lid
"SELECT count(NfID) as value
FROM {$tbpref}newsfeeds
where NfLgID = $lid"
);
if ($anztexts > 0 || $anzarchtexts > 0 || $anzwords > 0 || $anzfeeds > 0) {
$message = 'You must first delete texts, archived texts, newsfeeds and words with this language!';
} else {
$message = runsql(
'UPDATE ' . $tbpref . 'languages
SET LgName = "", LgDict1URI = "", LgDict2URI = "",
LgGoogleTranslateURI = "", LgExportTemplate = "", LgTextSize = DEFAULT,
LgCharacterSubstitutions = "", LgRegexpSplitSentences = "",
LgExceptionsSplitSentences = "", LgRegexpWordCharacters = "",
LgRemoveSpaces = DEFAULT, LgSplitEachChar = DEFAULT,
LgRightToLeft = DEFAULT where LgID = ' . $lid,
"DELETE FROM {$tbpref}languages
WHERE LgID = $lid",
"Deleted"
);
}
Expand Down Expand Up @@ -281,11 +276,11 @@ function edit_languages_op_change($lid): string

if ($needReParse) {
runsql(
'delete from ' . $tbpref . 'sentences where SeLgID = ' . $lid,
"DELETE FROM {$tbpref}sentences where SeLgID = $lid",
"Sentences deleted"
);
runsql(
'delete from ' . $tbpref . 'textitems2 where Ti2LgID = ' . $lid,
"DELETE FROM {$tbpref}textitems2 where Ti2LgID = $lid",
"Text items deleted"
);
adjust_autoincr('sentences', 'SeID');
Expand Down Expand Up @@ -1099,9 +1094,9 @@ function edit_languages_display($message)
$current = (int) getSetting('currentlanguage');

$recno = get_first_value(
'SELECT COUNT(*) AS value
FROM ' . $tbpref . 'languages
WHERE LgName<>""'
"SELECT COUNT(*) AS value
FROM {$tbpref}languages
WHERE LgName<>''"
);

?>
Expand Down Expand Up @@ -1136,28 +1131,28 @@ function edit_languages_display($message)

<?php

$sql = 'SELECT LgID, LgName, LgExportTemplate
FROM ' . $tbpref . 'languages
WHERE LgName<>"" ORDER BY LgName';
$sql = "SELECT LgID, LgName, LgExportTemplate
FROM {$tbpref}languages
WHERE LgName<>'' ORDER BY LgName";
if ($debug) {
echo $sql;
}
// May be refactored with KISS principle
$res = do_mysqli_query(
'select NfLgID, count(*) as value
from ' . $tbpref . 'newsfeeds
group by NfLgID'
"SELECT NfLgID, count(*) as value
FROM {$tbpref}newsfeeds
group by NfLgID"
);
$newsfeedcount = null;
while ($record = mysqli_fetch_assoc($res)) {
$newsfeedcount[$record['NfLgID']] = $record['value'];
}
// May be refactored with KISS principle
$res = do_mysqli_query(
'SELECT NfLgID, count(*) AS value
FROM ' . $tbpref . 'newsfeeds, ' . $tbpref . 'feedlinks
"SELECT NfLgID, count(*) AS value
FROM {$tbpref}newsfeeds, {$tbpref}feedlinks
WHERE NfID=FlNfID
GROUP BY NfLgID'
GROUP BY NfLgID"
);
$feedarticlescount = null;
while ($record = mysqli_fetch_assoc($res)) {
Expand All @@ -1167,21 +1162,21 @@ function edit_languages_display($message)
while ($record = mysqli_fetch_assoc($res)) {
$lid = (int)$record['LgID'];
$foo = get_first_value(
'select count(TxID) as value
from ' . $tbpref . 'texts
where TxLgID=' . $lid
"SELECT count(TxID) as value
FROM {$tbpref}texts
where TxLgID = $lid"
);
$textcount = is_numeric($foo) ? (int)$foo : 0;
$foo = get_first_value(
'select count(AtID) as value
from ' . $tbpref . 'archivedtexts
where AtLgID=' . $lid
"SELECT count(AtID) as value
FROM {$tbpref}archivedtexts
where AtLgID = $lid"
);
$archtextcount = is_numeric($foo) ? (int)$foo : 0;
$foo = get_first_value(
'select count(WoID) as value
from ' . $tbpref . 'words
where WoLgID=' . $lid
"SELECT count(WoID) as value
FROM {$tbpref}words
where WoLgID = $lid"
);
$wordcount = is_numeric($foo) ? (int)$foo : 0;
if (is_null($newsfeedcount)) {
Expand Down

0 comments on commit 05afb1b

Please sign in to comment.