Skip to content

Conversation

@mambax7
Copy link
Collaborator

@mambax7 mambax7 commented Mar 15, 2025

No description provided.

Copy link
Contributor

@ggoffy ggoffy left a comment

Choose a reason for hiding this comment

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

Point 1:
why [$count] = $xoopsDB->fetchRow($result); and not $count = $xoopsDB->fetchRow($result);

Point 2: do not repeat DB query, suggestion:
$count = $xoopsDB->fetchRow($result);
if ((int)$count > 0) {
$block['modules'][0]['adminlink'] = XOOPS_URL . '/modules/news/admin/index.php?op=newarticle';
[$block['modules'][0]['pendingnum']] = $count ;
$block['modules'][0]['lang_linkname'] = _MB_SYSTEM_SUBMS;
}

@mambax7
Copy link
Collaborator Author

mambax7 commented Mar 15, 2025

@ggoffy Point 1:

If you only need the count as a single value, [$count] = $xoopsDB->fetchRow($result) is more explicit and safer than $count = $xoopsDB->fetchRow($result), because:

  • With $count = $xoopsDB->fetchRow($result), $count would be an array ([5]), and you’d need to access $count[0] later.
  • With [$count] = ..., you directly get the scalar value (5), which aligns with the condition later if ((int)$count > 0) .

@ggoffy
Copy link
Contributor

ggoffy commented Mar 15, 2025

hi, sorry, didn't realize that fetchRow provides an array :(
therefore code is working properly

nevertheless I would avoid second DB query:

$count = count($xoopsDB->fetchRow($result));
if ((int)$count > 0) {
$block['modules'][0]['adminlink'] = XOOPS_URL . '/modules/news/admin/index.php?op=newarticle';
[$block['modules'][0]['pendingnum']] = $count ;
$block['modules'][0]['lang_linkname'] = _MB_SYSTEM_SUBMS;
}

@mambax7
Copy link
Collaborator Author

mambax7 commented Mar 15, 2025

Good point - I'll streamline it later

@mambax7
Copy link
Collaborator Author

mambax7 commented Mar 15, 2025

However, sometimes you'll need to run it twice, because some of the functions (like the fetchRow($result) requires mysqli_result, otherwise it will crash XOOPS.. Therefore:

  1. get $result from $xoopsDB->query($sql);
  2. Check: if ($xoopsDB->isResultSet($result))
  3. Only if it is mysqli_result, then you run fetchRow($result)

@mambax7
Copy link
Collaborator Author

mambax7 commented Mar 27, 2025

@ggoffy, please check it out - I've made some improvements

@ggoffy
Copy link
Contributor

ggoffy commented Mar 28, 2025

  1. got error: Warning: Undefined global variable $module_handler in file /modules/system/blocks/system_blocks.php line 204

therefore I changed into

$module_handler = xoops_getHandler('module');
if (xoops_isActiveModule($module) && $module_handler->getCount(new Criteria('dirname', $module))) {

@ggoffy
Copy link
Contributor

ggoffy commented Mar 28, 2025

  1. code is not working with empy $condition

suggestion:

        $sql = "SELECT COUNT(*) FROM " . $xoopsDB->prefix($table);
        if ('' !== $condition) {
            $sql .= " WHERE $condition";
        }

@ggoffy
Copy link
Contributor

ggoffy commented Mar 28, 2025

  1. I would remove $index from function checkPendingContent($module, $table, $condition, $adminlink, $lang_linkname, &$block, $index, $xoopsDB) {
    and change line $block['modules'][$index] = [ into $block['modules'][] = [

@mambax7
Copy link
Collaborator Author

mambax7 commented Mar 29, 2025

@ggoffy thanks for testing it. Regarding removing $index from function checkPendingContent(), is there anywhere an dependency on the index number?

@ggoffy
Copy link
Contributor

ggoffy commented Mar 29, 2025

I don't think that there is a dependency, because in the block itself there is only a simple walk through a foreach

@mambax7
Copy link
Collaborator Author

mambax7 commented Mar 30, 2025

@ggoffy your improvements are now included, please check if it works for you

@ggoffy
Copy link
Contributor

ggoffy commented Mar 30, 2025

works fine, thank you

@mambax7 mambax7 merged commit 60a7726 into XOOPS:master Mar 30, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants