BoostN
Well-known member
I'm calling an external API and then doing a check against the email passed and based on the result, I'm updating a field on the XF user record. Now, I want to be efficent with this.
I have two use cases:
1) The initial install where I need to sync this list to the current user table in XF.
2) Run the job once per night to keep values true from the Source (External API) to the XF user table.
Any improvements or suggestions I can make from what I have? My service actually works well, just wanted to be sure I'm approaching this in the correct "XF2" way..
I have two use cases:
1) The initial install where I need to sync this list to the current user table in XF.
2) Run the job once per night to keep values true from the Source (External API) to the XF user table.
PHP:
class Sync extends AbstractJob
{
public function run($maxRunTime)
{
$startTime = microtime(true);
$users = \XF::app()->finder('XF:User')->fetch();
foreach ($users as $user) {
$this->updateUser($user);
if (microtime(true) - $startTime >= $maxRunTime) {
return $this->resume();
}
}
return $this->complete();
}
public function updateUser(\XF\Entity\User $user)
{
$app = \XF::app();
/** @var \MyService\..\.. $myService */
$myService = \XF::service('///MY SERVICE');
$result = $myService->getStatus($user->email);
$userOptions = $user->getRelationOrDefault('Option');
if ($result == 'Something') {
$userOptions->fastUpdate('my_option', true);
}
else
{
//DO SOMETHING ELSE
}
}
public function getStatusMessage()
{
//////TODO
}
public function canCancel()
{
return true;
}
public function canTriggerByChoice()
{
return true;
}
}
Any improvements or suggestions I can make from what I have? My service actually works well, just wanted to be sure I'm approaching this in the correct "XF2" way..