mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-06-29 02:30:05 +02:00
added 'create symlink' task
This commit is contained in:
parent
02d8c1fc9d
commit
67c827db63
38
Mage/Task/Newcraft/Filesystem/CreateSymlinkTask.php
Normal file
38
Mage/Task/Newcraft/Filesystem/CreateSymlinkTask.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue