added 'create symlink' task

This commit is contained in:
Bart Swaalf 2015-10-19 16:24:06 +02:00
parent 02d8c1fc9d
commit 67c827db63

View file

@ -0,0 +1,38 @@
<?php
namespace Mage\Task\Newcraft\Filesystem;
use Mage\Task\AbstractTask;
class CreateSymlinkTask extends AbstractTask
{
/**
* @return string
*/
public function getName()
{
$targetPath = $this->getParameter('target', null);
$linkPath = $this->getParameter('link', null);
return 'Creating symlink ('.$linkPath.' -> '.$targetPath.') [newcraft]';
}
/**
* Removes any directory named current so it can be replaced with a symlink
* @see \Mage\Task\AbstractTask::run()
*/
public function run()
{
$targetPath = $this->getParameter('target', null);
$linkPath = $this->getParameter('link', null);
$sudo = (bool) $this->getParameter('sudo', false) ? 'sudo ' : '';
if(null !== $targetPath && null !== $linkPath){
$clearLinkPathCommand = 'test -h '.$linkPath.' && test -w '.$linkPath.' || '.$sudo.'rm -rf '.$linkPath.'; ';
$createLinkCommand = 'ln -snf '.$targetPath.' '.$linkPath;
$result = $this->runCommandRemote($clearLinkPathCommand.$createLinkCommand);
}
return isset($result) && $result;
}
}