1: <?php
2:
3: namespace Himedia\Padocc\Task\Base;
4:
5: use GAubry\Shell\PathStatus;
6: use Himedia\Padocc\AttributeProperties;
7: use Himedia\Padocc\Task;
8:
9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27: class Sync extends Task
28: {
29: 30: 31:
32: protected function init()
33: {
34: parent::init();
35:
36: $this->aAttrProperties = array(
37: 'src' => AttributeProperties::SRC_PATH | AttributeProperties::FILEJOKER | AttributeProperties::REQUIRED
38: | AttributeProperties::ALLOW_PARAMETER,
39: 'destdir' => AttributeProperties::DIR | AttributeProperties::REQUIRED
40: | AttributeProperties::ALLOW_PARAMETER,
41:
42: 'include' => AttributeProperties::FILEJOKER | AttributeProperties::DIRJOKER,
43:
44: 'exclude' => AttributeProperties::FILEJOKER | AttributeProperties::DIRJOKER,
45: );
46: }
47:
48: 49: 50: 51:
52: public static function getTagName ()
53: {
54: return 'sync';
55: }
56:
57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67:
68: public function check ()
69: {
70: parent::check();
71:
72: if (preg_match('#\*|\?|/$#', $this->aAttValues['src']) === 0
73: && $this->oShell->getPathStatus($this->aAttValues['src']) === PathStatus::STATUS_DIR
74: ) {
75: $this->aAttValues['destdir'] .= '/' . substr(strrchr($this->aAttValues['src'], '/'), 1);
76: $this->aAttValues['src'] .= '/';
77: }
78: }
79:
80: 81: 82: 83: 84: 85:
86: protected function centralExecute ()
87: {
88: parent::centralExecute();
89: $sMsg = "+++Synchronize '" . $this->aAttValues['src'] . "' with '" . $this->aAttValues['destdir'] . "'+++";
90: $this->getLogger()->info($sMsg);
91:
92:
93: $aIncludedPaths = (empty($this->aAttValues['include'])
94: ? array()
95: : explode(' ', $this->aAttValues['include']));
96: $aExcludedPaths = (empty($this->aAttValues['exclude'])
97: ? array()
98: : explode(' ', $this->aAttValues['exclude']));
99:
100: list($bIsDestRemote, $sDestServer, $sDestRawPath) = $this->oShell->isRemotePath($this->aAttValues['destdir']);
101: $sDestPath = ($bIsDestRemote ? '[]:' . $sDestRawPath : $sDestRawPath);
102: foreach ($this->processPath($sDestPath) as $sDestRealPath) {
103: $aResults = $this->oShell->sync(
104: $this->processSimplePath($this->aAttValues['src']),
105: $this->processSimplePath($sDestRealPath),
106: $this->processPath($sDestServer),
107: $aIncludedPaths,
108: $aExcludedPaths
109: );
110: foreach ($aResults as $sResult) {
111: $this->getLogger()->info($sResult);
112: }
113: }
114: $this->getLogger()->info('------');
115: }
116: }
117: