Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\core\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -29,7 +29,25 @@ class _profilesync extends \IPS\Task
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$totalToSync = \IPS\Db::i()->select( 'count(*)', 'core_members', array( "temp_ban=0 AND profilesync_lastsync > 0" ) )->first();
|
||||
/* Do we have any login methods that even support syncing enabled? */
|
||||
if( !$this->canSync() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$where = array( array( "temp_ban=?", 0 ), array( "profilesync_lastsync > ?", 0 ) );
|
||||
|
||||
/* Only check accounts that have visited in the last 6 months */
|
||||
$where[] = array( "GREATEST(last_activity, last_visit) > ?", \IPS\DateTime::create()->sub( new \DateInterval('P6M') )->getTimestamp() );
|
||||
|
||||
/* And only check accounts that are actually synchronizing, UNLESS the admin is also forcing synchronization for any login methods */
|
||||
if( !$this->hasForcedSync() )
|
||||
{
|
||||
$where[] = array( "profilesync IS NOT NULL and profilesync != ?", '[]' );
|
||||
}
|
||||
|
||||
|
||||
$totalToSync = \IPS\Db::i()->select( 'count(*)', 'core_members', $where )->first();
|
||||
|
||||
if( !$totalToSync )
|
||||
{
|
||||
@@ -42,11 +60,14 @@ class _profilesync extends \IPS\Task
|
||||
$accounts = ceil( $totalToSync / 12 );
|
||||
}
|
||||
|
||||
$this->runUntilTimeout( function()
|
||||
/* Only sync accounts we haven't synced in the last 12 hours */
|
||||
$where[] = array( "profilesync_lastsync < ?", ( time() - ( 60 * 60 * 12 ) ) );
|
||||
|
||||
$this->runUntilTimeout( function() use( $where )
|
||||
{
|
||||
try
|
||||
{
|
||||
$member = \IPS\Db::i()->select( '*', 'core_members', array( "temp_ban=0 AND profilesync_lastsync > 0 AND profilesync_lastsync < ?", ( time() - ( 60 * 60 * 12 ) ) ), 'profilesync_lastsync ASC', 1 )->first();
|
||||
$member = \IPS\Db::i()->select( '*', 'core_members', $where, 'profilesync_lastsync ASC', 1 )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
@@ -61,4 +82,40 @@ class _profilesync extends \IPS\Task
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if we can even sync
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function canSync()
|
||||
{
|
||||
foreach ( \IPS\Login::methods() as $method )
|
||||
{
|
||||
if( $method->hasSyncOptions() )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if any login handlers force syncing
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasForcedSync()
|
||||
{
|
||||
foreach ( \IPS\Login::methods() as $method )
|
||||
{
|
||||
if( \count( $method->forceSync() ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user