Files
Phraseanet/lib/Alchemy/Phrasea/Plugin/Importer/FolderImporter.php
2014-01-06 15:28:12 +01:00

45 lines
1.0 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Plugin\Importer;
use Alchemy\Phrasea\Plugin\Exception\ImportFailureException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\ExceptionInterface as FsException;
class FolderImporter implements ImporterInterface
{
private $fs;
public function __construct(Filesystem $fs)
{
$this->fs = $fs;
}
/**
* {@inheritdoc}
*/
public function import($source, $target)
{
try {
$this->fs->mirror($source, $target);
} catch (FsException $e) {
try {
$this->fs->remove($target);
} catch (FsException $e) {
}
throw new ImportFailureException(sprintf('Unable to import from `%s` to `%s`', $source, $target), $e->getCode(), $e);
}
}
}