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

56 lines
1.3 KiB
PHP
Raw Normal View History

<?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;
/**
* File System Task - Move a File
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class MoveTask extends AbstractFileTask
{
public function getName()
{
return 'fs/move';
}
public function getDescription()
{
2017-01-07 05:53:57 +01:00
try {
2017-02-07 23:27:00 +01:00
return sprintf('[FS] Move %s"%s" to "%s"', $this->getFlags(), $this->getFile('from'), $this->getFile('to'));
2017-01-07 05:53:57 +01:00
} catch (Exception $exception) {
return '[FS] Move [missing parameters]';
}
}
public function execute()
{
2017-01-07 22:44:28 +01:00
$moveFrom = $this->getFile('from');
$moveTo = $this->getFile('to');
2017-02-07 23:27:00 +01:00
$flags = $this->getFlags();
2017-02-07 23:27:00 +01:00
$cmd = sprintf('mv %s"%s" "%s"', $flags, $moveFrom, $moveTo);
/** @var Process $process */
$process = $this->runtime->runCommand($cmd);
return $process->isSuccessful();
}
protected function getParameters()
{
return ['from', 'to'];
}
}