DisableLanguageCommand.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Definition of command to
  4. * disable a language
  5. * Does not support multi-url yet
  6. */
  7. /**
  8. * Necessary namespaces definitions and usage
  9. */
  10. namespace Chash\Command\Translation;
  11. use Chash\Command\Database\CommonChamiloDatabaseCommand;
  12. use Symfony\Component\Console\Command\Command;
  13. use Symfony\Component\Console\Input\InputArgument;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Input\InputOption;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. /**
  18. * Definition of the translation:disable command
  19. */
  20. class DisableLanguageCommand extends CommonChamiloDatabaseCommand
  21. {
  22. protected function configure()
  23. {
  24. parent::configure();
  25. $this
  26. ->setName('translation:disable')
  27. ->setAliases(array('tdl'))
  28. ->setDescription('Disables a (enabled) language')
  29. ->addArgument(
  30. 'language',
  31. InputArgument::REQUIRED,
  32. 'The English name for the language to disable.'
  33. );
  34. }
  35. protected function execute(InputInterface $input, OutputInterface $output)
  36. {
  37. parent::execute($input, $output);
  38. $_configuration = $this->getHelper('configuration')->getConfiguration();
  39. $dbh = $this->getHelper('configuration')->getConnection();
  40. $lang = mysql_real_escape_string($input->getArgument('language'));
  41. $ls = "SELECT id, english_name, available FROM language WHERE english_name = '$lang'";
  42. $lq = mysql_query($ls);
  43. if ($lq === false) {
  44. $output->writeln('Error in query: '.mysql_error());
  45. return null;
  46. }
  47. $num = mysql_num_rows($lq);
  48. if ($num<1) {
  49. $output->writeln($lang.' language not found in the database. Please make sure you use an existing language name.');
  50. return null;
  51. }
  52. $lr = mysql_fetch_assoc($lq);
  53. if ($lr['available'] == 0) {
  54. $output->writeln($lang.' language is already disabled. Nothing to do.');
  55. return null;
  56. }
  57. // Everything is OK so far, enable the language
  58. $us = "UPDATE language SET available = 0 WHERE id = {$lr['id']}";
  59. $uq = mysql_query($us);
  60. if ($uq === false) {
  61. $output->writeln('Error in query: '.mysql_error());
  62. } else {
  63. $output->writeln($lang . ' language has been disabled.');
  64. }
  65. return null;
  66. }
  67. }