Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapting lansuite to abide STRICT_TRANS_TABLES #458

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

t-h-e
Copy link
Contributor

@t-h-e t-h-e commented Nov 10, 2020

if the database uses a strict setting STRICT_TRANS_TABLES
(https://mariadb.com/kb/en/sql-mode/#strict_trans_tables)
then incorrect queries (empty string instead of zero) will result in an
error.

STRICT_TRANS_TABLES is part of the defaults in mariadb and mysql
https://mariadb.com/kb/en/sql-mode/#defaults
https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sql-mode-strict

  • Fix setting int and enum correctly in UPDATE/DELETE query in
    MasterForm
  • Setting more reasonable default valuse (date, datetime, time never had
    defaults set and have been removed from db.xml)
  • field module in ip_locklist was increased in size as it was to small
    for some module names

fixes parts of #456

t-h-e and others added 2 commits November 10, 2020 20:02
if the database uses a strict setting STRICT_TRANS_TABLES
 (https://mariadb.com/kb/en/sql-mode/#strict_trans_tables)
 then incorrect queries (empty string instead of zero) will result in an
 error.

STRICT_TRANS_TABLES is part of the defaults in mariadb and mysql
 https://mariadb.com/kb/en/sql-mode/#defaults
 https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sql-mode-strict

- Fix setting int and enum correctly in UPDATE/DELETE query in
 MasterForm
- Setting more reasonable default valuse (date, datetime, time never had
 defaults set and have been removed from db.xml)
- field module in ip_locklist was increased in size as it was to small
 for some module names
M4LuZ added a commit that referenced this pull request Dec 3, 2020
… Travis (wrong method name applied in PR #458)

refs #455
fixes #461
andygrunwald pushed a commit that referenced this pull request Dec 3, 2020
… Travis (wrong method name applied in PR #458)

refs #455
fixes #461
@M4LuZ M4LuZ added the database-modification Ticket includes a database modification that may need (manual) application on existing databases label Mar 28, 2022
@aj-gh
Copy link
Contributor

aj-gh commented Jan 12, 2023

Still pending .....

Copy link
Collaborator

@andygrunwald andygrunwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this Pull Request, and sorry for letting it slip so long.

I added a few questions - Let me know what you think.

inc/Classes/MasterForm.php Outdated Show resolved Hide resolved
inc/Classes/MasterForm.php Outdated Show resolved Hide resolved
inc/Classes/MasterForm.php Outdated Show resolved Hide resolved
@@ -1117,14 +1117,18 @@ public function SendForm($BaseURL, $table, $idname = '', $id = 0)
foreach ($this->SQLFields as $key => $val) {
if (($SQLFieldTypes[$val] == 'datetime' or $SQLFieldTypes[$val] == 'date') and $_POST[$val] == 'NOW()') {
$db_query .= "$val = NOW(), ";
} elseif ($SQLFieldTypes[$val] == 'tinyint(1)') {
} elseif ($this->is_field_int($SQLFieldTypes[$val])) {
$db_query .= $val .' = '. (int)$_POST[$val] .', ';
} elseif ($SQLFieldTypes[$val] == 'varbinary(16)' and $val == 'ip') {
$db_query .= $val .' = INET6_ATON(\''. $_POST[$val] .'\'), ';
} elseif ($_POST[$val] == '++' and strpos($SQLFieldTypes[$val], 'int') !== false) {
$db_query .= "$val = $val + 1, ";
} elseif ($_POST[$val] == '--' and strpos($SQLFieldTypes[$val], 'int') !== false) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this check also benefit from is_field_int ?

@@ -1117,14 +1117,18 @@ public function SendForm($BaseURL, $table, $idname = '', $id = 0)
foreach ($this->SQLFields as $key => $val) {
if (($SQLFieldTypes[$val] == 'datetime' or $SQLFieldTypes[$val] == 'date') and $_POST[$val] == 'NOW()') {
$db_query .= "$val = NOW(), ";
} elseif ($SQLFieldTypes[$val] == 'tinyint(1)') {
} elseif ($this->is_field_int($SQLFieldTypes[$val])) {
$db_query .= $val .' = '. (int)$_POST[$val] .', ';
} elseif ($SQLFieldTypes[$val] == 'varbinary(16)' and $val == 'ip') {
$db_query .= $val .' = INET6_ATON(\''. $_POST[$val] .'\'), ';
} elseif ($_POST[$val] == '++' and strpos($SQLFieldTypes[$val], 'int') !== false) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this check also benefit from is_field_int ?

modules/install/Classes/Import.php Outdated Show resolved Hide resolved
@@ -229,7 +233,7 @@ public function ImportXML($rewrite = null)
// Handle structure changes in general
} elseif ($db_field["Type"] != $type
or (!($db_field["Null"] == $null or ($db_field["Null"] == 'YES' and $null == 'NULL')))
or ($db_field["Default"] != $default_xml and !($db_field["Default"] == 0 and $default_xml == '') and !($db_field["Default"] == '' and $default_xml == 0))
or ($db_field["Default"] != $default_xml and !($db_field["Default"] == 0 and $default_xml == '') and !($db_field["Default"] == '' and $default_xml === 0))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this ever work without casting/double checks?

$default_xml is set by

$default_xml = $this->xml->getFirstTagContent("default", $field);

getFirstTagContent will always return a string, even is 0 is in it.

Maybe it is better to run something like $default_xml === '0'?

See

public function getFirstTagContent($tag, $input, $save = false)
{
$start = strpos($input, '<' . $tag . '>') + strlen($tag) + 2;
// If the tag has attributes, remove them, for the end tag won't contain them
if (strpos($tag, ' ') > 0) {
$tag = substr($tag, 0, strpos($tag, ' '));
}
$end = strpos($input, '</' . $tag . '>') - $start;
if ($end <= 0) {
return '';
}
if ($save) {
return trim(
str_replace(
'--lt--',
'<',
str_replace('--gt--', '>', substr($input, $start, $end))
)
);
}
return trim(substr($input, $start, $end));
}

@@ -116,7 +116,7 @@
<type>datetime</type>
<null></null>
<key></key>
<default>0</default>
<default></default>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate a bit why removing the default is necessary here? (same question applies to the other datetime fields)

@@ -98,7 +98,7 @@
<type>datetime</type>
<null></null>
<key></key>
<default></default>
<default>0000-00-00 00:00:00</default>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes this datetime field different from the others when it comes to the default value?

@@ -333,7 +333,7 @@
<field>
<name>rules</name>
<type>text</type>
<null></null>
<null>YES</null>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate why this is needed?

Copy link
Collaborator

@andygrunwald andygrunwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this Pull Request, and sorry for letting it slip so long.

I added a few questions - Let me know what you think.

@andygrunwald
Copy link
Collaborator

FYI: #634 was implemented to mitigate this issue slightly. Making LanSuite support STRICT_TRANS_TABLES is still the better way.

t-h-e and others added 4 commits June 7, 2023 19:56
Co-authored-by: Andy Grunwald <andy.grunwald@aiven.io>
Co-authored-by: Andy Grunwald <andy.grunwald@aiven.io>
Co-authored-by: Andy Grunwald <andy.grunwald@aiven.io>
Co-authored-by: Andy Grunwald <andy.grunwald@aiven.io>
@sonarcloud
Copy link

sonarcloud bot commented Jun 7, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 22 Bugs
Vulnerability E 7 Vulnerabilities
Security Hotspot E 28 Security Hotspots
Code Smell A 626 Code Smells

No Coverage information No Coverage information
6.9% 6.9% Duplication

@sonarcloud
Copy link

sonarcloud bot commented Jun 7, 2023

Please retry analysis of this Pull-Request directly on SonarCloud.

@t-h-e
Copy link
Contributor Author

t-h-e commented Jun 7, 2023

After 2,5 years, I cannot tell you the reasoning behind all the changes anymore. As far as I remember I made one change after another to make lansuite work STRICT_TRANS_TABLES.
We have a version running with those changes for as long as this PR is open. If there have been other changes to make lansuite work with STRICT_TRANS_TABLES that is fine as well.
If this PR is not needed anymore. Feel free to close it.

@andygrunwald
Copy link
Collaborator

Thx @t-h-e.
This adds a lot of context.

Would you mind sharing the URL of your installation? Or is it locally?
And the list of modules you have activated?
This helps me to evaluate the impact.

I plan to look into this more in detail and get this merged soon(ish). I believe it is the right direction.

@t-h-e
Copy link
Contributor Author

t-h-e commented Jun 28, 2023

URL: https://www.haag-networx.at

Activedted modules:

  • Clanmanager
  • Downloads
  • Gästeliste
  • Info
  • Mai
  • Messenger
  • News
  • Partyverwaltung
  • Poll
  • Sitzplan
  • Sponsoren
  • Statistiken
  • Turnier
  • About
  • Anmeldung
  • Benutzermanager
  • Boxen
  • Cronjob
  • Installation
  • MasterSearch
  • Startseite

@sonarcloud
Copy link

sonarcloud bot commented Oct 14, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 13 Code Smells

No Coverage information No Coverage information
4.8% 4.8% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

Copy link

sonarcloud bot commented Apr 11, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
3.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflicts database-modification Ticket includes a database modification that may need (manual) application on existing databases pending-submitter-response
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants