protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getHelperSet()->get('dialog'); $command = $this->getApplication()->find('translations:fetch'); $arguments = array('command' => 'translations:fetch', '--username' => $input->getOption('username'), '--password' => $input->getOption('password')); $inputObject = new ArrayInput($arguments); $inputObject->setInteractive($input->isInteractive()); $command->run($inputObject, $output); $languages = API::getInstance()->getAvailableLanguageNames(); $languageCodes = array(); foreach ($languages as $languageInfo) { $languageCodes[] = $languageInfo['code']; } $plugin = $input->getOption('plugin'); $files = _glob(FetchFromOTrance::getDownloadPath() . DIRECTORY_SEPARATOR . '*.json'); $output->writeln("Starting to import new language files"); if (!$input->isInteractive()) { $output->writeln("(!) Non interactive mode: New languages will be skipped"); } $progress = $this->getHelperSet()->get('progress'); $progress->start($output, count($files)); foreach ($files as $filename) { $progress->advance(); $code = basename($filename, '.json'); if (!in_array($code, $languageCodes)) { if (!empty($plugin)) { continue; # never create a new language for plugin only } $createNewFile = false; if ($input->isInteractive()) { $createNewFile = $dialog->askConfirmation($output, "\nLanguage {$code} does not exist. Should it be added? ", false); } if (!$createNewFile) { continue; # do not create a new file for the language } @touch(PIWIK_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . $code . '.json'); API::unsetInstance(); // unset language manager instance, so valid names are refetched } $command = $this->getApplication()->find('translations:set'); $arguments = array('command' => 'translations:set', '--code' => $code, '--file' => $filename, '--plugin' => $plugin); $inputObject = new ArrayInput($arguments); $inputObject->setInteractive($input->isInteractive()); $command->run($inputObject, new NullOutput()); // update core modules that aren't in their own repo if (empty($plugin)) { foreach (self::getPluginsInCore() as $pluginName) { // update translation files $command = $this->getApplication()->find('translations:set'); $arguments = array('command' => 'translations:set', '--code' => $code, '--file' => $filename, '--plugin' => $pluginName); $inputObject = new ArrayInput($arguments); $inputObject->setInteractive($input->isInteractive()); $command->run($inputObject, new NullOutput()); } } } $progress->finish(); $output->writeln("Finished."); }
protected function execute(InputInterface $input, OutputInterface $output) { $changes = shell_exec('git status --porcelain -uno'); if (!empty($changes)) { $output->writeln("You have uncommited changes. Creating pull request is only available with a clean working directory"); return; } $unpushedCommits = shell_exec('git log origin/master..HEAD'); if (!empty($unpushedCommits)) { $output->writeln("You have unpushed commits. Creating pull request is only available with a clean working directory"); return; } chdir(PIWIK_DOCUMENT_ROOT); shell_exec(' git checkout master > /dev/null 2>&1 git pull > /dev/null 2>&1 git submodule init > /dev/null 2>&1 git submodule update > /dev/null 2>&1 '); $plugin = $input->getOption('plugin'); if (!empty($plugin)) { chdir(PIWIK_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $plugin); shell_exec(' git checkout master > /dev/null 2>&1 git pull > /dev/null 2>&1 '); } // check if branch exists localy and track it if not $branch = shell_exec('git branch | grep translationupdates'); if (empty($branch)) { shell_exec('git checkout -b translationupdates origin/translationupdates'); } // switch to branch and update it to latest master shell_exec(' git checkout translationupdates > /dev/null 2>&1 git merge master > /dev/null 2>&1 git push origin translationupdates > /dev/null 2>&1 '); // update translation files $command = $this->getApplication()->find('translations:update'); $arguments = array('command' => 'translations:update', '--username' => $input->getOption('username'), '--password' => $input->getOption('password'), '--plugin' => $plugin); $inputObject = new ArrayInput($arguments); $inputObject->setInteractive($input->isInteractive()); $command->run($inputObject, $output); shell_exec('git add lang/. > /dev/null 2>&1'); if (empty($plugin)) { foreach (Update::getPluginsInCore() as $pluginName) { shell_exec(sprintf('git add plugins/%s/lang/. > /dev/null 2>&1', $pluginName)); } } $changes = shell_exec('git status --porcelain -uno'); if (empty($changes)) { $output->writeln("Nothing changed. Everything is already up to date."); shell_exec('git checkout master > /dev/null 2>&1'); return; } API::unsetInstance(); // reset languagemanager api (to force refresh of data) $stats = shell_exec('git diff --numstat HEAD'); preg_match_all('/([0-9]+)\\t([0-9]+)\\t[a-zA-Z\\/]*lang\\/([a-z]{2,3})\\.json/', $stats, $lineChanges); $addedLinesSum = 0; if (!empty($lineChanges[1])) { $addedLinesSum = array_sum($lineChanges[1]); } $linesSumByLang = array(); for ($i = 0; $i < count($lineChanges[0]); $i++) { @($linesSumByLang[$lineChanges[3][$i]] += $lineChanges[1][$i]); } preg_match_all('/M [a-zA-Z\\/]*lang\\/([a-z]{2,3})\\.json/', $changes, $modifiedFiles); preg_match_all('/A [a-zA-Z\\/]*lang\\/([a-z]{2,3})\\.json/', $changes, $addedFiles); $messages = array(); $languageCodesTouched = array(); if (!empty($addedFiles[1])) { foreach ($addedFiles[1] as $addedFile) { $languageInfo = $this->getLanguageInfoByIsoCode($addedFile); $messages[$addedFile] = sprintf('- Added %s (%s changes / %s translated)\\n', $languageInfo['english_name'], $linesSumByLang[$addedFile], $languageInfo['percentage_complete']); } $languageCodesTouched = array_merge($languageCodesTouched, $addedFiles[1]); } if (!empty($modifiedFiles[1])) { foreach ($modifiedFiles[1] as $modifiedFile) { $languageInfo = $this->getLanguageInfoByIsoCode($modifiedFile); $messages[$modifiedFile] = sprintf('- Updated %s (%s changes / %s translated)\\n', $languageInfo['english_name'], $linesSumByLang[$modifiedFile], $languageInfo['percentage_complete']); } $languageCodesTouched = array_merge($languageCodesTouched, $modifiedFiles[1]); } $message = implode('', $messages); $languageCodesTouched = array_unique($languageCodesTouched, SORT_REGULAR); $title = sprintf('Updated %s strings in %u languages (%s)', $addedLinesSum, count($languageCodesTouched), implode(', ', $languageCodesTouched)); shell_exec('git commit -m "language update ${pluginName} refs #3430"'); shell_exec('git push'); shell_exec('git checkout master > /dev/null 2>&1'); $this->createPullRequest($output, $title, $message); }
protected function execute(InputInterface $input, OutputInterface $output) { $start = microtime(true); /** @var DialogHelper $dialog */ $dialog = $this->getHelperSet()->get('dialog'); $languages = API::getInstance()->getAvailableLanguageNames(); $languageCodes = array(); foreach ($languages as $languageInfo) { $languageCodes[] = $languageInfo['code']; } $plugin = $input->getOption('plugin'); if (!$input->isInteractive()) { $output->writeln("(!) Non interactive mode: New languages will be skipped"); } $pluginList = array($plugin); if (empty($plugin)) { $pluginList = self::getPluginsInCore(); array_unshift($pluginList, ''); } foreach ($pluginList as $plugin) { $output->writeln(""); // fetch base or specific plugin $this->fetchTranslations($input, $output, $plugin); $files = _glob(FetchTranslations::getDownloadPath() . DIRECTORY_SEPARATOR . '*.json'); if (count($files) == 0) { $output->writeln("No translation updates available! Skipped."); continue; } $output->writeln("Starting to import new language files"); /** @var ProgressHelper $progress */ $progress = $this->getHelperSet()->get('progress'); $progress->start($output, count($files)); foreach ($files as $filename) { $progress->advance(); $code = basename($filename, '.json'); if (!in_array($code, $languageCodes)) { if (!empty($plugin)) { continue; # never create a new language for plugin only } $createNewFile = false; if ($input->isInteractive()) { $createNewFile = $dialog->askConfirmation($output, "\nLanguage {$code} does not exist. Should it be added? ", false); } if (!$createNewFile) { continue; # do not create a new file for the language } @touch(PIWIK_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . $code . '.json'); API::unsetInstance(); // unset language manager instance, so valid names are refetched } $command = $this->getApplication()->find('translations:set'); $arguments = array('command' => 'translations:set', '--code' => $code, '--file' => $filename, '--plugin' => $plugin); $inputObject = new ArrayInput($arguments); $inputObject->setInteractive($input->isInteractive()); $command->run($inputObject, new NullOutput()); } $progress->finish(); } $output->writeln("Finished in " . round(microtime(true) - $start, 3) . "s"); }