1: <?php
2:
3: namespace Himedia\Padocc\Task\Extended;
4:
5: use Himedia\Padocc\AttributeProperties;
6: use Himedia\Padocc\Task;
7: use Himedia\Padocc\Task\Base\Sync;
8:
9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
34: class GitExport extends Task
35: {
36: 37: 38: 39:
40: private $oSyncTask;
41:
42: 43: 44:
45: protected function init()
46: {
47: parent::init();
48:
49: $this->aAttrProperties = array(
50: 'repository' => AttributeProperties::FILE | AttributeProperties::REQUIRED,
51: 'ref' => AttributeProperties::REQUIRED | AttributeProperties::ALLOW_PARAMETER,
52: 'localrepositorydir' => AttributeProperties::DIR,
53: 'srcsubdir' => AttributeProperties::DIR,
54: 'destdir' => AttributeProperties::DIR | AttributeProperties::REQUIRED
55: | AttributeProperties::ALLOW_PARAMETER,
56:
57: 'include' => AttributeProperties::FILEJOKER | AttributeProperties::DIRJOKER,
58: 'exclude' => AttributeProperties::FILEJOKER | AttributeProperties::DIRJOKER,
59: );
60:
61:
62: if (empty($this->aAttValues['localrepositorydir'])) {
63: $this->aAttValues['localrepositorydir'] =
64: $this->aConfig['dir']['repositories'] . '/git/'
65: . $this->oProperties->getProperty('project_name') . '_'
66: . $this->oProperties->getProperty('environment_name') . '_'
67: . $this->sCounter;
68: } else {
69: $this->aAttValues['localrepositorydir'] =
70: preg_replace('#/$#', '', $this->aAttValues['localrepositorydir']);
71: }
72:
73:
74: $this->oNumbering->addCounterDivision();
75: if (empty($this->aAttValues['srcsubdir'])) {
76: $this->aAttValues['srcsubdir'] = '';
77: } else {
78: $this->aAttValues['srcsubdir'] = '/' . preg_replace('#^/|/$#', '', $this->aAttValues['srcsubdir']);
79: }
80: $aSyncAttributes = array(
81: 'src' => $this->aAttValues['localrepositorydir'] . $this->aAttValues['srcsubdir'] . '/',
82: 'destdir' => $this->aAttValues['destdir'],
83: );
84: if (! empty($this->aAttValues['include'])) {
85: $aSyncAttributes['include'] = $this->aAttValues['include'];
86: }
87: if (! empty($this->aAttValues['exclude'])) {
88: $aSyncAttributes['exclude'] = $this->aAttValues['exclude'];
89: }
90: $this->oSyncTask = Sync::getNewInstance($aSyncAttributes, $this->oProject, $this->oDIContainer);
91: $this->oNumbering->removeCounterDivision();
92: }
93:
94: 95: 96: 97:
98: public static function getTagName ()
99: {
100: return 'gitexport';
101: }
102:
103: 104: 105:
106: public function setUp ()
107: {
108: parent::setUp();
109: $this->getLogger()->info('+++');
110:
111:
112:
113:
114: try {
115: $this->oSyncTask->setUp();
116: } catch (\UnexpectedValueException $oException) {
117: if ($oException->getMessage() !== "File or directory '" . $this->aAttValues['localrepositorydir']
118: . $this->aAttValues['srcsubdir'] . '/' . "' not found!") {
119: throw $oException;
120: }
121: }
122:
123: $this->getLogger()->info('---');
124: }
125:
126: 127: 128: 129: 130: 131:
132: protected function centralExecute ()
133: {
134: parent::centralExecute();
135: $this->getLogger()->info('+++');
136:
137: $aRef = $this->processPath($this->aAttValues['ref']);
138: $sRef = $aRef[0];
139:
140: $sMsg = "Export '$sRef' reference from '" . $this->aAttValues['repository'] . "' git repository+++";
141: $this->getLogger()->info($sMsg);
142: $aResult = $this->oShell->exec(
143: $this->aConfig['bash_path'] . ' ' . $this->aConfig['dir']['inc'] . '/gitexport.sh'
144: . ' "' . $this->aAttValues['repository'] . '"'
145: . ' "' . $sRef . '"'
146: . ' "' . $this->aAttValues['localrepositorydir'] . '"'
147: );
148: $this->getLogger()->info(implode("\n", $aResult) . '---');
149:
150: $this->oSyncTask->execute();
151: $this->getLogger()->info('---');
152: }
153: }
154: