Skip to content

Instantly share code, notes, and snippets.

@lutangar
Last active August 29, 2015 14:00
Show Gist options
  • Save lutangar/495dc42f0611894e1b1c to your computer and use it in GitHub Desktop.
Save lutangar/495dc42f0611894e1b1c to your computer and use it in GitHub Desktop.
Magallanese more flexible permissions/chmod task
<?php
namespace Task;
use Mage\Task\AbstractTask;
class Chmod extends AbstractTask
{
public function getName()
{
return 'Fixing file permissions';
}
public function run()
{
// Options
$mode = $this->getParameter('mode', '755');
$recursive = $this->getParameter('recursive', true);
$targets = $this->getParameter('targets', array('.'));
$options = ($recursive) ? ' -R ' : '';
$command = 'chmod '. $options . $mode . ' ' . implode(' ', $targets);
$result = $this->runCommandRemote($command);
return $result;
}
}

Put this task in the .mage/tasks/ directory :

namespace Task;

use Mage\Task\AbstractTask;

class Chmod extends AbstractTask
{
    public function getName()
    {
        return 'Fixing file permissions';
    }

    public function run()
    {
        // Options
        $mode = $this->getParameter('mode', '755');
        $recursive = $this->getParameter('recursive', true);
        $targets = $this->getParameter('targets', array('.'));

        $options = ($recursive) ? ' -R ' : '';

        $command = 'chmod '.  $options . $mode . ' ' . implode(' ', $targets);
        $result = $this->runCommandRemote($command);

        return $result;
    }
}

usage :

tasks:
  post-deploy:
    - chmod: { mode: "777", targets: ["log/single-log-file.log"], recursive: false }
    - chmod: { mode: "777", targets: ["cache/", "log/"] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment