protected function updateForUser($userId)
 {
     $userSettings = $this->getUserSettings($userId);
     $localUris = $userSettings->getLocalURIs();
     $xmlrpc = new XmlRpc($userSettings->getUsername(), $userSettings->getPassword());
     $start = (new \DateTime())->sub($userSettings->getSyncPeriodAsInterval());
     $end = new \DateTime();
     $this->logger->debug("Fetching itemized entries from %s to %s for user '%s' for localUris: %s", $start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s'), $userId, count($localUris) === 0 ? 'all' : implode($localUris, ', '));
     try {
         $itemized = $xmlrpc->itemizedEntriesGet($start, $end, count($localUris) === 0 ? null : $localUris);
     } catch (XmlRpcException $e) {
         $this->logger->error('An XMLRPC exception occurred: %s', $e->getMessage());
         throw $e;
     } catch (HttpException $e) {
         $this->loger->error('Remote backend failed with HTTP status code %d', $e->getCode());
         throw $e;
     }
     $this->logger->debug("Fetched %d entries for user '%s'", count($itemized), $userId);
     $count = 0;
     foreach ($itemized as $entry) {
         $count += $this->insert($userId, $entry, $userSettings);
     }
     $this->logger->debug("Inserted %d entries for user '%s'", $count, $userId);
     $userSettings->setLastUpdated();
 }