Commit 652e3b99 authored by dj3c1t's avatar dj3c1t

import.previous.version : licences

parent 66e7c033
......@@ -7,10 +7,8 @@ use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Dj3c1t\SourceMLBundle\Entity\Source;
use Dj3c1t\SourceMLBundle\Entity\DerivationSource;
use Dj3c1t\AppBundle\Entity\User;
use Dj3c1t\SourceMLBundle\Entity\Licence;
class ImportPreviousVersion {
......@@ -96,15 +94,12 @@ class ImportPreviousVersion {
public function importUsers() {
$this->log("import users");
$em = $this->container->get('doctrine')->getManager();
$metadata = $em->getClassMetaData(get_class(new User()));
$metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
$metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
$userRepo = $em->getRepository('Dj3c1tAppBundle:User');
$roleRepo = $em->getRepository('Dj3c1tAppBundle:Role');
$adminRole = $roleRepo->findOneByRole("ROLE_ADMIN");
$userRole = $roleRepo->findOneByRole("ROLE_USER");
$encoder_factory = $this->container->get('security.encoder_factory');
if(($users = $this->mw_data->users()) === null) {
if(($users = $this->mw_data->users()) === false) {
$this->error("can't load users from mw_data");
}
$mw_users = array();
......@@ -123,6 +118,7 @@ class ImportPreviousVersion {
}
$mw_emails[$mw_user["email"]] = true;
$user = new User();
$this->ignoreIdGenerator($user);
$user->setId($mw_user["id"]);
$user->setIsActive(true);
$user->setUsername($mw_user["login"]);
......@@ -163,9 +159,21 @@ class ImportPreviousVersion {
public function importLicences() {
$this->log("import licences");
// todo ...
$em = $this->container->get('doctrine')->getManager();
if(($licences = $this->mw_data->licences()) === false) {
$this->error("can't load licences from mw_data");
}
foreach($licences["list"] as $mw_licence) {
$this->log("creating new licence ".$mw_licence["nom"]);
$licence = new Licence();
$this->ignoreIdGenerator($licence);
$licence->setId($mw_licence["id"]);
$licence->setName($mw_licence["nom"]);
$licence->setUrl($mw_licence["url"]);
$em->persist($licence);
}
$this->log("persisting licences to database");
$em->flush();
}
// ----------------------------------------------------------------------
......@@ -303,4 +311,11 @@ class ImportPreviousVersion {
}
}
public function ignoreIdGenerator($entity) {
$em = $this->container->get('doctrine')->getManager();
$metadata = $em->getClassMetaData(get_class($entity));
$metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
$metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment