/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $language = $input->getArgument('language'); $tmpFolder = $input->getOption('tmp'); $_configuration = $this->getHelper('configuration')->getConfiguration(); $connection = $this->getHelper('configuration')->getConnection(); if ($connection) { $lang = isset($language) ? $language : null; $lang = mysql_real_escape_string($lang); $q = mysql_query("SELECT * FROM language WHERE english_name = '{$lang}' "); $langInfo = mysql_fetch_array($q, MYSQL_ASSOC); if (!$langInfo) { $output->writeln("<comment>Language '{$lang}' is not registered in the Chamilo Database</comment>"); $q = mysql_query("SELECT * FROM language WHERE parent_id IS NULL or parent_id = 0"); $output->writeln("<comment>Available languages are: </comment>"); while ($langRow = mysql_fetch_array($q, MYSQL_ASSOC)) { $output->write($langRow['english_name'] . ", "); } $output->writeln(' '); $q = mysql_query("SELECT * FROM language WHERE parent_id <> 0"); $output->writeln("<comment>Available sub languages are: </comment>"); while ($langRow = mysql_fetch_array($q, MYSQL_ASSOC)) { $output->write($langRow['english_name'] . ", "); } $output->writeln(' '); exit; } else { $output->writeln("<comment>Language</comment> <info>'{$lang}'</info> <comment>is registered in the Chamilo installation with iso code: </comment><info>{$langInfo['isocode']} </info>"); } $langFolder = $_configuration['root_sys'] . 'main/lang/' . $lang; if (!is_dir($langFolder)) { $output->writeln("<comment>Language '{$lang}' does not exist in the path: {$langFolder}</comment>"); } if (empty($tmpFolder)) { $tmpFolder = '/tmp/'; $output->writeln("<comment>No temporary directory defined. Assuming /tmp/. Please make sure you have *enough space* left on that device"); } if (!is_dir($tmpFolder)) { $output->writeln("<comment>Temporary directory: {$tmpFolder} is not a valid dir path, using /tmp/ </comment>"); $tmpFolder = '/tmp/'; } if ($langInfo) { $output->writeln("<comment>Creating translation package</comment>"); $fileName = $tmpFolder . $langInfo['english_name'] . '.tar'; $phar = new \PharData($fileName); $phar->buildFromDirectory($langFolder); $phar->setMetadata($langInfo); $output->writeln("<comment>File created:</comment> <info>{$fileName}</info>"); } } }
/** * Create PHAR archive * * @param string &$name Pack name * @param \Iterator $iterator Directory iterator * @param array $metadata Archive description OPTIONAL * @param boolean $compress Flag OPTIONAL * * @return \Phar */ protected static function pack(&$name, \Iterator $iterator, array $metadata = array(), $compress = true) { // To prevent existsing files usage \Includes\Utils\FileManager::deleteFile($name); $phar = new \PharData($name); // Files $phar->buildFromIterator($iterator, LC_DIR_ROOT); // Metadata $phar->setMetadata($metadata); // File hashes static::addPackHash($phar, $iterator); // GZ compression return $compress ? static::compress($phar, $name) : $phar; }