1
Hi All,
After importing into the newbb forum the data from another forum I was in need for a All Users Postr Count Synch.
I made the following changes to \modules\system\admin\users\users.php
In function modifyUser($user) after:
echo "n";
Add :
echo "n";
This will add a Synchronize All Users button
Create a new function:
function mysynchronize($id)
{
global $xoopsDB;
// Array of tables from which to count 'posts'
$tables = array();
// Count comments (approved only: com_status == XOOPS_COMMENT_ACTIVE)
include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
$tables[] = array ('table_name' => 'xoopscomments',
'uid_column' => 'com_uid', 'criteria' => new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
// Count forum posts
$tables[] = array ('table_name' => 'bb_posts',
'uid_column' => 'uid');
$total_posts = 0;
foreach ($tables as $table) {
$criteria = new CriteriaCompo();
$criteria->add (new Criteria($table['uid_column'], $id));
if (!empty($table['criteria'])) {
$criteria->add ($table['criteria']);
}
$sql = "SELECT COUNT(*) AS total
FROM ".$xoopsDB->prefix($table['table_name']) . ' ' . $criteria->renderWhere();
if ( $result = $xoopsDB->query($sql) ) {
if ($row = $xoopsDB->fetchArray($result)) {
$total_posts = $total_posts + $row['total'];
}
}
}
$sql = "UPDATE ".$xoopsDB->prefix("users")." SET posts = $total_posts WHERE uid = $id";
if ( !$result = $xoopsDB->query($sql) ) {
exit(sprintf(_AM_CNUUSER %s ,$id));
}
}
and replace the delivered funtion:
function synchronize($id, $type)
{
global $xoopsDB;
switch($type) {
case 'user':
mysynchronize($id);
break;
case 'all users':
$sql = "SELECT uid FROM ".$xoopsDB->prefix("users")."";
if ( !$result = $xoopsDB->query($sql) ) {
exit(_AM_CNGUSERID);
}
while ($row = $xoopsDB->fetchArray($result)) {
$id = $row['uid'];
mysynchronize($id);
}
break;
default:
break;
}
redirect_header("admin.php?fct=users&op=modifyUser&uid=".$id,1,_AM_DBUPDATED);
exit();
}
Enjoy it!