magallanes/src/Task/BuiltIn/FS/LinkTask.php

55 lines
1.2 KiB
PHP
Raw Normal View History

2017-01-06 20:09:00 +01:00
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\FS;
use Symfony\Component\Process\Process;
2017-01-07 05:53:57 +01:00
use Exception;
2017-01-06 20:09:00 +01:00
/**
* File System Task - Symlink a File
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class LinkTask extends AbstractFileTask
{
public function getName()
{
return 'fs/link';
}
public function getDescription()
{
2017-01-07 05:53:57 +01:00
try {
return sprintf('[FS] Link "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
} catch (Exception $exception) {
return '[FS] Link [missing parameters]';
}
2017-01-06 20:09:00 +01:00
}
public function execute()
{
2017-01-07 22:44:28 +01:00
$linkFrom = $this->getFile('from');
$linkTo = $this->getFile('to');
2017-01-06 20:09:00 +01:00
2017-01-07 22:44:28 +01:00
$cmd = sprintf('ln -snf %s %s', $linkFrom, $linkTo);
2017-01-06 20:09:00 +01:00
/** @var Process $process */
$process = $this->runtime->runCommand($cmd);
return $process->isSuccessful();
}
protected function getParameters()
{
return ['from', 'to'];
}
}