Location: PHPKode > projects > Anahita Social Engine > admin/controllers/maintenance.php
<?php
/**
* @version		0.9.4
* @package		Anahita Social Engine
* @copyright	Copyright (C) 2007 - 2010 rmd Studio Inc. and Peerglobe Technology Inc. All rights reserved.
* @license		GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
* @link 		http://www.anahitapolis.com
*/

class ComSocialengineControllerMaintenance extends AnUikitControllerAbstract 
{	
	/**
	 * 
	 */
	const SYNC_LIMIT = 100;
	
	/**
	 * Constructor.
	 *
	 * @param 	array 	An optional array with configuration options
	 */		
	public function __construct($options=array())
	{
		parent::__construct($options);
		
		$this->registerFunctionBefore(array('sync','read'), 'findUnsynchedUsers');
	}		
	
	/**
	 * Action Read
	 * 
	 * @return void
	 */
	public function _actionRead()
	{
		//get a list of users that needs to be synched
		$this->view()->assign('users', $this->users);
		parent::_actionRead();
	}
	
	/**
	 * Action Sync
	 * 
	 * @return void
	 */
	public function _actionSync()
	{	
		for($i=0; $i<self::SYNC_LIMIT; $i++)
		{
			$user = $this->users[$i];
			if (AnModelPersonHelper::createFromUser($user)) 
				unset( $this->users[$i] );
		}
		
		print json_encode(array('users'=>count($this->users)));
	}
	
	/**
	 * Find the users that needs to be synced and set it to the context
	 * 
	 * @return void
	 */
	public function findUnsynchedUsers()
	{
		$db		  	 = KFactory::get('lib.koowa.database');
		
		$this->users = array();
		$user_ids = $db->fetchResultList("SELECT user_id FROM #__socialengine_people");		
		if ( count($user_ids) )
			$this->users = $db->fetchObjectList("SELECT * FROM #__users AS user WHERE user.id NOT IN (".implode(',', $user_ids).")");
	}
}
Return current item: Anahita Social Engine