mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
Adding languages in DB ref #356
This commit is contained in:
parent
70f5e81fd0
commit
22df3cb17d
80
Command/LoadAndUpdateLanguagesCommand.php
Normal file
80
Command/LoadAndUpdateLanguagesCommand.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Command;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||||
|
use Symfony\Component\Intl\Intl;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Load or update the languages entities command
|
||||||
|
*/
|
||||||
|
class LoadAndUpdateLanguagesCommand extends ContainerAwareCommand
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* (non-PHPdoc)
|
||||||
|
* @see \Symfony\Component\Console\Command\Command::configure()
|
||||||
|
*/
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this->setName('chill:main:languages:populate')
|
||||||
|
->setDescription('Load or update languages in db. This command does not delete existing '.
|
||||||
|
'languages, but will update names according to available languages');
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-PHPdoc)
|
||||||
|
* @see \Symfony\Component\Console\Command\Command::execute()
|
||||||
|
*/
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
|
||||||
|
$chillAvailableLanguages = $this->getContainer()->getParameter('chill_main.available_languages');
|
||||||
|
$languageBundle = Intl::getLanguageBundle();
|
||||||
|
$languages = array();
|
||||||
|
|
||||||
|
foreach ($chillAvailableLanguages as $avLang) {
|
||||||
|
$languages[$avLang] = $languageBundle->getLanguageNames($avLang);
|
||||||
|
}
|
||||||
|
|
||||||
|
$languageCodes = array_keys($languages[$chillAvailableLanguages[0]]);
|
||||||
|
|
||||||
|
foreach ($languageCodes as $code) {
|
||||||
|
$langageDB = $em->getRepository('ChillMainBundle:Language')->find($code);
|
||||||
|
|
||||||
|
if (! $langageDB) {
|
||||||
|
$langageDB = new \Chill\MainBundle\Entity\Language();
|
||||||
|
$langageDB->setId($code);
|
||||||
|
$em->persist($langageDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
$avLangNames = array();
|
||||||
|
|
||||||
|
foreach ($chillAvailableLanguages as $avLang) {
|
||||||
|
$avLangNames[$avLang] = $languages[$avLang][$code];
|
||||||
|
}
|
||||||
|
|
||||||
|
$langageDB->setName($avLangNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
$em->flush();
|
||||||
|
}
|
||||||
|
}
|
82
Entity/Language.php
Normal file
82
Entity/Language.php
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Language
|
||||||
|
*/
|
||||||
|
class Language
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string array
|
||||||
|
*/
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get id
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set id
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* @return Language
|
||||||
|
*/
|
||||||
|
public function setId($id)
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set name
|
||||||
|
*
|
||||||
|
* @param string array $name
|
||||||
|
* @return Language
|
||||||
|
*/
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get name
|
||||||
|
*
|
||||||
|
* @return string array
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
}
|
10
Resources/config/doctrine/Language.orm.yml
Normal file
10
Resources/config/doctrine/Language.orm.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Chill\MainBundle\Entity\Language:
|
||||||
|
type: entity
|
||||||
|
table: null
|
||||||
|
id:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
fields:
|
||||||
|
name:
|
||||||
|
type: json_array
|
||||||
|
lifecycleCallbacks: { }
|
Loading…
x
Reference in New Issue
Block a user