1
irmtfan
how to synchronize users in 2.2+ ?
  • 2005/11/16 15:48

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


there is a function in 2.0 versions to SYNC users. now i want the same function for 2.2+. anyone can help? please

2
irmtfan
Re: how to synchronize users in 2.2+ ?
  • 2005/11/19 15:36

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


**BUMP**

3
irmtfan
Re: how to synchronize users in 2.2+ ?
  • 2005/12/2 13:55

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


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'2sprintf(_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 %,$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

4
hipoonios
Re: how to synchronize users in 2.2+ ?
  • 2007/8/16 13:15

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


thanks irmtfan for that script. Worked well on my site.
I love Xoops!

5
toddherrold
Re: how to synchronize users in 2.2+ ?

likewise. . works like a charm!

Login

Who's Online

207 user(s) are online (83 user(s) are browsing Support Forums)


Members: 0


Guests: 207


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits