1: <?php
2:
3: namespace Himedia\Padocc\Task\Base;
4:
5: use Himedia\Padocc\AttributeProperties;
6: use Himedia\Padocc\Task;
7:
8: 9: 10: 11: 12: 13: 14: 15:
16: class Rename extends Task
17: {
18: 19: 20:
21: protected function init()
22: {
23: parent::init();
24:
25: $this->aAttrProperties = array(
26: 'src' => AttributeProperties::SRC_PATH | AttributeProperties::REQUIRED
27: | AttributeProperties::ALLOW_PARAMETER,
28: 'dest' => AttributeProperties::FILE | AttributeProperties::DIR | AttributeProperties::REQUIRED
29: | AttributeProperties::ALLOW_PARAMETER
30: );
31: }
32:
33: 34: 35: 36:
37: public static function getTagName ()
38: {
39: return 'rename';
40: }
41:
42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52:
53: public function check ()
54: {
55: parent::check();
56:
57:
58: list(, $sSrcServer, ) = $this->oShell->isRemotePath($this->aAttValues['src']);
59: list(, $sDestServer, ) = $this->oShell->isRemotePath($this->aAttValues['dest']);
60: if ($sSrcServer != $sDestServer) {
61: throw new \DomainException('Paths must be local or on the same server!');
62: }
63: }
64:
65: 66: 67: 68: 69: 70:
71: protected function centralExecute ()
72: {
73: parent::centralExecute();
74: $aSrcPath = $this->processSimplePath($this->aAttValues['src']);
75: $aDestPath = $this->processSimplePath($this->aAttValues['dest']);
76: $this->getLogger()->info("+++Rename '$aSrcPath' to '$aDestPath'.");
77: $this->oShell->execSSH("mv %s '" . $aDestPath . "'", $aSrcPath);
78: $this->getLogger()->info('---');
79: }
80: }
81: