3
ok i wrote a script and save it in modules/profile/admin/sync.php
// $Id: sync.php,v 1.1 2005/012/1 10:30:33 irmtfan Exp $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, https://xoops.org/, http://www.xoopscube.jp/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
/*********************************************************/
/* Users Synchronize Function */
/*********************************************************/
include '../../../include/cp_header.php';
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
xoops_cp_header();
$form = new XoopsThemeForm(_PROFILE_AM_SYNCHRONIZE, 'form', 'sync.php');
$form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
$form->display();
// Synchronize all users after click on submit button
if (isset($_POST['submit'])){
$sql = "SELECT uid FROM ".$xoopsDB->prefix("users")."";
if ( !$result = $xoopsDB->query($sql) ) {
exit(_PROFILE_AM_CNGUSERID);
}
while ($row = $xoopsDB->fetchArray($result)) {
$id = $row['uid'];
synchronize($id, "user");
}
redirect_header('user.php', 2, sprintf(_PROFILE_AM_SAVEDSUCCESS, _PROFILE_AM_UPDATEUSER));
exit();
}
// synchronize function modified from XOOPS 2.0
function synchronize($id,$type)
{
global $xoopsDB;
switch($type) {
case 'user':
// 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("user_profile")." SET posts = $total_posts WHERE profileid = $id";
if ( !$result = $xoopsDB->query($sql) ) {
exit(sprintf(_PROFILE_AM_CNUUSER %s ,$id));
}
break;
case 'all users':
$sql = "SELECT uid FROM ".$xoopsDB->prefix("users")."";
if ( !$result = $xoopsDB->query($sql) ) {
exit(_PROFILE_AM_CNGUSERID);
}
while ($row = $xoopsDB->fetchArray($result)) {
$id = $row['uid'];
synchronize($id, "user");
echo $id;
}
break;
default:
break;
}
}
xoops_cp_footer();
?>
now i have a problem when the site has too many users it cause server overloaded