Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Chill-project
Chill-Main
Commits
42d49848
Commit
42d49848
authored
Nov 27, 2014
by
Marc Ducobu
Browse files
Exclude deadLanguages and RegionalVersionLanguages
parent
ab4d9e17
Changes
1
Hide whitespace changes
Inline
Side-by-side
Command/LoadAndUpdateLanguagesCommand.php
View file @
42d49848
...
...
@@ -22,6 +22,7 @@ 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\Input\InputOption
;
use
Symfony\Component\Console\Output\OutputInterface
;
/*
...
...
@@ -29,15 +30,40 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class
LoadAndUpdateLanguagesCommand
extends
ContainerAwareCommand
{
// The regional version of language are language with _ in the code
// This array contains regional code to not exclude
private
$regionalVersionToInclude
=
[
"ro_MD"
];
// Array of ancien languages (to exclude)
private
$ancientToExclude
=
[
"ang"
,
"egy"
,
"fro"
,
"goh"
,
"grc"
,
"la"
,
"non"
,
"peo"
,
"pro"
,
"sga"
,
"dum"
,
"enm"
,
"frm"
,
"gmh"
,
"mga"
,
"akk"
,
"phn"
,
"zxx"
,
"got"
,
"und"
];
const
INCLUDE_REGIONAL_VERSION
=
'include_regional'
;
const
INCLUDE_ANCIENT
=
'include_ancient'
;
/*
* (non-PHPdoc)
* @see \Symfony\Component\Console\Command\Command::configure()
*/
protected
function
configure
()
{
$this
->
setName
(
'chill:main:languages:populate'
)
$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'
);
'languages, but will update names according to available languages'
)
->
addOption
(
self
::
INCLUDE_REGIONAL_VERSION
,
null
,
InputOption
::
VALUE_NONE
,
'Include the regional languages. The regional languages are languages with code containing _ excepted '
.
implode
(
','
,
$this
->
regionalVersionToInclude
)
.
'.'
)
->
addOption
(
self
::
INCLUDE_ANCIENT
,
null
,
InputOption
::
VALUE_NONE
,
'Include the ancient languages that are languages with code '
.
implode
(
', '
,
$this
->
ancientToExclude
)
.
'.'
)
;
}
/*
...
...
@@ -58,21 +84,39 @@ class LoadAndUpdateLanguagesCommand extends ContainerAwareCommand
$languageCodes
=
array_keys
(
$languages
[
$chillAvailableLanguages
[
0
]]);
foreach
(
$languageCodes
as
$code
)
{
$excludeCode
=
(
(
!
$input
->
getOption
(
self
::
INCLUDE_REGIONAL_VERSION
)
and
strpos
(
$code
,
'_'
)
and
!
in_array
(
$code
,
$this
->
regionalVersionToInclude
)
)
or
(
!
$input
->
getOption
(
self
::
INCLUDE_ANCIENT
)
and
in_array
(
$code
,
$this
->
ancientToExclude
)
)
);
$langageDB
=
$em
->
getRepository
(
'ChillMainBundle:Language'
)
->
find
(
$code
);
if
(
!
$langageDB
)
{
$langageDB
=
new
\
Chill\MainBundle\Entity\Language
();
$langageDB
->
setId
(
$code
);
$em
->
persist
(
$langageDB
);
}
if
(
!
$excludeCode
)
{
if
(
!
$langageDB
)
{
$langageDB
=
new
\
Chill\MainBundle\Entity\Language
();
$langageDB
->
setId
(
$code
);
$em
->
persist
(
$langageDB
);
}
$avLangNames
=
array
();
$avLangNames
=
array
();
foreach
(
$chillAvailableLanguages
as
$avLang
)
{
$avLangNames
[
$avLang
]
=
$languages
[
$avLang
][
$code
];
}
foreach
(
$chillAvailableLanguages
as
$avLang
)
{
$avLangNames
[
$avLang
]
=
$languages
[
$avLang
][
$code
];
}
$langageDB
->
setName
(
$avLangNames
);
$langageDB
->
setName
(
$avLangNames
);
}
else
{
if
(
$langageDB
)
{
$em
->
remove
(
$langageDB
);
}
echo
"Code excluded : "
.
$code
.
" - "
.
$languageBundle
->
getLanguageName
(
$code
)
.
"
\n
"
;
}
}
$em
->
flush
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment