diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index b467a0974..cfeafe7c7 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -144,10 +144,28 @@ %kernel.environment% + + + + + + + + + gz + + + + + + bz2 + + + >>>>>>> Add archive builder manager and formatter manager services diff --git a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php index cd4cb662f..9bfc56cc1 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php @@ -13,12 +13,17 @@ namespace Thelia\Core\FileFormat\Archive; use Thelia\Core\FileFormat\FormatInterface; <<<<<<< HEAD +<<<<<<< HEAD use Thelia\Core\Translation\Translator; use Thelia\Exception\FileNotFoundException; use Thelia\Exception\FileNotReadableException; use Thelia\Log\Tlog; ======= >>>>>>> Define archive builders and formatters +======= +use Thelia\Core\Translation\Translator; +use Thelia\Log\Tlog; +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources use Thelia\Tools\FileDownload\FileDownloaderAwareTrait; /** @@ -29,6 +34,7 @@ use Thelia\Tools\FileDownload\FileDownloaderAwareTrait; abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilderInterface { use FileDownloaderAwareTrait; +<<<<<<< HEAD <<<<<<< HEAD const TEMP_DIRECTORY_NAME = "archive_builder"; @@ -36,6 +42,11 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder /** @var string */ protected $cacheFile; +======= + + const TEMP_DIRECTORY_NAME = "archive_builder"; + +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources /** @var \Thelia\Core\Translation\Translator */ protected $translator; @@ -45,9 +56,12 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder /** @var string */ protected $cacheDir; +<<<<<<< HEAD /** @var string */ protected $environment; +======= +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources public function __construct() { $this->translator = Translator::getInstance(); @@ -70,7 +84,11 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder ); } +<<<<<<< HEAD $archiveBuilderCacheDir = $this->cacheDir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; +======= + $archiveBuilderCacheDir = $this->cache_dir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources if (!is_dir($archiveBuilderCacheDir) && !mkdir($archiveBuilderCacheDir, 0755)) { throw new \ErrorException( @@ -86,6 +104,7 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder return $archiveBuilderCacheDir; } +<<<<<<< HEAD /** * @param $pathToFile * @param $destination @@ -177,6 +196,8 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder return $this; } +======= +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources public function getCacheDir() { @@ -198,6 +219,7 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder { return $this->translator; } +<<<<<<< HEAD public function getCacheFile() { @@ -219,3 +241,6 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder ======= } >>>>>>> Define archive builders and formatters +======= +} +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index 57357a4cb..6cf52a23d 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -41,10 +41,13 @@ use Thelia\Tools\FileDownload\FileDownloaderInterface; class ZipArchiveBuilder extends AbstractArchiveBuilder { <<<<<<< HEAD +<<<<<<< HEAD ======= const TEMP_DIRECTORY_NAME = "archive_builder"; >>>>>>> Define archive builders and formatters +======= +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources /** * @var \ZipArchive */ @@ -60,31 +63,23 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder /** * @var string This is the absolute path to the zip file in cache */ - protected $zip_cache_file; + protected $zipCacheFile; /** * @var string This is the path of the cache */ - protected $cache_dir; - - /** - * @var \Thelia\Log\Tlog - */ - protected $logger; - - /** - * @var Translator - */ - protected $translator; + protected $cacheDir; public function __construct() { - $this->zip = new \ZipArchive(); - - $this->logger = Tlog::getNewInstance(); + parent::__construct(); +<<<<<<< HEAD $this->translator = Translator::getInstance(); >>>>>>> Define archive builders and formatters +======= + $this->zip = new \ZipArchive(); +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources } /** @@ -100,6 +95,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if ($this->zip instanceof \ZipArchive) { @$this->zip->close(); +<<<<<<< HEAD <<<<<<< HEAD if (file_exists($this->cacheFile)) { unlink($this->cacheFile); @@ -107,6 +103,10 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if (file_exists($this->zip_cache_file)) { unlink($this->zip_cache_file); >>>>>>> Define archive builders and formatters +======= + if (file_exists($this->zipCacheFile)) { + unlink($this->zipCacheFile); +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources } } } @@ -250,7 +250,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $directoryInArchive = ""; } - if(!empty($directoryInArchive) && $directoryInArchive != "/") { + if(!empty($directoryInArchive)) { $directoryInArchive = $this->getDirectoryPath($directoryInArchive); >>>>>>> Define archive builders and formatters @@ -266,6 +266,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } } +<<<<<<< HEAD <<<<<<< HEAD return $this; } @@ -341,8 +342,14 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder return $initialString . "/"; ======= +======= + /** + * Download the file if it is online + * If it's local check if the file exists and if it is redable + */ +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources if ($isOnline) { - $fileDownloadCache = $this->cache_dir . DS . "download"; + $fileDownloadCache = $this->cacheDir . DS . "download"; $this->getFileDownloader() ->download($filePath, $fileDownloadCache) @@ -369,6 +376,10 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $name = basename($filePath); } + /** + * Then write the file in the archive and commit the changes + */ + $destination = $directoryInArchive . $name; if (!$this->zip->addFile($filePath,$destination)) { @@ -441,6 +452,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $this->commit(); +<<<<<<< HEAD <<<<<<< HEAD if (!file_exists($this->cacheFile)) { $this->throwFileNotFound($this->cacheFile); @@ -454,25 +466,40 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if (!is_readable($this->zip_cache_file)) { >>>>>>> Define archive builders and formatters +======= + if (!file_exists($this->zipCacheFile)) { + $this->throwFileNotFound($this->zipCacheFile); + } + + if (!is_readable($this->zipCacheFile)) { +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources throw new FileNotReadableException( $this->translator->trans( "The cache file %file is not readable", [ +<<<<<<< HEAD <<<<<<< HEAD "%file" => $this->cacheFile ======= "%file" => $this->zip_cache_file >>>>>>> Define archive builders and formatters +======= + "%file" => $this->zipCacheFile +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources ] ) ); } +<<<<<<< HEAD <<<<<<< HEAD $content = file_get_contents($this->cacheFile); ======= $content = file_get_contents($this->zip_cache_file); >>>>>>> Define archive builders and formatters +======= + $content = file_get_contents($this->zipCacheFile); +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources $this->zip->close(); @@ -642,6 +669,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function setEnvironment($environment) { +<<<<<<< HEAD <<<<<<< HEAD parent::setEnvironment($environment); @@ -678,6 +706,13 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $cacheFile = $archiveBuilderCacheDir . DS . $cacheFileName; $cacheFile .= "." . $this->getExtension(); >>>>>>> Define archive builders and formatters +======= + + $cacheFileName = md5 (uniqid()); + + $cacheFile = $this->getArchiveBuilderCacheDirectory($environment) . DS; + $cacheFile .= $cacheFileName . "." . $this->getExtension(); +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources if (file_exists($cacheFile)) { unlink($cacheFile); @@ -697,17 +732,25 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if($opening !== true) { throw new \ErrorException( $this->translator->trans( +<<<<<<< HEAD "Unknown" >>>>>>> Define archive builders and formatters +======= + "An unknown error append" +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources ) ); } +<<<<<<< HEAD <<<<<<< HEAD $this->cacheFile = $cacheFile; ======= $this->zip_cache_file = $cacheFile; >>>>>>> Define archive builders and formatters +======= + $this->zipCacheFile = $cacheFile; +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources return $this; } @@ -920,6 +963,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder /** <<<<<<< HEAD +<<<<<<< HEAD ======= * @return Tlog */ @@ -938,6 +982,8 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder /** >>>>>>> Define archive builders and formatters +======= +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources * @return \ZipArchive */ public function getRawZipArchive() @@ -950,12 +996,16 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder public function getZipCacheFile() { - return $this->zip_cache_file; + return $this->zipCacheFile; } +<<<<<<< HEAD public function getCacheDir() { return $this->cache_dir; } } >>>>>>> Define archive builders and formatters +======= +} +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index d9e3f64a0..12b263f07 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -55,6 +55,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase /** * This method formats a path to be compatible with \ZipArchive +<<<<<<< HEAD <<<<<<< HEAD */ public function testFormatFilePath() @@ -65,6 +66,8 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase ======= * * +======= +>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources */ public function testGetFilePath() {