Skip to content
Permalink
Browse files

support field notes with windows line feeds

  • Loading branch information...
teiling88 committed Apr 19, 2017
1 parent f163ff1 commit 1de801f320c3fb82223f1a1e48f9359e2eb8c89e
Showing with 5 additions and 7 deletions.
  1. +5 −7 htdocs/src/AppBundle/Service/FieldNoteService.php
@@ -44,7 +44,6 @@ public function __construct(EntityManagerInterface $entityManager, TranslatorInt
* @param string $fileName
* @param int $userId
* @param null|\DateTime $ignoreBeforeDate
*
* @return bool
* @throws \AppBundle\Exception\WrongDateFormatException
* @throws \AppBundle\Exception\WrongFileFormatException
@@ -54,6 +53,8 @@ public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate =
$content = file_get_contents($fileName);
$content = str_replace("\xFF\xFE", '', $content); // remove UTF16(LE) BOM
$content = mb_convert_encoding($content, 'UTF-8', 'UCS-2LE');
// unify line feeds
$content = str_replace("\r\n", "\n", $content);
$rows = ArrayUtil::trimExplode("\"\n", $content);
$notFoundGeocacheCodes = [];
foreach ($rows as $row) {
@@ -72,7 +73,7 @@ public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate =
if (!array_key_exists($data[2], self::LOG_TYPE)) {
$this->addError(
/** @Desc("Log type ""%type%"" is not implemented.") */
/** @Desc("Log type ""%type%"" is not implemented.") */
$this->translator->trans('field_notes.error.log_type_not_implemented', ['%type%' => $data[2]])
);
continue;
@@ -93,7 +94,7 @@ public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate =
if (!$geocache) {
$notFoundGeocacheCodes[] = $data[0];
$this->addError(
/** @Desc("Geocache ""%code%"" not found.") */
/** @Desc("Geocache ""%code%"" not found.") */
$this->translator->transChoice(
'field_notes.error.geocache_not_found',
count($notFoundGeocacheCodes),
@@ -128,7 +129,6 @@ public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate =
/**
* @param int $userId
*
* @return \DateTime|null
*/
public function getLatestFieldNoteOrLogDate($userId)
@@ -142,7 +142,6 @@ public function getLatestFieldNoteOrLogDate($userId)
/**
* @param string $entityName
* @param int $userId
*
* @return \DateTime|null
*/
protected function getMaxDateFromEntityByUserId($entityName, $userId)
@@ -153,7 +152,7 @@ protected function getMaxDateFromEntityByUserId($entityName, $userId)
->select('MAX(e.date) AS max_date')
->from($entityName, 'e')
->where('e.user = :user_id')
->setParameter('user_id', $userId)
->setParameter('user_id', $userId)
->setMaxResults(1);
$result = $query->getQuery()->getResult();
if ($result && isset($result[0]['max_date'])) {
@@ -165,7 +164,6 @@ protected function getMaxDateFromEntityByUserId($entityName, $userId)
/**
* @param string $dateString
*
* @throws \AppBundle\Exception\WrongDateFormatException
* @return \DateTime
*/

0 comments on commit 1de801f

Please sign in to comment.
You can’t perform that action at this time.