1: <?php
2:
3: namespace Himedia\Padocc\Task\Extended;
4:
5: use Himedia\Padocc\AttributeProperties;
6: use Himedia\Padocc\Task;
7:
8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18: class BuildLanguage extends Task
19: {
20: 21: 22:
23: protected function init()
24: {
25: parent::init();
26:
27: $this->aAttrProperties = array(
28: 'project' => AttributeProperties::REQUIRED,
29: 'destdir' => AttributeProperties::DIR | AttributeProperties::REQUIRED
30: | AttributeProperties::ALLOW_PARAMETER
31: );
32: }
33:
34: 35: 36: 37: 38: 39:
40: public static function getTagName ()
41: {
42: return 'buildlanguage';
43: }
44:
45: 46: 47: 48: 49: 50:
51: protected function centralExecute ()
52: {
53: parent::centralExecute();
54: $this->getLogger()->info('+++');
55:
56: $sLanguagesPath = tempnam(
57: $this->aConfig['dir']['tmp'],
58: $this->oProperties->getProperty('execution_id') . '_languages_'
59: );
60: $sURL = 'https://xyz/translation_tool/build_language_files.php?project='
61: . $this->aAttValues['project'];
62: $this->getLogger()->info('Generate language archive from web service: ' . $sURL);
63: if (! copy($sURL, $sLanguagesPath)) {
64: throw new \RuntimeException("Copy of '$sURL' to '$sLanguagesPath' failed!");
65: }
66:
67:
68: $this->getLogger()->info('Send language archive to all servers+++');
69: $aDestDirs = $this->processPath($this->aAttValues['destdir']);
70: foreach ($aDestDirs as $sDestDir) {
71: $aResult = $this->oShell->copy($sLanguagesPath, $sDestDir);
72: $sResult = implode("\n", $aResult);
73: if (trim($sResult) != '') {
74: $this->getLogger()->info($sResult);
75: }
76: }
77: $this->getLogger()->info('---');
78:
79:
80: $this->getLogger()->info('Extract language files from archive on each server+++');
81: $sPatternCmd = 'cd %1$s && tar -xf %1$s/"' . basename($sLanguagesPath)
82: . '" && rm -f %1$s/"' . basename($sLanguagesPath) . '"';
83: foreach ($aDestDirs as $sDestDir) {
84: $aResult = $this->oShell->execSSH($sPatternCmd, $sDestDir);
85: $sResult = implode("\n", $aResult);
86: if (trim($sResult) != '') {
87: $this->getLogger()->info($sResult);
88: }
89: }
90: $this->getLogger()->info('---');
91:
92: @unlink($sLanguagesPath);
93: $this->getLogger()->info('---');
94: }
95: }
96: