Skip to content
Permalink
Browse files

fix wrong date format in field notes, fix warning if user has no logs

  • Loading branch information...
mirsch committed Aug 24, 2016
1 parent 9e5034d commit 852f6963a07daa3fb6ff94b51be150546da4c1f4
@@ -14,6 +14,7 @@ field_notes:

# Desc: 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.'

field_notes: 'Field Notes'
@@ -35,7 +35,7 @@ public function indexAction(Request $request)
$file = $form->getData()[UploadFieldNotesType::FIELD_FILE];
try {
$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]);
}
$fieldNoteService->importFromFile($file->getRealPath(), $user->getId(), $ignoreDate);
@@ -0,0 +1,7 @@
<?php
namespace AppBundle\Exception;
class WrongDateFormatException extends \Exception
{
}
@@ -3,6 +3,7 @@
namespace AppBundle\Service;
use AppBundle\Entity\FieldNote;
use AppBundle\Exception\WrongDateFormatException;
use AppBundle\Exception\WrongFileFormatException;
use AppBundle\Service\Interfaces\FieldNoteServiceInterface;
use AppBundle\Service\Traits\ErrorTrait;
@@ -45,6 +46,7 @@ public function __construct(EntityManagerInterface $entityManager, TranslatorInt
* @param null|\DateTime $ignoreBeforeDate
*
* @return bool
* @throws \AppBundle\Exception\WrongDateFormatException
* @throws \AppBundle\Exception\WrongFileFormatException
*/
public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate = null)
@@ -65,6 +67,11 @@ public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate =
$data[1],
new DateTimeZone('UTC')
);
if (!$date) {
throw new WrongDateFormatException(
$this->translator->trans('field_notes.error.wrong_date_format')
);
}
if ($ignoreBeforeDate !== null && $date < $ignoreBeforeDate) {
continue;

0 comments on commit 852f696

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