Skip to content

Commit

Permalink
fix wrong date format in field notes, fix warning if user has no logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mirsch committed Aug 24, 2016
1 parent 9e5034d commit 852f696
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions htdocs/app/Resources/translations/messages.en.yml
Expand Up @@ -14,6 +14,7 @@ field_notes:


# Desc: Log type "%type%" is not implemented. # Desc: Log type "%type%" is not implemented.
log_type_not_implemented: 'Log type "%type%" is not implemented.' log_type_not_implemented: 'Log type "%type%" is not implemented.'
wrong_date_format: 'The date in this file is in wrong format.'
wrong_file_format: 'This file seems not to be a field notes file.' wrong_file_format: 'This file seems not to be a field notes file.'


field_notes: 'Field Notes' field_notes: 'Field Notes'
Expand Down
Expand Up @@ -35,7 +35,7 @@ public function indexAction(Request $request)
$file = $form->getData()[UploadFieldNotesType::FIELD_FILE]; $file = $form->getData()[UploadFieldNotesType::FIELD_FILE];
try { try {
$ignoreDate = null; $ignoreDate = null;
if ($form->getData()[UploadFieldNotesType::FIELD_IGNORE] && $form->getData()[UploadFieldNotesType::FIELD_IGNORE_DATE]) { if (!empty($form->getData()[UploadFieldNotesType::FIELD_IGNORE])) {
$ignoreDate = DateUtil::dateTimeFromMySqlFormat($form->getData()[UploadFieldNotesType::FIELD_IGNORE_DATE]); $ignoreDate = DateUtil::dateTimeFromMySqlFormat($form->getData()[UploadFieldNotesType::FIELD_IGNORE_DATE]);
} }
$fieldNoteService->importFromFile($file->getRealPath(), $user->getId(), $ignoreDate); $fieldNoteService->importFromFile($file->getRealPath(), $user->getId(), $ignoreDate);
Expand Down
7 changes: 7 additions & 0 deletions htdocs/src/AppBundle/Exception/WrongDateFormatException.php
@@ -0,0 +1,7 @@
<?php

namespace AppBundle\Exception;

class WrongDateFormatException extends \Exception
{
}
7 changes: 7 additions & 0 deletions htdocs/src/AppBundle/Service/FieldNoteService.php
Expand Up @@ -3,6 +3,7 @@
namespace AppBundle\Service; namespace AppBundle\Service;


use AppBundle\Entity\FieldNote; use AppBundle\Entity\FieldNote;
use AppBundle\Exception\WrongDateFormatException;
use AppBundle\Exception\WrongFileFormatException; use AppBundle\Exception\WrongFileFormatException;
use AppBundle\Service\Interfaces\FieldNoteServiceInterface; use AppBundle\Service\Interfaces\FieldNoteServiceInterface;
use AppBundle\Service\Traits\ErrorTrait; use AppBundle\Service\Traits\ErrorTrait;
Expand Down Expand Up @@ -45,6 +46,7 @@ public function __construct(EntityManagerInterface $entityManager, TranslatorInt
* @param null|\DateTime $ignoreBeforeDate * @param null|\DateTime $ignoreBeforeDate
* *
* @return bool * @return bool
* @throws \AppBundle\Exception\WrongDateFormatException
* @throws \AppBundle\Exception\WrongFileFormatException * @throws \AppBundle\Exception\WrongFileFormatException
*/ */
public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate = null) public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate = null)
Expand All @@ -65,6 +67,11 @@ public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate =
$data[1], $data[1],
new DateTimeZone('UTC') new DateTimeZone('UTC')
); );
if (!$date) {
throw new WrongDateFormatException(
$this->translator->trans('field_notes.error.wrong_date_format')
);
}


if ($ignoreBeforeDate !== null && $date < $ignoreBeforeDate) { if ($ignoreBeforeDate !== null && $date < $ignoreBeforeDate) {
continue; continue;
Expand Down

0 comments on commit 852f696

Please sign in to comment.