Hello guys,
I worked on an controller action to import a simple CSV-file.
This is my CSV
test@test.com ;test1;test2;test3
test2@test2.com ;test1;test2;test3
… and this is my Action. The result is an Error 500
/**
* @param array $csv
* @return void
*/
public function importcsvAction(array $csv) {
/* @var $fileResource \TYPO3\Flow\Resource\Resource */
$fileResource = $this->resourceManager->importUploadedResource($csv);
$uri = $fileResource->getUri();
$recipientList = file($uri);
foreach ($recipientList as $recipient) {
list($email, $firstname, $lastname, $gender) = explode(';', $recipient);
$user = new \DirectMail\Newsletter\Domain\Model\Recipient();
$user->setEmail($email);
$user->setFirstname($firstname);
$user->setLastname($lastname);
$user->setGender($gender);
$user->setCategory("0");
$user->setHidden("NULL");
$this->recipientRepository->add($user);
}
}
mrimann
(Mario Rimann)
December 8, 2015, 10:02am
#2
If you have an error 500 on your server, I’m pretty sure the hint towards the reason for the error is within your error log. Did you see something there? If so, what does it say at the time it throws an error 500 to you?
lsascha
(Sascha Löffler)
December 11, 2015, 12:20am
#3
Looks like you where working on something similar like myself for the Lelesys Newsletter Plugin?
I have created a fork for our website here with CSV Import.
the main actions are in the PersonController
<?php
namespace Lelesys\Plugin\Newsletter\Controller\Module\NewsletterManagement\Person;
/*
* This script belongs to the package "Lelesys.Plugin.Newsletter". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* */
use TYPO3\Flow\Annotations as Flow;
use Lelesys\Plugin\Newsletter\Controller\Module\NewsletterManagementController;
use Lelesys\Plugin\Newsletter\Domain\Model\Recipient\Person;
/**
* A Person Controller
*
* @Flow\Scope("singleton")
*/
This file has been truncated. show original
i just didn’t made it a file upload but instead a simple textarea.
1 Like
Very good idea, thank you!
lsascha
(Sascha Löffler)
December 11, 2015, 7:34pm
#5
you can just use the repository or fork it yourself. If you have any pull request you can create one too of course. Will be happy to merge something. Maybe it can even go back into the main repository later too.