Overview

Namespaces

  • GAubry
    • ErrorHandler
    • Helpers
    • Logger
    • Shell
  • Himedia
    • Padocc
      • DB
      • Minifier
      • Numbering
      • Properties
      • Task
        • Base
        • Extended
  • None
  • Psr
    • Log

Classes

  • Backup
  • Call
  • Composer
  • Copy
  • Environment
  • ExternalProperty
  • FillTemplate
  • HTTP
  • Link
  • MkDir
  • Project
  • Property
  • Rename
  • Sync
  • Target
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
 1: <?php
 2: 
 3: namespace Himedia\Padocc\Task\Base;
 4: 
 5: use Himedia\Padocc\AttributeProperties;
 6: use Himedia\Padocc\Task;
 7: 
 8: /**
 9:  * Renomme un fichier ou un répertoire.
10:  * À inclure dans une tâche env ou target.
11:  *
12:  * Exemple : <rename src="${TMPDIR}/v3" dest="${TMPDIR}/web" />
13:  *
14:  * @author Geoffroy AUBRY <gaubry@hi-media.com>
15:  */
16: class Rename extends Task
17: {
18:     /**
19:      * {@inheritdoc}
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:      * {@inheritdoc}
35:      * @codeCoverageIgnore
36:      */
37:     public static function getTagName ()
38:     {
39:         return 'rename';
40:     }
41: 
42:     /**
43:      * Vérifie au moyen de tests basiques que la tâche peut être exécutée.
44:      * Lance une exception si tel n'est pas le cas.
45:      *
46:      * Comme toute les tâches sont vérifiées avant que la première ne soit exécutée,
47:      * doit permettre de remonter au plus tôt tout dysfonctionnement.
48:      * Appelé avant la méthode execute().
49:      *
50:      * @throws \UnexpectedValueException en cas d'attribut ou fichier manquant
51:      * @throws \DomainException en cas de valeur non permise
52:      */
53:     public function check ()
54:     {
55:         parent::check();
56: 
57:         // Pour l'instant ne gère pas les chemins distants :
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:      * Phase de traitements centraux de l'exécution de la tâche.
67:      * Elle devrait systématiquement commencer par "parent::centralExecute();".
68:      * Appelé par execute().
69:      * @see execute()
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: 
Platform for Automatized Deployments with pOwerful Concise Configuration API documentation generated by ApiGen 2.8.0