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

do not return NULL, if database is empty #273

Merged
merged 1 commit into from
Oct 18, 2023
Merged

Conversation

stklcode
Copy link
Contributor

@stklcode stklcode commented Oct 16, 2023

Null causes trouble during further processing, i.e. PHP warnings in the API processing and later on problems building the dashboard widget in Javascript, because all methods expect the array to have all keys.

Move the caching (transient) directive into the conditional, so we still do not cache empty results and so not return NULL anymore.


This part will produce a couple of warnings, if get_stats() returns null:

$stats = Statify_Dashboard::get_stats( $refresh );
$visits = $stats['visits'];

And this part will fail:

statify/js/dashboard.js

Lines 161 to 166 in 0ec5f69

function renderTopList(table, data) {
// Get pre-existing rows.
const rows = table.querySelectorAll('tr');
// Update or append rows.
data.forEach((r, idx) => {

@stklcode stklcode added the bug label Oct 16, 2023
@stklcode stklcode force-pushed the fix/dashboard-empty-db branch 2 times, most recently from 81c467e to 3a57eb9 Compare October 16, 2023 16:08
@stklcode stklcode self-assigned this Oct 16, 2023
Null causes trouble during further processing, i.e. PHP warnings in the
API processing and later on problems building the dashboard widget in
Javascript, because all methods expect the array to have all keys.

Move the caching (transient) directive into the conditional, so we still
do not cache empty results and so not return NULL anymore.
@stklcode stklcode merged commit 83a29f1 into develop Oct 18, 2023
16 checks passed
@stklcode stklcode added this to the 2.0.0 milestone Oct 18, 2023
@stklcode stklcode deleted the fix/dashboard-empty-db branch October 18, 2023 12:52
@sonarcloud
Copy link

sonarcloud bot commented Oct 18, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

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

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants