Skip to content

Commit

Permalink
Fixing import if no data
Browse files Browse the repository at this point in the history
  • Loading branch information
ngodfraind committed Feb 2, 2015
1 parent 692ee1d commit 0b30055
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions Transfert/ForumImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,58 +108,60 @@ public function import(array $data)
{
$forum = new Forum();
$repo = $this->om->getRepository('ClarolineCoreBundle:User');

if (isset($data['data'])) {
foreach ($data['data'] as $category) {
$entityCategory = new Category();
$entityCategory->setForum($forum);
$entityCategory->setName($category['category']['name']);

foreach ($data['data'] as $category) {
$entityCategory = new Category();
$entityCategory->setForum($forum);
$entityCategory->setName($category['category']['name']);
foreach ($category['category']['subjects'] as $subject) {
$subjectEntity = new Subject();
$subjectEntity->setTitle($subject['subject']['name']);

foreach ($category['category']['subjects'] as $subject) {
$subjectEntity = new Subject();
$subjectEntity->setTitle($subject['subject']['name']);
$creator = null;

$creator = null;
if ($subject['subject']['creator'] !== null) {
$creator = $repo->findOneByUsername($subject['subject']['creator']);
}

if ($subject['subject']['creator'] !== null) {
$creator = $repo->findOneByUsername($subject['subject']['creator']);
}
if ($creator === null) {
$creator = $this->container->get('security.context')->getToken()->getUser();
}

if ($creator === null) {
$creator = $this->container->get('security.context')->getToken()->getUser();
}
$subjectEntity->setCreator($creator);
$subjectEntity->setCategory($entityCategory);

$subjectEntity->setCreator($creator);
$subjectEntity->setCategory($entityCategory);
foreach ($subject['subject']['messages'] as $message) {
$messageEntity = new Message();
$content = file_get_contents(
$this->getRootPath() . DIRECTORY_SEPARATOR . $message['message']['path']
);

foreach ($subject['subject']['messages'] as $message) {
$messageEntity = new Message();
$content = file_get_contents(
$this->getRootPath() . DIRECTORY_SEPARATOR . $message['message']['path']
);
$messageEntity->setContent($content);

$messageEntity->setContent($content);
$creator = null;

$creator = null;
if ($message['message']['creator'] !== null) {
$creator = $repo->findOneByUsername($message['message']['creator']);
}

if ($message['message']['creator'] !== null) {
$creator = $repo->findOneByUsername($message['message']['creator']);
}
if ($creator === null) {
$creator = $this->container->get('security.context')->getToken()->getUser();
}

if ($creator === null) {
$creator = $this->container->get('security.context')->getToken()->getUser();
}
$messageEntity->setCreator($creator);
$messageEntity->setSubject($subjectEntity);
$messageEntity->setAuthor($message['message']['author']);

$messageEntity->setCreator($creator);
$messageEntity->setSubject($subjectEntity);
$messageEntity->setAuthor($message['message']['author']);
$this->om->persist($messageEntity);
}

$this->om->persist($messageEntity);
$this->om->persist($subjectEntity);
}

$this->om->persist($subjectEntity);
$this->om->persist($entityCategory);
}

$this->om->persist($entityCategory);
}

return $forum;
Expand Down

0 comments on commit 0b30055

Please sign in to comment.