AndrewSimm
Well-known member
Just had this error:
- ErrorException: Country could not be determined for IP:
- src/XF/Error.php:82
- Generated by: Unknown account
- Jul 21, 2024 at 3:21 AM
Stack trace
#0 src/XF.php(257): XF\Error->logError('Country could n...', false)
#1 src/addons/Andrew/ModeratorPanel/XF/Entity/User.php(519): XF::logError('Country could n...')
#2 src/XF/Mvc/Entity/Entity.php(1324): Andrew\ModeratorPanel\XF\Entity\User->_postSave()
#3 src/XF/Service/User/RegistrationService.php(320): XF\Mvc\Entity\Entity->save()
#4 src/XF/Service/ValidateAndSavableTrait.php(42): XF\Service\User\RegistrationService->_save()
#5 src/XF/Pub/Controller/RegisterController.php(451): XF\Service\User\RegistrationService->save()
#6 src/XF/Mvc/Dispatcher.php(362): XF\Pub\Controller\RegisterController->actionRegister(Object(XF\Mvc\ParameterBag))
#7 src/XF/Mvc/Dispatcher.php(264): XF\Mvc\Dispatcher->dispatchClass('XF:Register', 'Register', Object(XF\Mvc\RouteMatch), Object(DigitalPoint\Analytics\XF\Pub\Controller\Register), NULL)
#8 src/XF/Mvc/Dispatcher.php(121): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(DigitalPoint\Analytics\XF\Pub\Controller\Register), NULL)
#9 src/XF/Mvc/Dispatcher.php(63): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#10 src/XF/App.php(2777): XF\Mvc\Dispatcher->run()
#11 src/XF.php(798): XF\App->run()
#12 index.php(23): XF::runApp('XF\\Pub\\App')
#13 {main}
I use error messages when testing code and it looks like I left one in. It just means no country was saved. I will remove for the next release.
PHP:
protected function _postSave()
{
parent::_postSave();
if ($this->isInsert()) {
$ipAddress = \XF::app()->request->getIp();
$country = \XF::repository('XF:User')->getIpCountry($ipAddress);
if (!empty($country)) {
$this->fastUpdate('andrew_reg_country', $country);
} else {
// Log an error or handle the case where the country is NULL
\XF::logError('Country could not be determined for IP: ' . $ipAddress);
}
}
}