mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-06-08 16:52:15 +02:00
More generic way to handle command line options
This commit is contained in:
parent
979a86992c
commit
ffdadb45cf
|
@ -113,18 +113,17 @@ class PermissionsTask extends AbstractTask
|
|||
public function run()
|
||||
{
|
||||
$command = '';
|
||||
$recursive = $this->recursive ? '-R' : '';
|
||||
|
||||
if ($this->paths && $this->owner) {
|
||||
$command .= 'chown '. $recursive .' ' . $this->owner . ' ' . $this->getPathsForCmd() . ';';
|
||||
$command .= 'chown '. $this->getOptionsForCmd() .' ' . $this->owner . ' ' . $this->getPathsForCmd() . ';';
|
||||
}
|
||||
|
||||
if ($this->paths && $this->group) {
|
||||
$command .= 'chgrp '. $recursive .' ' . $this->group . ' ' . $this->getPathsForCmd() . ';';
|
||||
$command .= 'chgrp '. $this->getOptionsForCmd() .' ' . $this->group . ' ' . $this->getPathsForCmd() . ';';
|
||||
}
|
||||
|
||||
if ($this->paths && $this->rights) {
|
||||
$command .= 'chmod '. $recursive .' ' . $this->rights . ' ' . $this->getPathsForCmd() . ';';
|
||||
$command .= 'chmod '. $this->getOptionsForCmd() .' ' . $this->rights . ' ' . $this->getPathsForCmd() . ';';
|
||||
}
|
||||
|
||||
$result = $this->runCommand($command);
|
||||
|
@ -132,6 +131,27 @@ class PermissionsTask extends AbstractTask
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the options for the commands to run. Only supports -R for now.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getOptionsForCmd()
|
||||
{
|
||||
$optionsForCmd = '';
|
||||
$options = array(
|
||||
'R' => $this->recursive
|
||||
);
|
||||
|
||||
foreach($options as $option => $apply) {
|
||||
if ($apply == true) {
|
||||
$optionsForCmd .= $option;
|
||||
}
|
||||
}
|
||||
|
||||
return $optionsForCmd ? '-' . $optionsForCmd : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms paths array to a string separated by 1 space in order to use
|
||||
* it in a command line.
|
||||
|
|
Loading…
Reference in a new issue