Browse Source

Allow for changing permissions on local host too depending on the stage

1.0
Jérémy Huet 10 years ago
parent
commit
9d1e6aba6f
  1. 28
      Mage/Task/BuiltIn/Filesystem/PermissionsTask.php
  2. 8
      Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php

28
Mage/Task/BuiltIn/Filesystem/PermissionsTask.php

@ -5,7 +5,14 @@ use Mage\Task\AbstractTask;
use Mage\Task\SkipException; use Mage\Task\SkipException;
/** /**
* Task for setting permissions on given paths. * Task for setting permissions on given paths. Change will be done on local or
* remote host depending on the stage of the deployment.
*
* Usage :
* pre-deploy:
* - filesystem/permissions: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, checkPathsExist: true, owner: www-data, group: www-data, rights: 775}
* on-deploy:
* - filesystem/permissions: {paths: app/cache:app/logs, checkPathsExist: true, owner: www-data, group: www-data, rights: 775}
* *
* @author Jérémy Huet <jeremy.huet@gmail.com> * @author Jérémy Huet <jeremy.huet@gmail.com>
*/ */
@ -14,12 +21,15 @@ class PermissionsTask extends AbstractTask
/** /**
* Paths to change of permissions separated by PATH_SEPARATOR. * Paths to change of permissions separated by PATH_SEPARATOR.
* *
* If the stage is on local host you should give full paths. If on remote
* you may give full or relative to the current release directory paths.
*
* @var string * @var string
*/ */
private $paths; private $paths;
/** /**
* If set to true, will check existance of given paths on remote host and * If set to true, will check existance of given paths on the host and
* throw SkipException if at least one does not exist. * throw SkipException if at least one does not exist.
* *
* @var boolean * @var boolean
@ -105,7 +115,7 @@ class PermissionsTask extends AbstractTask
$command .= 'chmod -R ' . $this->rights . ' ' . $this->getPathsForCmd() . ';'; $command .= 'chmod -R ' . $this->rights . ' ' . $this->getPathsForCmd() . ';';
} }
$result = $this->runCommandRemote($command); $result = $this->runCommand($command);
return $result; return $result;
} }
@ -126,7 +136,7 @@ class PermissionsTask extends AbstractTask
} }
/** /**
* Set paths. Will check if they exist on remote host depending on * Set paths. Will check if they exist on the host depending on
* checkPathsExist flag. * checkPathsExist flag.
* *
* @param array $paths * @param array $paths
@ -142,8 +152,8 @@ class PermissionsTask extends AbstractTask
} }
$command = implode(' && ', $commands); $command = implode(' && ', $commands);
if (! $this->runCommandRemote($command)) { if (! $this->runCommand($command)) {
throw new SkipException('Make sure all paths given exist on remote host : ' . $this->getPathsForCmd($paths)); throw new SkipException('Make sure all paths given exist on the host : ' . $this->getPathsForCmd($paths));
} }
} }
@ -184,7 +194,7 @@ class PermissionsTask extends AbstractTask
/** /**
* Set owner. * Set owner.
* *
* @todo check existance of $owner on remote, might be different ways depending on OS. * @todo check existance of $owner on host, might be different ways depending on OS.
* *
* @param string $owner * @param string $owner
* @return PermissionsTask * @return PermissionsTask
@ -207,7 +217,7 @@ class PermissionsTask extends AbstractTask
/** /**
* Set group. * Set group.
* *
* @todo check existance of $group on remote, might be different ways depending on OS. * @todo check existance of $group on host, might be different ways depending on OS.
* *
* @param string $group * @param string $group
* @return PermissionsTask * @return PermissionsTask
@ -253,4 +263,4 @@ class PermissionsTask extends AbstractTask
{ {
return $this->rights; return $this->rights;
} }
} }

8
Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php

@ -4,6 +4,12 @@ namespace Mage\Task\BuiltIn\Filesystem;
/** /**
* Task for giving Apache write permissions on given paths. * Task for giving Apache write permissions on given paths.
* *
* Usage :
* pre-deploy:
* - filesystem/permissions-writable-by-apache: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, checkPathsExist: true}
* on-deploy:
* - filesystem/permissions-writable-by-apache: {paths: app/cache:app/logs, checkPathsExist: true}
*
* @author Jérémy Huet <jeremy.huet@gmail.com> * @author Jérémy Huet <jeremy.huet@gmail.com>
*/ */
class PermissionsWritableByApacheTask extends PermissionsTask class PermissionsWritableByApacheTask extends PermissionsTask
@ -23,4 +29,4 @@ class PermissionsWritableByApacheTask extends PermissionsTask
{ {
return "Gives write permissions to Apache user for given paths [built-in]"; return "Gives write permissions to Apache user for given paths [built-in]";
} }
} }

Loading…
Cancel
Save