From d82fb479cf61b08fedac55d64c615d5d33f5bdc8 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Wed, 2 Jul 2014 14:00:49 +0200 Subject: [PATCH 001/158] =?UTF-8?q?Define=20archive=20builders=20and=20for?= =?UTF-8?q?matters=20=09nouveau=20fichier:=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Archive/AbstractArchiveBuilder.php=20=09nouveau=20fichier:?= =?UTF-8?q?=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipAr?= =?UTF-8?q?chiveBuilder.php=20=09nouveau=20fichier:=20core/lib/Thelia/Core?= =?UTF-8?q?/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php=20?= =?UTF-8?q?=09nouveau=20fichier:=20core/lib/Thelia/Core/FileFormat/Archive?= =?UTF-8?q?/ArchiveBuilderInterface.php=20=09nouveau=20fichier:=20core/lib?= =?UTF-8?q?/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php=20=09?= =?UTF-8?q?nouveau=20fichier:=20core/lib/Thelia/Core/FileFormat/FormatInte?= =?UTF-8?q?rface.php=20=09nouveau=20fichier:=20core/lib/Thelia/Core/FileFo?= =?UTF-8?q?rmat/Formatter/AbstractFormatter.php=20=09nouveau=20fichier:=20?= =?UTF-8?q?core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormatte?= =?UTF-8?q?dStringException.php=20=09nouveau=20fichier:=20core/lib/Thelia/?= =?UTF-8?q?Core/FileFormat/Formatter/FormatterManager.php=20=09nouveau=20f?= =?UTF-8?q?ichier:=20core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuild?= =?UTF-8?q?er/TestResources/bad=5Fformatted.zip=20=09nouveau=20fichier:=20?= =?UTF-8?q?core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestRes?= =?UTF-8?q?ources/test=5Ffile=20=09nouveau=20fichier:=20core/lib/Thelia/Te?= =?UTF-8?q?sts/FileFormat/Archive/ArchiveBuilder/TestResources/well=5Fform?= =?UTF-8?q?atted.zip=20=09nouveau=20fichier:=20core/lib/Thelia/Tests/FileF?= =?UTF-8?q?ormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php=20=09nou?= =?UTF-8?q?veau=20fichier:=20core/lib/Thelia/Tests/FileFormat/Archive/Arch?= =?UTF-8?q?iveBuilderManagerTest.php=20=09nouveau=20fichier:=20core/lib/Th?= =?UTF-8?q?elia/Tests/FileFormat/Formatter/FormatterManagerTest.php=20=09n?= =?UTF-8?q?ouveau=20fichier:=20core/lib/Thelia/Tests/Tools/FakeFileDownloa?= =?UTF-8?q?der.php=20=09nouveau=20fichier:=20core/lib/Thelia/Tests/Tools/F?= =?UTF-8?q?ileDownloaderTest.php=20=09nouveau=20fichier:=20core/lib/Thelia?= =?UTF-8?q?/Tools/FileDownload/FileDownloader.php=20=09nouveau=20fichier:?= =?UTF-8?q?=20core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.?= =?UTF-8?q?php=20=09nouveau=20fichier:=20core/lib/Thelia/Tools/FileDownloa?= =?UTF-8?q?d/FileDownloaderInterface.php=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Tools/URL.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/AbstractArchiveBuilder.php | 25 + .../ArchiveBuilder/ZipArchiveBuilder.php | 608 ++++++++++++ .../ArchiveBuilder/ZipArchiveException.php | 23 + .../Archive/ArchiveBuilderInterface.php | 90 ++ .../Archive/ArchiveBuilderManager.php | 76 ++ .../Core/FileFormat/FormatInterface.php | 58 ++ .../Formatter/AbstractFormatter.php | 41 + .../Exception/BadFormattedStringException.php | 23 + .../FileFormat/Formatter/FormatterManager.php | 69 ++ .../TestResources/bad_formatted.zip | 0 .../ArchiveBuilder/TestResources/test_file | 0 .../TestResources/well_formatted.zip | 0 .../ArchiveBuilder/ZipArchiveBuilderTest.php | 344 +++++++ .../Archive/ArchiveBuilderManagerTest.php | 75 ++ .../Formatter/FormatterManagerTest.php | 74 ++ .../Thelia/Tests/Tools/FakeFileDownloader.php | 44 + .../Thelia/Tests/Tools/FileDownloaderTest.php | 63 ++ .../Thelia/Tests/Tools/FileManagerTest.php | 900 ++++++++++++++++++ .../Tools/FileDownload/FileDownloader.php | 142 +++ .../FileDownload/FileDownloaderAwareTrait.php | 47 + .../FileDownload/FileDownloaderInterface.php | 44 + core/lib/Thelia/Tools/URL.php | 8 + 22 files changed, 2754 insertions(+) create mode 100644 core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php create mode 100644 core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php create mode 100644 core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php create mode 100644 core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php create mode 100644 core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php create mode 100644 core/lib/Thelia/Core/FileFormat/FormatInterface.php create mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php create mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php create mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php create mode 100644 core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.zip create mode 100644 core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/test_file create mode 100644 core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/well_formatted.zip create mode 100644 core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php create mode 100644 core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php create mode 100644 core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php create mode 100644 core/lib/Thelia/Tests/Tools/FakeFileDownloader.php create mode 100644 core/lib/Thelia/Tests/Tools/FileDownloaderTest.php create mode 100644 core/lib/Thelia/Tests/Tools/FileManagerTest.php create mode 100644 core/lib/Thelia/Tools/FileDownload/FileDownloader.php create mode 100644 core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php create mode 100644 core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php diff --git a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php new file mode 100644 index 000000000..66613ba45 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php @@ -0,0 +1,25 @@ + + */ +abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilderInterface +{ + use FileDownloaderAwareTrait; +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php new file mode 100644 index 000000000..f38b1c3fe --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -0,0 +1,608 @@ + + * + * This class is a driver defined by AbstractArchiveBuilder, + * it's goal is to manage Zip archives. + * + * You can create a new archive by creating a new instance, + * or load an existing zip with the static method loadArchive. + */ +class ZipArchiveBuilder extends AbstractArchiveBuilder +{ + const TEMP_DIRECTORY_NAME = "archive_builder"; + + /** + * @var \ZipArchive + */ + protected $zip; + + /** + * @var string This is the absolute path to the zip file in cache + */ + protected $zip_cache_file; + + /** + * @var string This is the path of the cache + */ + protected $cache_dir; + + /** + * @var \Thelia\Log\Tlog + */ + protected $logger; + + /** + * @var Translator + */ + protected $translator; + + public function __construct() + { + $this->zip = new \ZipArchive(); + + $this->logger = Tlog::getNewInstance(); + + $this->translator = Translator::getInstance(); + } + + /** + * On the destruction of the class, + * remove the temporary file. + */ + function __destruct() + { + if ($this->zip instanceof \ZipArchive) { + @$this->zip->close(); + + if (file_exists($this->zip_cache_file)) { + unlink($this->zip_cache_file); + } + } + } + + /** + * @param string $filePath It is the path to access the file. + * @param string $directoryInArchive This is the directory where it will be stored in the archive + * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name + * @param bool $isOnline + * @return $this + * @throws \Thelia\Exception\FileNotFoundException + * @throws \Thelia\Exception\FileNotReadableException + * + * This methods adds a file in the archive. + * If the file is local, $isOnline must be false, + * If the file online, $filePath must be an URL. + */ + public function addFile($filePath, $directoryInArchive = null, $name = null, $isOnline = false) + { + /** + * Add empty directory if it doesn't exist + */ + if (empty($directoryInArchive) || preg_match("#^\/+$#", $directoryInArchive)) { + $directoryInArchive = ""; + } + + if(!empty($directoryInArchive) && $directoryInArchive != "/") { + $directoryInArchive = $this->getDirectoryPath($directoryInArchive); + + if (!$this->zip->addEmptyDir($directoryInArchive)) { + throw new \ErrorException( + $this->translator->trans( + "The directory %dir has not been created in the archive", + [ + "%dir" => $directoryInArchive + ] + ) + ); + } + } + + if ($isOnline) { + $fileDownloadCache = $this->cache_dir . DS . "download"; + + $this->getFileDownloader() + ->download($filePath, $fileDownloadCache) + ; + + $filePath = $fileDownloadCache; + } else { + if (!file_exists($filePath)) { + $this->throwFileNotFound($filePath); + } else if (!is_readable($filePath)) { + throw new FileNotReadableException( + $this->translator + ->trans( + "The file %file is not readable", + [ + "%file" => $filePath, + ] + ) + ); + } + } + + if (empty($name)) { + $name = basename($filePath); + } + + $destination = $directoryInArchive . $name; + + if (!$this->zip->addFile($filePath,$destination)) { + $translatedErrorMessage = $this->translator->trans( + "An error occurred while adding this file to the archive: %file", + [ + "%file" => $filePath + ] + ); + + $this->logger->error($translatedErrorMessage); + + throw new \ErrorException($translatedErrorMessage); + } + + $this->commit(); + + return $this; + } + + /** + * @param $pathInArchive + * @return $this + * @throws \Thelia\Exception\FileNotFoundException + * @throws \ErrorException + * + * This method deletes a file in the archive + */ + public function deleteFile($pathInArchive) + { + $pathInArchive = $this->getFilePath($pathInArchive); + + if (!$this->hasFile($pathInArchive)) { + $this->throwFileNotFound($pathInArchive); + } + + $deleted = $this->zip->deleteName($pathInArchive); + + if (!$deleted) { + throw new \ErrorException( + $this->translator->trans( + "The file %file has not been deleted", + [ + "%file" => $pathInArchive, + ] + ) + ); + } + + return $this; + } + + /** + * @return \Thelia\Core\HttpFoundation\Response + * + * This method return an instance of a Response with the archive as content. + */ + public function buildArchiveResponse() + { + $this->zip->comment = "Generated by Thelia v" . Thelia::THELIA_VERSION; + + $this->commit(); + + if (!file_exists($this->zip_cache_file)) { + $this->throwFileNotFound($this->zip_cache_file); + } + + if (!is_readable($this->zip_cache_file)) { + throw new FileNotReadableException( + $this->translator->trans( + "The cache file %file is not readable", + [ + "%file" => $this->zip_cache_file + ] + ) + ); + } + + $content = file_get_contents($this->zip_cache_file); + + $this->zip->close(); + + return new Response( + $content, + 200, + [ + "Content-Type" => $this->getMimeType() + ] + ); + } + + /** + * @param string $pathToArchive + * @param string $environment + * @param bool $isOnline + * @param FileDownloaderInterface $fileDownloader + * @return $this + * @throws \Thelia\Exception\FileNotFoundException + * @throws \Thelia\Exception\HttpUrlException + * + * Loads an archive + */ + public static function loadArchive( + $pathToArchive, + $environment, + $isOnline = false, + FileDownloaderInterface $fileDownloader = null + ) { + /** @var ZipArchiveBuilder $instance */ + $instance = new static(); + + $instance->setEnvironment($environment); + $zip = $instance->getRawZipArchive(); + $zip->close(); + + if ($fileDownloader !== null) { + $instance->setFileDownloader($fileDownloader); + } + + if ($isOnline) { + /** + * It's an online file + */ + $instance->getFileDownloader() + ->download($pathToArchive, $instance->getZipCacheFile()) + ; + } else { + /** + * It's a local file + */ + if (!is_file($pathToArchive) || !is_readable($pathToArchive)) { + $instance->throwFileNotFound($pathToArchive); + } + + if (!copy($pathToArchive, $instance->getZipCacheFile())) { + $translatedErrorMessage = $instance->getTranslator()->trans( + "An unknown error happend while copying %prev to %dest", + [ + "%prev" => $pathToArchive, + "%dest" => $instance->getZipCacheFile(), + ] + ); + + $instance->getLogger() + ->error($translatedErrorMessage) + ; + + throw new \ErrorException($translatedErrorMessage); + } + } + + if (true !== $return = $zip->open($instance->getZipCacheFile())) { + throw new ZipArchiveException( + $instance->getZipErrorMessage($return) + ); + } + + return $instance; + } + + /** + * @param $pathToFile + * @return bool + * + * Checks if the archive has a file + */ + public function hasFile($pathToFile) + { + return $this->zip + ->locateName($this->getFilePath($pathToFile)) !== false + ; + } + + /** + * @param string $directory + * @return bool + * + * Checks if the link $directory exists and if it's not a file. + */ + public function hasDirectory($directory) + { + $link = $this->zip->locateName($this->getDirectoryPath($directory)); + + return $link !== false; + } + + /** + * @param string $environment + * @return $this + * + * Sets the execution environment of the Kernel, + * used to know which cache is used. + */ + public function setEnvironment($environment) + { + $theliaCacheDir = THELIA_CACHE_DIR . $environment . DS; + + if (!is_writable($theliaCacheDir)) { + throw new \ErrorException( + $this->translator->trans( + "The cache directory \"%env\" is not writable", + [ + "%env" => $environment + ] + ) + ); + } + + $archiveBuilderCacheDir = $this->cache_dir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; + + if (!is_dir($archiveBuilderCacheDir) && !mkdir($archiveBuilderCacheDir, 0755)) { + throw new \ErrorException( + $this->translator->trans( + "Error while creating the directory \"%directory\"", + [ + "%directory" => static::TEMP_DIRECTORY_NAME + ] + ) + ); + } + + $cacheFileName = md5 (uniqid()); + + $cacheFile = $archiveBuilderCacheDir . DS . $cacheFileName; + $cacheFile .= "." . $this->getExtension(); + + if (file_exists($cacheFile)) { + unlink($cacheFile); + } + + $opening = $this->zip->open( + $cacheFile, + \ZipArchive::CREATE + ); + + if($opening !== true) { + throw new \ErrorException( + $this->translator->trans( + "Unknown" + ) + ); + } + + $this->zip_cache_file = $cacheFile; + + return $this; + } + + /** + * @param $errorCode + * @return string + * + * Give the error message of a \ZipArchive error code + */ + public function getZipErrorMessage($errorCode) + { + switch ($errorCode) { + case \ZipArchive::ER_EXISTS: + $message = "The archive already exists"; + break; + + case \ZipArchive::ER_INCONS: + $message = "The archive is inconsistent"; + break; + + case \ZipArchive::ER_INVAL: + $message = "Invalid argument"; + break; + + case \ZipArchive::ER_MEMORY: + $message = "Memory error"; + break; + + case \ZipArchive::ER_NOENT: + $message = "The file doesn't exist"; + break; + + case \ZipArchive::ER_NOZIP: + $message = "The file is not a zip archive"; + break; + + case \ZipArchive::ER_OPEN: + $message = "The file could not be open"; + break; + + case \ZipArchive::ER_READ: + $message = "The file could not be read"; + break; + + case \ZipArchive::ER_SEEK: + $message = "Position error"; + break; + + default: + $message = "Unknown error on the ZIP archive"; + break; + } + + $zipMessageHead = $this->translator->trans( + "Zip Error" + ); + + $message = $this->translator->trans( + "[%zip_head] " . $message, + [ + "%zip_head" => $zipMessageHead + ] + ); + + return $message; + } + + public function commit() + { + $this->zip->close(); + $result = $this->zip->open($this->getZipCacheFile()); + + if ($result !== true) { + throw new \ErrorException( + $this->translator->trans( + "The changes could on the Zip Archive not be commited" + ) + ); + } + + return $this; + } + + /** + * @param string $initialString + * @return string + * + * Gives a valid file path for \ZipArchive + */ + public function getFilePath($initialString) + { + /** + * Remove the / at the beginning and the end. + */ + $initialString = trim($initialString, "/"); + + /** + * Remove the double, triple, ... slashes + */ + $initialString = preg_replace("#\/{2,}#", "/", $initialString); + + if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) { + $initialString = "/" . $initialString; + } + return $initialString; + } + + /** + * @param string $initialString + * @return string + * + * Gives a valid directory path for \ZipArchive + */ + public function getDirectoryPath($initialString) + { + $initialString = $this->getFilePath($initialString); + + if ($initialString[0] !== "/") { + $initialString = "/" . $initialString; + } + + return $initialString . "/"; + } + + public function throwFileNotFound($file) + { + + throw new FileNotFoundException( + $this->getTranslator() + ->trans( + "The file %file is missing or is not readable", + [ + "%file" => $file, + ] + ) + ); + } + + /** + * @return string + * + * This method must return a string, the name of the format. + * + * example: + * return "XML"; + */ + public function getName() + { + return "ZIP"; + } + + /** + * @return string + * + * This method must return a string, the extension of the file format, without the ".". + * The string should be lowercase. + * + * example: + * return "xml"; + */ + public function getExtension() + { + return "zip"; + } + + /** + * @return string + * + * This method must return a string, the mime type of the file format. + * + * example: + * return "application/json"; + */ + public function getMimeType() + { + return "application/zip"; + } + + /** + * @return Tlog + */ + public function getLogger() + { + return $this->logger; + } + + /** + * @return Translator + */ + public function getTranslator() + { + return $this->translator; + } + + /** + * @return \ZipArchive + */ + public function getRawZipArchive() + { + return $this->zip; + } + + public function getZipCacheFile() + { + return $this->zip_cache_file; + } + + public function getCacheDir() + { + return $this->cache_dir; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php new file mode 100644 index 000000000..c85fce339 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php @@ -0,0 +1,23 @@ + + */ +class ZipArchiveException extends \ErrorException +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php new file mode 100644 index 000000000..c779722a6 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -0,0 +1,90 @@ + + * + * This interface defines the methods that an archive creator must have. + */ +interface ArchiveBuilderInterface +{ + /** + * @param string $filePath It is the path to access the file. + * @param string $directoryInArchive This is the directory where it will be stored in the archive + * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name + * @param bool $isOnline + * @return $this + * @throws \Thelia\Exception\FileNotFoundException + * @throws \Thelia\Exception\FileNotReadableException + * + * This methods adds a file in the archive. + * If the file is local, $isOnline must be false, + * If the file online, $filePath must be an URL. + */ + public function addFile($filePath, $directoryInArchive = "/", $name = null, $isOnline = false); + + /** + * @param $pathInArchive + * @return $this + * @throws \Thelia\Exception\FileNotFoundException + * + * This method deletes a file in the archive + */ + public function deleteFile($pathInArchive); + + /** + * @return \Thelia\Core\HttpFoundation\Response + * + * This method return an instance of a Response with the archive as content. + */ + public function buildArchiveResponse(); + + /** + * @param string $pathToArchive + * @param bool $isOnline + * @return $this + * @throws \Thelia\Exception\FileNotFoundException + * @throws \Thelia\Exception\HttpUrlException + * + * Loads an archive + */ + public static function loadArchive($pathToArchive, $environment, $isOnline = false); + + /** + * @param $pathToFile + * @return bool + * + * Checks if the archive has a file + */ + public function hasFile($pathToFile); + + /** + * @param string $directory + * @return bool + * + * Check if the archive has a directory + */ + public function hasDirectory($directory); + + /** + * @param string $environment + * @return $this + * + * Sets the execution environment of the Kernel, + * used to know which cache is used. + */ + public function setEnvironment($environment); +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php new file mode 100644 index 000000000..7957fca4f --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php @@ -0,0 +1,76 @@ + + */ +class ArchiveBuilderManager +{ + protected $archiveCreators = array(); + + protected $environment; + + public function __construct($environment) + { + $this->environment = $environment; + } + /** + * @param AbstractArchiveBuilder $archiveCreator + * @return $this + */ + public function add(AbstractArchiveBuilder $archiveCreator) + { + if (null !== $archiveCreator) { + $archiveCreator->setEnvironment($this->environment); + + $this->archiveCreators[$archiveCreator->getName()] = $archiveCreator; + } + + return $this; + } + + /** + * @param $name + * @return $this + * @throws \OutOfBoundsException + */ + public function delete($name) + { + if (!array_key_exists($name, $this->archiveCreators)) { + throw new \OutOfBoundsException( + Translator::getInstance()->trans( + "The archive creator %name doesn't exist", + [ + "%name" => $name + ] + ) + ); + } + + unset($this->archiveCreators[$name]); + + return $this; + } + + /** + * @return array[AbstractArchiveBuilder] + */ + public function getAll() + { + return $this->archiveCreators; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/FormatInterface.php b/core/lib/Thelia/Core/FileFormat/FormatInterface.php new file mode 100644 index 000000000..cd10a0cb0 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/FormatInterface.php @@ -0,0 +1,58 @@ + + * + * This interface defines what a formatter must have: + * - A name ( example: XML, JSON, yaml ) + * - An extension ( example: xml, json, yml ) + * - A mime type ( example: application/xml, application/json, ... ) + */ +interface FormatInterface +{ + + /** + * @return string + * + * This method must return a string, the name of the format. + * + * example: + * return "XML"; + */ + public function getName(); + + /** + * @return string + * + * This method must return a string, the extension of the file format, without the ".". + * The string should be lowercase. + * + * example: + * return "xml"; + */ + public function getExtension(); + + /** + * @return string + * + * This method must return a string, the mime type of the file format. + * + * example: + * return "application/json"; + */ + public function getMimeType(); +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php new file mode 100644 index 000000000..f991535c8 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php @@ -0,0 +1,41 @@ + + */ +abstract class AbstractFormatter implements FormatInterface +{ + /** + * @param array $data + * @return mixed + * + * Encodes an array to the desired format. + * $data array only contains array and scalar data. + */ + abstract public function encode(array $data); + + /** + * @param $data + * @return array + * @throws \Thelia\Core\FileFormat\Formatter\Exception\BadFormattedStringException + * + * this method must do exactly the opposite of encode and return + * an array composed of array and scalar data. + */ + abstract public function decode($data); +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php b/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php new file mode 100644 index 000000000..6d763a01b --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php @@ -0,0 +1,23 @@ + + */ +class BadFormattedStringException extends \ErrorException +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php new file mode 100644 index 000000000..cc8aad8e4 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php @@ -0,0 +1,69 @@ + + */ +class FormatterManager +{ + + protected $formatters = array(); + + /** + * @param $archiveCreator + * @return $this + */ + public function add(AbstractFormatter $formatter) + { + if (null !== $formatter) { + $this->formatters[$formatter->getName()] = $formatter; + } + + return $this; + } + + /** + * @param $name + * @return $this + * @throws \OutOfBoundsException + */ + public function delete($name) + { + if (!array_key_exists($name, $this->formatters)) { + throw new \OutOfBoundsException( + Translator::getInstance()->trans( + "The formatter %name doesn't exist", + [ + "%name" => $name + ] + ) + ); + } + + unset($this->formatters[$name]); + + return $this; + } + + /** + * @return array[AbstractFormatter] + */ + public function getAll() + { + return $this->formatters; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.zip b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.zip new file mode 100644 index 000000000..e69de29bb diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/test_file b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/test_file new file mode 100644 index 000000000..e69de29bb diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/well_formatted.zip b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/well_formatted.zip new file mode 100644 index 000000000..e69de29bb diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php new file mode 100644 index 000000000..68c5fbfad --- /dev/null +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -0,0 +1,344 @@ + + */ +class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase +{ + /** @var ZipArchiveBuilder */ + protected $zip; + + /** @var ZipArchiveBuilder */ + protected $loadedZip; + + public function setUp() + { + new Translator( + new Container() + ); + + Tlog::getNewInstance(); + + $this->zip = new ZipArchiveBuilder(); + + $this->loadedZip = $this->zip->loadArchive( + __DIR__ . DS . "TestResources/well_formatted.zip", + "dev" + ); + } + + /** + * This method formats a path to be compatible with \ZipArchive + * + * + */ + public function testGetFilePath() + { + $this->assertEquals( + "foo", + $this->zip->getFilePath("foo") + ); + + $this->assertEquals( + "foo", + $this->zip->getFilePath("/foo") + ); + + $this->assertEquals( + "foo", + $this->zip->getFilePath("foo/") + ); + + $this->assertEquals( + "foo", + $this->zip->getFilePath("/foo/") + ); + + $this->assertEquals( + "/foo/bar", + $this->zip->getFilePath("foo/bar") + ); + + $this->assertEquals( + "/foo/bar", + $this->zip->getFilePath("/foo/bar") + ); + + $this->assertEquals( + "/foo/bar", + $this->zip->getFilePath("/foo//bar/") + ); + + $this->assertEquals( + "/foo/bar", + $this->zip->getFilePath("/foo/bar/") + ); + + $this->assertEquals( + "/foo/bar/baz", + $this->zip->getFilePath("foo/bar/baz") + ); + + $this->assertEquals( + "/foo/bar/baz", + $this->zip->getFilePath("//foo/bar///baz/") + ); + } + + public function testGetDirectoryPath() + { + $this->assertEquals( + "/foo/", + $this->zip->getDirectoryPath("foo") + ); + + $this->assertEquals( + "/foo/", + $this->zip->getDirectoryPath("/foo") + ); + + $this->assertEquals( + "/foo/", + $this->zip->getDirectoryPath("foo/") + ); + + $this->assertEquals( + "/foo/", + $this->zip->getDirectoryPath("/foo/") + ); + + $this->assertEquals( + "/foo/bar/", + $this->zip->getDirectoryPath("foo/bar") + ); + + $this->assertEquals( + "/foo/bar/", + $this->zip->getDirectoryPath("/foo/bar") + ); + + $this->assertEquals( + "/foo/bar/", + $this->zip->getDirectoryPath("/foo//bar/") + ); + + $this->assertEquals( + "/foo/bar/", + $this->zip->getDirectoryPath("/foo/bar/") + ); + + $this->assertEquals( + "/foo/bar/baz/", + $this->zip->getDirectoryPath("foo/bar/baz") + ); + + $this->assertEquals( + "/foo/bar/baz/", + $this->zip->getDirectoryPath("//foo/bar///baz/") + ); + } + + public function testLoadValidZip() + { + $loadedZip = $this->zip->loadArchive( + __DIR__ . DS . "TestResources/well_formatted.zip", + "dev" + ); + + $this->assertInstanceOf( + get_class($this->loadedZip), + $loadedZip + ); + } + + /** + * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException + * @expectedExceptionMessage [Zip Error] The file is not a zip archive + */ + public function testLoadNotValidZip() + { + $this->zip->loadArchive( + __DIR__ . DS . "TestResources/bad_formatted.zip", + "dev" + ); + } + + /** + * @expectedException \Thelia\Exception\FileNotFoundException + */ + public function testLoadNotExistingFile() + { + $this->zip->loadArchive( + __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", + "dev" + ); + } + + public function testLoadOnlineAvailableAndValidFile() + { + $this->zip->loadArchive( + __DIR__ . DS . "TestResources/well_formatted.zip", + "dev", + true, + FakeFileDownloader::getInstance() + ); + } + + /** + * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException + * @expectedExceptionMessage [Zip Error] The file is not a zip archive + */ + public function testLoadOnlineAvailableAndNotValidFile() + { + $this->zip->loadArchive( + __DIR__ . DS . "TestResources/bad_formatted.zip", + "dev", + true, + FakeFileDownloader::getInstance() + ); + } + + /** + * @expectedException \Thelia\Exception\FileNotFoundException + */ + public function testLoadOnlineNotExistingFile() + { + $this->zip->loadArchive( + __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", + "dev", + true, + FakeFileDownloader::getInstance() + ); + } + + public function testHasFile() + { + $this->assertTrue( + $this->loadedZip->hasFile("LICENSE.txt") + ); + + $this->assertFalse( + $this->loadedZip->hasFile("foo") + ); + + $this->assertFalse( + $this->loadedZip->hasFile("LICENSE.TXT") + ); + } + + public function testDeleteFile() + { + $this->assertInstanceOf( + get_class($this->loadedZip), + $this->loadedZip->deleteFile("LICENSE.txt") + ); + } + + /** + * @expectedException \Thelia\Exception\FileNotFoundException + */ + public function testDeleteNotExistingFile() + { + $this->loadedZip->deleteFile("foo"); + } + + public function testAddExistingFile() + { + $this->assertInstanceOf( + get_class($this->loadedZip), + $this->loadedZip->addFile( + __DIR__ . DS . "TestResources/test_file", + "/f/f/" + ) + ); + + /** + * Show that even weird paths are correctly interpreted + */ + $this->assertTrue( + $this->loadedZip->hasFile("///f//f/test_file/") + ); + } + + public function testAddExistingFileInNewDirectory() + { + $this->assertInstanceOf( + get_class($this->loadedZip), + $this->loadedZip->addFile( + __DIR__ . DS . "TestResources/test_file", + "testDir" + ) + ); + + /** + * You can create and check the directory and files + * without giving the initial and final slashes + */ + $this->assertTrue( + $this->loadedZip->hasDirectory("testDir") + ); + + $this->assertTrue( + $this->loadedZip->hasDirectory("/testDir") + ); + + $this->assertTrue( + $this->loadedZip->hasDirectory("testDir/") + ); + + $this->assertTrue( + $this->loadedZip->hasDirectory("/testDir/") + ); + + $this->assertTrue( + $this->loadedZip->hasFile("testDir/test_file") + ); + + $this->assertTrue( + $this->loadedZip->hasFile("/testDir/test_file") + ); + + $this->assertTrue( + $this->loadedZip->hasFile("testDir/test_file/") + ); + + $this->assertTrue( + $this->loadedZip->hasFile("/testDir/test_file/") + ); + } + + public function testBuildArchiveResponse() + { + $loadedArchiveResponse = $this->loadedZip + ->buildArchiveResponse() + ; + + $loadedArchiveResponseContent = $loadedArchiveResponse->getContent(); + + $content = file_get_contents(__DIR__ . DS . "TestResources/well_formatted.zip"); + + $this->assertEquals( + $content, + $loadedArchiveResponseContent + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php new file mode 100644 index 000000000..c01b35a45 --- /dev/null +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php @@ -0,0 +1,75 @@ + + */ +class ArchiveBuilderManagerTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var ArchiveBuilderManager + */ + protected $manager; + + public function setUp() + { + new Translator( + new Container() + ); + $this->manager = new ArchiveBuilderManager("dev"); + } + + public function testAddArchiveBuilder() + { + /** @var AbstractArchiveBuilder $instance */ + $instance = $this->getMock("Thelia\\Core\\FileFormat\\Archive\\AbstractArchiveBuilder"); + + $this->manager->add($instance); + + $archiveBuilders = $this->manager->getAll(); + + $this->assertTrue( + array_key_exists($instance->getName(), $archiveBuilders) + ); + } + + public function testDeleteArchiveBuilder() + { + /** @var AbstractArchiveBuilder $instance */ + $instance = $this->getMock("Thelia\\Core\\FileFormat\\Archive\\AbstractArchiveBuilder"); + + $this->manager->add($instance); + + $this->manager->delete($instance->getName()); + + $this->assertTrue( + count($this->manager->getAll()) === 0 + ); + } + + /** + * @expectedException \OutOfBoundsException + */ + public function testDeleteNotExistingArchiveBuilder() + { + $this->manager->delete("foo"); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php new file mode 100644 index 000000000..8759c2fca --- /dev/null +++ b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php @@ -0,0 +1,74 @@ + + */ +class FormatterManagerTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var FormatterManager + */ + protected $manager; + + public function setUp() + { + new Translator( + new Container() + ); + $this->manager = new FormatterManager(); + } + + public function testAddFormatter() + { + /** @var AbstractFormatter $instance */ + $instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatter\\AbstractFormatter"); + + $this->manager->add($instance); + + $archiveBuilders = $this->manager->getAll(); + + $this->assertTrue( + array_key_exists($instance->getName(), $archiveBuilders) + ); + } + + public function testDeleteFormatter() + { + /** @var AbstractFormatter $instance */ + $instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatter\\AbstractFormatter"); + + $this->manager->add($instance); + + $this->manager->delete($instance->getName()); + + $this->assertTrue( + count($this->manager->getAll()) === 0 + ); + } + + /** + * @expectedException \OutOfBoundsException + */ + public function testDeleteNotExistingFormatter() + { + $this->manager->delete("foo"); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php b/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php new file mode 100644 index 000000000..851036062 --- /dev/null +++ b/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php @@ -0,0 +1,44 @@ + + */ +class FakeFileDownloader extends FileDownloader +{ + /** + * @param string $url + * @param string $pathToStore + * @throws \Thelia\Exception\FileNotFoundException + * @throws \ErrorException + * @throws \HttpUrlException + * + * Downloads the file $url in $pathToStore + */ + public function download($url, $pathToStore) + { + if (!file_exists($url) || !is_readable($url)) { + throw new FileNotFoundException(); + } + + if (!copy($url, $pathToStore)) { + throw new \ErrorException(); + } + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php new file mode 100644 index 000000000..3ebc3e459 --- /dev/null +++ b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php @@ -0,0 +1,63 @@ + + */ +class FileDownloaderTest extends \PHPUnit_Framework_TestCase +{ + /** @var FileDownloader */ + protected $downloader; + + public function setUp() + { + $logger = Tlog::getNewInstance(); + $translator = new Translator( + new Container() + ); + + $this->downloader = new FileDownloader( + $logger, + $translator + ); + } + + /** + * @expectedException \Thelia\Exception\HttpUrlException + * @expectedExceptionMessage Tried to download a file, but the URL was not valid: foo + */ + public function testFileDownloadInvalidURL() + { + $this->downloader->download("foo", "bar"); + } + + /** + * @expectedException \Thelia\Exception\FileNotFoundException + */ + public function testFileDownloadNonExistingFile() + { + $this->downloader->download("https://github.com/foo/bar/baz", "baz"); + } + + public function testFileDownloadSuccess() + { + $this->downloader->download("https://github.com/thelia/thelia", "php://temp"); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Tools/FileManagerTest.php b/core/lib/Thelia/Tests/Tools/FileManagerTest.php new file mode 100644 index 000000000..29e4f2966 --- /dev/null +++ b/core/lib/Thelia/Tests/Tools/FileManagerTest.php @@ -0,0 +1,900 @@ +markTestIncomplete( + 'This test has not been implemented yet : Mock issue' + ); + + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + $stubTranslator->expects($this->any()) + ->method('trans') + ->will($this->returnValue('translated')); + + $stubRequest = $this->getMockBuilder('\Thelia\Core\HttpFoundation\Request') + ->disableOriginalConstructor() + ->getMock(); + + $stubSecurity = $this->getMockBuilder('\Thelia\Core\Security\SecurityContext') + ->disableOriginalConstructor() + ->getMock(); + $stubSecurity->expects($this->any()) + ->method('getAdminUser') + ->will($this->returnValue(new Admin())); + + // Create a map of arguments to return values. + $map = array( + array('thelia.translator', $stubTranslator), + array('request', $stubRequest), + array('thelia.securityContext', $stubSecurity) + ); + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValueMap($map)); + + $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage') + ->disableOriginalConstructor() + ->getMock(); + $stubProductImage->expects($this->any()) + ->method('getUploadDir') + ->will($this->returnValue(THELIA_LOCAL_DIR . 'media/images/product')); + $stubProductImage->expects($this->any()) + ->method('getId') + ->will($this->returnValue(42)); + $stubProductImage->expects($this->any()) + ->method('setFile') + ->will($this->returnValue(true)); + $stubProductImage->expects($this->any()) + ->method('save') + ->will($this->returnValue(0)); + + $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') + ->disableOriginalConstructor() + ->getMock(); + $stubUploadedFile->expects($this->any()) + ->method('getClientOriginalName') + ->will($this->returnValue('goodName')); + $stubUploadedFile->expects($this->any()) + ->method('getClientOriginalExtension') + ->will($this->returnValue('png')); + $stubUploadedFile->expects($this->any()) + ->method('move') + ->will($this->returnValue($stubUploadedFile)); + + $fileManager = new FileManager($stubContainer); + + $newUploadedFiles = array(); + + $actual = $fileManager->copyUploadedFile(24, FileManager::TYPE_PRODUCT, $stubProductImage, $stubUploadedFile, $newUploadedFiles, FileManager::FILE_TYPE_IMAGES); + + $this->assertCount(1, $actual); + }*/ + + /** + * @covers Thelia\Tools\FileManager::copyUploadedFile + * @expectedException \Thelia\Exception\ImageException + */ + /*public function testCopyUploadedFileExceptionImageException() + { + $this->markTestIncomplete( + 'This test has not been implemented yet : Mock issue' + ); + + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + $stubTranslator->expects($this->any()) + ->method('trans') + ->will($this->returnValue('translated')); + + $stubRequest = $this->getMockBuilder('\Thelia\Core\HttpFoundation\Request') + ->disableOriginalConstructor() + ->getMock(); + + $stubSecurity = $this->getMockBuilder('\Thelia\Core\Security\SecurityContext') + ->disableOriginalConstructor() + ->getMock(); + $stubSecurity->expects($this->any()) + ->method('getAdminUser') + ->will($this->returnValue(new Admin())); + + // Create a map of arguments to return values. + $map = array( + array('thelia.translator', $stubTranslator), + array('request', $stubRequest), + array('thelia.securityContext', $stubSecurity) + ); + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValueMap($map)); + + $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage') + ->disableOriginalConstructor() + ->getMock(); + $stubProductImage->expects($this->any()) + ->method('getUploadDir') + ->will($this->returnValue(THELIA_LOCAL_DIR . 'media/images/product')); + $stubProductImage->expects($this->any()) + ->method('getId') + ->will($this->returnValue(42)); + $stubProductImage->expects($this->any()) + ->method('setFile') + ->will($this->returnValue(true)); + $stubProductImage->expects($this->any()) + ->method('save') + ->will($this->returnValue(0)); + + $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') + ->disableOriginalConstructor() + ->getMock(); + $stubUploadedFile->expects($this->any()) + ->method('getClientOriginalName') + ->will($this->returnValue('goodName')); + $stubUploadedFile->expects($this->any()) + ->method('getClientOriginalExtension') + ->will($this->returnValue('png')); + $stubUploadedFile->expects($this->any()) + ->method('move') + ->will($this->returnValue($stubUploadedFile)); + + $fileManager = new FileManager($stubContainer); + + $newUploadedFiles = array(); + + $actual = $fileManager->copyUploadedFile(24, FileManager::TYPE_PRODUCT, $stubProductImage, $stubUploadedFile, $newUploadedFiles, FileManager::FILE_TYPE_DOCUMENTS); + + }*/ + + /** + * @covers Thelia\Tools\FileManager::saveImage + */ + public function testSaveImageProductImage() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage') + ->disableOriginalConstructor() + ->getMock(); + $stubProductImage->expects($this->any()) + ->method('save') + ->will($this->returnValue(10)); + $stubProductImage->expects($this->any()) + ->method('getFile') + ->will($this->returnValue('file')); + + $fileManager = new FileManager(); + + $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24); + + $expected = 10; + $actual = $fileManager->saveImage($event, $stubProductImage); + + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::saveDocument + */ + public function testSaveDocumentProductDocument() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $stubProductDocument = $this->getMockBuilder('\Thelia\Model\ProductDocument') + ->disableOriginalConstructor() + ->getMock(); + $stubProductDocument->expects($this->any()) + ->method('save') + ->will($this->returnValue(10)); + $stubProductDocument->expects($this->any()) + ->method('getFile') + ->will($this->returnValue('file')); + + $fileManager = new FileManager(); + + $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24); + + $expected = 10; + $actual = $fileManager->saveDocument($event, $stubProductDocument); + + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::saveImage + */ + public function testSaveImageCategoryImage() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $stubCategoryImage = $this->getMockBuilder('\Thelia\Model\CategoryImage') + ->disableOriginalConstructor() + ->getMock(); + $stubCategoryImage->expects($this->any()) + ->method('save') + ->will($this->returnValue(10)); + $stubCategoryImage->expects($this->any()) + ->method('getFile') + ->will($this->returnValue('file')); + + $fileManager = new FileManager(); + + $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_CATEGORY, 24); + + $expected = 10; + $actual = $fileManager->saveImage($event, $stubCategoryImage); + + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::saveDocument + */ + public function testSaveDocumentCategoryDocument() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $stubCategoryDocument = $this->getMockBuilder('\Thelia\Model\CategoryDocument') + ->disableOriginalConstructor() + ->getMock(); + $stubCategoryDocument->expects($this->any()) + ->method('save') + ->will($this->returnValue(10)); + $stubCategoryDocument->expects($this->any()) + ->method('getFile') + ->will($this->returnValue('file')); + + $fileManager = new FileManager(); + + $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_CATEGORY, 24); + + $expected = 10; + $actual = $fileManager->saveDocument($event, $stubCategoryDocument); + + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::saveImage + */ + public function testSaveImageFolderImage() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $stubFolderImage = $this->getMockBuilder('\Thelia\Model\FolderImage') + ->disableOriginalConstructor() + ->getMock(); + $stubFolderImage->expects($this->any()) + ->method('save') + ->will($this->returnValue(10)); + $stubFolderImage->expects($this->any()) + ->method('getFile') + ->will($this->returnValue('file')); + + $fileManager = new FileManager(); + + $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_FOLDER, 24); + + $expected = 10; + $actual = $fileManager->saveImage($event, $stubFolderImage); + + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::saveDocument + */ + public function testSaveDocumentFolderDocument() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $stubFolderDocument = $this->getMockBuilder('\Thelia\Model\FolderDocument') + ->disableOriginalConstructor() + ->getMock(); + $stubFolderDocument->expects($this->any()) + ->method('save') + ->will($this->returnValue(10)); + $stubFolderDocument->expects($this->any()) + ->method('getFile') + ->will($this->returnValue('file')); + + $fileManager = new FileManager(); + + $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_FOLDER, 24); + + $expected = 10; + $actual = $fileManager->saveDocument($event, $stubFolderDocument); + + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::saveImage + */ + public function testSaveImageContentImage() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $stubContentImage = $this->getMockBuilder('\Thelia\Model\ContentImage') + ->disableOriginalConstructor() + ->getMock(); + $stubContentImage->expects($this->any()) + ->method('save') + ->will($this->returnValue(10)); + $stubContentImage->expects($this->any()) + ->method('getFile') + ->will($this->returnValue('file')); + + $fileManager = new FileManager(); + + $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_CONTENT, 24); + + $expected = 10; + $actual = $fileManager->saveImage($event, $stubContentImage); + + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::saveDocument + */ + public function testSaveDocumentContentDocument() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $stubContentDocument = $this->getMockBuilder('\Thelia\Model\ContentDocument') + ->disableOriginalConstructor() + ->getMock(); + $stubContentDocument->expects($this->any()) + ->method('save') + ->will($this->returnValue(10)); + $stubContentDocument->expects($this->any()) + ->method('getFile') + ->will($this->returnValue('file')); + + $fileManager = new FileManager(); + + $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_CONTENT, 24); + + $expected = 10; + $actual = $fileManager->saveDocument($event, $stubContentDocument); + + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::saveImage + * @expectedException \Thelia\Exception\ImageException + */ + public function testSaveImageExceptionImageException() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + $fileManager = new FileManager(); + + $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage') + ->disableOriginalConstructor() + ->getMock(); + $stubProductImage->expects($this->any()) + ->method('save') + ->will($this->returnValue(10)); + $stubProductImage->expects($this->any()) + ->method('getFile') + ->will($this->returnValue('file')); + + $event = new ImageCreateOrUpdateEvent('bad', 24); + + $fileManager->saveImage($event, $stubProductImage); + } + + /** + * @covers Thelia\Tools\FileManager::saveDocument + * @expectedException \Thelia\Model\Exception\InvalidArgumentException + */ + public function testSaveDocumentExceptionDocumentException() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + $fileManager = new FileManager(); + + $stubProductDocument = $this->getMockBuilder('\Thelia\Model\ProductDocument') + ->disableOriginalConstructor() + ->getMock(); + $stubProductDocument->expects($this->any()) + ->method('save') + ->will($this->returnValue(10)); + $stubProductDocument->expects($this->any()) + ->method('getFile') + ->will($this->returnValue('file')); + + $event = new DocumentCreateOrUpdateEvent('bad', 24); + + $fileManager->saveDocument($event, $stubProductDocument); + } + + /** + * @covers Thelia\Tools\FileManager::saveImage + * @expectedException \Thelia\Exception\ImageException + */ + public function testSaveImageExceptionImageException2() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + $fileManager = new FileManager(); + + $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage') + ->disableOriginalConstructor() + ->getMock(); + $stubProductImage->expects($this->any()) + ->method('save') + ->will($this->returnValue(0)); + $stubProductImage->expects($this->any()) + ->method('getFile') + ->will($this->returnValue('file')); + + $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24); + + $fileManager->saveImage($event, $stubProductImage); + } + + /** + * @covers Thelia\Tools\FileManager::saveDocument + * @expectedException \Thelia\Model\Exception\InvalidArgumentException + */ + public function testSaveDocumentExceptionDocumentException2() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + $fileManager = new FileManager(); + + $stubProductDocument = $this->getMockBuilder('\Thelia\Model\ProductDocument') + ->disableOriginalConstructor() + ->getMock(); + $stubProductDocument->expects($this->any()) + ->method('save') + ->will($this->returnValue(0)); + $stubProductDocument->expects($this->any()) + ->method('getFile') + ->will($this->returnValue('file')); + + $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24); + + $fileManager->saveDocument($event, $stubProductDocument); + } + + /** + * @covers Thelia\Tools\FileManager::sanitizeFileName + */ + public function testSanitizeFileName() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $fileManager = new FileManager(); + $badFileName = 'a/ze\érà~çè§^"$*+-_°)(&é<>@#ty2/[\/:*?"<>|]/fi?.fUPPERile.exel../e*'; + + $expected = 'azer-_ty2fi.fupperile.exel..e'; + $actual = $fileManager->sanitizeFileName($badFileName); + + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::getImageModel + */ + public function testGetImageModel() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $fileManager = new FileManager(); + $actual = $fileManager->getImageModel(FileManager::TYPE_PRODUCT); + $this->assertInstanceOf('\Thelia\Model\ProductImage', $actual); + $actual = $fileManager->getImageModel(FileManager::TYPE_CATEGORY); + $this->assertInstanceOf('\Thelia\Model\CategoryImage', $actual); + $actual = $fileManager->getImageModel(FileManager::TYPE_CONTENT); + $this->assertInstanceOf('\Thelia\Model\ContentImage', $actual); + $actual = $fileManager->getImageModel(FileManager::TYPE_FOLDER); + $this->assertInstanceOf('\Thelia\Model\FolderImage', $actual); + $actual = $fileManager->getImageModel('bad'); + $this->assertNull($actual); + } + + /** + * @covers Thelia\Tools\FileManager::getDocumentModel + */ + public function testGetDocumentModel() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $fileManager = new FileManager(); + $actual = $fileManager->getDocumentModel(FileManager::TYPE_PRODUCT); + $this->assertInstanceOf('\Thelia\Model\ProductDocument', $actual); + $actual = $fileManager->getDocumentModel(FileManager::TYPE_CATEGORY); + $this->assertInstanceOf('\Thelia\Model\CategoryDocument', $actual); + $actual = $fileManager->getDocumentModel(FileManager::TYPE_CONTENT); + $this->assertInstanceOf('\Thelia\Model\ContentDocument', $actual); + $actual = $fileManager->getDocumentModel(FileManager::TYPE_FOLDER); + $this->assertInstanceOf('\Thelia\Model\FolderDocument', $actual); + $actual = $fileManager->getDocumentModel('bad'); + $this->assertNull($actual); + } + + /** + * @covers Thelia\Tools\FileManager::getImageModelQuery + */ + public function testGetImageModelQuery() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $fileManager = new FileManager(); + $actual = $fileManager->getImageModelQuery(FileManager::TYPE_PRODUCT); + $this->assertInstanceOf('\Thelia\Model\ProductImageQuery', $actual); + $actual = $fileManager->getImageModelQuery(FileManager::TYPE_CATEGORY); + $this->assertInstanceOf('\Thelia\Model\CategoryImageQuery', $actual); + $actual = $fileManager->getImageModelQuery(FileManager::TYPE_CONTENT); + $this->assertInstanceOf('\Thelia\Model\ContentImageQuery', $actual); + $actual = $fileManager->getImageModelQuery(FileManager::TYPE_FOLDER); + $this->assertInstanceOf('\Thelia\Model\FolderImageQuery', $actual); + $actual = $fileManager->getImageModelQuery('bad'); + $this->assertNull($actual); + } + + /** + * @covers Thelia\Tools\FileManager::getDocumentModelQuery + */ + public function testGetDocumentModelQuery() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $fileManager = new FileManager(); + $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_PRODUCT); + $this->assertInstanceOf('\Thelia\Model\ProductDocumentQuery', $actual); + $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_CATEGORY); + $this->assertInstanceOf('\Thelia\Model\CategoryDocumentQuery', $actual); + $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_CONTENT); + $this->assertInstanceOf('\Thelia\Model\ContentDocumentQuery', $actual); + $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_FOLDER); + $this->assertInstanceOf('\Thelia\Model\FolderDocumentQuery', $actual); + $actual = $fileManager->getDocumentModelQuery('bad'); + $this->assertNull($actual); + } + + /** + * @covers Thelia\Tools\FileManager::getParentFileModel + */ + public function testGetParentFileModel() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $fileManager = new FileManager(); + $actual = $fileManager->getParentFileModel(FileManager::TYPE_PRODUCT, ProductQuery::create()->findOne()->getId()); + $this->assertInstanceOf('\Thelia\Model\Product', $actual); + $actual = $fileManager->getParentFileModel(FileManager::TYPE_CATEGORY, CategoryQuery::create()->findOne()->getId()); + $this->assertInstanceOf('\Thelia\Model\Category', $actual); + $actual = $fileManager->getParentFileModel(FileManager::TYPE_CONTENT, ContentQuery::create()->findOne()->getId()); + $this->assertInstanceOf('\Thelia\Model\Content', $actual); + $actual = $fileManager->getParentFileModel(FileManager::TYPE_FOLDER, FolderQuery::create()->findOne()->getId()); + $this->assertInstanceOf('\Thelia\Model\Folder', $actual, 1); + $actual = $fileManager->getParentFileModel('bad', 1); + $this->assertNull($actual); + } + + /** + * @covers Thelia\Tools\FileManager::getImageForm + */ + /* public function testGetImageForm() + { + // Mock issue + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + }*/ + /** + * @covers Thelia\Tools\FileManager::getDocumentForm + */ + /* public function testGetDocumentForm() + { + // Mock issue + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + }*/ + + /** + * @covers Thelia\Tools\FileManager::getUploadDir + */ + public function testGetUploadDir() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $fileManager = new FileManager(); + + $actual = $fileManager->getUploadDir(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/product', $actual); + $actual = $fileManager->getUploadDir(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/category', $actual); + $actual = $fileManager->getUploadDir(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/content', $actual); + $actual = $fileManager->getUploadDir(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/folder', $actual); + $actual = $fileManager->getUploadDir('bad', FileManager::FILE_TYPE_IMAGES); + $this->assertEquals(false, $actual); + + $actual = $fileManager->getUploadDir(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals(THELIA_LOCAL_DIR . 'media/documents/product', $actual); + $actual = $fileManager->getUploadDir(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals(THELIA_LOCAL_DIR . 'media/documents/category', $actual); + $actual = $fileManager->getUploadDir(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals(THELIA_LOCAL_DIR . 'media/documents/content', $actual); + $actual = $fileManager->getUploadDir(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals(THELIA_LOCAL_DIR . 'media/documents/folder', $actual); + $actual = $fileManager->getUploadDir('bad', FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals(false, $actual); + + $actual = $fileManager->getUploadDir(FileManager::TYPE_FOLDER, 'bad'); + $this->assertEquals(false, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::getRedirectionUrl + */ + public function testGetRedirectionUrl() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $fileManager = new FileManager(); + + $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_PRODUCT, 1, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals('/admin/products/update?product_id=1¤t_tab=images', $actual); + $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_CATEGORY, 1, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals('/admin/categories/update?category_id=1¤t_tab=images', $actual); + $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_CONTENT, 1, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals('/admin/content/update/1?current_tab=images', $actual); + $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_FOLDER, 1, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals('/admin/folders/update/1?current_tab=images', $actual); + $actual = $fileManager->getRedirectionUrl('bad', 1, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals(false, $actual); + + $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_PRODUCT, 1, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals('/admin/products/update?product_id=1¤t_tab=documents', $actual); + $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_CATEGORY, 1, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals('/admin/categories/update?category_id=1¤t_tab=documents', $actual); + $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_CONTENT, 1, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals('/admin/content/update/1?current_tab=documents', $actual); + $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_FOLDER, 1, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals('/admin/folders/update/1?current_tab=documents', $actual); + $actual = $fileManager->getRedirectionUrl('bad', 1, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals(false, $actual); + + $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_FOLDER, 1, 'bad'); + $this->assertEquals(false, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::getFormId + */ + public function testGetFormId() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $fileManager = new FileManager(); + + $actual = $fileManager->getFormId(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals('thelia.admin.product.image.modification', $actual); + $actual = $fileManager->getFormId(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals('thelia.admin.category.image.modification', $actual); + $actual = $fileManager->getFormId(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals('thelia.admin.content.image.modification', $actual); + $actual = $fileManager->getFormId(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_IMAGES); + $this->assertEquals('thelia.admin.folder.image.modification', $actual); + $actual = $fileManager->getFormId('bad', FileManager::FILE_TYPE_IMAGES); + $this->assertEquals(false, $actual); + + $actual = $fileManager->getFormId(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals('thelia.admin.product.document.modification', $actual); + $actual = $fileManager->getFormId(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals('thelia.admin.category.document.modification', $actual); + $actual = $fileManager->getFormId(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals('thelia.admin.content.document.modification', $actual); + $actual = $fileManager->getFormId(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals('thelia.admin.folder.document.modification', $actual); + $actual = $fileManager->getFormId('bad', FileManager::FILE_TYPE_DOCUMENTS); + $this->assertEquals(false, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::renameFile + */ + public function testRenameFile() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') + ->disableOriginalConstructor() + ->getMock(); + $stubUploadedFile->expects($this->any()) + ->method('getClientOriginalExtension') + ->will($this->returnValue('yml')); + $stubUploadedFile->expects($this->any()) + ->method('getClientOriginalName') + ->will($this->returnValue('or1-g_n?al*/&é"filen@me#')); + + $fileManager = new FileManager(); + + $expected = 'or1-g_nalfilenme-1.yml'; + $actual = $fileManager->renameFile(1, $stubUploadedFile); + + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::renameFile + */ + public function testRenameFileWithoutExtension() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') + ->disableOriginalConstructor() + ->getMock(); + $stubUploadedFile->expects($this->any()) + ->method('getClientOriginalExtension') + ->will($this->returnValue('')); + $stubUploadedFile->expects($this->any()) + ->method('getClientOriginalName') + ->will($this->returnValue('or1-g_n?al*/&é"filen@me#')); + + $fileManager = new FileManager(); + + $expected = 'or1-g_nalfilenme-1'; + $actual = $fileManager->renameFile(1, $stubUploadedFile); + + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::isImage + */ + public function testIsImage() + { + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $fileManager = new FileManager(); + + $actual = $fileManager->isImage('image/jpeg'); + $this->assertTrue($actual); + $actual = $fileManager->isImage('image/png'); + $this->assertTrue($actual); + $actual = $fileManager->isImage('image/gif'); + $this->assertTrue($actual); + + $actual = $fileManager->isImage('bad'); + $this->assertFalse($actual); + $actual = $fileManager->isImage('image/jpg'); + $this->assertFalse($actual); + $actual = $fileManager->isImage('application/x-msdownload'); + $this->assertFalse($actual); + $actual = $fileManager->isImage('application/x-sh'); + $this->assertFalse($actual); + + } + + /** + * @covers Thelia\Tools\FileManager::getAvailableTypes + */ + public function testGetAvailableTypes() + { + $expected = array( + FileManager::TYPE_CATEGORY, + FileManager::TYPE_CONTENT, + FileManager::TYPE_FOLDER, + FileManager::TYPE_PRODUCT, + FileManager::TYPE_MODULE, + ); + $actual = FileManager::getAvailableTypes(); + + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Tools\FileManager::adminLogAppend + */ + /* public function testAdminLogAppend() + { + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + }*/ + + /** + * @covers Thelia\Tools\FileManager::deleteFile + */ + /* public function testDeleteFile() + { + // @todo see http://tech.vg.no/2011/03/09/mocking-the-file-system-using-phpunit-and-vfsstream/ + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + }*/ +} diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php new file mode 100644 index 000000000..10eb1ef88 --- /dev/null +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php @@ -0,0 +1,142 @@ + + */ +class FileDownloader implements FileDownloaderInterface +{ + /** @var LoggerInterface */ + protected $logger; + + /** @var Translator */ + protected $translator; + + public function __construct(LoggerInterface $logger, Translator $translator) + { + $this->logger = $logger; + + $this->translator = $translator; + } + + public static function getInstance() + { + return new static(Tlog::getInstance(), TheliaTranslator::getInstance()); + } + + /** + * @param string $url + * @param string $pathToStore + * @throws \Thelia\Exception\FileNotFoundException + * @throws \ErrorException + * @throws \HttpUrlException + * + * Downloads the file $url in $pathToStore + */ + public function download($url, $pathToStore) + { + if (!URL::checkUrl($url)) { + /** + * The URL is not valid + */ + throw new HttpUrlException( + $this->translator->trans( + "Tried to download a file, but the URL was not valid: %url", + [ + "%url" => $url + ] + ) + ); + } + + /** + * Try to get the file if it is online + */ + $con = curl_init($url); + curl_setopt($con, CURLOPT_RETURNTRANSFER, true); + + $response = curl_exec($con); + $errno = curl_errno($con); + $curlErrorMessage = curl_error($con); + + $httpCode = curl_getinfo($con, CURLINFO_HTTP_CODE); + + curl_close($con); + + if (false === $response || $errno !== 0 || + ($httpCode != "200" && $httpCode != "204") + ) { + /** + * The server is down ? The file doesn't exist ? Anything else ? + */ + $errorMessage = $this->translator->trans( + "cURL errno %errno, http code %http_code on link \"%path\": %error", + [ + "%errno" => $errno, + "%path" => $url, + "%error" => $curlErrorMessage, + "%http_code" => $httpCode, + ] + ); + + $this->logger + ->error($errorMessage) + ; + + throw new FileNotFoundException($errorMessage); + } + + /** + * Inform that you've downloaded a file + */ + $this->logger + ->info( + $this->translator->trans( + "The file %path has been successfully downloaded", + [ + "%path" => $url + ] + ) + ) + ; + + /** + * Then try to write it on the disk + */ + $file = @fopen($pathToStore, "w"); + + if($file === false) { + $translatedErrorMessage = $this->translator->trans( + "Failed to open a writing stream on the file: %file", + [ + "%file" => $pathToStore + ] + ); + + $this->logger->error($translatedErrorMessage); + throw new \ErrorException($translatedErrorMessage); + } + + fputs($file, $response); + fclose($file); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php b/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php new file mode 100644 index 000000000..e9b99d73d --- /dev/null +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php @@ -0,0 +1,47 @@ + + */ +trait FileDownloaderAwareTrait +{ + /** @var FileDownloaderInterface */ + protected $fileDownloader; + + /** + * @return FileDownloaderInterface + */ + public function getFileDownloader() + { + if (!$this->fileDownloader instanceof FileDownloaderInterface) { + $this->fileDownloader = FileDownloader::getInstance(); + } + + return $this->fileDownloader; + } + + /** + * @param FileDownloaderInterface $fileDownloader + * @return $this + */ + public function setFileDownloader(FileDownloaderInterface $fileDownloader) + { + $this->fileDownloader = $fileDownloader; + + return $this; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php b/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php new file mode 100644 index 000000000..bdfebb5f9 --- /dev/null +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php @@ -0,0 +1,44 @@ + + */ +interface FileDownloaderInterface +{ + /** + * @param string $url + * @param string $pathToStore + * @throws \Thelia\Exception\FileNotFoundException + * @throws \ErrorException + * @throws \HttpUrlException + * + * Downloads the file $url in $pathToStore + */ + public function download($url, $pathToStore); + + public function __construct(LoggerInterface $logger, Translator $translator); + + /** + * @return $this + * + * Returns an hydrated instance + */ + public static function getInstance(); +} \ No newline at end of file diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 65a03ed65..569b15780 100644 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -13,6 +13,7 @@ namespace Thelia\Tools; use Symfony\Component\Routing\RequestContext; +use Symfony\Component\Validator\Constraints\UrlValidator; use Thelia\Model\ConfigQuery; use Thelia\Rewriting\RewritingResolver; use Thelia\Rewriting\RewritingRetriever; @@ -313,4 +314,11 @@ class URL strtolower($clean) : $clean; } + + public function checkUrl($url, array $protocols = ["http", "https"]) + { + $pattern = sprintf(UrlValidator::PATTERN, implode('|', $protocols)); + + return (bool) preg_match($pattern, $url); + } } From 8ddec1a21e68dec00af69781de90d5810536cfc5 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Wed, 2 Jul 2014 14:07:42 +0200 Subject: [PATCH 002/158] =?UTF-8?q?Add=20archive=20builder=20manager=20and?= =?UTF-8?q?=20formatter=20manager=20services=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Config/Resources/config.xml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/config.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 81ffc3333..9a287e0cd 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -135,6 +135,18 @@ + + + + + %kernel.environment% + + + + + + + From 5f298aac75ec2a02bc32051f093cb79f8e8bd496 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Wed, 2 Jul 2014 14:14:32 +0200 Subject: [PATCH 003/158] =?UTF-8?q?Add=20compiler=20pass=20for=20archive?= =?UTF-8?q?=20builders=20and=20formatters=20managers=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Core/Bundle/TheliaBundl?= =?UTF-8?q?e.php=20=09nouveau=20fichier:=20core/lib/Thelia/Core/Dependency?= =?UTF-8?q?Injection/Compiler/RegisterArchiveBuilderPass.php=20=09nouveau?= =?UTF-8?q?=20fichier:=20core/lib/Thelia/Core/DependencyInjection/Compiler?= =?UTF-8?q?/RegisterFormatterPass.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Core/Bundle/TheliaBundle.php | 4 ++ .../Compiler/RegisterArchiveBuilderPass.php | 54 +++++++++++++++++++ .../Compiler/RegisterFormatterPass.php | 54 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterArchiveBuilderPass.php create mode 100644 core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterFormatterPass.php diff --git a/core/lib/Thelia/Core/Bundle/TheliaBundle.php b/core/lib/Thelia/Core/Bundle/TheliaBundle.php index bb476c402..69065eccc 100644 --- a/core/lib/Thelia/Core/Bundle/TheliaBundle.php +++ b/core/lib/Thelia/Core/Bundle/TheliaBundle.php @@ -17,7 +17,9 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Scope; +use Thelia\Core\DependencyInjection\Compiler\RegisterArchiveBuilderPass; use Thelia\Core\DependencyInjection\Compiler\RegisterCouponPass; +use Thelia\Core\DependencyInjection\Compiler\RegisterFormatterPass; use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass; use Thelia\Core\DependencyInjection\Compiler\RegisterParserPluginPass; use Thelia\Core\DependencyInjection\Compiler\RegisterRouterPass; @@ -57,6 +59,8 @@ class TheliaBundle extends Bundle ->addCompilerPass(new RegisterRouterPass()) ->addCompilerPass(new RegisterCouponPass()) ->addCompilerPass(new RegisterCouponConditionPass()) + ->addCompilerPass(new RegisterArchiveBuilderPass()) + ->addCompilerPass(new RegisterFormatterPass()) ; } } diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterArchiveBuilderPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterArchiveBuilderPass.php new file mode 100644 index 000000000..590e307d7 --- /dev/null +++ b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterArchiveBuilderPass.php @@ -0,0 +1,54 @@ + + */ +class RegisterArchiveBuilderPass implements CompilerPassInterface +{ + const MANAGER_DEFINITION = "thelia.manager.archive_builder_manager"; + + const SERVICE_TAG = "thelia.manager.archive_builder"; + + /** + * You can modify the container here before it is dumped to PHP code. + * + * @param ContainerBuilder $container Container + * + * @api + */ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition(static::MANAGER_DEFINITION)) { + return; + } + + $manager = $container->getDefinition(static::MANAGER_DEFINITION); + $services = $container->findTaggedServiceIds(static::SERVICE_TAG); + + foreach ($services as $id => $condition) { + $manager->addMethodCall( + 'add', + array( + new Reference($id) + ) + ); + } + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterFormatterPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterFormatterPass.php new file mode 100644 index 000000000..c10fb8dde --- /dev/null +++ b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterFormatterPass.php @@ -0,0 +1,54 @@ + + */ +class RegisterFormatterPass implements CompilerPassInterface +{ + const MANAGER_DEFINITION = "thelia.manager.formatter_manager"; + + const SERVICE_TAG = "thelia.manager.formatter"; + + /** + * You can modify the container here before it is dumped to PHP code. + * + * @param ContainerBuilder $container Container + * + * @api + */ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition(static::MANAGER_DEFINITION)) { + return; + } + + $manager = $container->getDefinition(static::MANAGER_DEFINITION); + $services = $container->findTaggedServiceIds(static::SERVICE_TAG); + + foreach ($services as $id => $condition) { + $manager->addMethodCall( + 'add', + array( + new Reference($id) + ) + ); + } + } +} \ No newline at end of file From ce3089e106183c7a754691786055ef1a14a9533d Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Wed, 2 Jul 2014 14:18:40 +0200 Subject: [PATCH 004/158] Add exceptions nouveau fichier: core/lib/Thelia/Exception/FileNotFoundException.php nouveau fichier: core/lib/Thelia/Exception/FileNotReadableException.php nouveau fichier: core/lib/Thelia/Exception/HttpUrlException.php --- .../Exception/FileNotFoundException.php | 23 +++++++++++++++++++ .../Exception/FileNotReadableException.php | 23 +++++++++++++++++++ .../lib/Thelia/Exception/HttpUrlException.php | 23 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 core/lib/Thelia/Exception/FileNotFoundException.php create mode 100644 core/lib/Thelia/Exception/FileNotReadableException.php create mode 100644 core/lib/Thelia/Exception/HttpUrlException.php diff --git a/core/lib/Thelia/Exception/FileNotFoundException.php b/core/lib/Thelia/Exception/FileNotFoundException.php new file mode 100644 index 000000000..ceb27f5de --- /dev/null +++ b/core/lib/Thelia/Exception/FileNotFoundException.php @@ -0,0 +1,23 @@ + + */ +class FileNotFoundException extends \Exception +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Exception/FileNotReadableException.php b/core/lib/Thelia/Exception/FileNotReadableException.php new file mode 100644 index 000000000..e88aa6441 --- /dev/null +++ b/core/lib/Thelia/Exception/FileNotReadableException.php @@ -0,0 +1,23 @@ + + */ +class FileNotReadableException extends \Exception +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Exception/HttpUrlException.php b/core/lib/Thelia/Exception/HttpUrlException.php new file mode 100644 index 000000000..18088a474 --- /dev/null +++ b/core/lib/Thelia/Exception/HttpUrlException.php @@ -0,0 +1,23 @@ + + */ +class HttpUrlException extends \Exception +{ + +} \ No newline at end of file From 50fb4b0dd8bb423ac308aac82b2f8a7f17ecb438 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Wed, 2 Jul 2014 15:14:52 +0200 Subject: [PATCH 005/158] =?UTF-8?q?Begin=20tar,=20tar.bz2=20and=20tar.gz?= =?UTF-8?q?=20formatter,=20fix=20zip=20test=20resources=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Config/Resources/con?= =?UTF-8?q?fig.xml=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/T?= =?UTF-8?q?helia/Core/FileFormat/Archive/AbstractArchiveBuilder.php=20=09m?= =?UTF-8?q?odifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/Fil?= =?UTF-8?q?eFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php=20=09modif?= =?UTF-8?q?i=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFo?= =?UTF-8?q?rmat/Archive/ArchiveBuilder/TestResources/bad=5Fformatted.zip?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/T?= =?UTF-8?q?ests/FileFormat/Archive/ArchiveBuilder/TestResources/well=5Ffor?= =?UTF-8?q?matted.zip=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/li?= =?UTF-8?q?b/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuil?= =?UTF-8?q?derTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/config.xml | 18 +++ .../Archive/AbstractArchiveBuilder.php | 73 +++++++++++++ .../ArchiveBuilder/ZipArchiveBuilder.php | 103 +++++------------- .../TestResources/bad_formatted.zip | 2 + .../TestResources/well_formatted.zip | Bin 0 -> 2789 bytes .../ArchiveBuilder/ZipArchiveBuilderTest.php | 2 - 6 files changed, 119 insertions(+), 79 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 9a287e0cd..74392256a 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -142,10 +142,28 @@ %kernel.environment% + + + + + + + + + gz + + + + + + bz2 + + + diff --git a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php index 66613ba45..447bf1265 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php @@ -12,6 +12,8 @@ namespace Thelia\Core\FileFormat\Archive; use Thelia\Core\FileFormat\FormatInterface; +use Thelia\Core\Translation\Translator; +use Thelia\Log\Tlog; use Thelia\Tools\FileDownload\FileDownloaderAwareTrait; /** @@ -22,4 +24,75 @@ use Thelia\Tools\FileDownload\FileDownloaderAwareTrait; abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilderInterface { use FileDownloaderAwareTrait; + + const TEMP_DIRECTORY_NAME = "archive_builder"; + + /** @var \Thelia\Core\Translation\Translator */ + protected $translator; + + /** @var \Thelia\Log\Tlog */ + protected $logger; + + /** @var string */ + protected $cacheDir; + + public function __construct() + { + $this->translator = Translator::getInstance(); + + $this->logger = Tlog::getNewInstance(); + } + + public function getArchiveBuilderCacheDirectory($environment) + { + $theliaCacheDir = THELIA_CACHE_DIR . $environment . DS; + + if (!is_writable($theliaCacheDir)) { + throw new \ErrorException( + $this->translator->trans( + "The cache directory \"%env\" is not writable", + [ + "%env" => $environment + ] + ) + ); + } + + $archiveBuilderCacheDir = $this->cache_dir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; + + if (!is_dir($archiveBuilderCacheDir) && !mkdir($archiveBuilderCacheDir, 0755)) { + throw new \ErrorException( + $this->translator->trans( + "Error while creating the directory \"%directory\"", + [ + "%directory" => static::TEMP_DIRECTORY_NAME + ] + ) + ); + } + + return $archiveBuilderCacheDir; + } + + + public function getCacheDir() + { + return $this->cacheDir; + } + + /** + * @return Tlog + */ + public function getLogger() + { + return $this->logger; + } + + /** + * @return Translator + */ + public function getTranslator() + { + return $this->translator; + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index f38b1c3fe..41611330a 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -33,8 +33,6 @@ use Thelia\Tools\FileDownload\FileDownloaderInterface; */ class ZipArchiveBuilder extends AbstractArchiveBuilder { - const TEMP_DIRECTORY_NAME = "archive_builder"; - /** * @var \ZipArchive */ @@ -43,30 +41,18 @@ 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() { + parent::__construct(); + $this->zip = new \ZipArchive(); - - $this->logger = Tlog::getNewInstance(); - - $this->translator = Translator::getInstance(); } /** @@ -78,8 +64,8 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if ($this->zip instanceof \ZipArchive) { @$this->zip->close(); - if (file_exists($this->zip_cache_file)) { - unlink($this->zip_cache_file); + if (file_exists($this->zipCacheFile)) { + unlink($this->zipCacheFile); } } } @@ -106,7 +92,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $directoryInArchive = ""; } - if(!empty($directoryInArchive) && $directoryInArchive != "/") { + if(!empty($directoryInArchive)) { $directoryInArchive = $this->getDirectoryPath($directoryInArchive); if (!$this->zip->addEmptyDir($directoryInArchive)) { @@ -121,8 +107,12 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } } + /** + * Download the file if it is online + * If it's local check if the file exists and if it is redable + */ if ($isOnline) { - $fileDownloadCache = $this->cache_dir . DS . "download"; + $fileDownloadCache = $this->cacheDir . DS . "download"; $this->getFileDownloader() ->download($filePath, $fileDownloadCache) @@ -149,6 +139,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)) { @@ -212,22 +206,22 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $this->commit(); - if (!file_exists($this->zip_cache_file)) { - $this->throwFileNotFound($this->zip_cache_file); + if (!file_exists($this->zipCacheFile)) { + $this->throwFileNotFound($this->zipCacheFile); } - if (!is_readable($this->zip_cache_file)) { + if (!is_readable($this->zipCacheFile)) { throw new FileNotReadableException( $this->translator->trans( "The cache file %file is not readable", [ - "%file" => $this->zip_cache_file + "%file" => $this->zipCacheFile ] ) ); } - $content = file_get_contents($this->zip_cache_file); + $content = file_get_contents($this->zipCacheFile); $this->zip->close(); @@ -344,36 +338,11 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function setEnvironment($environment) { - $theliaCacheDir = THELIA_CACHE_DIR . $environment . DS; - - if (!is_writable($theliaCacheDir)) { - throw new \ErrorException( - $this->translator->trans( - "The cache directory \"%env\" is not writable", - [ - "%env" => $environment - ] - ) - ); - } - - $archiveBuilderCacheDir = $this->cache_dir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; - - if (!is_dir($archiveBuilderCacheDir) && !mkdir($archiveBuilderCacheDir, 0755)) { - throw new \ErrorException( - $this->translator->trans( - "Error while creating the directory \"%directory\"", - [ - "%directory" => static::TEMP_DIRECTORY_NAME - ] - ) - ); - } $cacheFileName = md5 (uniqid()); - $cacheFile = $archiveBuilderCacheDir . DS . $cacheFileName; - $cacheFile .= "." . $this->getExtension(); + $cacheFile = $this->getArchiveBuilderCacheDirectory($environment) . DS; + $cacheFile .= $cacheFileName . "." . $this->getExtension(); if (file_exists($cacheFile)) { unlink($cacheFile); @@ -387,12 +356,12 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if($opening !== true) { throw new \ErrorException( $this->translator->trans( - "Unknown" + "An unknown error append" ) ); } - $this->zip_cache_file = $cacheFile; + $this->zipCacheFile = $cacheFile; return $this; } @@ -572,22 +541,6 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder return "application/zip"; } - /** - * @return Tlog - */ - public function getLogger() - { - return $this->logger; - } - - /** - * @return Translator - */ - public function getTranslator() - { - return $this->translator; - } - /** * @return \ZipArchive */ @@ -598,11 +551,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder public function getZipCacheFile() { - return $this->zip_cache_file; + return $this->zipCacheFile; } - public function getCacheDir() - { - return $this->cache_dir; - } } \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.zip b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.zip index e69de29bb..3bd1f0e29 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.zip +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.zip @@ -0,0 +1,2 @@ +foo +bar diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/well_formatted.zip b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/well_formatted.zip index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b19e372b9636f905a1ccfdf3f7a37735e61e21ee 100644 GIT binary patch literal 2789 zcmVqAA7dZ+50OK7101E&d08B|kMNU&iE_8TwRa6N8 z1BJ`8Q;o~BQ+0R?009K)0{{R7=>q@&y;*H<+_(|`u3tg;%h|x*=CxP!P!w=|PMX4( zGvZ5&e&kBrT{e=qB_(gRzrN4RkP@Zcb$mFW27=fUIh@yLo}rXF`g#BHv%0%|c)0zf z-rs(_{d9e&?mz$a?!%43zuS)wx5e=u{`rUT!MawxS*X{4Qh)DTqh7y!`NyJAH*RcOqMz4k`EbA4Os4!alXLt8G@pSNAN`|-t#byzQ*-@N!sp>7|I zKR5`rLG6rhY}c7ebxxI#u5??e%7)I{Ro@wfwJXSL=%qEGP;RZdEq2znG;J`da%JC` zwp%EySLIf>8{2M_?MQsOj(j0FPG|iT>6t)+g7yTx7R`S0qeKM8;eL>u*c%T7s{J8^dyg;)K`2_ zoc6_nt)`_HY}@_ax8$7>#EM@0iZyq3<+VTLay0x3SukPm{1>&MKicG_(Ue8uaEQk< z-9j&Q4Tsv2(@!}MDL1ZJS=#td5~G8v$Ws$fUbpHZ+jl`}quYZV48fgh^cTYpC8KbP zMZo-8mqzWpd$g6QiWt3UiKOCwYs+m)Le_I{A!DT}GEgwvuq-5k$XkuHSe3O7oKNrr z|2n8WIfsN-1{qXgVdE-OU`roZ%qcZz+r@l!F>#XEFV293&ChVw6q40z2eTfQKpU95JXjB@c7N_>`mLugB%6u*Bz7l5~RFJhL z#ey~fGX`upwv4iCK?o8M9ZGhKs0CL?`~;pBlWfU+EoI1=l`@GOk)V6@!_<~MS~pPg zTb^*Mf19#nd+5LySe%(S_++9Oz%ug)nt?7z*S@p0?GBVw8?S+$tud67B*Pm?HQIFS zrnPqsYcn~9N^EpK?Rq!>B%7F2=oKfO&YpR-RJUJCvtvI1ZXRIdF>K%8@#25E9{EQV z&_0^O9GcMX06;+m1V|uT-ws_W0u^VtgT^aE+ODWeQdNbg4t~9a>U1V;`Po%=ZN~@; z(0^E~1F1(ZMKyHLX>oC;P*iB8m!;8(0q+VRgajr>-*w-X2}LP_^mJvUV_5-&Dclx} zl)y;N8#M^M%mJE!6%Ly#7&d=3nm;7fLIAoY>J@!=hHkhu$;dsYw3xc84dnuRkAlEi_-3ho5uhMUA>J3+ z5+^PU@D>Mf8K=(mH={|rceXZR0IM8r$OEz8=3b^O$k-VE&ZHL_jECi}Z7nflju~Ay z?M$<>4n3NWC{VBh(S1zx+**pK+&Z{pmPJSlk)7#P6@y}t0Mr&dS7>gF{P!@ZCe3tX zun>{wG6U`H%MJ-w)EXyt!ZCGOf|5B}MF5PpRzvmDyFe+4W^9HulMR5uUCm_mvNN1| zYqK}pw+$7Ss!hA;wkR*EfC{yZGEFX8J0i>o-B3vH?IV+j2HTPNFb7_cWHK6V%d0Vu zAqODVK}K1ano_IlBA1j^!xDN(X-< zag-ogX_{ckZV1c(e`PyK=QZ4NJLTlj_R%1^$6?`dma-c>X$%+ zea67Z{rC+?d?tQL$V`JoHHMk{dq$Yfl9}09%){#RmQ7r3uGGDd3ecy}p~FiWeP}6d zvysQOP%a|!-t~1gUM(=X5i9&pZ@o~BNK^#Y?I>$HwhW0<#9Koqi{u|ZO`rkT)RA-9 z)FXLPo2?}GR<@oZC(je<3m$S=jxG!T*Jr$ zehWbGz>;IcX>horl>I|Sj)swYLXgnzV0FTYIPzE%@s)0i<2_S;$x)<|qB{}R)g}O^ zi>-PTm>85qT;|O9t~hlV5v$DMky^(WGs;j*I!rzy=y(&BA>awdSENZHR_Zq?_LPzw z9dUw{1WXQ@`$*38QgH#r20m{{QctkGlXggF9Y$G_GF~^H zx*1(W_&_d6`S0mYo8V<_rT4P~llN#vW_21OC;npPe^{zd=Fx`iLgm??1BQ9^+@}x8 ze%ceZ#JTyHczxEIeS)M=Jo^KLT!EnxG8p6krFx)jgtT<+5u}mPEe%FZx@<+!gq`)a zO9-C&W85JP1-cf1N>D@EP#Me+HD3Z%6_y897!gJzqdZ`2D2_CEkg`S!cxJ1J!023UIbx*e`L&ZJ+lOI@aU2}3A7BQf7#&HaI%jnCec$m*gJL8O33}0*h2T)4^0v-bt00008 z0LNJ3L>qAA7dZ+50OK7101E&Z00000009610JMPs0000?Nkc_WQ$;Rxcyv`%1potu r%d=B;cnbgl1nC0+00ij+002-+1qJ{B000310RT||004dp00000&&4#E literal 0 HcmV?d00001 diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index 68c5fbfad..aae3402fc 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -48,8 +48,6 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase /** * This method formats a path to be compatible with \ZipArchive - * - * */ public function testGetFilePath() { From e72d3bfb60b95372b0e07d5b66cc51b5c0011a3d Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 3 Jul 2014 13:10:53 +0200 Subject: [PATCH 006/158] =?UTF-8?q?Finish=20implementing=20and=20testing?= =?UTF-8?q?=20zip=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Th?= =?UTF-8?q?elia/Core/FileFormat/Archive/AbstractArchiveBuilder.php=20=09no?= =?UTF-8?q?uveau=20fichier:=20core/lib/Thelia/Core/FileFormat/Archive/Arch?= =?UTF-8?q?iveBuilder/Exception/TarArchiveException.php=20=09renomm=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Arch?= =?UTF-8?q?ive/ArchiveBuilder/ZipArchiveException.php=20->=20core/lib/Thel?= =?UTF-8?q?ia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveE?= =?UTF-8?q?xception.php=20=09nouveau=20fichier:=20core/lib/Thelia/Core/Fil?= =?UTF-8?q?eFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php=20=09modif?= =?UTF-8?q?i=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFor?= =?UTF-8?q?mat/Archive/ArchiveBuilder/ZipArchiveBuilder.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Archive/ArchiveBuilderInterface.php=20=09nouveau=20fichier:?= =?UTF-8?q?=20core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarA?= =?UTF-8?q?rchiveBuilderTest.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/Z?= =?UTF-8?q?ipArchiveBuilderTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/AbstractArchiveBuilder.php | 103 +++- .../Exception/TarArchiveException.php | 23 + .../{ => Exception}/ZipArchiveException.php | 2 +- .../ArchiveBuilder/TarArchiveBuilder.php | 479 ++++++++++++++++++ .../ArchiveBuilder/ZipArchiveBuilder.php | 300 ++++++----- .../Archive/ArchiveBuilderInterface.php | 36 +- .../ArchiveBuilder/TarArchiveBuilderTest.php | 86 ++++ .../ArchiveBuilder/ZipArchiveBuilderTest.php | 89 +++- 8 files changed, 964 insertions(+), 154 deletions(-) create mode 100644 core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php rename core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/{ => Exception}/ZipArchiveException.php (94%) create mode 100644 core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php create mode 100644 core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php diff --git a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php index 447bf1265..b444860b6 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php @@ -13,6 +13,8 @@ namespace Thelia\Core\FileFormat\Archive; use Thelia\Core\FileFormat\FormatInterface; use Thelia\Core\Translation\Translator; +use Thelia\Exception\FileNotFoundException; +use Thelia\Exception\FileNotReadableException; use Thelia\Log\Tlog; use Thelia\Tools\FileDownload\FileDownloaderAwareTrait; @@ -27,6 +29,9 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder const TEMP_DIRECTORY_NAME = "archive_builder"; + /** @var string */ + protected $cacheFile; + /** @var \Thelia\Core\Translation\Translator */ protected $translator; @@ -58,7 +63,7 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder ); } - $archiveBuilderCacheDir = $this->cache_dir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; + $archiveBuilderCacheDir = $this->cacheDir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; if (!is_dir($archiveBuilderCacheDir) && !mkdir($archiveBuilderCacheDir, 0755)) { throw new \ErrorException( @@ -74,6 +79,97 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder return $archiveBuilderCacheDir; } + /** + * @param $pathToFile + * @param $destination + * @param $isOnline + * @return $this + * @throws \ErrorException + */ + public function copyFile($pathToFile, $destination, $isOnline) + { + if ($isOnline) { + /** + * It's an online file + */ + $this->getFileDownloader() + ->download($pathToFile, $destination) + ; + } else { + /** + * It's a local file + */ + if (!is_file($pathToFile)) { + $this->throwFileNotFound($pathToFile); + } elseif (!is_readable($pathToFile)) { + throw new FileNotReadableException( + $this->translator + ->trans( + "The file %file is not readable", + [ + "%file" => $pathToFile, + ] + ) + ); + } + + if (!copy($pathToFile, $destination)) { + $translatedErrorMessage = $this->translator->trans( + "An error happend while copying %prev to %dest", + [ + "%prev" => $pathToFile, + "%dest" => $destination, + ] + ); + + $this->logger + ->error($translatedErrorMessage) + ; + + throw new \ErrorException($translatedErrorMessage); + } + } + + return $this; + } + + /** + * @return string + */ + public function generateCacheFile($environment) + { + $cacheFileName = md5(uniqid()); + + $cacheFile = $this->getArchiveBuilderCacheDirectory($environment) . DS; + $cacheFile .= $cacheFileName . "." . $this->getExtension(); + + return $cacheFile; + } + + public function throwFileNotFound($file) + { + + throw new FileNotFoundException( + $this->translator + ->trans( + "The file %file is missing or is not readable", + [ + "%file" => $file, + ] + ) + ); + } + + /** + * @param $path + * @return $this + */ + public function setCacheFile($path) + { + $this->cacheFile = $path; + + return $this; + } public function getCacheDir() { @@ -95,4 +191,9 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder { return $this->translator; } + + public function getCacheFile() + { + return $this->cacheFile; + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php new file mode 100644 index 000000000..9945a65be --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php @@ -0,0 +1,23 @@ + + */ +class TarArchiveException extends \Exception +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php similarity index 94% rename from core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php rename to core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php index c85fce339..24f9ddb37 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php @@ -10,7 +10,7 @@ /* file that was distributed with this source code. */ /*************************************************************************************/ -namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; +namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception; /** * Class ZipArchiveException diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php new file mode 100644 index 000000000..c5b019f46 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -0,0 +1,479 @@ + + */ +class TarArchiveBuilder extends AbstractArchiveBuilder +{ + const PHAR_FORMAT = \Phar::TAR; + + /** @var string */ + protected $environment; + + /** @var null|string */ + protected $compression; + + /** @var string */ + protected $tarCacheFile; + + /** @var \PharData */ + protected $tar; + + /** @var \Thelia\Core\Translation\Translator */ + protected $translator; + + /** @var \Thelia\Log\Tlog */ + protected $logger; + + function __construct($compressionType = null) + { + $this->translator = Translator::getInstance(); + $this->logger = Tlog::getNewInstance(); + + $supportedCompression = [ + "gz", + "bz2", + null + ]; + + if (!in_array($compressionType, $supportedCompression)) { + throw new TarArchiveException( + $this->translator->trans( + "The compression %type is not supported" + ) + ); + } + + $this->compression = $compressionType; + } + + /** + public function __destruct() + { + if ($this->tar instanceof \PharData) { + if (file_exists($this->cacheFile)) { + unlink($this->cacheFile); + } + } + }*/ + + /** + * @param string $filePath It is the path to access the file. + * @param string $directoryInArchive This is the directory where it will be stored in the archive + * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name + * @param bool $isOnline + * @return $this + * @throws \Thelia\Exception\FileNotFoundException + * @throws \Thelia\Exception\FileNotReadableException + * @throws \ErrorException + * + * This methods adds a file in the archive. + * If the file is local, $isOnline must be false, + * If the file online, $filePath must be an URL. + */ + public function addFile($filePath, $directoryInArchive = "/", $name = null, $isOnline = false) + { + if (empty($name) || !is_scalar($name)) { + $name = basename($filePath); + } + + /** + * Download the file if it is online + * If it's local check if the file exists and if it is redable + */ + $fileDownloadCache = $this->cacheDir . DS . "download.tmp"; + $this->copyFile($filePath, $fileDownloadCache, $isOnline); + + /** + * Then write the file in the archive + */ + $directoryInArchive = $this->formatDirectoryPath($directoryInArchive); + + if (!empty($directoryInArchive)) { + $name = $this->formatFilePath( + $directoryInArchive . $name + ); + } + + $this->tar->addFile($filePath, $name); + + return $this; + } + + /** + * @param $content + * @param $name + * @param string $directoryInArchive + * @return mixed + * @throws \ErrorException + * + * This method creates a file in the archive with its content + */ + public function addFileFromString($content, $name, $directoryInArchive = "/") + { + if (empty($name) || !is_scalar($name)) { + throw new \ErrorException( + $this->translator->trans( + "The file name must be valid" + ) + ); + } + + $directoryInArchive = $this->formatDirectoryPath($directoryInArchive); + + if (!empty($directoryInArchive)) { + $name = $this->formatFilePath( + $directoryInArchive . $name + ); + } + try { + $this->tar->addFromString($name, $content); + } catch(\Exception $e) { + throw new \ErrorException( + $this->translator->trans( + "Error while writing the file into the archive, error message: %errmes", + [ + "%errmes" => $e->getMessage() + ] + ) + ); + } + } + + + /** + * @param $directoryPath + * @return $this + * @throws \ErrorException + * + * This method creates an empty directory + */ + public function addDirectory($directoryPath) + { + $directoryInArchive = $this->formatDirectoryPath($directoryPath); + + if (!empty($directoryInArchive)) { + + try { + $this->tar->addEmptyDir($directoryInArchive); + } catch(\Exception $e) { + throw new \ErrorException( + $this->translator->trans( + "The directory %dir has not been created in the archive", + [ + "%dir" => $directoryInArchive + ] + ) + ); + } + } + + return $this; + } + + /** + * @param string $pathToFile + * @return null|string + * @throws \Thelia\Exception\FileNotFoundException + * @throws \Thelia\Exception\FileNotReadableException + * @throws \ErrorException + * + * This method returns a file content + */ + public function getFileContent($pathToFile) + { + + } + + + /** + * @param $pathInArchive + * @return $this + * @throws \Thelia\Exception\FileNotFoundException + * @throws \ErrorException + * + * This method deletes a file in the archive + */ + public function deleteFile($pathInArchive) + { + if (!$this->hasFile($pathInArchive)) { + $this->throwFileNotFound($pathInArchive); + } + + if (false === $this->tar->delete($pathInArchive)) { + throw new \ErrorException( + $this->translator->trans( + "Unknown error while deleting the file %file", + [ + "%file" => $pathInArchive + ] + ) + ); + } + } + + /** + * @return \Thelia\Core\HttpFoundation\Response + * + * This method return an instance of a Response with the archive as content. + */ + public function buildArchiveResponse() + { + + } + + /** + * @param string $pathToArchive + * @param string $environment + * @param bool $isOnline + * @param FileDownloaderInterface $fileDownloader + * @return $this + * @throws \Thelia\Exception\FileNotFoundException + * @throws \Thelia\Exception\HttpUrlException + * @throws TarArchiveException + * + * Loads an archive + */ + public static function loadArchive( + $pathToArchive, + $environment, + $isOnline = false, + FileDownloaderInterface $fileDownloader = null + ) { + /** @var TarArchiveBuilder $instance */ + $instance = new static(); + + if ($fileDownloader !== null) { + $instance->setFileDownloader($fileDownloader); + } + + $instance->setCacheFile($instance->getCacheFile()) + ->copyFile($pathToArchive, $isOnline); + + /** + * This throws TarArchiveBuilderException if + * the archive is not valid. + */ + $instance->setEnvironment($environment); + + return $instance; + } + + /** + * @param $pathToFile + * @return bool + * + * Checks if the archive has a file. + * In \PharData, if you call it as a array, + * the keys are the files in the archive. + */ + public function hasFile($pathToFile) + { + $isFile = false; + + $pathToFile = $this->formatFilePath($pathToFile); + try { + /** @var \PharFileInfo $fileInfo */ + $fileInfo = $this->tar[$pathToFile]; + + if($fileInfo->isFile()) { + $isFile = true; + } + /** + * Catch the exception to avoid its displaying. + */ + } catch(\BadMethodCallException $e) {} + + return $isFile; + } + + /** + * @param string $directory + * @return bool + * + * Check if the archive has a directory + */ + public function hasDirectory($directory) + { + $isDir = false; + + $pathToDir = $this->formatDirectoryPath($directory); + try { + /** @var \PharFileInfo $fileInfo */ + $fileInfo = $this->tar[$pathToDir]; + + if($fileInfo->isDir()) { + $isDir = true; + } + /** + * Catch the exception to avoid its displaying. + */ + } catch(\BadMethodCallException $e) {} + + return $isDir; + } + + /** + * @param string $environment + * @return $this + * + * Sets the execution environment of the Kernel, + * used to know which cache is used. + */ + public function setEnvironment($environment) + { + if ($this->cacheFile === null) { + $cacheFile = $this->generateCacheFile($environment); + + if (file_exists($cacheFile)) { + unlink($cacheFile); + } + } else { + $cacheFile = $this->cacheFile; + } + + $errorMessage = null; + + try { + $this->tar = new \PharData($cacheFile, null, null, static::PHAR_FORMAT); + + switch ($this->compression) { + case "gz": + $this->tar = $this->tar->compress(\Phar::GZ); + $cacheFile .= ".gz"; + break; + case "bz2": + $this->tar = $this->tar->compress(\Phar::BZ2); + $cacheFile .= ".bz2"; + break; + } + + } catch(\BadMethodCallException $e) { + /** + * This should not happen + */ + $errorMessage = "You have badly called the method setEnvironment twice for %file"; + } catch(\UnexpectedValueException $e) { + $errorMessage = "The file %file is corrupted"; + } + + if ($errorMessage !== null) { + throw new TarArchiveException( + $this->translator->trans( + $errorMessage, + [ + "%file" => $cacheFile + ] + ) + ); + } + + $this->cacheFile = $cacheFile; + + return $this; + } + + /** + * @param string $initialString + * @return string + * + * Gives a valid file path for \ZipArchive + */ + public function formatFilePath($initialString) + { + /** + * Remove the / at the beginning and the end. + */ + $initialString = trim($initialString, "/"); + + /** + * Remove the double, triple, ... slashes + */ + $initialString = preg_replace("#\/{2,}#", "/", $initialString); + + return $initialString; + } + + /** + * @param string $initialString + * @return string + * + * Gives a valid directory path for \ZipArchive + */ + public function formatDirectoryPath($initialString) + { + $initialString = $this->formatFilePath($initialString); + + return $initialString . "/"; + } + + /** + * @return string + * + * This method must return a string, the name of the format. + * + * example: + * return "XML"; + */ + public function getName() + { + $name = "tar"; + + if ($this->compression !== null) { + $name .= "." . $this->compression; + } + + return $name; + } + + /** + * @return string + * + * This method must return a string, the extension of the file format, without the ".". + * The string should be lowercase. + * + * example: + * return "xml"; + */ + public function getExtension() + { + return $this->getName(); + } + + /** + * @return string + * + * This method must return a string, the mime type of the file format. + * + * example: + * return "application/json"; + */ + public function getMimeType() + { + return $this->compression === null ? + "application/x-tar" : + "application/x-gtar" + ; + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index 41611330a..fd750bc0c 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -12,12 +12,10 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder; +use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException; use Thelia\Core\HttpFoundation\Response; use Thelia\Core\Thelia; -use Thelia\Core\Translation\Translator; -use Thelia\Exception\FileNotFoundException; use Thelia\Exception\FileNotReadableException; -use Thelia\Log\Tlog; use Thelia\Tools\FileDownload\FileDownloaderInterface; /** @@ -38,16 +36,6 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ protected $zip; - /** - * @var string This is the absolute path to the zip file in cache - */ - protected $zipCacheFile; - - /** - * @var string This is the path of the cache - */ - protected $cacheDir; - public function __construct() { parent::__construct(); @@ -64,8 +52,8 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if ($this->zip instanceof \ZipArchive) { @$this->zip->close(); - if (file_exists($this->zipCacheFile)) { - unlink($this->zipCacheFile); + if (file_exists($this->cacheFile)) { + unlink($this->cacheFile); } } } @@ -78,6 +66,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException + * @throws \ErrorException * * This methods adds a file in the archive. * If the file is local, $isOnline must be false, @@ -85,71 +74,37 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function addFile($filePath, $directoryInArchive = null, $name = null, $isOnline = false) { + $directoryInArchive = $this->formatDirectoryPath($directoryInArchive); + /** * Add empty directory if it doesn't exist */ - if (empty($directoryInArchive) || preg_match("#^\/+$#", $directoryInArchive)) { - $directoryInArchive = ""; - } if(!empty($directoryInArchive)) { - $directoryInArchive = $this->getDirectoryPath($directoryInArchive); + $this->addDirectory($directoryInArchive); + } - if (!$this->zip->addEmptyDir($directoryInArchive)) { - throw new \ErrorException( - $this->translator->trans( - "The directory %dir has not been created in the archive", - [ - "%dir" => $directoryInArchive - ] - ) - ); - } + if (empty($name) || !is_scalar($name)) { + $name = basename($filePath); } /** * Download the file if it is online * If it's local check if the file exists and if it is redable */ - if ($isOnline) { - $fileDownloadCache = $this->cacheDir . DS . "download"; - - $this->getFileDownloader() - ->download($filePath, $fileDownloadCache) - ; - - $filePath = $fileDownloadCache; - } else { - if (!file_exists($filePath)) { - $this->throwFileNotFound($filePath); - } else if (!is_readable($filePath)) { - throw new FileNotReadableException( - $this->translator - ->trans( - "The file %file is not readable", - [ - "%file" => $filePath, - ] - ) - ); - } - } - - if (empty($name)) { - $name = basename($filePath); - } + $fileDownloadCache = $this->cacheDir . DS . "download.tmp"; + $this->copyFile($filePath, $fileDownloadCache, $isOnline); /** * Then write the file in the archive and commit the changes */ - $destination = $directoryInArchive . $name; - if (!$this->zip->addFile($filePath,$destination)) { + if (!$this->zip->addFile($fileDownloadCache, $destination)) { $translatedErrorMessage = $this->translator->trans( "An error occurred while adding this file to the archive: %file", [ - "%file" => $filePath + "%file" => $fileDownloadCache ] ); @@ -163,6 +118,146 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder return $this; } + /** + * @param $content + * @param $name + * @param string $directoryInArchive + * @return mixed + * @throws \ErrorException + * + * This method creates a file in the archive with its content + */ + public function addFileFromString($content, $name, $directoryInArchive = "/") + { + $directoryInArchive = $this->formatDirectoryPath($directoryInArchive); + + if (!empty($directoryInArchive) && $directoryInArchive !== "/") { + $this->addDirectory($directoryInArchive); + } + + if (empty($name) || !is_scalar($name)) { + throw new \ErrorException( + $this->translator->trans( + "The filename is not correct" + ) + ); + } + + $filePath = $this->getFilePath($directoryInArchive . DS . $name); + + if (!$this->zip->addFromString($filePath, $content)) { + throw new \ErrorException( + $this->translator->trans( + "Unable to write the file %file into the archive", + [ + "%file" => $filePath, + ] + ) + ); + } + + $this->commit(); + } + + + /** + * @param $directoryPath + * @return $this + * @throws \ErrorException + * + * This method creates an empty directory + */ + public function addDirectory($directoryPath) + { + $directoryInArchive = $this->formatDirectoryPath($directoryPath); + + if (!empty($directoryInArchive)) { + if (!$this->zip->addEmptyDir($directoryInArchive)) { + throw new \ErrorException( + $this->translator->trans( + "The directory %dir has not been created in the archive", + [ + "%dir" => $directoryInArchive + ] + ) + ); + } + } + + return $this; + } + + /** + * @param string $pathToFile + * @return null|string + * @throws \Thelia\Exception\FileNotFoundException + * @throws \Thelia\Exception\FileNotReadableException + * @throws \ErrorException + * + * This method returns a file content + */ + public function getFileContent($pathToFile) + { + $pathToFile = $this->formatFilePath($pathToFile); + + if (!$this->hasFile($pathToFile)) { + $this->throwFileNotFound($pathToFile); + } + + $stream = $this->zip->getStream($pathToFile); + $content = ""; + + while (!feof($stream)) { + $content .= fread($stream, 2); + } + + fclose($stream); + + return $content; + } + + + /** + * @param string $initialString + * @return string + * + * Gives a valid file path for \ZipArchive + */ + public function getFilePath($initialString) + { + /** + * Remove the / at the beginning and the end. + */ + $initialString = trim($initialString, "/"); + + /** + * Remove the double, triple, ... slashes + */ + $initialString = preg_replace("#\/{2,}#", "/", $initialString); + + if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) { + $initialString = "/" . $initialString; + } + return $initialString; + } + + /** + * @param string $initialString + * @return string + * + * Gives a valid directory path for \ZipArchive + */ + public function getDirectoryPath($initialString) + { + $initialString = $this->getFilePath($initialString); + + if ($initialString[0] !== "/") { + $initialString = "/" . $initialString; + } + + return $initialString . "/"; + } + /** * @param $pathInArchive * @return $this @@ -173,7 +268,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function deleteFile($pathInArchive) { - $pathInArchive = $this->getFilePath($pathInArchive); + $pathInArchive = $this->formatFilePath($pathInArchive); if (!$this->hasFile($pathInArchive)) { $this->throwFileNotFound($pathInArchive); @@ -206,22 +301,22 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $this->commit(); - if (!file_exists($this->zipCacheFile)) { - $this->throwFileNotFound($this->zipCacheFile); + if (!file_exists($this->cacheFile)) { + $this->throwFileNotFound($this->cacheFile); } - if (!is_readable($this->zipCacheFile)) { + if (!is_readable($this->cacheFile)) { throw new FileNotReadableException( $this->translator->trans( "The cache file %file is not readable", [ - "%file" => $this->zipCacheFile + "%file" => $this->cacheFile ] ) ); } - $content = file_get_contents($this->zipCacheFile); + $content = file_get_contents($this->cacheFile); $this->zip->close(); @@ -262,39 +357,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $instance->setFileDownloader($fileDownloader); } - if ($isOnline) { - /** - * It's an online file - */ - $instance->getFileDownloader() - ->download($pathToArchive, $instance->getZipCacheFile()) - ; - } else { - /** - * It's a local file - */ - if (!is_file($pathToArchive) || !is_readable($pathToArchive)) { - $instance->throwFileNotFound($pathToArchive); - } + $instance->copyFile($pathToArchive, $instance->getCacheFile(), $isOnline); - if (!copy($pathToArchive, $instance->getZipCacheFile())) { - $translatedErrorMessage = $instance->getTranslator()->trans( - "An unknown error happend while copying %prev to %dest", - [ - "%prev" => $pathToArchive, - "%dest" => $instance->getZipCacheFile(), - ] - ); - - $instance->getLogger() - ->error($translatedErrorMessage) - ; - - throw new \ErrorException($translatedErrorMessage); - } - } - - if (true !== $return = $zip->open($instance->getZipCacheFile())) { + if (true !== $return = $zip->open($instance->getCacheFile())) { throw new ZipArchiveException( $instance->getZipErrorMessage($return) ); @@ -312,7 +377,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder public function hasFile($pathToFile) { return $this->zip - ->locateName($this->getFilePath($pathToFile)) !== false + ->locateName($this->formatFilePath($pathToFile)) !== false ; } @@ -324,7 +389,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function hasDirectory($directory) { - $link = $this->zip->locateName($this->getDirectoryPath($directory)); + $link = $this->zip->locateName($this->formatDirectoryPath($directory)); return $link !== false; } @@ -339,10 +404,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder public function setEnvironment($environment) { - $cacheFileName = md5 (uniqid()); - - $cacheFile = $this->getArchiveBuilderCacheDirectory($environment) . DS; - $cacheFile .= $cacheFileName . "." . $this->getExtension(); + $cacheFile = $this->generateCacheFile($environment); if (file_exists($cacheFile)) { unlink($cacheFile); @@ -361,7 +423,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder ); } - $this->zipCacheFile = $cacheFile; + $this->cacheFile = $cacheFile; return $this; } @@ -433,7 +495,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder public function commit() { $this->zip->close(); - $result = $this->zip->open($this->getZipCacheFile()); + $result = $this->zip->open($this->getCacheFile()); if ($result !== true) { throw new \ErrorException( @@ -452,7 +514,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * * Gives a valid file path for \ZipArchive */ - public function getFilePath($initialString) + public function formatFilePath($initialString) { /** * Remove the / at the beginning and the end. @@ -476,31 +538,17 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * * Gives a valid directory path for \ZipArchive */ - public function getDirectoryPath($initialString) + public function formatDirectoryPath($initialString) { - $initialString = $this->getFilePath($initialString); + $initialString = $this->formatFilePath($initialString); - if ($initialString[0] !== "/") { + if ($initialString !== "" && $initialString[0] !== "/") { $initialString = "/" . $initialString; } return $initialString . "/"; } - public function throwFileNotFound($file) - { - - throw new FileNotFoundException( - $this->getTranslator() - ->trans( - "The file %file is missing or is not readable", - [ - "%file" => $file, - ] - ) - ); - } - /** * @return string * @@ -548,10 +596,4 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder { return $this->zip; } - - public function getZipCacheFile() - { - return $this->zipCacheFile; - } - } \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php index c779722a6..2365ee624 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -11,6 +11,7 @@ /*************************************************************************************/ namespace Thelia\Core\FileFormat\Archive; +use Thelia\Tools\FileDownload\FileDownloaderInterface; /** * Interface ArchiveBuilderInterface @@ -29,6 +30,7 @@ interface ArchiveBuilderInterface * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException + * @throws \ErrorException * * This methods adds a file in the archive. * If the file is local, $isOnline must be false, @@ -36,15 +38,45 @@ interface ArchiveBuilderInterface */ public function addFile($filePath, $directoryInArchive = "/", $name = null, $isOnline = false); + /** + * @param $content + * @param $name + * @param string $directoryInArchive + * @return mixed + * @throws \ErrorException + * + * This method creates a file in the archive with its content + */ + public function addFileFromString($content, $name, $directoryInArchive = "/"); + + /** + * @param string $pathToFile + * @return null|string + * @throws \Thelia\Exception\FileNotFoundException + * @throws \Thelia\Exception\FileNotReadableException + * @throws \ErrorException + * + * This method returns a file content + */ + public function getFileContent($pathToFile); /** * @param $pathInArchive * @return $this * @throws \Thelia\Exception\FileNotFoundException + * @throws \ErrorException * * This method deletes a file in the archive */ public function deleteFile($pathInArchive); + /** + * @param $directoryPath + * @return $this + * @throws \ErrorException + * + * This method creates an empty directory + */ + public function addDirectory($directoryPath); /** * @return \Thelia\Core\HttpFoundation\Response * @@ -54,14 +86,16 @@ interface ArchiveBuilderInterface /** * @param string $pathToArchive + * @param string $environment * @param bool $isOnline + * @param FileDownloaderInterface $fileDownloader * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException * * Loads an archive */ - public static function loadArchive($pathToArchive, $environment, $isOnline = false); + public static function loadArchive($pathToArchive, $environment, $isOnline = false, FileDownloaderInterface $fileDownloader = null); /** * @param $pathToFile diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php new file mode 100644 index 000000000..df48f0629 --- /dev/null +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -0,0 +1,86 @@ + + */ +class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase +{ + /** @var TarArchiveBuilder */ + protected $tar; + + public function setUp() + { + new Translator(new Container()); + + Tlog::getNewInstance(); + + $this->tar = new TarArchiveBuilder(); + } + + public function testAddFileAndDirectory() + { + $this->tar->setEnvironment("dev"); + + /** + * File + */ + $tar = $this->tar->addFile( + __DIR__ . DS . "TestResources/test_file" + ); + + $this->assertTrue($tar->hasFile("test_file")); + + $this->assertFalse($tar->hasDirectory("test_file")); + + $tar = $this->tar->addFile( + __DIR__ . DS . "TestResources/test_file", + null, + "TEST.txt" + ); + + $this->assertTrue($tar->hasFile("TEST.txt")); + + $this->assertFalse($tar->hasDirectory("TEST.txt")); + + /** + * Directory + */ + $this->tar->addDirectory("foo"); + + $this->assertTrue($tar->hasDirectory("foo")); + + $this->assertFalse($tar->hasFile("foo")); + + /**s + * File in a directory + */ + $this->tar->addFile( + __DIR__ . DS . "TestResources/test_file", + "bar", + "baz" + ); + + $this->assertTrue($this->tar->hasFile("bar/baz")); + + $this->assertTrue($this->tar->hasDirectory("bar")); + + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index aae3402fc..0ad6ca76c 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -53,52 +53,52 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase { $this->assertEquals( "foo", - $this->zip->getFilePath("foo") + $this->zip->formatFilePath("foo") ); $this->assertEquals( "foo", - $this->zip->getFilePath("/foo") + $this->zip->formatFilePath("/foo") ); $this->assertEquals( "foo", - $this->zip->getFilePath("foo/") + $this->zip->formatFilePath("foo/") ); $this->assertEquals( "foo", - $this->zip->getFilePath("/foo/") + $this->zip->formatFilePath("/foo/") ); $this->assertEquals( "/foo/bar", - $this->zip->getFilePath("foo/bar") + $this->zip->formatFilePath("foo/bar") ); $this->assertEquals( "/foo/bar", - $this->zip->getFilePath("/foo/bar") + $this->zip->formatFilePath("/foo/bar") ); $this->assertEquals( "/foo/bar", - $this->zip->getFilePath("/foo//bar/") + $this->zip->formatFilePath("/foo//bar/") ); $this->assertEquals( "/foo/bar", - $this->zip->getFilePath("/foo/bar/") + $this->zip->formatFilePath("/foo/bar/") ); $this->assertEquals( "/foo/bar/baz", - $this->zip->getFilePath("foo/bar/baz") + $this->zip->formatFilePath("foo/bar/baz") ); $this->assertEquals( "/foo/bar/baz", - $this->zip->getFilePath("//foo/bar///baz/") + $this->zip->formatFilePath("//foo/bar///baz/") ); } @@ -106,52 +106,52 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase { $this->assertEquals( "/foo/", - $this->zip->getDirectoryPath("foo") + $this->zip->formatDirectoryPath("foo") ); $this->assertEquals( "/foo/", - $this->zip->getDirectoryPath("/foo") + $this->zip->formatDirectoryPath("/foo") ); $this->assertEquals( "/foo/", - $this->zip->getDirectoryPath("foo/") + $this->zip->formatDirectoryPath("foo/") ); $this->assertEquals( "/foo/", - $this->zip->getDirectoryPath("/foo/") + $this->zip->formatDirectoryPath("/foo/") ); $this->assertEquals( "/foo/bar/", - $this->zip->getDirectoryPath("foo/bar") + $this->zip->formatDirectoryPath("foo/bar") ); $this->assertEquals( "/foo/bar/", - $this->zip->getDirectoryPath("/foo/bar") + $this->zip->formatDirectoryPath("/foo/bar") ); $this->assertEquals( "/foo/bar/", - $this->zip->getDirectoryPath("/foo//bar/") + $this->zip->formatDirectoryPath("/foo//bar/") ); $this->assertEquals( "/foo/bar/", - $this->zip->getDirectoryPath("/foo/bar/") + $this->zip->formatDirectoryPath("/foo/bar/") ); $this->assertEquals( "/foo/bar/baz/", - $this->zip->getDirectoryPath("foo/bar/baz") + $this->zip->formatDirectoryPath("foo/bar/baz") ); $this->assertEquals( "/foo/bar/baz/", - $this->zip->getDirectoryPath("//foo/bar///baz/") + $this->zip->formatDirectoryPath("//foo/bar///baz/") ); } @@ -169,7 +169,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException + * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException * @expectedExceptionMessage [Zip Error] The file is not a zip archive */ public function testLoadNotValidZip() @@ -202,7 +202,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException + * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException * @expectedExceptionMessage [Zip Error] The file is not a zip archive */ public function testLoadOnlineAvailableAndNotValidFile() @@ -339,4 +339,49 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase $loadedArchiveResponseContent ); } + + public function testAddValidFileFromString() + { + $this->loadedZip->addFileFromString( + "foo", "bar" + ); + + $this->assertTrue( + $this->loadedZip->hasFile("bar") + ); + + $this->assertEquals( + "foo", + $this->loadedZip->getFileContent("bar") + ); + } + + /** + * @expectedException \Thelia\Exception\FileNotFoundException + */ + public function testGetFileContentFileNotFound() + { + $this->loadedZip->getFileContent("bar"); + } + + /** + * @expectedException \ErrorException + */ + public function testAddNotValidFileFromString() + { + $this->loadedZip->addFileFromString( + "foo", $this + ); + } + + /** + * @expectedException \ErrorException + */ + public function testAddNotValidFileValueFromString() + { + $this->loadedZip->addFileFromString( + $this, "bar" + ); + } + } \ No newline at end of file From 21bf9fd0e231ee18cf4d9faa1b8227846df780f5 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 3 Jul 2014 13:38:40 +0200 Subject: [PATCH 007/158] =?UTF-8?q?Complete=20zip=20tests=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Archive/ArchiveBuilder/TarArchiveBuilder.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Archive/ArchiveBuilderInterface.php=20=09modifi=C3=A9:=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFormat/Archive/A?= =?UTF-8?q?rchiveBuilder/TarArchiveBuilderTest.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFormat/Archiv?= =?UTF-8?q?e/ArchiveBuilder/ZipArchiveBuilderTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/ArchiveBuilder/TarArchiveBuilder.php | 4 ++-- .../FileFormat/Archive/ArchiveBuilderInterface.php | 2 +- .../ArchiveBuilder/TarArchiveBuilderTest.php | 7 +++++++ .../ArchiveBuilder/ZipArchiveBuilderTest.php | 13 +++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index c5b019f46..d34824cfe 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -101,7 +101,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * Download the file if it is online * If it's local check if the file exists and if it is redable */ - $fileDownloadCache = $this->cacheDir . DS . "download.tmp"; + $fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp"; $this->copyFile($filePath, $fileDownloadCache, $isOnline); /** @@ -202,7 +202,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getFileContent($pathToFile) { - + } diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php index 2365ee624..88f5da78f 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -18,7 +18,7 @@ use Thelia\Tools\FileDownload\FileDownloaderInterface; * @package Thelia\Core\FileFormat\Archive * @author Benjamin Perche * - * This interface defines the methods that an archive creator must have. + * This interface defines the methods that an archive builder must have. */ interface ArchiveBuilderInterface { diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index df48f0629..269de3c91 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -83,4 +83,11 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->tar->hasDirectory("bar")); } + + public function testAddValidFileFromString() + { + $this->tar->addFileFromString( + + ) + } } \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index 0ad6ca76c..7fd5aeed8 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -354,6 +354,19 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase "foo", $this->loadedZip->getFileContent("bar") ); + + $this->loadedZip->addFileFromString( + "foo", "bar", "baz" + ); + + $this->assertTrue( + $this->loadedZip->hasFile("baz/bar") + ); + + $this->assertEquals( + "foo", + $this->loadedZip->getFileContent("baz/bar") + ); } /** From 9e66c4759ae01166a8a37ca5cc561ae91c8e46ae Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 3 Jul 2014 13:43:59 +0200 Subject: [PATCH 008/158] =?UTF-8?q?Fix=20FileDownloader=20test=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Archive/ArchiveBuilder/ZipArchiveBuilder.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFor?= =?UTF-8?q?mat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php=20=09modif?= =?UTF-8?q?i=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/Tools/?= =?UTF-8?q?FileDownloaderTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php | 2 +- .../FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php | 2 -- core/lib/Thelia/Tests/Tools/FileDownloaderTest.php | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index fd750bc0c..72ce37c91 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -235,7 +235,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ $initialString = preg_replace("#\/{2,}#", "/", $initialString); - if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) { + if (preg_match("#\/?[^\/]+\/[^\/]+\/?#", $initialString)) { $initialString = "/" . $initialString; } return $initialString; diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index 269de3c91..055ae03c9 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -86,8 +86,6 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testAddValidFileFromString() { - $this->tar->addFileFromString( - ) } } \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php index 3ebc3e459..7bc36523f 100644 --- a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php +++ b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php @@ -14,7 +14,7 @@ namespace Thelia\Tests\Type; use Symfony\Component\DependencyInjection\Container; use Thelia\Core\Translation\Translator; use Thelia\Log\Tlog; -use Thelia\Tools\FileDownloader; +use Thelia\Tools\FileDownload\FileDownloader; /** * Class FileDownloaderTest From 4b78f23fa3f4007643281fda87aeac3dbdc2ef16 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 3 Jul 2014 14:20:31 +0200 Subject: [PATCH 009/158] =?UTF-8?q?Fix=20FileDownloader=20test=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Archive/ArchiveBuilder/TarArchiveBuilder.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFor?= =?UTF-8?q?mat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php=20=09modif?= =?UTF-8?q?i=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tools/FileDo?= =?UTF-8?q?wnload/FileDownloader.php=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/Tools/URL.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchiveBuilder/TarArchiveBuilder.php | 24 ++++++- .../ArchiveBuilder/TarArchiveBuilderTest.php | 65 ++++++++++++++++++- .../Tools/FileDownload/FileDownloader.php | 1 + core/lib/Thelia/Tools/URL.php | 2 +- 4 files changed, 87 insertions(+), 5 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index d34824cfe..b9ccb6a6a 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -14,6 +14,7 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder; use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException; use Thelia\Core\FileFormat\Archive\ArchiveBuilderInterface; +use Thelia\Core\Thelia; use Thelia\Core\Translation\Translator; use Thelia\Log\Tlog; use Thelia\Tools\FileDownload\FileDownloaderInterface; @@ -202,7 +203,24 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getFileContent($pathToFile) { + $pathToFile = $this->formatFilePath($pathToFile); + if (!$this->hasFile($pathToFile)) { + $this->throwFileNotFound($pathToFile); + } + + /** @var \PharFileInfo $fileInfo*/ + $fileInfo = $this->tar[$pathToFile]; + + /** @var \SplFileObject $file */ + $file = $fileInfo->openFile(); + $content = ""; + + while (false !== ($char = $file->fgetc())) { + $content .= $char; + } + + return $content; } @@ -239,6 +257,8 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function buildArchiveResponse() { + $this->tar->setMetadata("comment", "Generated by Thelia v" . Thelia::THELIA_VERSION); + } @@ -267,8 +287,8 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $instance->setFileDownloader($fileDownloader); } - $instance->setCacheFile($instance->getCacheFile()) - ->copyFile($pathToArchive, $isOnline); + $instance->setCacheFile($instance->generateCacheFile($environment)) + ->copyFile($pathToArchive, $instance->getCacheFile(), $isOnline); /** * This throws TarArchiveBuilderException if diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index 055ae03c9..6c3bc61a7 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -33,12 +33,11 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase Tlog::getNewInstance(); $this->tar = new TarArchiveBuilder(); + $this->tar->setEnvironment("dev"); } public function testAddFileAndDirectory() { - $this->tar->setEnvironment("dev"); - /** * File */ @@ -86,6 +85,68 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testAddValidFileFromString() { + $this->tar->addFileFromString( + "foo", "bar" + ); + $this->assertTrue( + $this->tar->hasFile("bar") + ); + + $this->assertEquals( + "foo", + $this->tar->getFileContent("bar") + ); + + $this->tar->addFileFromString( + "foo", "bar", "baz" + ); + + $this->assertTrue( + $this->tar->hasFile("baz/bar") + ); + + $this->assertEquals( + "foo", + $this->tar->getFileContent("baz/bar") + ); + } + + /** + * @expectedException \ErrorException + */ + public function testAddNotValidFileFromString() + { + $this->tar->addFileFromString( + "foo", $this + ); + } + + /** + * @expectedException \ErrorException + */ + public function testAddNotValidFileValueFromString() + { + $this->tar->addFileFromString( + $this, "foo" + ); + } + + + public function testDeleteFile() + { + $this->tar->addFileFromString( + "foo", "bar" + ); + + $this->assertTrue( + $this->tar->hasFile("bar") + ); + + $this->tar->deleteFile("bar"); + + $this->assertFalse( + $this->tar->hasFile("bar") + ); } } \ No newline at end of file diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php index 10eb1ef88..be8b8f53a 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php @@ -17,6 +17,7 @@ use Thelia\Core\Translation\Translator as TheliaTranslator; use Thelia\Exception\FileNotFoundException; use Thelia\Exception\HttpUrlException; use Thelia\Log\Tlog; +use Thelia\Tools\URL; /** * Class FileDownloader diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 569b15780..ab52472e6 100644 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -315,7 +315,7 @@ class URL $clean; } - public function checkUrl($url, array $protocols = ["http", "https"]) + public static function checkUrl($url, array $protocols = ["http", "https"]) { $pattern = sprintf(UrlValidator::PATTERN, implode('|', $protocols)); From c4d22b8c793039563d835c0c5fd8fdcdc1510b14 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 3 Jul 2014 14:51:20 +0200 Subject: [PATCH 010/158] =?UTF-8?q?Finish=20Tar=20archive=20builder=20=09m?= =?UTF-8?q?odifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/Fil?= =?UTF-8?q?eFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php=20=09modif?= =?UTF-8?q?i=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFo?= =?UTF-8?q?rmat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php=20=09nouv?= =?UTF-8?q?eau=20fichier:=20core/lib/Thelia/Tests/FileFormat/Archive/Archi?= =?UTF-8?q?veBuilder/TestResources/bad=5Fformatted.tar=20=09nouveau=20fich?= =?UTF-8?q?ier:=20core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/?= =?UTF-8?q?TestResources/well=5Fformatted.tar=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Tests/FileFormat/Archive/Arch?= =?UTF-8?q?iveBuilder/ZipArchiveBuilderTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchiveBuilder/TarArchiveBuilder.php | 37 ++++- .../ArchiveBuilder/TarArchiveBuilderTest.php | 135 +++++++++++++++++- .../TestResources/bad_formatted.tar | 2 + .../TestResources/well_formatted.tar | Bin 0 -> 9216 bytes .../ArchiveBuilder/ZipArchiveBuilderTest.php | 4 +- 5 files changed, 171 insertions(+), 7 deletions(-) create mode 100644 core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.tar create mode 100644 core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/well_formatted.tar diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index b9ccb6a6a..08cd483e9 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -13,9 +13,10 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder; use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException; -use Thelia\Core\FileFormat\Archive\ArchiveBuilderInterface; +use Thelia\Core\HttpFoundation\Response; use Thelia\Core\Thelia; use Thelia\Core\Translation\Translator; +use Thelia\Exception\FileNotReadableException; use Thelia\Log\Tlog; use Thelia\Tools\FileDownload\FileDownloaderInterface; @@ -68,7 +69,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $this->compression = $compressionType; } - /** + public function __destruct() { if ($this->tar instanceof \PharData) { @@ -76,7 +77,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder unlink($this->cacheFile); } } - }*/ + } /** * @param string $filePath It is the path to access the file. @@ -118,6 +119,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $this->tar->addFile($filePath, $name); + /** + * And clear the download temp file + */ + unlink($fileDownloadCache); + return $this; } @@ -257,9 +263,32 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function buildArchiveResponse() { - $this->tar->setMetadata("comment", "Generated by Thelia v" . Thelia::THELIA_VERSION); + $this->tar->setMetadata("Generated by Thelia v" . Thelia::THELIA_VERSION); + if (!is_file($this->cacheFile)) { + $this->throwFileNotFound($this->cacheFile); + } + if (!is_readable($this->cacheFile)) { + throw new FileNotReadableException( + $this->translator->trans( + "The file %file is not readable", + [ + "%file" => $this->cacheFile + ] + ) + ); + } + + $content = file_get_contents($this->cacheFile); + + return new Response( + $content, + 200, + [ + "Content-Type" => $this->getMimeType(), + ] + ); } /** diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index 6c3bc61a7..323300714 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -132,7 +132,6 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase ); } - public function testDeleteFile() { $this->tar->addFileFromString( @@ -149,4 +148,138 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->tar->hasFile("bar") ); } + + public function testLoadValidArchive() + { + $tar = TarArchiveBuilder::loadArchive( + __DIR__ . DS . "TestResources/well_formatted.tar", + "dev" + ); + + $this->assertInstanceOf( + get_class($this->tar), + $tar + ); + + $this->assertTrue( + $tar->hasFile("LICENSE.txt") + ); + } + + /** + * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException + */ + public function testLoadInvalidArchive() + { + $tar = TarArchiveBuilder::loadArchive( + __DIR__ . DS . "TestResources/bad_formatted.tar", + "dev" + ); + } + + public function testFormatDirectoryPath() + { + $this->assertEquals( + "foo/", + $this->tar->formatDirectoryPath("foo") + ); + + $this->assertEquals( + "foo/", + $this->tar->formatDirectoryPath("/foo") + ); + + $this->assertEquals( + "foo/", + $this->tar->formatDirectoryPath("foo/") + ); + + $this->assertEquals( + "foo/", + $this->tar->formatDirectoryPath("/foo/") + ); + + $this->assertEquals( + "foo/bar/", + $this->tar->formatDirectoryPath("foo/bar") + ); + + $this->assertEquals( + "foo/bar/", + $this->tar->formatDirectoryPath("/foo/bar") + ); + + $this->assertEquals( + "foo/bar/", + $this->tar->formatDirectoryPath("/foo//bar/") + ); + + $this->assertEquals( + "foo/bar/", + $this->tar->formatDirectoryPath("/foo/bar/") + ); + + $this->assertEquals( + "foo/bar/baz/", + $this->tar->formatDirectoryPath("foo/bar/baz") + ); + + $this->assertEquals( + "foo/bar/baz/", + $this->tar->formatDirectoryPath("//foo/bar///baz/") + ); + } + + public function testFormatFilePath() + { + $this->assertEquals( + "foo", + $this->tar->formatFilePath("foo") + ); + + $this->assertEquals( + "foo", + $this->tar->formatFilePath("/foo") + ); + + $this->assertEquals( + "foo", + $this->tar->formatFilePath("foo/") + ); + + $this->assertEquals( + "foo", + $this->tar->formatFilePath("/foo/") + ); + + $this->assertEquals( + "foo/bar", + $this->tar->formatFilePath("foo/bar") + ); + + $this->assertEquals( + "foo/bar", + $this->tar->formatFilePath("/foo/bar") + ); + + $this->assertEquals( + "foo/bar", + $this->tar->formatFilePath("/foo//bar/") + ); + + $this->assertEquals( + "foo/bar", + $this->tar->formatFilePath("/foo/bar/") + ); + + $this->assertEquals( + "foo/bar/baz", + $this->tar->formatFilePath("foo/bar/baz") + ); + + $this->assertEquals( + "foo/bar/baz", + $this->tar->formatFilePath("//foo/bar///baz/") + ); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.tar b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.tar new file mode 100644 index 000000000..3bd1f0e29 --- /dev/null +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.tar @@ -0,0 +1,2 @@ +foo +bar diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/well_formatted.tar b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/well_formatted.tar new file mode 100644 index 0000000000000000000000000000000000000000..3bff92c8e4bd7b74d49959707e36ec89faab6335 GIT binary patch literal 9216 zcmeHMU2ogS70ok$#f4sK1F9m&j)N|W0&dnxz0jscoTTXEh#X1WP^3B}Evvu2=iHg0 zNXbr8EVkW;1PE-4oICg9+;cxPyLo;6?(TZhJT%XKtAEq!^z!mTo=vA`uU?+@f8xpX z?DEycxtzT?e|hoh;^pP^rA*H*&M(fN$@I5Us4usz8{?qb+?KzXbzb(L^?(1`bDA=p z(m4OKfA)9$yBz;}`|hL6uJ7)y-^<(Uch~Q)W^()Sud|!ig8u|da(qTV`D9(4SEZbf z<;9=mr?#~6Vmf`5B=Wl2>|DNFHFEO$R6mqA&RV&v7R}Z;D{rc{%uIvRW4S5QiTruh zG@BouKVQ^~N#&N$|B}e{y>+_^Li1WS)~)lVv6(cLq>wJA%p}X}#^v+2v4VH!khkW; z+}4Ry3u#t3S>&lLYb#lmwrg89W5N59u1vYi%cbNE#g|nhrYNed%_a%-mk&G&nQEVk zvZ8*nb#0xzwWW2YklS_+`7#T4QOWkfZg{AH=f4+lRR!rulK?ikBO+{&JtuI-a0z*Wm6S>;I`lDUsrPo5AUe(gp z5W2F?=7_{dJr*t=iL(oMfF6HT-WF@OdprA@ye9;yqN5KGG|T7C zxLse4LAaqCOxRZLvn=^X8NGxEMjs{>G;#2pDWR8K!J&Do@RQ1k0bbYhoCp6wF{YM` zo}!@6lUJpTdgn%jjVX8jVhCuJUvh zL8y9ebKrGu7#U<2eHac*5+6a})&Lgsv@o^e34YLDJGDJZ!Z8ZZED)68*t*JW0tMTe z@PAaz2(s>00O?9b11EX=z4b6JYg2k_hj`GF6b;7~dHLDjlJs0B+q_u~%woR5OU5;M z+7`xjcng^q6iM`;_ZPh~P)N22+uCGG7pAB|6Ub;N#WzPYXafI#@)BHv6~jI zT5DVe*O2Y^&gZGS9Y}H=atgH~a_|67>Y1~NTtB3C!`P4p?_eZ<9n$vgOke(I)dGLa zfb!m=KH--hHKE*rfNC$Gh6LJr;ji8kl_I=?#&huTQs%6Z%&Kti@rz$f5F_5nBR^MJ zzR33xu2r|2h3u#vA9~eLL5InuNMTg?rt_}`j;!%40g?H@?5l#2MO%80AmEH3oiw+; zVo?dGKBQYzMKC3bj%JW_LQnbxO=1<}mRhet3n;lD_?1;I+$#dN<>h?^IG>Igch&qb z1baKxcqo-1Dy)`2us(`86(5>@=^J;9t-0rY2X;qLmsJHU8Zww&AaxszeU7H-7MdkuV7Hu&GJFEHgz4@UDxt)zYL6>a30!E%_H>w5i?t4y* zFRk+ezNozS*sduG&nNPCPZZ=7_I;sSQsBY>mxGBljbr8dn+2mgd6O5`Bl!dT+GiVj zfLab=rYPujWB9u#Ju&EbRPF+Dy^;VE>rXT|mOhb#w60qeYp+0}bQjR0jUM#SG}KA-C9)qCRzY1B{(wP=Kf?a`d@?JDgVn{|+gL7SDhQEi6FfHOnE$kNV=BrFDDQvlH zR!A>g0_1{_fct=nMa700q3aUqZGNx44yGysALhUd9!%E2ZQ8eo)BPAKC%`iVQw%)Z zp{*%P9dn3v9Lz!g#aH+tVUG8}7J52TuJ&0F5&Azxp8)GuDf*KQD=-E1b<^I!+o84y(@6LRW_lVzFTLxVOcQ zp&(e$v0(l|;q}}WJ6eTVa@bQux1l~YpaWnm(9}S8wbqeJU?`%G7Xd;P7PcvwowrLJ zn=}pjw-RE$$Y}2c1vTVg2zvV0VP&Wwao}lZ4~72)T83Ku8oWq)iUIg|?ofndrbSNf zYK5Yop?xBuhi@4P+HN0gibjdkvu~rwV)p1r*LcO)n|0*{;B9105R7tC%hrM|@YDFQ z&z4BtEO&%l=(dn&7@cpWS%#S+*{S?kp%?8c%KKQNqx7enRrZ%BN?i@{v4@wkEi&UV)S|kfu)UXg;`e$?LU( zlD;6W)cgP_iU~lSaNz7D?T;eQi5+$P30pTdk|+zVg|YcsaY->lBJa>&IFx;k763mA zR2YdEwLdW5)*Eb+T=aXbV}g(R32Mi-*MZUf2t1hhiTFh!q1r_aRB;&5tp@(cTQSEG zW6>8O+EK(O->!OB+f%vq%LKGf*kl%d2*e+RZ5RkS@>C_13yi$2+5)QtxY=>FK*4Cz zo&8sf{MJ?j=5Rp)mva@dmlYB$jvo;yln@f$`$uo{)BtWmFTqNUxE#szxmj8^D%j-^ z$>>aJhvul~HNvPvb?DXuM0xW7=P?m<)`$s5WOXSQ=!+-6E%7u*hZ#4KlN;@I*#`kH z=)`ppyvU|L^PdWatg&xqW9HiqD#3jIBB`;j875m#Z|{K2P9)5918vTHr>2+2nDV~9 zdX&(EOW=wBiXbRrz!3-f268y%i1D)59Qiar)le|U1_|X3wWbI>5k^9m7KISE#m4WM z`b!S1M?J4_C!!-Ve=31Nz~L*3g0v4jRn;l9oXW zlfQzV3=~?zs7Swbgh?TZlS0VUueR932KMNRz()Npw#MYpb00(3t%B5pV?oSVqL&-yb|njbq7ejyF4T(^sFX##v0i9OO?Nz$a{Ma((G1dgO10qz@PX!Km~k& zc~5=yft*7z;#Uau3UutR0g$*pEA2M+0yWpQbQ3A}i#Ph&nT1gMH2j>%9Vs2s;@Sh9 z9t#<_G#E9xY(>)4o7`c{3Jf0WW1wEYriQKwwnz9zfCn;*8KU3;tOig{xu)Bai&4n1 zv-AB!iehQl*N;H4n*+kH5K@|+Mk7xn?&}|m-4O(9Oi?03{P&vDd3boFLb88T$J?iI6&)9ogKa(ZP5O@8uc5Rf zassertEquals( "foo", @@ -102,7 +102,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase ); } - public function testGetDirectoryPath() + public function testFormatDirectoryPath() { $this->assertEquals( "/foo/", From f62b14b84227c96dba1ef15ff3018b94f17730d7 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 09:00:03 +0200 Subject: [PATCH 011/158] =?UTF-8?q?Finish=20tar,=20tar.gz,=20tar.bz2=20and?= =?UTF-8?q?=20tests=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/?= =?UTF-8?q?Thelia/Config/Resources/config.xml=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Abstr?= =?UTF-8?q?actArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Ta?= =?UTF-8?q?rArchiveBuilder.php=20=09nouveau=20fichier:=20core/lib/Thelia/C?= =?UTF-8?q?ore/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php?= =?UTF-8?q?=20=09nouveau=20fichier:=20core/lib/Thelia/Core/FileFormat/Arch?= =?UTF-8?q?ive/ArchiveBuilder/TarGzArchiveBuilder.php=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Arch?= =?UTF-8?q?ive/ArchiveBuilder/ZipArchiveBuilder.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive?= =?UTF-8?q?/ArchiveBuilderInterface.php=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBui?= =?UTF-8?q?lder/TarArchiveBuilderTest.php=20=09nouveau=20fichier:=20core/l?= =?UTF-8?q?ib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2Archive?= =?UTF-8?q?BuilderTest.php=20=09nouveau=20fichier:=20core/lib/Thelia/Tests?= =?UTF-8?q?/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/T?= =?UTF-8?q?ests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.ph?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/config.xml | 6 +- .../Archive/AbstractArchiveBuilder.php | 15 +++ .../ArchiveBuilder/TarArchiveBuilder.php | 95 +++++++------------ .../ArchiveBuilder/TarBz2ArchiveBuilder.php | 47 +++++++++ .../ArchiveBuilder/TarGzArchiveBuilder.php | 52 ++++++++++ .../ArchiveBuilder/ZipArchiveBuilder.php | 46 ++++----- .../Archive/ArchiveBuilderInterface.php | 14 +-- .../ArchiveBuilder/TarArchiveBuilderTest.php | 18 ++-- .../TarBz2ArchiveBuilderTest.php | 38 ++++++++ .../TarGzArchiveBuilderTest.php | 39 ++++++++ .../ArchiveBuilder/ZipArchiveBuilderTest.php | 32 +++---- 11 files changed, 280 insertions(+), 122 deletions(-) create mode 100644 core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php create mode 100644 core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php create mode 100644 core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php create mode 100644 core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 74392256a..60f1eb0e6 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -148,18 +148,18 @@ - + - + gz - + bz2 diff --git a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php index b444860b6..aa6e2ccad 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php @@ -41,6 +41,9 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder /** @var string */ protected $cacheDir; + /** @var string */ + protected $environment; + public function __construct() { $this->translator = Translator::getInstance(); @@ -196,4 +199,16 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder { return $this->cacheFile; } + + /** + * @param string $environment + * @return $this + * + * Sets the execution environment of the Kernel, + * used to know which cache is used. + */ + public function setEnvironment($environment) + { + $this->environment = $environment; + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index 08cd483e9..6d9db55fd 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -47,29 +47,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \Thelia\Log\Tlog */ protected $logger; - function __construct($compressionType = null) - { - $this->translator = Translator::getInstance(); - $this->logger = Tlog::getNewInstance(); - - $supportedCompression = [ - "gz", - "bz2", - null - ]; - - if (!in_array($compressionType, $supportedCompression)) { - throw new TarArchiveException( - $this->translator->trans( - "The compression %type is not supported" - ) - ); - } - - $this->compression = $compressionType; - } - - public function __destruct() { if ($this->tar instanceof \PharData) { @@ -303,29 +280,19 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * * Loads an archive */ - public static function loadArchive( - $pathToArchive, - $environment, - $isOnline = false, - FileDownloaderInterface $fileDownloader = null - ) { - /** @var TarArchiveBuilder $instance */ - $instance = new static(); + public function loadArchive($pathToArchive, $isOnline = false) + { + $tar = clone $this; - if ($fileDownloader !== null) { - $instance->setFileDownloader($fileDownloader); - } - - $instance->setCacheFile($instance->generateCacheFile($environment)) - ->copyFile($pathToArchive, $instance->getCacheFile(), $isOnline); + $tar + ->setCacheFile($tar->generateCacheFile($this->environment)) + ->copyFile($pathToArchive, $tar->getCacheFile(), $isOnline); /** * This throws TarArchiveBuilderException if * the archive is not valid. */ - $instance->setEnvironment($environment); - - return $instance; + return $tar->setEnvironment($tar->environment); } /** @@ -391,6 +358,14 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function setEnvironment($environment) { + if (empty($environment)) { + throw new \ErrorException( + $this->translator->trans( + "You must define an environment when you use an archive builder" + ) + ); + } + if ($this->cacheFile === null) { $cacheFile = $this->generateCacheFile($environment); @@ -406,16 +381,8 @@ class TarArchiveBuilder extends AbstractArchiveBuilder try { $this->tar = new \PharData($cacheFile, null, null, static::PHAR_FORMAT); - switch ($this->compression) { - case "gz": - $this->tar = $this->tar->compress(\Phar::GZ); - $cacheFile .= ".gz"; - break; - case "bz2": - $this->tar = $this->tar->compress(\Phar::BZ2); - $cacheFile .= ".bz2"; - break; - } + $this->compressionEntryPoint(); + } catch(\BadMethodCallException $e) { /** @@ -438,6 +405,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } $this->cacheFile = $cacheFile; + $this->environment = $environment; return $this; } @@ -486,13 +454,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getName() { - $name = "tar"; - - if ($this->compression !== null) { - $name .= "." . $this->compression; - } - - return $name; + return "tar"; } /** @@ -506,7 +468,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getExtension() { - return $this->getName(); + return "tar"; } /** @@ -519,10 +481,19 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getMimeType() { - return $this->compression === null ? - "application/x-tar" : - "application/x-gtar" - ; + return "application/x-tar"; } + protected function compressionEntryPoint() + { + /** + * This method must be overwritten if you want to do some + * stuff to compress you archive + */ + } + + public function getCompression() + { + return $this->compression; + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php new file mode 100644 index 000000000..bd85d8599 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php @@ -0,0 +1,47 @@ + + */ +class TarBz2ArchiveBuilder extends TarArchiveBuilder +{ + public function getName() + { + return "tar.bz2"; + } + + public function getMimeType() + { + return "application/x-gtar"; + } + + public function getExtension() + { + return "tar.bz2"; + } + + protected function compressionEntryPoint() + { + if ($this->compression != \Phar::BZ2) { + $this->tar = $this->tar->compress(\Phar::BZ2, $this->getExtension()); + } + + $this->compression = \Phar::BZ2; + + return $this; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php new file mode 100644 index 000000000..33c16aba9 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php @@ -0,0 +1,52 @@ + + */ +class TarGzArchiveBuilder extends TarArchiveBuilder +{ + public function getName() + { + return "tar.gz"; + } + + public function getMimeType() + { + return "application/x-gtar"; + } + + public function getExtension() + { + return "tar.gz"; + } + + public function setEnvironment($environment) + { + parent::setEnvironment($environment); + + $this->previousFile = $this->cacheFile; + + if ($this->compression != \Phar::GZ) { + $this->tar = $this->tar->compress(\Phar::BZ2, $this->getExtension()); + } + + $this->compression = \Phar::GZ; + + return $this; + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index 72ce37c91..7262923a8 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -92,7 +92,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * Download the file if it is online * If it's local check if the file exists and if it is redable */ - $fileDownloadCache = $this->cacheDir . DS . "download.tmp"; + $fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp"; $this->copyFile($filePath, $fileDownloadCache, $isOnline); /** @@ -110,9 +110,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $this->logger->error($translatedErrorMessage); + // if error delete the cache file + unlink($fileDownloadCache); + throw new \ErrorException($translatedErrorMessage); } + // If not too + unlink($fileDownloadCache); + $this->commit(); return $this; @@ -331,41 +337,36 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder /** * @param string $pathToArchive - * @param string $environment * @param bool $isOnline * @param FileDownloaderInterface $fileDownloader - * @return $this + * @return ZipArchiveBuilder * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException * * Loads an archive */ - public static function loadArchive( - $pathToArchive, - $environment, - $isOnline = false, - FileDownloaderInterface $fileDownloader = null - ) { - /** @var ZipArchiveBuilder $instance */ - $instance = new static(); + public function loadArchive($pathToArchive, $isOnline = false) + { + $back = $this->zip; + $this->zip = new \ZipArchive(); + $zip = clone $this; + $this->zip = $back; - $instance->setEnvironment($environment); - $zip = $instance->getRawZipArchive(); - $zip->close(); + $zip->setEnvironment($this->environment); - if ($fileDownloader !== null) { - $instance->setFileDownloader($fileDownloader); - } + $zip->copyFile( + $pathToArchive, + $zip->getCacheFile(), + $isOnline + ); - $instance->copyFile($pathToArchive, $instance->getCacheFile(), $isOnline); - - if (true !== $return = $zip->open($instance->getCacheFile())) { + if (true !== $return = $zip->getRawZipArchive()->open($zip->getCacheFile())) { throw new ZipArchiveException( - $instance->getZipErrorMessage($return) + $zip->getZipErrorMessage($return) ); } - return $instance; + return $zip; } /** @@ -403,6 +404,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function setEnvironment($environment) { + parent::setEnvironment($environment); $cacheFile = $this->generateCacheFile($environment); diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php index 88f5da78f..c8166779b 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -11,7 +11,7 @@ /*************************************************************************************/ namespace Thelia\Core\FileFormat\Archive; -use Thelia\Tools\FileDownload\FileDownloaderInterface; + /** * Interface ArchiveBuilderInterface @@ -86,16 +86,14 @@ interface ArchiveBuilderInterface /** * @param string $pathToArchive - * @param string $environment * @param bool $isOnline - * @param FileDownloaderInterface $fileDownloader * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException * * Loads an archive */ - public static function loadArchive($pathToArchive, $environment, $isOnline = false, FileDownloaderInterface $fileDownloader = null); + public function loadArchive($pathToArchive, $isOnline = false); /** * @param $pathToFile @@ -113,12 +111,4 @@ interface ArchiveBuilderInterface */ public function hasDirectory($directory); - /** - * @param string $environment - * @return $this - * - * Sets the execution environment of the Kernel, - * used to know which cache is used. - */ - public function setEnvironment($environment); } \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index 323300714..fe8728d14 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -151,9 +151,8 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testLoadValidArchive() { - $tar = TarArchiveBuilder::loadArchive( - __DIR__ . DS . "TestResources/well_formatted.tar", - "dev" + $tar = $this->tar->loadArchive( + __DIR__ . DS . "TestResources/well_formatted.tar" ); $this->assertInstanceOf( @@ -171,9 +170,8 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase */ public function testLoadInvalidArchive() { - $tar = TarArchiveBuilder::loadArchive( - __DIR__ . DS . "TestResources/bad_formatted.tar", - "dev" + $tar = $this->tar->loadArchive( + __DIR__ . DS . "TestResources/bad_formatted.tar" ); } @@ -282,4 +280,12 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->tar->formatFilePath("//foo/bar///baz/") ); } + + public function testCompression() + { + $this->assertEquals( + null, + $this->tar->getCompression() + ); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php new file mode 100644 index 000000000..f968bf759 --- /dev/null +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php @@ -0,0 +1,38 @@ + + */ +class TarBz2ArchiveBuilderTest extends TarArchiveBuilderTest +{ + public function setUp() + { + parent::setUp(); + + $this->tar = new TarBz2ArchiveBuilder(); + $this->tar->setEnvironment("dev"); + } + + public function testCompression() + { + $this->assertEquals( + \Phar::BZ2, + $this->tar->getCompression() + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php new file mode 100644 index 000000000..e70ea33ee --- /dev/null +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php @@ -0,0 +1,39 @@ + + */ +class TarGzArchiveBuilderTest extends TarArchiveBuilderTest +{ + public function setUp() + { + parent::setUp(); + + $this->tar = new TarGzArchiveBuilder(); + $this->tar->setEnvironment("dev"); + } + + public function testCompression() + { + $this->assertEquals( + \Phar::GZ, + $this->tar->getCompression() + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index 0f141d1b6..bc3560694 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -40,9 +40,10 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->zip = new ZipArchiveBuilder(); + $this->zip->setEnvironment("dev"); + $this->loadedZip = $this->zip->loadArchive( - __DIR__ . DS . "TestResources/well_formatted.zip", - "dev" + __DIR__ . DS . "TestResources/well_formatted.zip" ); } @@ -158,8 +159,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testLoadValidZip() { $loadedZip = $this->zip->loadArchive( - __DIR__ . DS . "TestResources/well_formatted.zip", - "dev" + __DIR__ . DS . "TestResources/well_formatted.zip" ); $this->assertInstanceOf( @@ -175,8 +175,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testLoadNotValidZip() { $this->zip->loadArchive( - __DIR__ . DS . "TestResources/bad_formatted.zip", - "dev" + __DIR__ . DS . "TestResources/bad_formatted.zip" ); } @@ -186,18 +185,17 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testLoadNotExistingFile() { $this->zip->loadArchive( - __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", - "dev" + __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip" ); } public function testLoadOnlineAvailableAndValidFile() { + $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); + $this->zip->loadArchive( __DIR__ . DS . "TestResources/well_formatted.zip", - "dev", - true, - FakeFileDownloader::getInstance() + true ); } @@ -207,11 +205,11 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase */ public function testLoadOnlineAvailableAndNotValidFile() { + $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); + $this->zip->loadArchive( __DIR__ . DS . "TestResources/bad_formatted.zip", - "dev", - true, - FakeFileDownloader::getInstance() + true ); } @@ -220,11 +218,11 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase */ public function testLoadOnlineNotExistingFile() { + $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); + $this->zip->loadArchive( __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", - "dev", - true, - FakeFileDownloader::getInstance() + true ); } From 66a0beddb1702fb646797618d2ef30ce939af8a4 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 09:29:57 +0200 Subject: [PATCH 012/158] =?UTF-8?q?Fix=20services=20=09modifi=C3=A9:=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20core/lib/Thelia/Config/Resources/config.xm?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/config.xml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 60f1eb0e6..db21517e8 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -136,7 +136,7 @@ - + %kernel.environment% @@ -154,17 +154,16 @@ - gz - bz2 + - + From ef7586334274a1e32e867d6f844d3e8840ec6e8f Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 09:38:27 +0200 Subject: [PATCH 013/158] =?UTF-8?q?revert=20file=20to=20ccd16dc=20=09modif?= =?UTF-8?q?i=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/Tools/?= =?UTF-8?q?FileManagerTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Tests/Tools/FileManagerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Tests/Tools/FileManagerTest.php b/core/lib/Thelia/Tests/Tools/FileManagerTest.php index 29e4f2966..e611b2c53 100644 --- a/core/lib/Thelia/Tests/Tools/FileManagerTest.php +++ b/core/lib/Thelia/Tests/Tools/FileManagerTest.php @@ -787,7 +787,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->getMock(); $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') - ->disableOriginalConstructor() + ->setConstructorArgs([__DIR__ . '/fixtures/test.xml', 'test.xml']) ->getMock(); $stubUploadedFile->expects($this->any()) ->method('getClientOriginalExtension') @@ -814,7 +814,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->getMock(); $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') - ->disableOriginalConstructor() + ->setConstructorArgs([__DIR__ . '/fixtures/test.xml', 'test.xml']) ->getMock(); $stubUploadedFile->expects($this->any()) ->method('getClientOriginalExtension') From 2702c20014f20a2079a9800ff1fa88109b3ed05a Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 09:46:21 +0200 Subject: [PATCH 014/158] =?UTF-8?q?Fix=20Zip=20add=20file,=20we=20must=20f?= =?UTF-8?q?irst=20commit=20and=20then=20delete=20the=20temporary=20file=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core?= =?UTF-8?q?/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index 7262923a8..85ee78da8 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -116,11 +116,11 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder throw new \ErrorException($translatedErrorMessage); } - // If not too - unlink($fileDownloadCache); - $this->commit(); + // Delete the temp file + unlink($fileDownloadCache); + return $this; } From 671b0f3d736eb3fc6f17125f0c879d8ba74b34ab Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 10:01:29 +0200 Subject: [PATCH 015/158] =?UTF-8?q?Fix=20cs=20=09modifi=C3=A9:=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Abstract?= =?UTF-8?q?ArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Excep?= =?UTF-8?q?tion/TarArchiveException.php=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuil?= =?UTF-8?q?der/Exception/ZipArchiveException.php=20=09modifi=C3=A9:=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Ar?= =?UTF-8?q?chiveBuilder/TarArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Archi?= =?UTF-8?q?veBuilder/TarBz2ArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Archi?= =?UTF-8?q?veBuilder/TarGzArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Archi?= =?UTF-8?q?veBuilder/ZipArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveB?= =?UTF-8?q?uilderInterface.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManage?= =?UTF-8?q?r.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/The?= =?UTF-8?q?lia/Core/FileFormat/FormatInterface.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatt?= =?UTF-8?q?er/AbstractFormatter.php=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/Core/FileFormat/Formatter/Exception/Ba?= =?UTF-8?q?dFormattedStringException.php=20=09nouveau=20fichier:=20core/li?= =?UTF-8?q?b/Thelia/Core/FileFormat/Formatter/FormatterData.php=20=09nouve?= =?UTF-8?q?au=20fichier:=20core/lib/Thelia/Core/FileFormat/Formatter/Forma?= =?UTF-8?q?tterInterface.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/T?= =?UTF-8?q?ests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.ph?= =?UTF-8?q?p=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/?= =?UTF-8?q?Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTes?= =?UTF-8?q?t.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/The?= =?UTF-8?q?lia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder?= =?UTF-8?q?Test.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/?= =?UTF-8?q?Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilde?= =?UTF-8?q?rTest.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib?= =?UTF-8?q?/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/T?= =?UTF-8?q?ests/FileFormat/Formatter/FormatterManagerTest.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/Tools/F?= =?UTF-8?q?akeFileDownloader.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Tests/Tools/FileDownloaderTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/AbstractArchiveBuilder.php | 4 +- .../Exception/TarArchiveException.php | 2 +- .../Exception/ZipArchiveException.php | 2 +- .../ArchiveBuilder/TarArchiveBuilder.php | 50 +++++++++---------- .../ArchiveBuilder/TarBz2ArchiveBuilder.php | 2 +- .../ArchiveBuilder/TarGzArchiveBuilder.php | 2 +- .../ArchiveBuilder/ZipArchiveBuilder.php | 40 ++++++++------- .../Archive/ArchiveBuilderInterface.php | 21 ++++---- .../Archive/ArchiveBuilderManager.php | 4 +- .../Core/FileFormat/FormatInterface.php | 2 +- .../Formatter/AbstractFormatter.php | 21 +------- .../Exception/BadFormattedStringException.php | 2 +- .../FileFormat/Formatter/FormatterData.php | 23 +++++++++ .../Formatter/FormatterInterface.php | 39 +++++++++++++++ .../FileFormat/Formatter/FormatterManager.php | 4 +- .../ArchiveBuilder/TarArchiveBuilderTest.php | 4 +- .../TarBz2ArchiveBuilderTest.php | 2 +- .../TarGzArchiveBuilderTest.php | 3 +- .../ArchiveBuilder/ZipArchiveBuilderTest.php | 2 +- .../Archive/ArchiveBuilderManagerTest.php | 2 +- .../Formatter/FormatterManagerTest.php | 2 +- .../Thelia/Tests/Tools/FakeFileDownloader.php | 6 +-- .../Thelia/Tests/Tools/FileDownloaderTest.php | 2 +- 23 files changed, 142 insertions(+), 99 deletions(-) create mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php create mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php diff --git a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php index aa6e2ccad..e873d74ef 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php @@ -201,7 +201,7 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder } /** - * @param string $environment + * @param string $environment * @return $this * * Sets the execution environment of the Kernel, @@ -211,4 +211,4 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder { $this->environment = $environment; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php index 9945a65be..3e2d583d6 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php @@ -20,4 +20,4 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception; class TarArchiveException extends \Exception { -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php index 24f9ddb37..f69375dec 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php @@ -20,4 +20,4 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception; class ZipArchiveException extends \ErrorException { -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index 6d9db55fd..0f2cd67c7 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -57,10 +57,10 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** - * @param string $filePath It is the path to access the file. - * @param string $directoryInArchive This is the directory where it will be stored in the archive - * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name - * @param bool $isOnline + * @param string $filePath It is the path to access the file. + * @param string $directoryInArchive This is the directory where it will be stored in the archive + * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name + * @param bool $isOnline * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -107,7 +107,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** * @param $content * @param $name - * @param string $directoryInArchive + * @param string $directoryInArchive * @return mixed * @throws \ErrorException * @@ -132,7 +132,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } try { $this->tar->addFromString($name, $content); - } catch(\Exception $e) { + } catch (\Exception $e) { throw new \ErrorException( $this->translator->trans( "Error while writing the file into the archive, error message: %errmes", @@ -144,7 +144,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } } - /** * @param $directoryPath * @return $this @@ -160,7 +159,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder try { $this->tar->addEmptyDir($directoryInArchive); - } catch(\Exception $e) { + } catch (\Exception $e) { throw new \ErrorException( $this->translator->trans( "The directory %dir has not been created in the archive", @@ -176,7 +175,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** - * @param string $pathToFile + * @param string $pathToFile * @return null|string * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -206,7 +205,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder return $content; } - /** * @param $pathInArchive * @return $this @@ -269,10 +267,10 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** - * @param string $pathToArchive - * @param string $environment - * @param bool $isOnline - * @param FileDownloaderInterface $fileDownloader + * @param string $pathToArchive + * @param string $environment + * @param bool $isOnline + * @param FileDownloaderInterface $fileDownloader * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException @@ -292,6 +290,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * This throws TarArchiveBuilderException if * the archive is not valid. */ + return $tar->setEnvironment($tar->environment); } @@ -312,19 +311,19 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \PharFileInfo $fileInfo */ $fileInfo = $this->tar[$pathToFile]; - if($fileInfo->isFile()) { + if ($fileInfo->isFile()) { $isFile = true; } /** * Catch the exception to avoid its displaying. */ - } catch(\BadMethodCallException $e) {} + } catch (\BadMethodCallException $e) {} return $isFile; } /** - * @param string $directory + * @param string $directory * @return bool * * Check if the archive has a directory @@ -338,19 +337,19 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \PharFileInfo $fileInfo */ $fileInfo = $this->tar[$pathToDir]; - if($fileInfo->isDir()) { + if ($fileInfo->isDir()) { $isDir = true; } /** * Catch the exception to avoid its displaying. */ - } catch(\BadMethodCallException $e) {} + } catch (\BadMethodCallException $e) {} return $isDir; } /** - * @param string $environment + * @param string $environment * @return $this * * Sets the execution environment of the Kernel, @@ -383,13 +382,12 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $this->compressionEntryPoint(); - - } catch(\BadMethodCallException $e) { + } catch (\BadMethodCallException $e) { /** * This should not happen */ $errorMessage = "You have badly called the method setEnvironment twice for %file"; - } catch(\UnexpectedValueException $e) { + } catch (\UnexpectedValueException $e) { $errorMessage = "The file %file is corrupted"; } @@ -411,7 +409,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** - * @param string $initialString + * @param string $initialString * @return string * * Gives a valid file path for \ZipArchive @@ -432,7 +430,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** - * @param string $initialString + * @param string $initialString * @return string * * Gives a valid directory path for \ZipArchive @@ -496,4 +494,4 @@ class TarArchiveBuilder extends AbstractArchiveBuilder { return $this->compression; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php index bd85d8599..774d082df 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php @@ -44,4 +44,4 @@ class TarBz2ArchiveBuilder extends TarArchiveBuilder return $this; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php index 33c16aba9..4722417fa 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php @@ -49,4 +49,4 @@ class TarGzArchiveBuilder extends TarArchiveBuilder return $this; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index 85ee78da8..fd49b5c87 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -47,7 +47,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * On the destruction of the class, * remove the temporary file. */ - function __destruct() + public function __destruct() { if ($this->zip instanceof \ZipArchive) { @$this->zip->close(); @@ -59,10 +59,10 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** - * @param string $filePath It is the path to access the file. - * @param string $directoryInArchive This is the directory where it will be stored in the archive - * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name - * @param bool $isOnline + * @param string $filePath It is the path to access the file. + * @param string $directoryInArchive This is the directory where it will be stored in the archive + * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name + * @param bool $isOnline * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -80,7 +80,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * Add empty directory if it doesn't exist */ - if(!empty($directoryInArchive)) { + if (!empty($directoryInArchive)) { $this->addDirectory($directoryInArchive); } @@ -127,7 +127,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder /** * @param $content * @param $name - * @param string $directoryInArchive + * @param string $directoryInArchive * @return mixed * @throws \ErrorException * @@ -194,7 +194,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** - * @param string $pathToFile + * @param string $pathToFile * @return null|string * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -224,7 +224,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder /** - * @param string $initialString + * @param string $initialString * @return string * * Gives a valid file path for \ZipArchive @@ -244,11 +244,12 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if (preg_match("#\/?[^\/]+\/[^\/]+\/?#", $initialString)) { $initialString = "/" . $initialString; } + return $initialString; } /** - * @param string $initialString + * @param string $initialString * @return string * * Gives a valid directory path for \ZipArchive @@ -336,9 +337,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** - * @param string $pathToArchive - * @param bool $isOnline - * @param FileDownloaderInterface $fileDownloader + * @param string $pathToArchive + * @param bool $isOnline + * @param FileDownloaderInterface $fileDownloader * @return ZipArchiveBuilder * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException @@ -383,7 +384,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** - * @param string $directory + * @param string $directory * @return bool * * Checks if the link $directory exists and if it's not a file. @@ -396,7 +397,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** - * @param string $environment + * @param string $environment * @return $this * * Sets the execution environment of the Kernel, @@ -417,7 +418,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder \ZipArchive::CREATE ); - if($opening !== true) { + if ($opening !== true) { throw new \ErrorException( $this->translator->trans( "An unknown error append" @@ -511,7 +512,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** - * @param string $initialString + * @param string $initialString * @return string * * Gives a valid file path for \ZipArchive @@ -531,11 +532,12 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) { $initialString = "/" . $initialString; } + return $initialString; } /** - * @param string $initialString + * @param string $initialString * @return string * * Gives a valid directory path for \ZipArchive @@ -598,4 +600,4 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder { return $this->zip; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php index c8166779b..ab37760ca 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -12,7 +12,6 @@ namespace Thelia\Core\FileFormat\Archive; - /** * Interface ArchiveBuilderInterface * @package Thelia\Core\FileFormat\Archive @@ -23,10 +22,10 @@ namespace Thelia\Core\FileFormat\Archive; interface ArchiveBuilderInterface { /** - * @param string $filePath It is the path to access the file. - * @param string $directoryInArchive This is the directory where it will be stored in the archive - * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name - * @param bool $isOnline + * @param string $filePath It is the path to access the file. + * @param string $directoryInArchive This is the directory where it will be stored in the archive + * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name + * @param bool $isOnline * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -41,7 +40,7 @@ interface ArchiveBuilderInterface /** * @param $content * @param $name - * @param string $directoryInArchive + * @param string $directoryInArchive * @return mixed * @throws \ErrorException * @@ -50,7 +49,7 @@ interface ArchiveBuilderInterface public function addFileFromString($content, $name, $directoryInArchive = "/"); /** - * @param string $pathToFile + * @param string $pathToFile * @return null|string * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -85,8 +84,8 @@ interface ArchiveBuilderInterface public function buildArchiveResponse(); /** - * @param string $pathToArchive - * @param bool $isOnline + * @param string $pathToArchive + * @param bool $isOnline * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException @@ -104,11 +103,11 @@ interface ArchiveBuilderInterface public function hasFile($pathToFile); /** - * @param string $directory + * @param string $directory * @return bool * * Check if the archive has a directory */ public function hasDirectory($directory); -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php index 7957fca4f..21e0fe338 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php @@ -29,7 +29,7 @@ class ArchiveBuilderManager $this->environment = $environment; } /** - * @param AbstractArchiveBuilder $archiveCreator + * @param AbstractArchiveBuilder $archiveCreator * @return $this */ public function add(AbstractArchiveBuilder $archiveCreator) @@ -73,4 +73,4 @@ class ArchiveBuilderManager { return $this->archiveCreators; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/FormatInterface.php b/core/lib/Thelia/Core/FileFormat/FormatInterface.php index cd10a0cb0..4b327271d 100644 --- a/core/lib/Thelia/Core/FileFormat/FormatInterface.php +++ b/core/lib/Thelia/Core/FileFormat/FormatInterface.php @@ -55,4 +55,4 @@ interface FormatInterface * return "application/json"; */ public function getMimeType(); -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php index f991535c8..605bc6362 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php @@ -18,24 +18,7 @@ use Thelia\Core\FileFormat\FormatInterface; * @package Thelia\Core\FileFormat\Formatter * @author Benjamin Perche */ -abstract class AbstractFormatter implements FormatInterface +abstract class AbstractFormatter implements FormatInterface, FormatterInterface { - /** - * @param array $data - * @return mixed - * - * Encodes an array to the desired format. - * $data array only contains array and scalar data. - */ - abstract public function encode(array $data); - /** - * @param $data - * @return array - * @throws \Thelia\Core\FileFormat\Formatter\Exception\BadFormattedStringException - * - * this method must do exactly the opposite of encode and return - * an array composed of array and scalar data. - */ - abstract public function decode($data); -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php b/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php index 6d763a01b..18d28bb78 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php @@ -20,4 +20,4 @@ namespace Thelia\Core\FileFormat\Formatter\Exception; class BadFormattedStringException extends \ErrorException { -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php new file mode 100644 index 000000000..689ad0ba6 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php @@ -0,0 +1,23 @@ + + */ +class FormatterData +{ + +} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php new file mode 100644 index 000000000..4d2d2d91e --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php @@ -0,0 +1,39 @@ + + */ +interface FormatterInterface +{ + /** + * @param FormatterData $data + * @return mixed + * + * This method must use a FormatterData object and output + * a formatted value. + */ + public function encode(FormatterData $data); + + /** + * @param $rawData + * @return FormatterData + * + * This must takes raw data as argument and outputs + * a FormatterData object. + */ + public function decode($rawData); +} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php index cc8aad8e4..b8e5d5d66 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php @@ -18,7 +18,7 @@ use Thelia\Core\Translation\Translator; * @package Thelia\Core\FileFormat\Formatter * @author Benjamin Perche */ -class FormatterManager +class FormatterManager { protected $formatters = array(); @@ -66,4 +66,4 @@ class FormatterManager { return $this->formatters; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index fe8728d14..e34acdf76 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -227,7 +227,7 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->tar->formatDirectoryPath("//foo/bar///baz/") ); } - + public function testFormatFilePath() { $this->assertEquals( @@ -288,4 +288,4 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->tar->getCompression() ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php index f968bf759..a65892424 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php @@ -35,4 +35,4 @@ class TarBz2ArchiveBuilderTest extends TarArchiveBuilderTest $this->tar->getCompression() ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php index e70ea33ee..5b1aded6e 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php @@ -12,7 +12,6 @@ namespace Thelia\Tests\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarGzArchiveBuilder; -use Thelia\Core\HttpFoundation\Response; /** * Class TarGzArchiveBuilderTest @@ -36,4 +35,4 @@ class TarGzArchiveBuilderTest extends TarArchiveBuilderTest $this->tar->getCompression() ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index bc3560694..c3b039bd4 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -395,4 +395,4 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php index c01b35a45..69fdfdb9a 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php @@ -72,4 +72,4 @@ class ArchiveBuilderManagerTest extends \PHPUnit_Framework_TestCase $this->manager->delete("foo"); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php index 8759c2fca..39bf06cb3 100644 --- a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php @@ -71,4 +71,4 @@ class FormatterManagerTest extends \PHPUnit_Framework_TestCase { $this->manager->delete("foo"); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php b/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php index 851036062..a45a3b8ec 100644 --- a/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php +++ b/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php @@ -22,8 +22,8 @@ use Thelia\Tools\FileDownload\FileDownloader; class FakeFileDownloader extends FileDownloader { /** - * @param string $url - * @param string $pathToStore + * @param string $url + * @param string $pathToStore * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException * @throws \HttpUrlException @@ -41,4 +41,4 @@ class FakeFileDownloader extends FileDownloader } } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php index 7bc36523f..e62840494 100644 --- a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php +++ b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php @@ -60,4 +60,4 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase { $this->downloader->download("https://github.com/thelia/thelia", "php://temp"); } -} \ No newline at end of file +} From dd77d27892af4e5604fdbc2a5626a4608960ac16 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 13:44:28 +0200 Subject: [PATCH 016/158] =?UTF-8?q?Fix=20cs=20and=20add=20get=20method=20i?= =?UTF-8?q?n=20managers=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/?= =?UTF-8?q?lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core?= =?UTF-8?q?/FileFormat/Formatter/FormatterData.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatt?= =?UTF-8?q?er/FormatterManager.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Tools/FileDownload/FileDownloader.php=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tool?= =?UTF-8?q?s/FileDownload/FileDownloaderAwareTrait.php=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tools/FileDownload/F?= =?UTF-8?q?ileDownloaderInterface.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/ArchiveBuilderManager.php | 40 +++++++++++++------ .../FileFormat/Formatter/FormatterData.php | 25 ++++++++++++ .../FileFormat/Formatter/FormatterManager.php | 34 ++++++++++++---- .../Tools/FileDownload/FileDownloader.php | 8 ++-- .../FileDownload/FileDownloaderAwareTrait.php | 4 +- .../FileDownload/FileDownloaderInterface.php | 7 ++-- 6 files changed, 87 insertions(+), 31 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php index 21e0fe338..220de27bd 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php @@ -20,7 +20,7 @@ use Thelia\Core\Translation\Translator; */ class ArchiveBuilderManager { - protected $archiveCreators = array(); + protected $archiveBuilders = array(); protected $environment; @@ -37,7 +37,7 @@ class ArchiveBuilderManager if (null !== $archiveCreator) { $archiveCreator->setEnvironment($this->environment); - $this->archiveCreators[$archiveCreator->getName()] = $archiveCreator; + $this->archiveBuilders[$archiveCreator->getName()] = $archiveCreator; } return $this; @@ -50,18 +50,11 @@ class ArchiveBuilderManager */ public function delete($name) { - if (!array_key_exists($name, $this->archiveCreators)) { - throw new \OutOfBoundsException( - Translator::getInstance()->trans( - "The archive creator %name doesn't exist", - [ - "%name" => $name - ] - ) - ); + if (!array_key_exists($name, $this->archiveBuilders)) { + $this->throwOutOfBounds($name); } - unset($this->archiveCreators[$name]); + unset($this->archiveBuilders[$name]); return $this; } @@ -71,6 +64,27 @@ class ArchiveBuilderManager */ public function getAll() { - return $this->archiveCreators; + return $this->archiveBuilders; + } + + public function get($name) + { + if (!array_key_exists($name, $this->archiveBuilders)) { + $this->throwOutOfBounds($name); + } + + return $this->archiveBuilders[$name]; + } + + protected function throwOutOfBounds($name) + { + throw new \OutOfBoundsException( + Translator::getInstance()->trans( + "The archive creator %name doesn't exist", + [ + "%name" => $name + ] + ) + ); } } diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php index 689ad0ba6..a74ecef90 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php @@ -11,6 +11,8 @@ /*************************************************************************************/ namespace Thelia\Core\FileFormat\Formatter; +use Propel\Runtime\ActiveQuery\ModelCriteria; +use Thelia\Core\Translation\Translator; /** * Class FormatterData @@ -19,5 +21,28 @@ namespace Thelia\Core\FileFormat\Formatter; */ class FormatterData { + /** @var array */ + protected $data; + /** @var Translator */ + protected $translator; + + public function __construct() + { + $this->translator = Translator::getInstance(); + } + + public function loadModelCriteria(ModelCriteria $criteria) + { + + $propelData = + $criteria + ->find() + ; + + if (empty($propelData)) { + return null; + } + + } } diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php index b8e5d5d66..4035927ae 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php @@ -44,14 +44,7 @@ class FormatterManager public function delete($name) { if (!array_key_exists($name, $this->formatters)) { - throw new \OutOfBoundsException( - Translator::getInstance()->trans( - "The formatter %name doesn't exist", - [ - "%name" => $name - ] - ) - ); + $this->throwOutOfBounds($name); } unset($this->formatters[$name]); @@ -59,6 +52,15 @@ class FormatterManager return $this; } + public function get($name) + { + if (!array_key_exists($name, $this->formatters)) { + $this->throwOutOfBounds($name); + } + + return $this->formatters[$name]; + } + /** * @return array[AbstractFormatter] */ @@ -66,4 +68,20 @@ class FormatterManager { return $this->formatters; } + + /** + * @param $name + * @throws \OutOfBoundsException + */ + protected function throwOutOfBounds($name) + { + throw new \OutOfBoundsException( + Translator::getInstance()->trans( + "The formatter %name doesn't exist", + [ + "%name" => $name + ] + ) + ); + } } diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php index be8b8f53a..2f77226cf 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php @@ -45,8 +45,8 @@ class FileDownloader implements FileDownloaderInterface } /** - * @param string $url - * @param string $pathToStore + * @param string $url + * @param string $pathToStore * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException * @throws \HttpUrlException @@ -125,7 +125,7 @@ class FileDownloader implements FileDownloaderInterface */ $file = @fopen($pathToStore, "w"); - if($file === false) { + if ($file === false) { $translatedErrorMessage = $this->translator->trans( "Failed to open a writing stream on the file: %file", [ @@ -140,4 +140,4 @@ class FileDownloader implements FileDownloaderInterface fputs($file, $response); fclose($file); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php b/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php index e9b99d73d..78347bdd9 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php @@ -35,7 +35,7 @@ trait FileDownloaderAwareTrait } /** - * @param FileDownloaderInterface $fileDownloader + * @param FileDownloaderInterface $fileDownloader * @return $this */ public function setFileDownloader(FileDownloaderInterface $fileDownloader) @@ -44,4 +44,4 @@ trait FileDownloaderAwareTrait return $this; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php b/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php index bdfebb5f9..4c29daf29 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php @@ -14,7 +14,6 @@ namespace Thelia\Tools\FileDownload; use Psr\Log\LoggerInterface; use Symfony\Component\Translation\Translator; - /** * Class FileDownloader * @package Thelia\Tools\FileDownload @@ -23,8 +22,8 @@ use Symfony\Component\Translation\Translator; interface FileDownloaderInterface { /** - * @param string $url - * @param string $pathToStore + * @param string $url + * @param string $pathToStore * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException * @throws \HttpUrlException @@ -41,4 +40,4 @@ interface FileDownloaderInterface * Returns an hydrated instance */ public static function getInstance(); -} \ No newline at end of file +} From d9db2adfc8b3cb44fed60f56ac6290576daa7688 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 14:34:30 +0200 Subject: [PATCH 017/158] =?UTF-8?q?Add=20filename=20in=20build=20archive?= =?UTF-8?q?=20response=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/l?= =?UTF-8?q?ib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuil?= =?UTF-8?q?der.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/T?= =?UTF-8?q?helia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.?= =?UTF-8?q?php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Theli?= =?UTF-8?q?a/Core/FileFormat/Archive/ArchiveBuilderInterface.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php | 3 ++- .../FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php | 5 +++-- .../Core/FileFormat/Archive/ArchiveBuilderInterface.php | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index 0f2cd67c7..35f9a5d55 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -236,7 +236,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * * This method return an instance of a Response with the archive as content. */ - public function buildArchiveResponse() + public function buildArchiveResponse($filename) { $this->tar->setMetadata("Generated by Thelia v" . Thelia::THELIA_VERSION); @@ -262,6 +262,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder 200, [ "Content-Type" => $this->getMimeType(), + "Content-Disposition" => $filename . "." . $this->getExtension(), ] ); } diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index fd49b5c87..220cd24e4 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -302,7 +302,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * * This method return an instance of a Response with the archive as content. */ - public function buildArchiveResponse() + public function buildArchiveResponse($filename) { $this->zip->comment = "Generated by Thelia v" . Thelia::THELIA_VERSION; @@ -331,7 +331,8 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $content, 200, [ - "Content-Type" => $this->getMimeType() + "Content-Type" => $this->getMimeType(), + "Content-Disposition" => $filename . "." . $this->getExtension(), ] ); } diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php index ab37760ca..0ff882ae5 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -76,12 +76,14 @@ interface ArchiveBuilderInterface * This method creates an empty directory */ public function addDirectory($directoryPath); + /** + * @params string $filename * @return \Thelia\Core\HttpFoundation\Response * * This method return an instance of a Response with the archive as content. */ - public function buildArchiveResponse(); + public function buildArchiveResponse($filename); /** * @param string $pathToArchive From d120e57684e1ec1272d090c2fe97afa4c8415af7 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 14:49:35 +0200 Subject: [PATCH 018/158] =?UTF-8?q?Fix=20Test=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Tests/FileFormat/Archive/Arch?= =?UTF-8?q?iveBuilder/ZipArchiveBuilderTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index c3b039bd4..450af71b2 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -325,7 +325,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testBuildArchiveResponse() { $loadedArchiveResponse = $this->loadedZip - ->buildArchiveResponse() + ->buildArchiveResponse("test") ; $loadedArchiveResponseContent = $loadedArchiveResponse->getContent(); From 8418974e8eb39394813f4cb25e7cf57c72f68101 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 15:07:07 +0200 Subject: [PATCH 019/158] =?UTF-8?q?Add=20getNames=20methods=20to=20manager?= =?UTF-8?q?s=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/?= =?UTF-8?q?Core/FileFormat/Archive/ArchiveBuilderManager.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Formatter/FormatterManager.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/ArchiveBuilderManager.php | 28 +++++++++++++++---- .../FileFormat/Formatter/FormatterManager.php | 15 ++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php index 220de27bd..938445822 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php @@ -20,6 +20,7 @@ use Thelia\Core\Translation\Translator; */ class ArchiveBuilderManager { + /** @var array */ protected $archiveBuilders = array(); protected $environment; @@ -29,15 +30,15 @@ class ArchiveBuilderManager $this->environment = $environment; } /** - * @param AbstractArchiveBuilder $archiveCreator + * @param AbstractArchiveBuilder $archiveBuilder * @return $this */ - public function add(AbstractArchiveBuilder $archiveCreator) + public function add(AbstractArchiveBuilder $archiveBuilder) { - if (null !== $archiveCreator) { - $archiveCreator->setEnvironment($this->environment); + if (null !== $archiveBuilder) { + $archiveBuilder->setEnvironment($this->environment); - $this->archiveBuilders[$archiveCreator->getName()] = $archiveCreator; + $this->archiveBuilders[$archiveBuilder->getName()] = $archiveBuilder; } return $this; @@ -60,13 +61,28 @@ class ArchiveBuilderManager } /** - * @return array[AbstractArchiveBuilder] + * @return array */ public function getAll() { return $this->archiveBuilders; } + /** + * @return array + */ + public function getNames() + { + $names = []; + + /** @var AbstractArchiveBuilder $builder */ + foreach($this->archiveBuilders as $builder) { + $names[] = $builder->getName(); + } + + return $names; + } + public function get($name) { if (!array_key_exists($name, $this->archiveBuilders)) { diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php index 4035927ae..b7801c7a9 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php @@ -69,6 +69,21 @@ class FormatterManager return $this->formatters; } + /** + * @return array + */ + public function getNames() + { + $names = []; + + /** @var AbstractFormatter $formatter */ + foreach($this->formatters as $formatter) { + $names[] = $formatter->getName(); + } + + return $names; + } + /** * @param $name * @throws \OutOfBoundsException From 314a064f11d62d5bb13fb5473f6b88258352ab2d Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 16:57:38 +0200 Subject: [PATCH 020/158] =?UTF-8?q?Begin=20FormatterData=20=09modifi=C3=A9?= =?UTF-8?q?:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/For?= =?UTF-8?q?matter/FormatterData.php=20=09nouveau=20fichier:=20core/lib/The?= =?UTF-8?q?lia/Tests/FileFormat/Formatter/FormatterDataTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileFormat/Formatter/FormatterData.php | 28 ++++++-- .../Formatter/FormatterDataTest.php | 70 +++++++++++++++++++ 2 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php index a74ecef90..0a7ed344d 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php @@ -12,6 +12,8 @@ namespace Thelia\Core\FileFormat\Formatter; use Propel\Runtime\ActiveQuery\ModelCriteria; +use Propel\Runtime\Collection\ArrayCollection; +use Propel\Runtime\Collection\ObjectCollection; use Thelia\Core\Translation\Translator; /** @@ -34,15 +36,31 @@ class FormatterData public function loadModelCriteria(ModelCriteria $criteria) { - - $propelData = - $criteria - ->find() - ; + $propelData = $criteria->find(); if (empty($propelData)) { return null; } + $asColumns = $propelData->getFormatter()->getAsColumns(); + + if (empty($asColumns) && $propelData instanceof ObjectCollection) { + /** + * Full request ( without select nor join ) + */ + } elseif (empty($asColumns) && $propelData instanceof ArrayCollection) { + /** + * Request with joins, but without select + */ + } elseif (count($asColumns) > 1) { + /** + * Request with multiple select + */ + } elseif (count($asColumns) === 1) { + /** + * Request with one select + */ + } + } } diff --git a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php new file mode 100644 index 000000000..369e2bc41 --- /dev/null +++ b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php @@ -0,0 +1,70 @@ + + */ +class FormatterDataTest extends \PHPUnit_Framework_TestCase +{ + + protected $data; + + public function setUp() + { + new Translator(new Container()); + $this->data = new FormatterData(); + + $query = ProductQuery::create() + ->filterById([3,4,5], Criteria::IN); + + $this->data->loadModelCriteria($query); + + $query = ProductSaleElementsQuery::create() + ->joinProduct() + ->select(["ProductSaleElements.id", "Product.id"]) + ->filterById([3,4,5], Criteria::IN) + ; + + $this->data->loadModelCriteria($query); + + $query = ProductSaleElementsQuery::create() + ->joinProduct() + ->select(["ProductSaleElements.id"]) + ->filterById([3,4,5], Criteria::IN) + ; + + $this->data->loadModelCriteria($query); + + $query = ProductQuery::create() + ->joinProductSaleElements() + ->filterById([3,4,5], Criteria::IN); + + $this->data->loadModelCriteria($query); + } + + public function testA() + { + + } +} From 962c2eb7ad891d8d0c11c7ee13a9b0f0313a9269 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Mon, 7 Jul 2014 13:42:20 +0200 Subject: [PATCH 021/158] =?UTF-8?q?Add=20some=20tests=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Form?= =?UTF-8?q?atter/FormatterData.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataT?= =?UTF-8?q?est.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileFormat/Formatter/FormatterData.php | 124 ++++++- .../Formatter/FormatterDataTest.php | 314 +++++++++++++++++- 2 files changed, 419 insertions(+), 19 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php index 0a7ed344d..f2aaa8507 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php @@ -11,9 +11,10 @@ /*************************************************************************************/ namespace Thelia\Core\FileFormat\Formatter; +use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\ModelCriteria; -use Propel\Runtime\Collection\ArrayCollection; -use Propel\Runtime\Collection\ObjectCollection; +use Propel\Runtime\ActiveQuery\ModelJoin; +use Propel\Runtime\Map\TableMap; use Thelia\Core\Translation\Translator; /** @@ -26,14 +27,74 @@ class FormatterData /** @var array */ protected $data; + /** @var null|array */ + protected $aliases; + /** @var Translator */ protected $translator; - public function __construct() + /** + * @param array $aliases + * + * $aliases is a associative array where the key represents propel TYPE_PHP_NAME of column if you use + * loadModelCriteria, or your own aliases for setData, and the value + * is the alias. It can be null or empty if you don't want aliases, + * but remember to always define all the fields the you want: + * non aliases fields will be ignored. + */ + public function __construct(array $aliases = null) { $this->translator = Translator::getInstance(); + + if (!is_array($aliases)) { + $aliases = []; + } + + /** + * Lower all the values + */ + foreach ($aliases as $key => $value) { + $lowerKey = strtolower($key); + $lowerValue = strtolower($value); + if ($lowerKey !== $key) { + $aliases[$lowerKey] = $lowerValue; + unset($aliases[$key]); + } else { + $aliases[$key] = $lowerValue; + } + } + + $this->aliases = $aliases; } + /** + * @param array $data + * @return $this + * + * Sets raw data with aliases + */ + public function setData(array $data) + { + if (empty($this->aliases)) { + $this->data = $data; + return $this; + } + + $this->data = $this->applyAliases($data, $this->aliases); + + return $this; + } + + /** + * @param ModelCriteria $criteria + * @return $this|null + * + * Loads a model criteria. + * Warning: if you want to do multi table export, + * you'll have to use you own select and not the joinYourTable method. + * For more details, please see the unit test + * Thelia\Tests\FileFormat\Formatter\FormatterDataTest::testFormatSimpleMultipleTableQuery + */ public function loadModelCriteria(ModelCriteria $criteria) { $propelData = $criteria->find(); @@ -44,23 +105,62 @@ class FormatterData $asColumns = $propelData->getFormatter()->getAsColumns(); - if (empty($asColumns) && $propelData instanceof ObjectCollection) { - /** - * Full request ( without select nor join ) - */ - } elseif (empty($asColumns) && $propelData instanceof ArrayCollection) { - /** - * Request with joins, but without select - */ - } elseif (count($asColumns) > 1) { + /** + * Format it correctly + * After this pass, we MUST have a 2D array. + * The first may be keyed with integers. + */ + $formattedResult = $propelData + ->toArray(null, false, TableMap::TYPE_COLNAME); + + if (count($asColumns) > 1) { /** * Request with multiple select + * Apply propel aliases */ + $formattedResult = $this->applyAliases($formattedResult, $asColumns); } elseif (count($asColumns) === 1) { /** * Request with one select */ + $key = str_replace("\"", "", array_keys($asColumns)[0]); + $formattedResult = [[$key => $formattedResult[0]]]; } + $data = $this->applyAliases($formattedResult, $this->aliases); + + /** + * Then store it + */ + $this->data = $data; + + return $this; + } + + /** + * @param array $data + * @param array $aliases + */ + protected function applyAliases(array $data, array $aliases) + { + $formattedData = []; + + foreach ($data as $key=>$entry) { + $key = strtolower($key); + + if (is_array($entry)) { + $formattedData[$key] = $this->applyAliases($entry, $aliases); + } else { + $alias = isset($aliases[$key]) ? $aliases[$key] : $key; + $formattedData[$alias] = $entry; + } + } + + return $formattedData; + } + + public function getData() + { + return $this->data; } } diff --git a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php index 369e2bc41..31949a60c 100644 --- a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php @@ -11,13 +11,20 @@ /*************************************************************************************/ namespace Thelia\Tests\FileFormat\Formatter; +use Propel\Generator\Builder\Om\QueryBuilder; use Propel\Runtime\ActiveQuery\Criteria; +use Propel\Runtime\DataFetcher\ArrayDataFetcher; +use Propel\Runtime\Formatter\ArrayFormatter; +use Propel\Runtime\Map\TableMap; +use Propel\Runtime\Propel; use Symfony\Component\DependencyInjection\Container; use Thelia\Core\FileFormat\Formatter\FormatterData; +use Thelia\Core\Thelia; use Thelia\Core\Translation\Translator; use Thelia\Model\Base\ProductQuery; use Thelia\Model\Base\ProductSaleElementsQuery; -use Thelia\Model\LangQuery; +use Thelia\Model\ConfigQuery; +use Thelia\Model\Map\ProductTableMap; use Thelia\Model\Product; /** @@ -28,14 +35,11 @@ use Thelia\Model\Product; class FormatterDataTest extends \PHPUnit_Framework_TestCase { - protected $data; - public function setUp() { new Translator(new Container()); - $this->data = new FormatterData(); - $query = ProductQuery::create() + /* ->filterById([3,4,5], Criteria::IN); $this->data->loadModelCriteria($query); @@ -60,11 +64,307 @@ class FormatterDataTest extends \PHPUnit_Framework_TestCase ->joinProductSaleElements() ->filterById([3,4,5], Criteria::IN); - $this->data->loadModelCriteria($query); + $this->data->loadModelCriteria($query);*/ } - public function testA() + public function testFormatSimpleQuery() { + $formatterData = new FormatterData(); + $query = ConfigQuery::create() + ->limit(1) + ; + + $formattedData = $formatterData + ->loadModelCriteria($query) + ->getData() + ; + + /** @var \Thelia\Model\Config $result */ + $result = $query->findOne(); + + $formattedResult = [ + [ + "config.id" => $result->getId(), + "config.name" => $result->getName(), + "config.value" => $result->getValue(), + "config.created_at" => $result->getCreatedAt(), + "config.updated_at" => $result->getUpdatedAt(), + "config.hidden" => $result->getHidden(), + "config.secured" => $result->getHidden(), + ], + ]; + + $this->assertEquals($formattedResult,$formattedData); } + + public function testFormatSimpleQueryWithAliases() + { + /** + * Aliases must not be case sensitive + */ + $aliases = [ + "coNfiG.iD" => "id", + "conFig.NaMe" => "name", + "CoNfIg.Value" => "value", + "config.hidden" => "hidden", + "ConFig.Secured" => "secured", + ]; + + $formatterData = new FormatterData($aliases); + + $query = ConfigQuery::create() + ->limit(1) + ; + + $formattedData = $formatterData + ->loadModelCriteria($query) + ->getData() + ; + + /** @var \Thelia\Model\Config $result */ + $result = $query->findOne(); + + $formattedResult = [ + [ + "id" => $result->getId(), + "name" => $result->getName(), + "value" => $result->getValue(), + "config.created_at" => $result->getCreatedAt(), + "config.updated_at" => $result->getUpdatedAt(), + "hidden" => $result->getHidden(), + "secured" => $result->getHidden(), + ], + ]; + + $this->assertEquals($formattedResult,$formattedData); + } + + public function testFormatSimpleMultipleTableQuery() + { + $formatterData = new FormatterData(); + + + } + + public function testFormatSimpleMultipleTableQueryWithAliases() + { + /** + * Aliases must not be case sensitive + */ + $aliases = [ + "coNfiG.iD" => "id", + "conFig.NaMe" => "name", + "CoNfIg.Value" => "value", + "config.hidden" => "hidden", + "ConFig.Secured" => "secured", + ]; + + $formatterData = new FormatterData($aliases); + + $query = ConfigQuery::create() + ->limit(1) + ; + + $formattedData = $formatterData + ->loadModelCriteria($query) + ->getData() + ; + + /** @var \Thelia\Model\Config $result */ + $result = $query->findOne(); + + $formattedResult = [ + [ + "id" => $result->getId(), + "name" => $result->getName(), + "value" => $result->getValue(), + "config.created_at" => $result->getCreatedAt(), + "config.updated_at" => $result->getUpdatedAt(), + "hidden" => $result->getHidden(), + "secured" => $result->getHidden(), + ], + ]; + + $this->assertEquals($formattedResult,$formattedData); + } + + public function testSetRawDataDepth1() { + $formatterData = new FormatterData(); + + $data = [ + "foo" => "bar", + "baz" => "foo", + ]; + + $formattedData = $formatterData + ->setData($data) + ->getData() + ; + + $this->assertEquals($data,$formattedData); + } + + public function testSetRawDataDepth1WithAliases() { + $aliases = [ + "FoO" => "orange", + "Baz" => "banana", + ]; + + $formatterData = new FormatterData($aliases); + + $data = [ + "fOo" => "bar", + "bAZ" => "foo", + ]; + + $expectedData = [ + "orange" => "bar", + "banana" => "foo", + ]; + + $formattedData = $formatterData + ->setData($data) + ->getData() + ; + + $this->assertEquals($expectedData,$formattedData); + } + + public function testSetRawDataDepth2() { + $formatterData = new FormatterData(); + + $data = [ + [ + "orange" => "banana", + "apple" => "pear", + ], + [ + "strawberry" => "raspberry", + "blackberry" => "cranberry", + ] + ]; + + $formattedData = $formatterData + ->setData($data) + ->getData() + ; + + $this->assertEquals($data,$formattedData); + } + + public function testSetRawDataDepth2WithAliases() { + $aliases = [ + "orange" => "cherry", + "blackberry" => "banana", + ]; + + $formatterData = new FormatterData($aliases); + + $data = [ + [ + "orange" => "banana", + "apple" => "pear", + ], + [ + "strawberry" => "raspberry", + "blackberry" => "cranberry", + ] + ]; + + $expectedData = [ + [ + "cherry" => "banana", + "apple" => "pear", + ], + [ + "strawberry" => "raspberry", + "banana" => "cranberry", + ] + ]; + + $formattedData = $formatterData + ->setData($data) + ->getData() + ; + + $this->assertEquals($expectedData,$formattedData); + } + + public function testSetRawDataMultipleDepth() { + $formatterData = new FormatterData(); + + $data = [ + [ + "orange" => "banana", + "apple" => "pear", + ], + [ + "strawberry" => "raspberry", + "blackberry" => "cranberry", + ] + ]; + + $formattedData = $formatterData + ->setData($data) + ->getData() + ; + + $this->assertEquals($data,$formattedData); + } + + public function testSetRawDataMultipleDepthWithAliases() { + $aliases = [ + "orange" => "cherry", + "blackberry" => "banana", + ]; + + $formatterData = new FormatterData($aliases); + + $data = [ + "orange" => "banana", + "apple" => "pear", + [ + "orange" => "tomato", + "pepper" => "pear", + ], + [ + [ + "strawberry" => "raspberry", + "blackberry" => "cranberry", + ], + [ + "cherry" => "lemon", + "mango" => "cranberry", + ] + ], + ]; + + $expectedData = [ + "cherry" => "banana", + "apple" => "pear", + [ + "cherry" => "tomato", + "pepper" => "pear", + ], + [ + [ + "strawberry" => "raspberry", + "banana" => "cranberry", + ], + [ + "cherry" => "lemon", + "mango" => "cranberry", + ] + ], + ]; + + $formattedData = $formatterData + ->setData($data) + ->getData() + ; + + $this->assertEquals($expectedData,$formattedData); + } + } From 50adcecc27a18ccbfccadd03fcc4dcc8bb14ac47 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Mon, 7 Jul 2014 16:50:10 +0200 Subject: [PATCH 022/158] =?UTF-8?q?End=20formatter=20data=20and=20refactor?= =?UTF-8?q?=20Thelia\Core\FileFormat\Formatter=20=09renomm=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatter/Abs?= =?UTF-8?q?tractFormatter.php=20->=20core/lib/Thelia/Core/FileFormat/Forma?= =?UTF-8?q?tting/AbstractFormatter.php=20=09renomm=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatter/Exception?= =?UTF-8?q?/BadFormattedStringException.php=20->=20core/lib/Thelia/Core/Fi?= =?UTF-8?q?leFormat/Formatting/Exception/BadFormattedStringException.php?= =?UTF-8?q?=20=09renomm=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/C?= =?UTF-8?q?ore/FileFormat/Formatter/FormatterData.php=20->=20core/lib/Thel?= =?UTF-8?q?ia/Core/FileFormat/Formatting/FormatterData.php=20=09renomm?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Formatter/FormatterInterface.php=20->=20core/lib/Thelia/Core?= =?UTF-8?q?/FileFormat/Formatting/FormatterInterface.php=20=09renomm=C3=A9?= =?UTF-8?q?:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/For?= =?UTF-8?q?matter/FormatterManager.php=20->=20core/lib/Thelia/Core/FileFor?= =?UTF-8?q?mat/Formatting/FormatterManager.php=20=09renomm=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Tests/FileFormat/Formatter/Fo?= =?UTF-8?q?rmatterDataTest.php=20->=20core/lib/Thelia/Tests/FileFormat/For?= =?UTF-8?q?matting/FormatterDataTest.php=20=09renomm=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Tests/FileFormat/Formatter/Formatte?= =?UTF-8?q?rManagerTest.php=20->=20core/lib/Thelia/Tests/FileFormat/Format?= =?UTF-8?q?ting/FormatterManagerTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractFormatter.php | 4 +- .../Exception/BadFormattedStringException.php | 0 .../FormatterData.php | 11 +- .../FormatterInterface.php | 2 +- .../FormatterManager.php | 4 +- .../FormatterDataTest.php | 136 +++++++++--------- .../FormatterManagerTest.php | 12 +- 7 files changed, 80 insertions(+), 89 deletions(-) rename core/lib/Thelia/Core/FileFormat/{Formatter => Formatting}/AbstractFormatter.php (92%) rename core/lib/Thelia/Core/FileFormat/{Formatter => Formatting}/Exception/BadFormattedStringException.php (100%) rename core/lib/Thelia/Core/FileFormat/{Formatter => Formatting}/FormatterData.php (92%) rename core/lib/Thelia/Core/FileFormat/{Formatter => Formatting}/FormatterInterface.php (97%) rename core/lib/Thelia/Core/FileFormat/{Formatter => Formatting}/FormatterManager.php (96%) rename core/lib/Thelia/Tests/FileFormat/{Formatter => Formatting}/FormatterDataTest.php (79%) rename core/lib/Thelia/Tests/FileFormat/{Formatter => Formatting}/FormatterManagerTest.php (89%) diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php similarity index 92% rename from core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php rename to core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php index 605bc6362..103167d42 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php @@ -10,12 +10,12 @@ /* file that was distributed with this source code. */ /*************************************************************************************/ -namespace Thelia\Core\FileFormat\Formatter; +namespace Thelia\Core\FileFormat\Formatting; use Thelia\Core\FileFormat\FormatInterface; /** * Class AbstractFormatter - * @package Thelia\Core\FileFormat\Formatter + * @package Thelia\Core\FileFormat\Formatting * @author Benjamin Perche */ abstract class AbstractFormatter implements FormatInterface, FormatterInterface diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php b/core/lib/Thelia/Core/FileFormat/Formatting/Exception/BadFormattedStringException.php similarity index 100% rename from core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php rename to core/lib/Thelia/Core/FileFormat/Formatting/Exception/BadFormattedStringException.php diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php similarity index 92% rename from core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php rename to core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php index f2aaa8507..103e3d616 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php @@ -10,7 +10,7 @@ /* file that was distributed with this source code. */ /*************************************************************************************/ -namespace Thelia\Core\FileFormat\Formatter; +namespace Thelia\Core\FileFormat\Formatting; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\ModelCriteria; use Propel\Runtime\ActiveQuery\ModelJoin; @@ -19,7 +19,7 @@ use Thelia\Core\Translation\Translator; /** * Class FormatterData - * @package Thelia\Core\FileFormat\Formatter + * @package Thelia\Core\FileFormat\Formatting * @author Benjamin Perche */ class FormatterData @@ -90,10 +90,9 @@ class FormatterData * @return $this|null * * Loads a model criteria. - * Warning: if you want to do multi table export, - * you'll have to use you own select and not the joinYourTable method. - * For more details, please see the unit test - * Thelia\Tests\FileFormat\Formatter\FormatterDataTest::testFormatSimpleMultipleTableQuery + * Warning: This doesn't goodly support multi table queries. + * If you need to use more than one table, use a PDO instance and + * use the fetchArray() method, or select every columns you need */ public function loadModelCriteria(ModelCriteria $criteria) { diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterInterface.php similarity index 97% rename from core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php rename to core/lib/Thelia/Core/FileFormat/Formatting/FormatterInterface.php index 4d2d2d91e..c88c36c54 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterInterface.php @@ -10,7 +10,7 @@ /* file that was distributed with this source code. */ /*************************************************************************************/ -namespace Thelia\Core\FileFormat\Formatter; +namespace Thelia\Core\FileFormat\Formatting; /** * Interface FormatterInterface diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterManager.php similarity index 96% rename from core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php rename to core/lib/Thelia/Core/FileFormat/Formatting/FormatterManager.php index b7801c7a9..254982fe8 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterManager.php @@ -10,12 +10,12 @@ /* file that was distributed with this source code. */ /*************************************************************************************/ -namespace Thelia\Core\FileFormat\Formatter; +namespace Thelia\Core\FileFormat\Formatting; use Thelia\Core\Translation\Translator; /** * Class FormatterManager - * @package Thelia\Core\FileFormat\Formatter + * @package Thelia\Core\FileFormat\Formatting * @author Benjamin Perche */ class FormatterManager diff --git a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php b/core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php similarity index 79% rename from core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php rename to core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php index 31949a60c..d5747ef33 100644 --- a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php @@ -10,26 +10,18 @@ /* file that was distributed with this source code. */ /*************************************************************************************/ -namespace Thelia\Tests\FileFormat\Formatter; -use Propel\Generator\Builder\Om\QueryBuilder; -use Propel\Runtime\ActiveQuery\Criteria; -use Propel\Runtime\DataFetcher\ArrayDataFetcher; -use Propel\Runtime\Formatter\ArrayFormatter; -use Propel\Runtime\Map\TableMap; -use Propel\Runtime\Propel; +namespace Thelia\Tests\FileFormat\Formatting; use Symfony\Component\DependencyInjection\Container; -use Thelia\Core\FileFormat\Formatter\FormatterData; -use Thelia\Core\Thelia; +use Thelia\Core\FileFormat\Formatting\FormatterData; use Thelia\Core\Translation\Translator; -use Thelia\Model\Base\ProductQuery; use Thelia\Model\Base\ProductSaleElementsQuery; use Thelia\Model\ConfigQuery; +use Thelia\Model\Map\ProductSaleElementsTableMap; use Thelia\Model\Map\ProductTableMap; -use Thelia\Model\Product; /** * Class FormatterDataTest - * @package Thelia\Tests\FileFormat\Formatter + * @package Thelia\Tests\FileFormat\Formatting * @author Benjamin Perche */ class FormatterDataTest extends \PHPUnit_Framework_TestCase @@ -38,33 +30,6 @@ class FormatterDataTest extends \PHPUnit_Framework_TestCase public function setUp() { new Translator(new Container()); - - /* - ->filterById([3,4,5], Criteria::IN); - - $this->data->loadModelCriteria($query); - - $query = ProductSaleElementsQuery::create() - ->joinProduct() - ->select(["ProductSaleElements.id", "Product.id"]) - ->filterById([3,4,5], Criteria::IN) - ; - - $this->data->loadModelCriteria($query); - - $query = ProductSaleElementsQuery::create() - ->joinProduct() - ->select(["ProductSaleElements.id"]) - ->filterById([3,4,5], Criteria::IN) - ; - - $this->data->loadModelCriteria($query); - - $query = ProductQuery::create() - ->joinProductSaleElements() - ->filterById([3,4,5], Criteria::IN); - - $this->data->loadModelCriteria($query);*/ } public function testFormatSimpleQuery() @@ -140,29 +105,20 @@ class FormatterDataTest extends \PHPUnit_Framework_TestCase $this->assertEquals($formattedResult,$formattedData); } - public function testFormatSimpleMultipleTableQuery() + public function testFormatComplexQuery() { $formatterData = new FormatterData(); - - } - - public function testFormatSimpleMultipleTableQueryWithAliases() - { - /** - * Aliases must not be case sensitive - */ - $aliases = [ - "coNfiG.iD" => "id", - "conFig.NaMe" => "name", - "CoNfIg.Value" => "value", - "config.hidden" => "hidden", - "ConFig.Secured" => "secured", - ]; - - $formatterData = new FormatterData($aliases); - - $query = ConfigQuery::create() + $query = ProductSaleElementsQuery::create() + ->useProductQuery() + ->addAsColumn("\"".ProductTableMap::ID."\"", ProductTableMap::ID) + ->endUse() + ->select( + [ + ProductSaleElementsTableMap::ID, + ProductSaleElementsTableMap::QUANTITY, + ] + ) ->limit(1) ; @@ -170,23 +126,59 @@ class FormatterDataTest extends \PHPUnit_Framework_TestCase ->loadModelCriteria($query) ->getData() ; + /** @var array $data */ + $data = $query->findOne(); - /** @var \Thelia\Model\Config $result */ - $result = $query->findOne(); - - $formattedResult = [ + $expectedData = [ [ - "id" => $result->getId(), - "name" => $result->getName(), - "value" => $result->getValue(), - "config.created_at" => $result->getCreatedAt(), - "config.updated_at" => $result->getUpdatedAt(), - "hidden" => $result->getHidden(), - "secured" => $result->getHidden(), - ], + "product.id" => $data["product.ID"], + "product_sale_elements.id" => $data["product_sale_elements.ID"], + "product_sale_elements.quantity" => $data["product_sale_elements.QUANTITY"], + ] ]; - $this->assertEquals($formattedResult,$formattedData); + $this->assertEquals($expectedData, $formattedData); + } + + public function testFormatComplexQueryWithAliases() + { + $aliases = [ + "product.id" => "pid", + "product_sale_elements.id" => "pseid", + "product_sale_elements.quantity" => "stock" + ]; + + $formatterData = new FormatterData($aliases); + + $query = ProductSaleElementsQuery::create() + ->useProductQuery() + ->addAsColumn("\"".ProductTableMap::ID."\"", ProductTableMap::ID) + ->endUse() + ->select( + [ + ProductSaleElementsTableMap::ID, + ProductSaleElementsTableMap::QUANTITY, + ] + ) + ->limit(1) + ; + + $formattedData = $formatterData + ->loadModelCriteria($query) + ->getData() + ; + /** @var array $data */ + $data = $query->findOne(); + + $expectedData = [ + [ + "pid" => $data["product.ID"], + "pseid" => $data["product_sale_elements.ID"], + "stock" => $data["product_sale_elements.QUANTITY"], + ] + ]; + + $this->assertEquals($expectedData, $formattedData); } public function testSetRawDataDepth1() { diff --git a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php b/core/lib/Thelia/Tests/FileFormat/Formatting/FormatterManagerTest.php similarity index 89% rename from core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php rename to core/lib/Thelia/Tests/FileFormat/Formatting/FormatterManagerTest.php index 39bf06cb3..b28a2cb88 100644 --- a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Formatting/FormatterManagerTest.php @@ -10,15 +10,15 @@ /* file that was distributed with this source code. */ /*************************************************************************************/ -namespace Thelia\Tests\FileFormat\Formatter; +namespace Thelia\Tests\FileFormat\Formatting; use Symfony\Component\DependencyInjection\Container; -use Thelia\Core\FileFormat\Formatter\AbstractFormatter; -use Thelia\Core\FileFormat\Formatter\FormatterManager; +use Thelia\Core\FileFormat\Formatting\AbstractFormatter; +use Thelia\Core\FileFormat\Formatting\FormatterManager; use Thelia\Core\Translation\Translator; /** * Class FormatterManagerTest - * @package Thelia\Tests\FileFormat\Formatter + * @package Thelia\Tests\FileFormat\Formatting * @author Benjamin Perche */ class FormatterManagerTest extends \PHPUnit_Framework_TestCase @@ -39,7 +39,7 @@ class FormatterManagerTest extends \PHPUnit_Framework_TestCase public function testAddFormatter() { /** @var AbstractFormatter $instance */ - $instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatter\\AbstractFormatter"); + $instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatting\\AbstractFormatter"); $this->manager->add($instance); @@ -53,7 +53,7 @@ class FormatterManagerTest extends \PHPUnit_Framework_TestCase public function testDeleteFormatter() { /** @var AbstractFormatter $instance */ - $instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatter\\AbstractFormatter"); + $instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatting\\AbstractFormatter"); $this->manager->add($instance); From 6af18cd3e722cb9a5c3b745dde8cfc7a651c8db8 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Wed, 2 Jul 2014 14:00:49 +0200 Subject: [PATCH 023/158] =?UTF-8?q?Define=20archive=20builders=20and=20for?= =?UTF-8?q?matters=20=09nouveau=20fichier:=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Archive/AbstractArchiveBuilder.php=20=09nouveau=20fichier:?= =?UTF-8?q?=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipAr?= =?UTF-8?q?chiveBuilder.php=20=09nouveau=20fichier:=20core/lib/Thelia/Core?= =?UTF-8?q?/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php=20?= =?UTF-8?q?=09nouveau=20fichier:=20core/lib/Thelia/Core/FileFormat/Archive?= =?UTF-8?q?/ArchiveBuilderInterface.php=20=09nouveau=20fichier:=20core/lib?= =?UTF-8?q?/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php=20=09?= =?UTF-8?q?nouveau=20fichier:=20core/lib/Thelia/Core/FileFormat/FormatInte?= =?UTF-8?q?rface.php=20=09nouveau=20fichier:=20core/lib/Thelia/Core/FileFo?= =?UTF-8?q?rmat/Formatter/AbstractFormatter.php=20=09nouveau=20fichier:=20?= =?UTF-8?q?core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormatte?= =?UTF-8?q?dStringException.php=20=09nouveau=20fichier:=20core/lib/Thelia/?= =?UTF-8?q?Core/FileFormat/Formatter/FormatterManager.php=20=09nouveau=20f?= =?UTF-8?q?ichier:=20core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuild?= =?UTF-8?q?er/TestResources/bad=5Fformatted.zip=20=09nouveau=20fichier:=20?= =?UTF-8?q?core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestRes?= =?UTF-8?q?ources/test=5Ffile=20=09nouveau=20fichier:=20core/lib/Thelia/Te?= =?UTF-8?q?sts/FileFormat/Archive/ArchiveBuilder/TestResources/well=5Fform?= =?UTF-8?q?atted.zip=20=09nouveau=20fichier:=20core/lib/Thelia/Tests/FileF?= =?UTF-8?q?ormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php=20=09nou?= =?UTF-8?q?veau=20fichier:=20core/lib/Thelia/Tests/FileFormat/Archive/Arch?= =?UTF-8?q?iveBuilderManagerTest.php=20=09nouveau=20fichier:=20core/lib/Th?= =?UTF-8?q?elia/Tests/FileFormat/Formatter/FormatterManagerTest.php=20=09n?= =?UTF-8?q?ouveau=20fichier:=20core/lib/Thelia/Tests/Tools/FakeFileDownloa?= =?UTF-8?q?der.php=20=09nouveau=20fichier:=20core/lib/Thelia/Tests/Tools/F?= =?UTF-8?q?ileDownloaderTest.php=20=09nouveau=20fichier:=20core/lib/Thelia?= =?UTF-8?q?/Tools/FileDownload/FileDownloader.php=20=09nouveau=20fichier:?= =?UTF-8?q?=20core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.?= =?UTF-8?q?php=20=09nouveau=20fichier:=20core/lib/Thelia/Tools/FileDownloa?= =?UTF-8?q?d/FileDownloaderInterface.php=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Tools/URL.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/AbstractArchiveBuilder.php | 7 + .../ArchiveBuilder/ZipArchiveBuilder.php | 357 ++++++++++++++++++ .../ArchiveBuilder/ZipArchiveException.php | 23 ++ .../Archive/ArchiveBuilderInterface.php | 51 +++ .../Archive/ArchiveBuilderManager.php | 41 ++ .../Core/FileFormat/FormatInterface.php | 4 + .../Formatter/AbstractFormatter.php | 41 ++ .../Exception/BadFormattedStringException.php | 23 ++ .../FileFormat/Formatter/FormatterManager.php | 69 ++++ .../ArchiveBuilder/ZipArchiveBuilderTest.php | 152 ++++++++ .../Archive/ArchiveBuilderManagerTest.php | 4 + .../Formatter/FormatterManagerTest.php | 74 ++++ .../Thelia/Tests/Tools/FakeFileDownloader.php | 9 + .../Thelia/Tests/Tools/FileDownloaderTest.php | 8 + .../Thelia/Tests/Tools/FileManagerTest.php | 4 +- .../Tools/FileDownload/FileDownloader.php | 16 + .../FileDownload/FileDownloaderAwareTrait.php | 8 + .../FileDownload/FileDownloaderInterface.php | 13 + core/lib/Thelia/Tools/URL.php | 4 + 19 files changed, 906 insertions(+), 2 deletions(-) create mode 100644 core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php create mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php create mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php create mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php create mode 100644 core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php diff --git a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php index e873d74ef..cd4cb662f 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php @@ -12,10 +12,13 @@ namespace Thelia\Core\FileFormat\Archive; use Thelia\Core\FileFormat\FormatInterface; +<<<<<<< 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\Tools\FileDownload\FileDownloaderAwareTrait; /** @@ -26,6 +29,7 @@ use Thelia\Tools\FileDownload\FileDownloaderAwareTrait; abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilderInterface { use FileDownloaderAwareTrait; +<<<<<<< HEAD const TEMP_DIRECTORY_NAME = "archive_builder"; @@ -212,3 +216,6 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder $this->environment = $environment; } } +======= +} +>>>>>>> Define archive builders and formatters diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index 220cd24e4..57357a4cb 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -12,10 +12,19 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder; +<<<<<<< HEAD use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException; use Thelia\Core\HttpFoundation\Response; use Thelia\Core\Thelia; use Thelia\Exception\FileNotReadableException; +======= +use Thelia\Core\HttpFoundation\Response; +use Thelia\Core\Thelia; +use Thelia\Core\Translation\Translator; +use Thelia\Exception\FileNotFoundException; +use Thelia\Exception\FileNotReadableException; +use Thelia\Log\Tlog; +>>>>>>> Define archive builders and formatters use Thelia\Tools\FileDownload\FileDownloaderInterface; /** @@ -31,34 +40,79 @@ use Thelia\Tools\FileDownload\FileDownloaderInterface; */ class ZipArchiveBuilder extends AbstractArchiveBuilder { +<<<<<<< HEAD +======= + const TEMP_DIRECTORY_NAME = "archive_builder"; + +>>>>>>> Define archive builders and formatters /** * @var \ZipArchive */ protected $zip; +<<<<<<< HEAD public function __construct() { parent::__construct(); $this->zip = new \ZipArchive(); +======= + /** + * @var string This is the absolute path to the zip file in cache + */ + protected $zip_cache_file; + + /** + * @var string This is the path of the cache + */ + protected $cache_dir; + + /** + * @var \Thelia\Log\Tlog + */ + protected $logger; + + /** + * @var Translator + */ + protected $translator; + + public function __construct() + { + $this->zip = new \ZipArchive(); + + $this->logger = Tlog::getNewInstance(); + + $this->translator = Translator::getInstance(); +>>>>>>> Define archive builders and formatters } /** * On the destruction of the class, * remove the temporary file. */ +<<<<<<< HEAD public function __destruct() +======= + function __destruct() +>>>>>>> Define archive builders and formatters { if ($this->zip instanceof \ZipArchive) { @$this->zip->close(); +<<<<<<< HEAD if (file_exists($this->cacheFile)) { unlink($this->cacheFile); +======= + if (file_exists($this->zip_cache_file)) { + unlink($this->zip_cache_file); +>>>>>>> Define archive builders and formatters } } } /** +<<<<<<< HEAD * @param string $filePath It is the path to access the file. * @param string $directoryInArchive This is the directory where it will be stored in the archive * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name @@ -67,6 +121,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException * @throws \ErrorException +======= + * @param string $filePath It is the path to access the file. + * @param string $directoryInArchive This is the directory where it will be stored in the archive + * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name + * @param bool $isOnline + * @return $this + * @throws \Thelia\Exception\FileNotFoundException + * @throws \Thelia\Exception\FileNotReadableException +>>>>>>> Define archive builders and formatters * * This methods adds a file in the archive. * If the file is local, $isOnline must be false, @@ -74,6 +137,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function addFile($filePath, $directoryInArchive = null, $name = null, $isOnline = false) { +<<<<<<< HEAD $directoryInArchive = $this->formatDirectoryPath($directoryInArchive); /** @@ -178,6 +242,18 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $directoryInArchive = $this->formatDirectoryPath($directoryPath); if (!empty($directoryInArchive)) { +======= + /** + * Add empty directory if it doesn't exist + */ + if (empty($directoryInArchive) || preg_match("#^\/+$#", $directoryInArchive)) { + $directoryInArchive = ""; + } + + if(!empty($directoryInArchive) && $directoryInArchive != "/") { + $directoryInArchive = $this->getDirectoryPath($directoryInArchive); + +>>>>>>> Define archive builders and formatters if (!$this->zip->addEmptyDir($directoryInArchive)) { throw new \ErrorException( $this->translator->trans( @@ -190,6 +266,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } } +<<<<<<< HEAD return $this; } @@ -263,6 +340,54 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } return $initialString . "/"; +======= + if ($isOnline) { + $fileDownloadCache = $this->cache_dir . DS . "download"; + + $this->getFileDownloader() + ->download($filePath, $fileDownloadCache) + ; + + $filePath = $fileDownloadCache; + } else { + if (!file_exists($filePath)) { + $this->throwFileNotFound($filePath); + } else if (!is_readable($filePath)) { + throw new FileNotReadableException( + $this->translator + ->trans( + "The file %file is not readable", + [ + "%file" => $filePath, + ] + ) + ); + } + } + + if (empty($name)) { + $name = basename($filePath); + } + + $destination = $directoryInArchive . $name; + + if (!$this->zip->addFile($filePath,$destination)) { + $translatedErrorMessage = $this->translator->trans( + "An error occurred while adding this file to the archive: %file", + [ + "%file" => $filePath + ] + ); + + $this->logger->error($translatedErrorMessage); + + throw new \ErrorException($translatedErrorMessage); + } + + $this->commit(); + + return $this; +>>>>>>> Define archive builders and formatters } /** @@ -275,7 +400,11 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function deleteFile($pathInArchive) { +<<<<<<< HEAD $pathInArchive = $this->formatFilePath($pathInArchive); +======= + $pathInArchive = $this->getFilePath($pathInArchive); +>>>>>>> Define archive builders and formatters if (!$this->hasFile($pathInArchive)) { $this->throwFileNotFound($pathInArchive); @@ -302,28 +431,48 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * * This method return an instance of a Response with the archive as content. */ +<<<<<<< HEAD public function buildArchiveResponse($filename) +======= + public function buildArchiveResponse() +>>>>>>> Define archive builders and formatters { $this->zip->comment = "Generated by Thelia v" . Thelia::THELIA_VERSION; $this->commit(); +<<<<<<< HEAD if (!file_exists($this->cacheFile)) { $this->throwFileNotFound($this->cacheFile); } if (!is_readable($this->cacheFile)) { +======= + if (!file_exists($this->zip_cache_file)) { + $this->throwFileNotFound($this->zip_cache_file); + } + + if (!is_readable($this->zip_cache_file)) { +>>>>>>> Define archive builders and formatters throw new FileNotReadableException( $this->translator->trans( "The cache file %file is not readable", [ +<<<<<<< HEAD "%file" => $this->cacheFile +======= + "%file" => $this->zip_cache_file +>>>>>>> Define archive builders and formatters ] ) ); } +<<<<<<< HEAD $content = file_get_contents($this->cacheFile); +======= + $content = file_get_contents($this->zip_cache_file); +>>>>>>> Define archive builders and formatters $this->zip->close(); @@ -331,22 +480,35 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $content, 200, [ +<<<<<<< HEAD "Content-Type" => $this->getMimeType(), "Content-Disposition" => $filename . "." . $this->getExtension(), +======= + "Content-Type" => $this->getMimeType() +>>>>>>> Define archive builders and formatters ] ); } /** +<<<<<<< HEAD * @param string $pathToArchive * @param bool $isOnline * @param FileDownloaderInterface $fileDownloader * @return ZipArchiveBuilder +======= + * @param string $pathToArchive + * @param string $environment + * @param bool $isOnline + * @param FileDownloaderInterface $fileDownloader + * @return $this +>>>>>>> Define archive builders and formatters * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException * * Loads an archive */ +<<<<<<< HEAD public function loadArchive($pathToArchive, $isOnline = false) { $back = $this->zip; @@ -369,6 +531,64 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } return $zip; +======= + public static function loadArchive( + $pathToArchive, + $environment, + $isOnline = false, + FileDownloaderInterface $fileDownloader = null + ) { + /** @var ZipArchiveBuilder $instance */ + $instance = new static(); + + $instance->setEnvironment($environment); + $zip = $instance->getRawZipArchive(); + $zip->close(); + + if ($fileDownloader !== null) { + $instance->setFileDownloader($fileDownloader); + } + + if ($isOnline) { + /** + * It's an online file + */ + $instance->getFileDownloader() + ->download($pathToArchive, $instance->getZipCacheFile()) + ; + } else { + /** + * It's a local file + */ + if (!is_file($pathToArchive) || !is_readable($pathToArchive)) { + $instance->throwFileNotFound($pathToArchive); + } + + if (!copy($pathToArchive, $instance->getZipCacheFile())) { + $translatedErrorMessage = $instance->getTranslator()->trans( + "An unknown error happend while copying %prev to %dest", + [ + "%prev" => $pathToArchive, + "%dest" => $instance->getZipCacheFile(), + ] + ); + + $instance->getLogger() + ->error($translatedErrorMessage) + ; + + throw new \ErrorException($translatedErrorMessage); + } + } + + if (true !== $return = $zip->open($instance->getZipCacheFile())) { + throw new ZipArchiveException( + $instance->getZipErrorMessage($return) + ); + } + + return $instance; +>>>>>>> Define archive builders and formatters } /** @@ -380,25 +600,41 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder public function hasFile($pathToFile) { return $this->zip +<<<<<<< HEAD ->locateName($this->formatFilePath($pathToFile)) !== false +======= + ->locateName($this->getFilePath($pathToFile)) !== false +>>>>>>> Define archive builders and formatters ; } /** +<<<<<<< HEAD * @param string $directory +======= + * @param string $directory +>>>>>>> Define archive builders and formatters * @return bool * * Checks if the link $directory exists and if it's not a file. */ public function hasDirectory($directory) { +<<<<<<< HEAD $link = $this->zip->locateName($this->formatDirectoryPath($directory)); +======= + $link = $this->zip->locateName($this->getDirectoryPath($directory)); +>>>>>>> Define archive builders and formatters return $link !== false; } /** +<<<<<<< HEAD * @param string $environment +======= + * @param string $environment +>>>>>>> Define archive builders and formatters * @return $this * * Sets the execution environment of the Kernel, @@ -406,9 +642,42 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function setEnvironment($environment) { +<<<<<<< HEAD parent::setEnvironment($environment); $cacheFile = $this->generateCacheFile($environment); +======= + $theliaCacheDir = THELIA_CACHE_DIR . $environment . DS; + + if (!is_writable($theliaCacheDir)) { + throw new \ErrorException( + $this->translator->trans( + "The cache directory \"%env\" is not writable", + [ + "%env" => $environment + ] + ) + ); + } + + $archiveBuilderCacheDir = $this->cache_dir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; + + if (!is_dir($archiveBuilderCacheDir) && !mkdir($archiveBuilderCacheDir, 0755)) { + throw new \ErrorException( + $this->translator->trans( + "Error while creating the directory \"%directory\"", + [ + "%directory" => static::TEMP_DIRECTORY_NAME + ] + ) + ); + } + + $cacheFileName = md5 (uniqid()); + + $cacheFile = $archiveBuilderCacheDir . DS . $cacheFileName; + $cacheFile .= "." . $this->getExtension(); +>>>>>>> Define archive builders and formatters if (file_exists($cacheFile)) { unlink($cacheFile); @@ -419,15 +688,26 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder \ZipArchive::CREATE ); +<<<<<<< HEAD if ($opening !== true) { throw new \ErrorException( $this->translator->trans( "An unknown error append" +======= + if($opening !== true) { + throw new \ErrorException( + $this->translator->trans( + "Unknown" +>>>>>>> Define archive builders and formatters ) ); } +<<<<<<< HEAD $this->cacheFile = $cacheFile; +======= + $this->zip_cache_file = $cacheFile; +>>>>>>> Define archive builders and formatters return $this; } @@ -499,7 +779,11 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder public function commit() { $this->zip->close(); +<<<<<<< HEAD $result = $this->zip->open($this->getCacheFile()); +======= + $result = $this->zip->open($this->getZipCacheFile()); +>>>>>>> Define archive builders and formatters if ($result !== true) { throw new \ErrorException( @@ -513,12 +797,20 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** +<<<<<<< HEAD * @param string $initialString +======= + * @param string $initialString +>>>>>>> Define archive builders and formatters * @return string * * Gives a valid file path for \ZipArchive */ +<<<<<<< HEAD public function formatFilePath($initialString) +======= + public function getFilePath($initialString) +>>>>>>> Define archive builders and formatters { /** * Remove the / at the beginning and the end. @@ -533,27 +825,59 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) { $initialString = "/" . $initialString; } +<<<<<<< HEAD +======= +>>>>>>> Define archive builders and formatters return $initialString; } /** +<<<<<<< HEAD * @param string $initialString +======= + * @param string $initialString +>>>>>>> Define archive builders and formatters * @return string * * Gives a valid directory path for \ZipArchive */ +<<<<<<< HEAD public function formatDirectoryPath($initialString) { $initialString = $this->formatFilePath($initialString); if ($initialString !== "" && $initialString[0] !== "/") { +======= + public function getDirectoryPath($initialString) + { + $initialString = $this->getFilePath($initialString); + + if ($initialString[0] !== "/") { +>>>>>>> Define archive builders and formatters $initialString = "/" . $initialString; } return $initialString . "/"; } +<<<<<<< HEAD +======= + public function throwFileNotFound($file) + { + + throw new FileNotFoundException( + $this->getTranslator() + ->trans( + "The file %file is missing or is not readable", + [ + "%file" => $file, + ] + ) + ); + } + +>>>>>>> Define archive builders and formatters /** * @return string * @@ -595,10 +919,43 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** +<<<<<<< HEAD +======= + * @return Tlog + */ + public function getLogger() + { + return $this->logger; + } + + /** + * @return Translator + */ + public function getTranslator() + { + return $this->translator; + } + + /** +>>>>>>> Define archive builders and formatters * @return \ZipArchive */ public function getRawZipArchive() { return $this->zip; } +<<<<<<< HEAD } +======= + + public function getZipCacheFile() + { + return $this->zip_cache_file; + } + + public function getCacheDir() + { + return $this->cache_dir; + } +} +>>>>>>> Define archive builders and formatters diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php new file mode 100644 index 000000000..c85fce339 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php @@ -0,0 +1,23 @@ + + */ +class ZipArchiveException extends \ErrorException +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php index 0ff882ae5..96de43666 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -17,11 +17,16 @@ namespace Thelia\Core\FileFormat\Archive; * @package Thelia\Core\FileFormat\Archive * @author Benjamin Perche * +<<<<<<< HEAD * This interface defines the methods that an archive builder must have. +======= + * This interface defines the methods that an archive creator must have. +>>>>>>> Define archive builders and formatters */ interface ArchiveBuilderInterface { /** +<<<<<<< HEAD * @param string $filePath It is the path to access the file. * @param string $directoryInArchive This is the directory where it will be stored in the archive * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name @@ -30,6 +35,15 @@ interface ArchiveBuilderInterface * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException * @throws \ErrorException +======= + * @param string $filePath It is the path to access the file. + * @param string $directoryInArchive This is the directory where it will be stored in the archive + * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name + * @param bool $isOnline + * @return $this + * @throws \Thelia\Exception\FileNotFoundException + * @throws \Thelia\Exception\FileNotReadableException +>>>>>>> Define archive builders and formatters * * This methods adds a file in the archive. * If the file is local, $isOnline must be false, @@ -38,6 +52,7 @@ interface ArchiveBuilderInterface public function addFile($filePath, $directoryInArchive = "/", $name = null, $isOnline = false); /** +<<<<<<< HEAD * @param $content * @param $name * @param string $directoryInArchive @@ -63,12 +78,18 @@ interface ArchiveBuilderInterface * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException +======= + * @param $pathInArchive + * @return $this + * @throws \Thelia\Exception\FileNotFoundException +>>>>>>> Define archive builders and formatters * * This method deletes a file in the archive */ public function deleteFile($pathInArchive); /** +<<<<<<< HEAD * @param $directoryPath * @return $this * @throws \ErrorException @@ -79,22 +100,36 @@ interface ArchiveBuilderInterface /** * @params string $filename +======= +>>>>>>> Define archive builders and formatters * @return \Thelia\Core\HttpFoundation\Response * * This method return an instance of a Response with the archive as content. */ +<<<<<<< HEAD public function buildArchiveResponse($filename); /** * @param string $pathToArchive * @param bool $isOnline +======= + public function buildArchiveResponse(); + + /** + * @param string $pathToArchive + * @param bool $isOnline +>>>>>>> Define archive builders and formatters * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException * * Loads an archive */ +<<<<<<< HEAD public function loadArchive($pathToArchive, $isOnline = false); +======= + public static function loadArchive($pathToArchive, $environment, $isOnline = false); +>>>>>>> Define archive builders and formatters /** * @param $pathToFile @@ -105,11 +140,27 @@ interface ArchiveBuilderInterface public function hasFile($pathToFile); /** +<<<<<<< HEAD * @param string $directory +======= + * @param string $directory +>>>>>>> Define archive builders and formatters * @return bool * * Check if the archive has a directory */ public function hasDirectory($directory); +<<<<<<< HEAD } +======= + /** + * @param string $environment + * @return $this + * + * Sets the execution environment of the Kernel, + * used to know which cache is used. + */ + public function setEnvironment($environment); +} +>>>>>>> Define archive builders and formatters diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php index 938445822..7e62c2c34 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php @@ -20,8 +20,12 @@ use Thelia\Core\Translation\Translator; */ class ArchiveBuilderManager { +<<<<<<< HEAD /** @var array */ protected $archiveBuilders = array(); +======= + protected $archiveCreators = array(); +>>>>>>> Define archive builders and formatters protected $environment; @@ -30,6 +34,7 @@ class ArchiveBuilderManager $this->environment = $environment; } /** +<<<<<<< HEAD * @param AbstractArchiveBuilder $archiveBuilder * @return $this */ @@ -39,6 +44,17 @@ class ArchiveBuilderManager $archiveBuilder->setEnvironment($this->environment); $this->archiveBuilders[$archiveBuilder->getName()] = $archiveBuilder; +======= + * @param AbstractArchiveBuilder $archiveCreator + * @return $this + */ + public function add(AbstractArchiveBuilder $archiveCreator) + { + if (null !== $archiveCreator) { + $archiveCreator->setEnvironment($this->environment); + + $this->archiveCreators[$archiveCreator->getName()] = $archiveCreator; +>>>>>>> Define archive builders and formatters } return $this; @@ -51,16 +67,32 @@ class ArchiveBuilderManager */ public function delete($name) { +<<<<<<< HEAD if (!array_key_exists($name, $this->archiveBuilders)) { $this->throwOutOfBounds($name); } unset($this->archiveBuilders[$name]); +======= + if (!array_key_exists($name, $this->archiveCreators)) { + throw new \OutOfBoundsException( + Translator::getInstance()->trans( + "The archive creator %name doesn't exist", + [ + "%name" => $name + ] + ) + ); + } + + unset($this->archiveCreators[$name]); +>>>>>>> Define archive builders and formatters return $this; } /** +<<<<<<< HEAD * @return array */ public function getAll() @@ -104,3 +136,12 @@ class ArchiveBuilderManager ); } } +======= + * @return array[AbstractArchiveBuilder] + */ + public function getAll() + { + return $this->archiveCreators; + } +} +>>>>>>> Define archive builders and formatters diff --git a/core/lib/Thelia/Core/FileFormat/FormatInterface.php b/core/lib/Thelia/Core/FileFormat/FormatInterface.php index 4b327271d..f51e35905 100644 --- a/core/lib/Thelia/Core/FileFormat/FormatInterface.php +++ b/core/lib/Thelia/Core/FileFormat/FormatInterface.php @@ -55,4 +55,8 @@ interface FormatInterface * return "application/json"; */ public function getMimeType(); +<<<<<<< HEAD } +======= +} +>>>>>>> Define archive builders and formatters diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php new file mode 100644 index 000000000..f991535c8 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php @@ -0,0 +1,41 @@ + + */ +abstract class AbstractFormatter implements FormatInterface +{ + /** + * @param array $data + * @return mixed + * + * Encodes an array to the desired format. + * $data array only contains array and scalar data. + */ + abstract public function encode(array $data); + + /** + * @param $data + * @return array + * @throws \Thelia\Core\FileFormat\Formatter\Exception\BadFormattedStringException + * + * this method must do exactly the opposite of encode and return + * an array composed of array and scalar data. + */ + abstract public function decode($data); +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php b/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php new file mode 100644 index 000000000..6d763a01b --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php @@ -0,0 +1,23 @@ + + */ +class BadFormattedStringException extends \ErrorException +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php new file mode 100644 index 000000000..cc8aad8e4 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php @@ -0,0 +1,69 @@ + + */ +class FormatterManager +{ + + protected $formatters = array(); + + /** + * @param $archiveCreator + * @return $this + */ + public function add(AbstractFormatter $formatter) + { + if (null !== $formatter) { + $this->formatters[$formatter->getName()] = $formatter; + } + + return $this; + } + + /** + * @param $name + * @return $this + * @throws \OutOfBoundsException + */ + public function delete($name) + { + if (!array_key_exists($name, $this->formatters)) { + throw new \OutOfBoundsException( + Translator::getInstance()->trans( + "The formatter %name doesn't exist", + [ + "%name" => $name + ] + ) + ); + } + + unset($this->formatters[$name]); + + return $this; + } + + /** + * @return array[AbstractFormatter] + */ + public function getAll() + { + return $this->formatters; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index 450af71b2..d9e3f64a0 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -40,65 +40,115 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->zip = new ZipArchiveBuilder(); +<<<<<<< HEAD $this->zip->setEnvironment("dev"); $this->loadedZip = $this->zip->loadArchive( __DIR__ . DS . "TestResources/well_formatted.zip" +======= + $this->loadedZip = $this->zip->loadArchive( + __DIR__ . DS . "TestResources/well_formatted.zip", + "dev" +>>>>>>> Define archive builders and formatters ); } /** * This method formats a path to be compatible with \ZipArchive +<<<<<<< HEAD */ public function testFormatFilePath() { $this->assertEquals( "foo", $this->zip->formatFilePath("foo") +======= + * + * + */ + public function testGetFilePath() + { + $this->assertEquals( + "foo", + $this->zip->getFilePath("foo") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "foo", +<<<<<<< HEAD $this->zip->formatFilePath("/foo") +======= + $this->zip->getFilePath("/foo") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "foo", +<<<<<<< HEAD $this->zip->formatFilePath("foo/") +======= + $this->zip->getFilePath("foo/") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "foo", +<<<<<<< HEAD $this->zip->formatFilePath("/foo/") +======= + $this->zip->getFilePath("/foo/") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/bar", +<<<<<<< HEAD $this->zip->formatFilePath("foo/bar") +======= + $this->zip->getFilePath("foo/bar") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/bar", +<<<<<<< HEAD $this->zip->formatFilePath("/foo/bar") +======= + $this->zip->getFilePath("/foo/bar") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/bar", +<<<<<<< HEAD $this->zip->formatFilePath("/foo//bar/") +======= + $this->zip->getFilePath("/foo//bar/") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/bar", +<<<<<<< HEAD $this->zip->formatFilePath("/foo/bar/") +======= + $this->zip->getFilePath("/foo/bar/") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/bar/baz", +<<<<<<< HEAD $this->zip->formatFilePath("foo/bar/baz") +======= + $this->zip->getFilePath("foo/bar/baz") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/bar/baz", +<<<<<<< HEAD $this->zip->formatFilePath("//foo/bar///baz/") ); } @@ -108,58 +158,110 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->assertEquals( "/foo/", $this->zip->formatDirectoryPath("foo") +======= + $this->zip->getFilePath("//foo/bar///baz/") + ); + } + + public function testGetDirectoryPath() + { + $this->assertEquals( + "/foo/", + $this->zip->getDirectoryPath("foo") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/", +<<<<<<< HEAD $this->zip->formatDirectoryPath("/foo") +======= + $this->zip->getDirectoryPath("/foo") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/", +<<<<<<< HEAD $this->zip->formatDirectoryPath("foo/") +======= + $this->zip->getDirectoryPath("foo/") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/", +<<<<<<< HEAD $this->zip->formatDirectoryPath("/foo/") +======= + $this->zip->getDirectoryPath("/foo/") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/bar/", +<<<<<<< HEAD $this->zip->formatDirectoryPath("foo/bar") +======= + $this->zip->getDirectoryPath("foo/bar") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/bar/", +<<<<<<< HEAD $this->zip->formatDirectoryPath("/foo/bar") +======= + $this->zip->getDirectoryPath("/foo/bar") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/bar/", +<<<<<<< HEAD $this->zip->formatDirectoryPath("/foo//bar/") +======= + $this->zip->getDirectoryPath("/foo//bar/") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/bar/", +<<<<<<< HEAD $this->zip->formatDirectoryPath("/foo/bar/") +======= + $this->zip->getDirectoryPath("/foo/bar/") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/bar/baz/", +<<<<<<< HEAD $this->zip->formatDirectoryPath("foo/bar/baz") +======= + $this->zip->getDirectoryPath("foo/bar/baz") +>>>>>>> Define archive builders and formatters ); $this->assertEquals( "/foo/bar/baz/", +<<<<<<< HEAD $this->zip->formatDirectoryPath("//foo/bar///baz/") +======= + $this->zip->getDirectoryPath("//foo/bar///baz/") +>>>>>>> Define archive builders and formatters ); } public function testLoadValidZip() { $loadedZip = $this->zip->loadArchive( +<<<<<<< HEAD __DIR__ . DS . "TestResources/well_formatted.zip" +======= + __DIR__ . DS . "TestResources/well_formatted.zip", + "dev" +>>>>>>> Define archive builders and formatters ); $this->assertInstanceOf( @@ -169,13 +271,22 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase } /** +<<<<<<< HEAD * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException +======= + * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException +>>>>>>> Define archive builders and formatters * @expectedExceptionMessage [Zip Error] The file is not a zip archive */ public function testLoadNotValidZip() { $this->zip->loadArchive( +<<<<<<< HEAD __DIR__ . DS . "TestResources/bad_formatted.zip" +======= + __DIR__ . DS . "TestResources/bad_formatted.zip", + "dev" +>>>>>>> Define archive builders and formatters ); } @@ -185,31 +296,56 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testLoadNotExistingFile() { $this->zip->loadArchive( +<<<<<<< HEAD __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip" +======= + __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", + "dev" +>>>>>>> Define archive builders and formatters ); } public function testLoadOnlineAvailableAndValidFile() { +<<<<<<< HEAD $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); $this->zip->loadArchive( __DIR__ . DS . "TestResources/well_formatted.zip", true +======= + $this->zip->loadArchive( + __DIR__ . DS . "TestResources/well_formatted.zip", + "dev", + true, + FakeFileDownloader::getInstance() +>>>>>>> Define archive builders and formatters ); } /** +<<<<<<< HEAD * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException +======= + * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException +>>>>>>> Define archive builders and formatters * @expectedExceptionMessage [Zip Error] The file is not a zip archive */ public function testLoadOnlineAvailableAndNotValidFile() { +<<<<<<< HEAD $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); $this->zip->loadArchive( __DIR__ . DS . "TestResources/bad_formatted.zip", true +======= + $this->zip->loadArchive( + __DIR__ . DS . "TestResources/bad_formatted.zip", + "dev", + true, + FakeFileDownloader::getInstance() +>>>>>>> Define archive builders and formatters ); } @@ -218,11 +354,19 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase */ public function testLoadOnlineNotExistingFile() { +<<<<<<< HEAD $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); $this->zip->loadArchive( __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", true +======= + $this->zip->loadArchive( + __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", + "dev", + true, + FakeFileDownloader::getInstance() +>>>>>>> Define archive builders and formatters ); } @@ -325,7 +469,11 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testBuildArchiveResponse() { $loadedArchiveResponse = $this->loadedZip +<<<<<<< HEAD ->buildArchiveResponse("test") +======= + ->buildArchiveResponse() +>>>>>>> Define archive builders and formatters ; $loadedArchiveResponseContent = $loadedArchiveResponse->getContent(); @@ -337,6 +485,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase $loadedArchiveResponseContent ); } +<<<<<<< HEAD public function testAddValidFileFromString() { @@ -396,3 +545,6 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase } } +======= +} +>>>>>>> Define archive builders and formatters diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php index 69fdfdb9a..7e92216bf 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php @@ -72,4 +72,8 @@ class ArchiveBuilderManagerTest extends \PHPUnit_Framework_TestCase $this->manager->delete("foo"); } +<<<<<<< HEAD } +======= +} +>>>>>>> Define archive builders and formatters diff --git a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php new file mode 100644 index 000000000..8759c2fca --- /dev/null +++ b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php @@ -0,0 +1,74 @@ + + */ +class FormatterManagerTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var FormatterManager + */ + protected $manager; + + public function setUp() + { + new Translator( + new Container() + ); + $this->manager = new FormatterManager(); + } + + public function testAddFormatter() + { + /** @var AbstractFormatter $instance */ + $instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatter\\AbstractFormatter"); + + $this->manager->add($instance); + + $archiveBuilders = $this->manager->getAll(); + + $this->assertTrue( + array_key_exists($instance->getName(), $archiveBuilders) + ); + } + + public function testDeleteFormatter() + { + /** @var AbstractFormatter $instance */ + $instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatter\\AbstractFormatter"); + + $this->manager->add($instance); + + $this->manager->delete($instance->getName()); + + $this->assertTrue( + count($this->manager->getAll()) === 0 + ); + } + + /** + * @expectedException \OutOfBoundsException + */ + public function testDeleteNotExistingFormatter() + { + $this->manager->delete("foo"); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php b/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php index a45a3b8ec..eb3a32918 100644 --- a/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php +++ b/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php @@ -22,8 +22,13 @@ use Thelia\Tools\FileDownload\FileDownloader; class FakeFileDownloader extends FileDownloader { /** +<<<<<<< HEAD * @param string $url * @param string $pathToStore +======= + * @param string $url + * @param string $pathToStore +>>>>>>> Define archive builders and formatters * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException * @throws \HttpUrlException @@ -41,4 +46,8 @@ class FakeFileDownloader extends FileDownloader } } +<<<<<<< HEAD } +======= +} +>>>>>>> Define archive builders and formatters diff --git a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php index e62840494..457a8e634 100644 --- a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php +++ b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php @@ -14,7 +14,11 @@ namespace Thelia\Tests\Type; use Symfony\Component\DependencyInjection\Container; use Thelia\Core\Translation\Translator; use Thelia\Log\Tlog; +<<<<<<< HEAD use Thelia\Tools\FileDownload\FileDownloader; +======= +use Thelia\Tools\FileDownloader; +>>>>>>> Define archive builders and formatters /** * Class FileDownloaderTest @@ -60,4 +64,8 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase { $this->downloader->download("https://github.com/thelia/thelia", "php://temp"); } +<<<<<<< HEAD } +======= +} +>>>>>>> Define archive builders and formatters diff --git a/core/lib/Thelia/Tests/Tools/FileManagerTest.php b/core/lib/Thelia/Tests/Tools/FileManagerTest.php index e611b2c53..29e4f2966 100644 --- a/core/lib/Thelia/Tests/Tools/FileManagerTest.php +++ b/core/lib/Thelia/Tests/Tools/FileManagerTest.php @@ -787,7 +787,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->getMock(); $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') - ->setConstructorArgs([__DIR__ . '/fixtures/test.xml', 'test.xml']) + ->disableOriginalConstructor() ->getMock(); $stubUploadedFile->expects($this->any()) ->method('getClientOriginalExtension') @@ -814,7 +814,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->getMock(); $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') - ->setConstructorArgs([__DIR__ . '/fixtures/test.xml', 'test.xml']) + ->disableOriginalConstructor() ->getMock(); $stubUploadedFile->expects($this->any()) ->method('getClientOriginalExtension') diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php index 2f77226cf..94e7170ca 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php @@ -17,7 +17,10 @@ use Thelia\Core\Translation\Translator as TheliaTranslator; use Thelia\Exception\FileNotFoundException; use Thelia\Exception\HttpUrlException; use Thelia\Log\Tlog; +<<<<<<< HEAD use Thelia\Tools\URL; +======= +>>>>>>> Define archive builders and formatters /** * Class FileDownloader @@ -45,8 +48,13 @@ class FileDownloader implements FileDownloaderInterface } /** +<<<<<<< HEAD * @param string $url * @param string $pathToStore +======= + * @param string $url + * @param string $pathToStore +>>>>>>> Define archive builders and formatters * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException * @throws \HttpUrlException @@ -125,7 +133,11 @@ class FileDownloader implements FileDownloaderInterface */ $file = @fopen($pathToStore, "w"); +<<<<<<< HEAD if ($file === false) { +======= + if($file === false) { +>>>>>>> Define archive builders and formatters $translatedErrorMessage = $this->translator->trans( "Failed to open a writing stream on the file: %file", [ @@ -140,4 +152,8 @@ class FileDownloader implements FileDownloaderInterface fputs($file, $response); fclose($file); } +<<<<<<< HEAD } +======= +} +>>>>>>> Define archive builders and formatters diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php b/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php index 78347bdd9..d0472b41d 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php @@ -35,7 +35,11 @@ trait FileDownloaderAwareTrait } /** +<<<<<<< HEAD * @param FileDownloaderInterface $fileDownloader +======= + * @param FileDownloaderInterface $fileDownloader +>>>>>>> Define archive builders and formatters * @return $this */ public function setFileDownloader(FileDownloaderInterface $fileDownloader) @@ -44,4 +48,8 @@ trait FileDownloaderAwareTrait return $this; } +<<<<<<< HEAD } +======= +} +>>>>>>> Define archive builders and formatters diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php b/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php index 4c29daf29..0f451396b 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php @@ -14,6 +14,10 @@ namespace Thelia\Tools\FileDownload; use Psr\Log\LoggerInterface; use Symfony\Component\Translation\Translator; +<<<<<<< HEAD +======= + +>>>>>>> Define archive builders and formatters /** * Class FileDownloader * @package Thelia\Tools\FileDownload @@ -22,8 +26,13 @@ use Symfony\Component\Translation\Translator; interface FileDownloaderInterface { /** +<<<<<<< HEAD * @param string $url * @param string $pathToStore +======= + * @param string $url + * @param string $pathToStore +>>>>>>> Define archive builders and formatters * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException * @throws \HttpUrlException @@ -40,4 +49,8 @@ interface FileDownloaderInterface * Returns an hydrated instance */ public static function getInstance(); +<<<<<<< HEAD } +======= +} +>>>>>>> Define archive builders and formatters diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index ab52472e6..9351bcac4 100644 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -315,7 +315,11 @@ class URL $clean; } +<<<<<<< HEAD public static function checkUrl($url, array $protocols = ["http", "https"]) +======= + public function checkUrl($url, array $protocols = ["http", "https"]) +>>>>>>> Define archive builders and formatters { $pattern = sprintf(UrlValidator::PATTERN, implode('|', $protocols)); From d5188bfe3cdb0722b839274c3029058eab078f73 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Wed, 2 Jul 2014 14:07:42 +0200 Subject: [PATCH 024/158] =?UTF-8?q?Add=20archive=20builder=20manager=20and?= =?UTF-8?q?=20formatter=20manager=20services=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Config/Resources/config.xml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/config.xml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index db21517e8..b467a0974 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -135,6 +135,22 @@ +<<<<<<< HEAD +======= + + + + + %kernel.environment% + + + + + + + + +>>>>>>> Add archive builder manager and formatter manager services From 9eecad5658d011b6a515ba3613d94ca8d2dce2c2 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Wed, 2 Jul 2014 15:14:52 +0200 Subject: [PATCH 025/158] =?UTF-8?q?Begin=20tar,=20tar.bz2=20and=20tar.gz?= =?UTF-8?q?=20formatter,=20fix=20zip=20test=20resources=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Config/Resources/con?= =?UTF-8?q?fig.xml=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/T?= =?UTF-8?q?helia/Core/FileFormat/Archive/AbstractArchiveBuilder.php=20=09m?= =?UTF-8?q?odifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/Fil?= =?UTF-8?q?eFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php=20=09modif?= =?UTF-8?q?i=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFo?= =?UTF-8?q?rmat/Archive/ArchiveBuilder/TestResources/bad=5Fformatted.zip?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/T?= =?UTF-8?q?ests/FileFormat/Archive/ArchiveBuilder/TestResources/well=5Ffor?= =?UTF-8?q?matted.zip=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/li?= =?UTF-8?q?b/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuil?= =?UTF-8?q?derTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/config.xml | 18 ++++ .../Archive/AbstractArchiveBuilder.php | 25 ++++++ .../ArchiveBuilder/ZipArchiveBuilder.php | 86 +++++++++++++++---- .../ArchiveBuilder/ZipArchiveBuilderTest.php | 3 + 4 files changed, 114 insertions(+), 18 deletions(-) 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() { From 83cf3b59e04360d7e191ea29e7b4755b0486dadd Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 3 Jul 2014 13:10:53 +0200 Subject: [PATCH 026/158] =?UTF-8?q?Finish=20implementing=20and=20testing?= =?UTF-8?q?=20zip=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Th?= =?UTF-8?q?elia/Core/FileFormat/Archive/AbstractArchiveBuilder.php=20=09no?= =?UTF-8?q?uveau=20fichier:=20core/lib/Thelia/Core/FileFormat/Archive/Arch?= =?UTF-8?q?iveBuilder/Exception/TarArchiveException.php=20=09renomm=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Arch?= =?UTF-8?q?ive/ArchiveBuilder/ZipArchiveException.php=20->=20core/lib/Thel?= =?UTF-8?q?ia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveE?= =?UTF-8?q?xception.php=20=09nouveau=20fichier:=20core/lib/Thelia/Core/Fil?= =?UTF-8?q?eFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php=20=09modif?= =?UTF-8?q?i=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFor?= =?UTF-8?q?mat/Archive/ArchiveBuilder/ZipArchiveBuilder.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Archive/ArchiveBuilderInterface.php=20=09nouveau=20fichier:?= =?UTF-8?q?=20core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarA?= =?UTF-8?q?rchiveBuilderTest.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/Z?= =?UTF-8?q?ipArchiveBuilderTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/AbstractArchiveBuilder.php | 23 ++ .../Exception/TarArchiveException.php | 4 + .../Exception/ZipArchiveException.php | 2 +- .../ZipArchiveException.php~HEAD} | 4 +- .../ArchiveBuilder/TarArchiveBuilder.php | 193 ++++++++++++ .../ArchiveBuilder/ZipArchiveBuilder.php | 282 +++++++++++++++--- .../Archive/ArchiveBuilderInterface.php | 38 +++ .../ArchiveBuilder/TarArchiveBuilderTest.php | 12 + .../ArchiveBuilder/ZipArchiveBuilderTest.php | 98 ++++++ 9 files changed, 611 insertions(+), 45 deletions(-) rename core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/{ZipArchiveException.php => Exception/ZipArchiveException.php~HEAD} (94%) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php index 9bfc56cc1..d709e5525 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php @@ -46,7 +46,13 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder const TEMP_DIRECTORY_NAME = "archive_builder"; +<<<<<<< HEAD >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources +======= + /** @var string */ + protected $cacheFile; + +>>>>>>> Finish implementing and testing zip /** @var \Thelia\Core\Translation\Translator */ protected $translator; @@ -84,11 +90,15 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder ); } +<<<<<<< HEAD <<<<<<< 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 +======= + $archiveBuilderCacheDir = $this->cacheDir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; +>>>>>>> Finish implementing and testing zip if (!is_dir($archiveBuilderCacheDir) && !mkdir($archiveBuilderCacheDir, 0755)) { throw new \ErrorException( @@ -105,6 +115,9 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder } <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Finish implementing and testing zip /** * @param $pathToFile * @param $destination @@ -196,8 +209,11 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder return $this; } +<<<<<<< HEAD ======= >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources +======= +>>>>>>> Finish implementing and testing zip public function getCacheDir() { @@ -220,11 +236,15 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder return $this->translator; } <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Finish implementing and testing zip public function getCacheFile() { return $this->cacheFile; } +<<<<<<< HEAD /** * @param string $environment @@ -244,3 +264,6 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder ======= } >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources +======= +} +>>>>>>> Finish implementing and testing zip diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php index 3e2d583d6..9566c4eaa 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php @@ -20,4 +20,8 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception; class TarArchiveException extends \Exception { +<<<<<<< HEAD } +======= +} +>>>>>>> Finish implementing and testing zip diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php index f69375dec..24f9ddb37 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php @@ -20,4 +20,4 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception; class ZipArchiveException extends \ErrorException { -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php~HEAD similarity index 94% rename from core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php rename to core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php~HEAD index c85fce339..f69375dec 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php~HEAD @@ -10,7 +10,7 @@ /* file that was distributed with this source code. */ /*************************************************************************************/ -namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; +namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception; /** * Class ZipArchiveException @@ -20,4 +20,4 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; class ZipArchiveException extends \ErrorException { -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index 35f9a5d55..e00a3fe93 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -13,10 +13,15 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder; use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException; +<<<<<<< HEAD use Thelia\Core\HttpFoundation\Response; use Thelia\Core\Thelia; use Thelia\Core\Translation\Translator; use Thelia\Exception\FileNotReadableException; +======= +use Thelia\Core\FileFormat\Archive\ArchiveBuilderInterface; +use Thelia\Core\Translation\Translator; +>>>>>>> Finish implementing and testing zip use Thelia\Log\Tlog; use Thelia\Tools\FileDownload\FileDownloaderInterface; @@ -47,6 +52,32 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \Thelia\Log\Tlog */ protected $logger; +<<<<<<< HEAD +======= + function __construct($compressionType = null) + { + $this->translator = Translator::getInstance(); + $this->logger = Tlog::getNewInstance(); + + $supportedCompression = [ + "gz", + "bz2", + null + ]; + + if (!in_array($compressionType, $supportedCompression)) { + throw new TarArchiveException( + $this->translator->trans( + "The compression %type is not supported" + ) + ); + } + + $this->compression = $compressionType; + } + + /** +>>>>>>> Finish implementing and testing zip public function __destruct() { if ($this->tar instanceof \PharData) { @@ -54,6 +85,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder unlink($this->cacheFile); } } +<<<<<<< HEAD } /** @@ -61,6 +93,15 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * @param string $directoryInArchive This is the directory where it will be stored in the archive * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name * @param bool $isOnline +======= + }*/ + + /** + * @param string $filePath It is the path to access the file. + * @param string $directoryInArchive This is the directory where it will be stored in the archive + * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name + * @param bool $isOnline +>>>>>>> Finish implementing and testing zip * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -80,7 +121,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * Download the file if it is online * If it's local check if the file exists and if it is redable */ +<<<<<<< HEAD $fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp"; +======= + $fileDownloadCache = $this->cacheDir . DS . "download.tmp"; +>>>>>>> Finish implementing and testing zip $this->copyFile($filePath, $fileDownloadCache, $isOnline); /** @@ -96,18 +141,25 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $this->tar->addFile($filePath, $name); +<<<<<<< HEAD /** * And clear the download temp file */ unlink($fileDownloadCache); +======= +>>>>>>> Finish implementing and testing zip return $this; } /** * @param $content * @param $name +<<<<<<< HEAD * @param string $directoryInArchive +======= + * @param string $directoryInArchive +>>>>>>> Finish implementing and testing zip * @return mixed * @throws \ErrorException * @@ -132,7 +184,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } try { $this->tar->addFromString($name, $content); +<<<<<<< HEAD } catch (\Exception $e) { +======= + } catch(\Exception $e) { +>>>>>>> Finish implementing and testing zip throw new \ErrorException( $this->translator->trans( "Error while writing the file into the archive, error message: %errmes", @@ -144,6 +200,10 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } } +<<<<<<< HEAD +======= + +>>>>>>> Finish implementing and testing zip /** * @param $directoryPath * @return $this @@ -159,7 +219,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder try { $this->tar->addEmptyDir($directoryInArchive); +<<<<<<< HEAD } catch (\Exception $e) { +======= + } catch(\Exception $e) { +>>>>>>> Finish implementing and testing zip throw new \ErrorException( $this->translator->trans( "The directory %dir has not been created in the archive", @@ -175,7 +239,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** +<<<<<<< HEAD * @param string $pathToFile +======= + * @param string $pathToFile +>>>>>>> Finish implementing and testing zip * @return null|string * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -185,6 +253,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getFileContent($pathToFile) { +<<<<<<< HEAD $pathToFile = $this->formatFilePath($pathToFile); if (!$this->hasFile($pathToFile)) { @@ -205,6 +274,12 @@ class TarArchiveBuilder extends AbstractArchiveBuilder return $content; } +======= + + } + + +>>>>>>> Finish implementing and testing zip /** * @param $pathInArchive * @return $this @@ -236,6 +311,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * * This method return an instance of a Response with the archive as content. */ +<<<<<<< HEAD public function buildArchiveResponse($filename) { $this->tar->setMetadata("Generated by Thelia v" . Thelia::THELIA_VERSION); @@ -272,6 +348,18 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * @param string $environment * @param bool $isOnline * @param FileDownloaderInterface $fileDownloader +======= + public function buildArchiveResponse() + { + + } + + /** + * @param string $pathToArchive + * @param string $environment + * @param bool $isOnline + * @param FileDownloaderInterface $fileDownloader +>>>>>>> Finish implementing and testing zip * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException @@ -279,6 +367,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * * Loads an archive */ +<<<<<<< HEAD public function loadArchive($pathToArchive, $isOnline = false) { $tar = clone $this; @@ -286,13 +375,36 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $tar ->setCacheFile($tar->generateCacheFile($this->environment)) ->copyFile($pathToArchive, $tar->getCacheFile(), $isOnline); +======= + public static function loadArchive( + $pathToArchive, + $environment, + $isOnline = false, + FileDownloaderInterface $fileDownloader = null + ) { + /** @var TarArchiveBuilder $instance */ + $instance = new static(); + + if ($fileDownloader !== null) { + $instance->setFileDownloader($fileDownloader); + } + + $instance->setCacheFile($instance->getCacheFile()) + ->copyFile($pathToArchive, $isOnline); +>>>>>>> Finish implementing and testing zip /** * This throws TarArchiveBuilderException if * the archive is not valid. */ +<<<<<<< HEAD return $tar->setEnvironment($tar->environment); +======= + $instance->setEnvironment($environment); + + return $instance; +>>>>>>> Finish implementing and testing zip } /** @@ -312,19 +424,31 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \PharFileInfo $fileInfo */ $fileInfo = $this->tar[$pathToFile]; +<<<<<<< HEAD if ($fileInfo->isFile()) { +======= + if($fileInfo->isFile()) { +>>>>>>> Finish implementing and testing zip $isFile = true; } /** * Catch the exception to avoid its displaying. */ +<<<<<<< HEAD } catch (\BadMethodCallException $e) {} +======= + } catch(\BadMethodCallException $e) {} +>>>>>>> Finish implementing and testing zip return $isFile; } /** +<<<<<<< HEAD * @param string $directory +======= + * @param string $directory +>>>>>>> Finish implementing and testing zip * @return bool * * Check if the archive has a directory @@ -338,19 +462,31 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \PharFileInfo $fileInfo */ $fileInfo = $this->tar[$pathToDir]; +<<<<<<< HEAD if ($fileInfo->isDir()) { +======= + if($fileInfo->isDir()) { +>>>>>>> Finish implementing and testing zip $isDir = true; } /** * Catch the exception to avoid its displaying. */ +<<<<<<< HEAD } catch (\BadMethodCallException $e) {} +======= + } catch(\BadMethodCallException $e) {} +>>>>>>> Finish implementing and testing zip return $isDir; } /** +<<<<<<< HEAD * @param string $environment +======= + * @param string $environment +>>>>>>> Finish implementing and testing zip * @return $this * * Sets the execution environment of the Kernel, @@ -358,6 +494,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function setEnvironment($environment) { +<<<<<<< HEAD if (empty($environment)) { throw new \ErrorException( $this->translator->trans( @@ -366,6 +503,8 @@ class TarArchiveBuilder extends AbstractArchiveBuilder ); } +======= +>>>>>>> Finish implementing and testing zip if ($this->cacheFile === null) { $cacheFile = $this->generateCacheFile($environment); @@ -381,14 +520,33 @@ class TarArchiveBuilder extends AbstractArchiveBuilder try { $this->tar = new \PharData($cacheFile, null, null, static::PHAR_FORMAT); +<<<<<<< HEAD $this->compressionEntryPoint(); } catch (\BadMethodCallException $e) { +======= + switch ($this->compression) { + case "gz": + $this->tar = $this->tar->compress(\Phar::GZ); + $cacheFile .= ".gz"; + break; + case "bz2": + $this->tar = $this->tar->compress(\Phar::BZ2); + $cacheFile .= ".bz2"; + break; + } + + } catch(\BadMethodCallException $e) { +>>>>>>> Finish implementing and testing zip /** * This should not happen */ $errorMessage = "You have badly called the method setEnvironment twice for %file"; +<<<<<<< HEAD } catch (\UnexpectedValueException $e) { +======= + } catch(\UnexpectedValueException $e) { +>>>>>>> Finish implementing and testing zip $errorMessage = "The file %file is corrupted"; } @@ -404,13 +562,20 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } $this->cacheFile = $cacheFile; +<<<<<<< HEAD $this->environment = $environment; +======= +>>>>>>> Finish implementing and testing zip return $this; } /** +<<<<<<< HEAD * @param string $initialString +======= + * @param string $initialString +>>>>>>> Finish implementing and testing zip * @return string * * Gives a valid file path for \ZipArchive @@ -431,7 +596,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** +<<<<<<< HEAD * @param string $initialString +======= + * @param string $initialString +>>>>>>> Finish implementing and testing zip * @return string * * Gives a valid directory path for \ZipArchive @@ -453,7 +622,17 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getName() { +<<<<<<< HEAD return "tar"; +======= + $name = "tar"; + + if ($this->compression !== null) { + $name .= "." . $this->compression; + } + + return $name; +>>>>>>> Finish implementing and testing zip } /** @@ -467,7 +646,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getExtension() { +<<<<<<< HEAD return "tar"; +======= + return $this->getName(); +>>>>>>> Finish implementing and testing zip } /** @@ -480,6 +663,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getMimeType() { +<<<<<<< HEAD return "application/x-tar"; } @@ -496,3 +680,12 @@ class TarArchiveBuilder extends AbstractArchiveBuilder return $this->compression; } } +======= + return $this->compression === null ? + "application/x-tar" : + "application/x-gtar" + ; + } + +} +>>>>>>> Finish implementing and testing zip diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index 6cf52a23d..4cee2676b 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -13,18 +13,23 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder; <<<<<<< HEAD +<<<<<<< HEAD use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException; use Thelia\Core\HttpFoundation\Response; use Thelia\Core\Thelia; use Thelia\Exception\FileNotReadableException; ======= +======= +use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException; +>>>>>>> Finish implementing and testing zip use Thelia\Core\HttpFoundation\Response; use Thelia\Core\Thelia; -use Thelia\Core\Translation\Translator; -use Thelia\Exception\FileNotFoundException; use Thelia\Exception\FileNotReadableException; +<<<<<<< HEAD use Thelia\Log\Tlog; >>>>>>> Define archive builders and formatters +======= +>>>>>>> Finish implementing and testing zip use Thelia\Tools\FileDownload\FileDownloaderInterface; /** @@ -53,6 +58,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ protected $zip; +<<<<<<< HEAD <<<<<<< HEAD public function __construct() { @@ -70,6 +76,8 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ protected $cacheDir; +======= +>>>>>>> Finish implementing and testing zip public function __construct() { parent::__construct(); @@ -95,6 +103,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if ($this->zip instanceof \ZipArchive) { @$this->zip->close(); +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD if (file_exists($this->cacheFile)) { @@ -107,6 +116,10 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if (file_exists($this->zipCacheFile)) { unlink($this->zipCacheFile); >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources +======= + if (file_exists($this->cacheFile)) { + unlink($this->cacheFile); +>>>>>>> Finish implementing and testing zip } } } @@ -129,7 +142,11 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException +<<<<<<< HEAD >>>>>>> Define archive builders and formatters +======= + * @throws \ErrorException +>>>>>>> Finish implementing and testing zip * * This methods adds a file in the archive. * If the file is local, $isOnline must be false, @@ -137,6 +154,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function addFile($filePath, $directoryInArchive = null, $name = null, $isOnline = false) { +<<<<<<< HEAD <<<<<<< HEAD $directoryInArchive = $this->formatDirectoryPath($directoryInArchive); @@ -243,16 +261,19 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if (!empty($directoryInArchive)) { ======= +======= + $directoryInArchive = $this->formatDirectoryPath($directoryInArchive); + +>>>>>>> Finish implementing and testing zip /** * Add empty directory if it doesn't exist */ - if (empty($directoryInArchive) || preg_match("#^\/+$#", $directoryInArchive)) { - $directoryInArchive = ""; - } if(!empty($directoryInArchive)) { - $directoryInArchive = $this->getDirectoryPath($directoryInArchive); + $this->addDirectory($directoryInArchive); + } +<<<<<<< HEAD >>>>>>> Define archive builders and formatters if (!$this->zip->addEmptyDir($directoryInArchive)) { throw new \ErrorException( @@ -264,6 +285,10 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder ) ); } +======= + if (empty($name) || !is_scalar($name)) { + $name = basename($filePath); +>>>>>>> Finish implementing and testing zip } <<<<<<< HEAD @@ -347,6 +372,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * Download the file if it is online * If it's local check if the file exists and if it is redable */ +<<<<<<< HEAD >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources if ($isOnline) { $fileDownloadCache = $this->cacheDir . DS . "download"; @@ -375,18 +401,21 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if (empty($name)) { $name = basename($filePath); } +======= + $fileDownloadCache = $this->cacheDir . DS . "download.tmp"; + $this->copyFile($filePath, $fileDownloadCache, $isOnline); +>>>>>>> Finish implementing and testing zip /** * Then write the file in the archive and commit the changes */ - $destination = $directoryInArchive . $name; - if (!$this->zip->addFile($filePath,$destination)) { + if (!$this->zip->addFile($fileDownloadCache, $destination)) { $translatedErrorMessage = $this->translator->trans( "An error occurred while adding this file to the archive: %file", [ - "%file" => $filePath + "%file" => $fileDownloadCache ] ); @@ -401,6 +430,146 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder >>>>>>> Define archive builders and formatters } + /** + * @param $content + * @param $name + * @param string $directoryInArchive + * @return mixed + * @throws \ErrorException + * + * This method creates a file in the archive with its content + */ + public function addFileFromString($content, $name, $directoryInArchive = "/") + { + $directoryInArchive = $this->formatDirectoryPath($directoryInArchive); + + if (!empty($directoryInArchive) && $directoryInArchive !== "/") { + $this->addDirectory($directoryInArchive); + } + + if (empty($name) || !is_scalar($name)) { + throw new \ErrorException( + $this->translator->trans( + "The filename is not correct" + ) + ); + } + + $filePath = $this->getFilePath($directoryInArchive . DS . $name); + + if (!$this->zip->addFromString($filePath, $content)) { + throw new \ErrorException( + $this->translator->trans( + "Unable to write the file %file into the archive", + [ + "%file" => $filePath, + ] + ) + ); + } + + $this->commit(); + } + + + /** + * @param $directoryPath + * @return $this + * @throws \ErrorException + * + * This method creates an empty directory + */ + public function addDirectory($directoryPath) + { + $directoryInArchive = $this->formatDirectoryPath($directoryPath); + + if (!empty($directoryInArchive)) { + if (!$this->zip->addEmptyDir($directoryInArchive)) { + throw new \ErrorException( + $this->translator->trans( + "The directory %dir has not been created in the archive", + [ + "%dir" => $directoryInArchive + ] + ) + ); + } + } + + return $this; + } + + /** + * @param string $pathToFile + * @return null|string + * @throws \Thelia\Exception\FileNotFoundException + * @throws \Thelia\Exception\FileNotReadableException + * @throws \ErrorException + * + * This method returns a file content + */ + public function getFileContent($pathToFile) + { + $pathToFile = $this->formatFilePath($pathToFile); + + if (!$this->hasFile($pathToFile)) { + $this->throwFileNotFound($pathToFile); + } + + $stream = $this->zip->getStream($pathToFile); + $content = ""; + + while (!feof($stream)) { + $content .= fread($stream, 2); + } + + fclose($stream); + + return $content; + } + + + /** + * @param string $initialString + * @return string + * + * Gives a valid file path for \ZipArchive + */ + public function getFilePath($initialString) + { + /** + * Remove the / at the beginning and the end. + */ + $initialString = trim($initialString, "/"); + + /** + * Remove the double, triple, ... slashes + */ + $initialString = preg_replace("#\/{2,}#", "/", $initialString); + + if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) { + $initialString = "/" . $initialString; + } + return $initialString; + } + + /** + * @param string $initialString + * @return string + * + * Gives a valid directory path for \ZipArchive + */ + public function getDirectoryPath($initialString) + { + $initialString = $this->getFilePath($initialString); + + if ($initialString[0] !== "/") { + $initialString = "/" . $initialString; + } + + return $initialString . "/"; + } + /** * @param $pathInArchive * @return $this @@ -411,11 +580,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function deleteFile($pathInArchive) { +<<<<<<< HEAD <<<<<<< HEAD $pathInArchive = $this->formatFilePath($pathInArchive); ======= $pathInArchive = $this->getFilePath($pathInArchive); >>>>>>> Define archive builders and formatters +======= + $pathInArchive = $this->formatFilePath($pathInArchive); +>>>>>>> Finish implementing and testing zip if (!$this->hasFile($pathInArchive)) { $this->throwFileNotFound($pathInArchive); @@ -452,6 +625,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $this->commit(); +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD if (!file_exists($this->cacheFile)) { @@ -473,11 +647,19 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if (!is_readable($this->zipCacheFile)) { >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources +======= + if (!file_exists($this->cacheFile)) { + $this->throwFileNotFound($this->cacheFile); + } + + if (!is_readable($this->cacheFile)) { +>>>>>>> Finish implementing and testing zip throw new FileNotReadableException( $this->translator->trans( "The cache file %file is not readable", [ <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD "%file" => $this->cacheFile ======= @@ -486,11 +668,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder ======= "%file" => $this->zipCacheFile >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources +======= + "%file" => $this->cacheFile +>>>>>>> Finish implementing and testing zip ] ) ); } +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD $content = file_get_contents($this->cacheFile); @@ -500,6 +686,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder ======= $content = file_get_contents($this->zipCacheFile); >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources +======= + $content = file_get_contents($this->cacheFile); +>>>>>>> Finish implementing and testing zip $this->zip->close(); @@ -576,39 +765,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $instance->setFileDownloader($fileDownloader); } - if ($isOnline) { - /** - * It's an online file - */ - $instance->getFileDownloader() - ->download($pathToArchive, $instance->getZipCacheFile()) - ; - } else { - /** - * It's a local file - */ - if (!is_file($pathToArchive) || !is_readable($pathToArchive)) { - $instance->throwFileNotFound($pathToArchive); - } + $instance->copyFile($pathToArchive, $instance->getCacheFile(), $isOnline); - if (!copy($pathToArchive, $instance->getZipCacheFile())) { - $translatedErrorMessage = $instance->getTranslator()->trans( - "An unknown error happend while copying %prev to %dest", - [ - "%prev" => $pathToArchive, - "%dest" => $instance->getZipCacheFile(), - ] - ); - - $instance->getLogger() - ->error($translatedErrorMessage) - ; - - throw new \ErrorException($translatedErrorMessage); - } - } - - if (true !== $return = $zip->open($instance->getZipCacheFile())) { + if (true !== $return = $zip->open($instance->getCacheFile())) { throw new ZipArchiveException( $instance->getZipErrorMessage($return) ); @@ -627,11 +786,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder public function hasFile($pathToFile) { return $this->zip +<<<<<<< HEAD <<<<<<< HEAD ->locateName($this->formatFilePath($pathToFile)) !== false ======= ->locateName($this->getFilePath($pathToFile)) !== false >>>>>>> Define archive builders and formatters +======= + ->locateName($this->formatFilePath($pathToFile)) !== false +>>>>>>> Finish implementing and testing zip ; } @@ -647,11 +810,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function hasDirectory($directory) { +<<<<<<< HEAD <<<<<<< HEAD $link = $this->zip->locateName($this->formatDirectoryPath($directory)); ======= $link = $this->zip->locateName($this->getDirectoryPath($directory)); >>>>>>> Define archive builders and formatters +======= + $link = $this->zip->locateName($this->formatDirectoryPath($directory)); +>>>>>>> Finish implementing and testing zip return $link !== false; } @@ -708,11 +875,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder >>>>>>> Define archive builders and formatters ======= +<<<<<<< HEAD $cacheFileName = md5 (uniqid()); $cacheFile = $this->getArchiveBuilderCacheDirectory($environment) . DS; $cacheFile .= $cacheFileName . "." . $this->getExtension(); >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources +======= + $cacheFile = $this->generateCacheFile($environment); +>>>>>>> Finish implementing and testing zip if (file_exists($cacheFile)) { unlink($cacheFile); @@ -742,6 +913,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder ); } +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD $this->cacheFile = $cacheFile; @@ -751,6 +923,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder ======= $this->zipCacheFile = $cacheFile; >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources +======= + $this->cacheFile = $cacheFile; +>>>>>>> Finish implementing and testing zip return $this; } @@ -822,11 +997,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder public function commit() { $this->zip->close(); +<<<<<<< HEAD <<<<<<< HEAD $result = $this->zip->open($this->getCacheFile()); ======= $result = $this->zip->open($this->getZipCacheFile()); >>>>>>> Define archive builders and formatters +======= + $result = $this->zip->open($this->getCacheFile()); +>>>>>>> Finish implementing and testing zip if ($result !== true) { throw new \ErrorException( @@ -849,11 +1028,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * * Gives a valid file path for \ZipArchive */ +<<<<<<< HEAD <<<<<<< HEAD public function formatFilePath($initialString) ======= public function getFilePath($initialString) >>>>>>> Define archive builders and formatters +======= + public function formatFilePath($initialString) +>>>>>>> Finish implementing and testing zip { /** * Remove the / at the beginning and the end. @@ -885,6 +1068,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * * Gives a valid directory path for \ZipArchive */ +<<<<<<< HEAD <<<<<<< HEAD public function formatDirectoryPath($initialString) { @@ -893,17 +1077,25 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if ($initialString !== "" && $initialString[0] !== "/") { ======= public function getDirectoryPath($initialString) +======= + public function formatDirectoryPath($initialString) +>>>>>>> Finish implementing and testing zip { - $initialString = $this->getFilePath($initialString); + $initialString = $this->formatFilePath($initialString); +<<<<<<< HEAD if ($initialString[0] !== "/") { >>>>>>> Define archive builders and formatters +======= + if ($initialString !== "" && $initialString[0] !== "/") { +>>>>>>> Finish implementing and testing zip $initialString = "/" . $initialString; } return $initialString . "/"; } +<<<<<<< HEAD <<<<<<< HEAD ======= public function throwFileNotFound($file) @@ -921,6 +1113,8 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } >>>>>>> Define archive builders and formatters +======= +>>>>>>> Finish implementing and testing zip /** * @return string * @@ -991,6 +1185,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder return $this->zip; } <<<<<<< HEAD +<<<<<<< HEAD } ======= @@ -1009,3 +1204,6 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder ======= } >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources +======= +} +>>>>>>> Finish implementing and testing zip diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php index 96de43666..56d49de3c 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -11,6 +11,7 @@ /*************************************************************************************/ namespace Thelia\Core\FileFormat\Archive; +use Thelia\Tools\FileDownload\FileDownloaderInterface; /** * Interface ArchiveBuilderInterface @@ -43,7 +44,11 @@ interface ArchiveBuilderInterface * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException +<<<<<<< HEAD >>>>>>> Define archive builders and formatters +======= + * @throws \ErrorException +>>>>>>> Finish implementing and testing zip * * This methods adds a file in the archive. * If the file is local, $isOnline must be false, @@ -52,10 +57,16 @@ interface ArchiveBuilderInterface public function addFile($filePath, $directoryInArchive = "/", $name = null, $isOnline = false); /** +<<<<<<< HEAD <<<<<<< HEAD * @param $content * @param $name * @param string $directoryInArchive +======= + * @param $content + * @param $name + * @param string $directoryInArchive +>>>>>>> Finish implementing and testing zip * @return mixed * @throws \ErrorException * @@ -64,7 +75,11 @@ interface ArchiveBuilderInterface public function addFileFromString($content, $name, $directoryInArchive = "/"); /** +<<<<<<< HEAD * @param string $pathToFile +======= + * @param string $pathToFile +>>>>>>> Finish implementing and testing zip * @return null|string * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -74,6 +89,7 @@ interface ArchiveBuilderInterface */ public function getFileContent($pathToFile); /** +<<<<<<< HEAD * @param $pathInArchive * @return $this * @throws \Thelia\Exception\FileNotFoundException @@ -83,6 +99,12 @@ interface ArchiveBuilderInterface * @return $this * @throws \Thelia\Exception\FileNotFoundException >>>>>>> Define archive builders and formatters +======= + * @param $pathInArchive + * @return $this + * @throws \Thelia\Exception\FileNotFoundException + * @throws \ErrorException +>>>>>>> Finish implementing and testing zip * * This method deletes a file in the archive */ @@ -90,6 +112,9 @@ interface ArchiveBuilderInterface /** <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Finish implementing and testing zip * @param $directoryPath * @return $this * @throws \ErrorException @@ -97,11 +122,15 @@ interface ArchiveBuilderInterface * This method creates an empty directory */ public function addDirectory($directoryPath); +<<<<<<< HEAD /** * @params string $filename ======= >>>>>>> Define archive builders and formatters +======= + /** +>>>>>>> Finish implementing and testing zip * @return \Thelia\Core\HttpFoundation\Response * * This method return an instance of a Response with the archive as content. @@ -117,19 +146,28 @@ interface ArchiveBuilderInterface /** * @param string $pathToArchive + * @param string $environment * @param bool $isOnline +<<<<<<< HEAD >>>>>>> Define archive builders and formatters +======= + * @param FileDownloaderInterface $fileDownloader +>>>>>>> Finish implementing and testing zip * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException * * Loads an archive */ +<<<<<<< HEAD <<<<<<< HEAD public function loadArchive($pathToArchive, $isOnline = false); ======= public static function loadArchive($pathToArchive, $environment, $isOnline = false); >>>>>>> Define archive builders and formatters +======= + public static function loadArchive($pathToArchive, $environment, $isOnline = false, FileDownloaderInterface $fileDownloader = null); +>>>>>>> Finish implementing and testing zip /** * @param $pathToFile diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index e34acdf76..74605ac01 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -33,11 +33,19 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase Tlog::getNewInstance(); $this->tar = new TarArchiveBuilder(); +<<<<<<< HEAD $this->tar->setEnvironment("dev"); +======= +>>>>>>> Finish implementing and testing zip } public function testAddFileAndDirectory() { +<<<<<<< HEAD +======= + $this->tar->setEnvironment("dev"); + +>>>>>>> Finish implementing and testing zip /** * File */ @@ -82,6 +90,7 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->tar->hasDirectory("bar")); } +<<<<<<< HEAD public function testAddValidFileFromString() { @@ -289,3 +298,6 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase ); } } +======= +} +>>>>>>> Finish implementing and testing zip diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index 12b263f07..bbb692b37 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -73,84 +73,121 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase { $this->assertEquals( "foo", +<<<<<<< HEAD $this->zip->getFilePath("foo") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatFilePath("foo") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "foo", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatFilePath("/foo") ======= $this->zip->getFilePath("/foo") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatFilePath("/foo") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "foo", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatFilePath("foo/") ======= $this->zip->getFilePath("foo/") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatFilePath("foo/") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "foo", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatFilePath("/foo/") ======= $this->zip->getFilePath("/foo/") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatFilePath("/foo/") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatFilePath("foo/bar") ======= $this->zip->getFilePath("foo/bar") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatFilePath("foo/bar") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatFilePath("/foo/bar") ======= $this->zip->getFilePath("/foo/bar") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatFilePath("/foo/bar") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatFilePath("/foo//bar/") ======= $this->zip->getFilePath("/foo//bar/") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatFilePath("/foo//bar/") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatFilePath("/foo/bar/") ======= $this->zip->getFilePath("/foo/bar/") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatFilePath("/foo/bar/") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/baz", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatFilePath("foo/bar/baz") ======= $this->zip->getFilePath("foo/bar/baz") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatFilePath("foo/bar/baz") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/baz", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatFilePath("//foo/bar///baz/") ); @@ -163,6 +200,9 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->zip->formatDirectoryPath("foo") ======= $this->zip->getFilePath("//foo/bar///baz/") +======= + $this->zip->formatFilePath("//foo/bar///baz/") +>>>>>>> Finish implementing and testing zip ); } @@ -170,89 +210,129 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase { $this->assertEquals( "/foo/", +<<<<<<< HEAD $this->zip->getDirectoryPath("foo") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatDirectoryPath("foo") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatDirectoryPath("/foo") ======= $this->zip->getDirectoryPath("/foo") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatDirectoryPath("/foo") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatDirectoryPath("foo/") ======= $this->zip->getDirectoryPath("foo/") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatDirectoryPath("foo/") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatDirectoryPath("/foo/") ======= $this->zip->getDirectoryPath("/foo/") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatDirectoryPath("/foo/") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatDirectoryPath("foo/bar") ======= $this->zip->getDirectoryPath("foo/bar") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatDirectoryPath("foo/bar") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatDirectoryPath("/foo/bar") ======= $this->zip->getDirectoryPath("/foo/bar") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatDirectoryPath("/foo/bar") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatDirectoryPath("/foo//bar/") ======= $this->zip->getDirectoryPath("/foo//bar/") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatDirectoryPath("/foo//bar/") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatDirectoryPath("/foo/bar/") ======= $this->zip->getDirectoryPath("/foo/bar/") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatDirectoryPath("/foo/bar/") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/baz/", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatDirectoryPath("foo/bar/baz") ======= $this->zip->getDirectoryPath("foo/bar/baz") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatDirectoryPath("foo/bar/baz") +>>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/baz/", +<<<<<<< HEAD <<<<<<< HEAD $this->zip->formatDirectoryPath("//foo/bar///baz/") ======= $this->zip->getDirectoryPath("//foo/bar///baz/") >>>>>>> Define archive builders and formatters +======= + $this->zip->formatDirectoryPath("//foo/bar///baz/") +>>>>>>> Finish implementing and testing zip ); } @@ -274,11 +354,15 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase } /** +<<<<<<< HEAD <<<<<<< HEAD * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException ======= * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException >>>>>>> Define archive builders and formatters +======= + * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException +>>>>>>> Finish implementing and testing zip * @expectedExceptionMessage [Zip Error] The file is not a zip archive */ public function testLoadNotValidZip() @@ -327,11 +411,15 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase } /** +<<<<<<< HEAD <<<<<<< HEAD * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException ======= * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException >>>>>>> Define archive builders and formatters +======= + * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException +>>>>>>> Finish implementing and testing zip * @expectedExceptionMessage [Zip Error] The file is not a zip archive */ public function testLoadOnlineAvailableAndNotValidFile() @@ -489,6 +577,9 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase ); } <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Finish implementing and testing zip public function testAddValidFileFromString() { @@ -504,6 +595,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase "foo", $this->loadedZip->getFileContent("bar") ); +<<<<<<< HEAD $this->loadedZip->addFileFromString( "foo", "bar", "baz" @@ -517,6 +609,8 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase "foo", $this->loadedZip->getFileContent("baz/bar") ); +======= +>>>>>>> Finish implementing and testing zip } /** @@ -547,7 +641,11 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase ); } +<<<<<<< HEAD } ======= } >>>>>>> Define archive builders and formatters +======= +} +>>>>>>> Finish implementing and testing zip From ee2c383c732037bceca7909fa3784570aaae6112 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 3 Jul 2014 13:38:40 +0200 Subject: [PATCH 027/158] =?UTF-8?q?Complete=20zip=20tests=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Archive/ArchiveBuilder/TarArchiveBuilder.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Archive/ArchiveBuilderInterface.php=20=09modifi=C3=A9:=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFormat/Archive/A?= =?UTF-8?q?rchiveBuilder/TarArchiveBuilderTest.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFormat/Archiv?= =?UTF-8?q?e/ArchiveBuilder/ZipArchiveBuilderTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/ArchiveBuilder/TarArchiveBuilder.php | 8 ++++++++ .../FileFormat/Archive/ArchiveBuilderInterface.php | 4 ++++ .../Archive/ArchiveBuilder/TarArchiveBuilderTest.php | 10 ++++++++++ .../Archive/ArchiveBuilder/ZipArchiveBuilderTest.php | 6 ++++++ 4 files changed, 28 insertions(+) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index e00a3fe93..7d633db87 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -121,11 +121,15 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * Download the file if it is online * If it's local check if the file exists and if it is redable */ +<<<<<<< HEAD <<<<<<< HEAD $fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp"; ======= $fileDownloadCache = $this->cacheDir . DS . "download.tmp"; >>>>>>> Finish implementing and testing zip +======= + $fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp"; +>>>>>>> Complete zip tests $this->copyFile($filePath, $fileDownloadCache, $isOnline); /** @@ -253,6 +257,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getFileContent($pathToFile) { +<<<<<<< HEAD <<<<<<< HEAD $pathToFile = $this->formatFilePath($pathToFile); @@ -276,6 +281,9 @@ class TarArchiveBuilder extends AbstractArchiveBuilder ======= +======= + +>>>>>>> Complete zip tests } diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php index 56d49de3c..1b4cb8688 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -18,11 +18,15 @@ use Thelia\Tools\FileDownload\FileDownloaderInterface; * @package Thelia\Core\FileFormat\Archive * @author Benjamin Perche * +<<<<<<< HEAD <<<<<<< HEAD * This interface defines the methods that an archive builder must have. ======= * This interface defines the methods that an archive creator must have. >>>>>>> Define archive builders and formatters +======= + * This interface defines the methods that an archive builder must have. +>>>>>>> Complete zip tests */ interface ArchiveBuilderInterface { diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index 74605ac01..fb4f5c86b 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -91,10 +91,14 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase } <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Complete zip tests public function testAddValidFileFromString() { $this->tar->addFileFromString( +<<<<<<< HEAD "foo", "bar" ); @@ -301,3 +305,9 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase ======= } >>>>>>> Finish implementing and testing zip +======= + + ) + } +} +>>>>>>> Complete zip tests diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index bbb692b37..10558a2c6 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -596,6 +596,9 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->loadedZip->getFileContent("bar") ); <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Complete zip tests $this->loadedZip->addFileFromString( "foo", "bar", "baz" @@ -609,8 +612,11 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase "foo", $this->loadedZip->getFileContent("baz/bar") ); +<<<<<<< HEAD ======= >>>>>>> Finish implementing and testing zip +======= +>>>>>>> Complete zip tests } /** From 9d928c1f5305c69dc179938b8a261bc3a6001cc0 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 3 Jul 2014 13:43:59 +0200 Subject: [PATCH 028/158] =?UTF-8?q?Fix=20FileDownloader=20test=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Archive/ArchiveBuilder/ZipArchiveBuilder.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFor?= =?UTF-8?q?mat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php=20=09modif?= =?UTF-8?q?i=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/Tools/?= =?UTF-8?q?FileDownloaderTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php | 2 +- .../Archive/ArchiveBuilder/TarArchiveBuilderTest.php | 4 +++- core/lib/Thelia/Tests/Tools/FileDownloaderTest.php | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index 4cee2676b..796be2fe1 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -547,7 +547,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ $initialString = preg_replace("#\/{2,}#", "/", $initialString); - if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) { + if (preg_match("#\/?[^\/]+\/[^\/]+\/?#", $initialString)) { $initialString = "/" . $initialString; } return $initialString; diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index fb4f5c86b..cf65ea3d1 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -97,6 +97,7 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testAddValidFileFromString() { +<<<<<<< HEAD $this->tar->addFileFromString( <<<<<<< HEAD "foo", "bar" @@ -306,8 +307,9 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase } >>>>>>> Finish implementing and testing zip ======= +======= +>>>>>>> Fix FileDownloader test - ) } } >>>>>>> Complete zip tests diff --git a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php index 457a8e634..263d67db7 100644 --- a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php +++ b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php @@ -15,10 +15,14 @@ use Symfony\Component\DependencyInjection\Container; use Thelia\Core\Translation\Translator; use Thelia\Log\Tlog; <<<<<<< HEAD +<<<<<<< HEAD use Thelia\Tools\FileDownload\FileDownloader; ======= use Thelia\Tools\FileDownloader; >>>>>>> Define archive builders and formatters +======= +use Thelia\Tools\FileDownload\FileDownloader; +>>>>>>> Fix FileDownloader test /** * Class FileDownloaderTest From c9b485d3e5866d861dd4c8fa1deb76420cc2d15e Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 3 Jul 2014 14:20:31 +0200 Subject: [PATCH 029/158] =?UTF-8?q?Fix=20FileDownloader=20test=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Archive/ArchiveBuilder/TarArchiveBuilder.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFor?= =?UTF-8?q?mat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php=20=09modif?= =?UTF-8?q?i=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tools/FileDo?= =?UTF-8?q?wnload/FileDownloader.php=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/Tools/URL.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchiveBuilder/TarArchiveBuilder.php | 19 ++++++ .../ArchiveBuilder/TarArchiveBuilderTest.php | 64 +++++++++++++++++++ .../Tools/FileDownload/FileDownloader.php | 4 ++ core/lib/Thelia/Tools/URL.php | 4 ++ 4 files changed, 91 insertions(+) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index 7d633db87..d51251499 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -20,6 +20,7 @@ use Thelia\Core\Translation\Translator; use Thelia\Exception\FileNotReadableException; ======= use Thelia\Core\FileFormat\Archive\ArchiveBuilderInterface; +use Thelia\Core\Thelia; use Thelia\Core\Translation\Translator; >>>>>>> Finish implementing and testing zip use Thelia\Log\Tlog; @@ -259,6 +260,9 @@ class TarArchiveBuilder extends AbstractArchiveBuilder { <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Fix FileDownloader test $pathToFile = $this->formatFilePath($pathToFile); if (!$this->hasFile($pathToFile)) { @@ -267,11 +271,19 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \PharFileInfo $fileInfo*/ $fileInfo = $this->tar[$pathToFile]; +<<<<<<< HEAD /** @var \SplFileObject $file */ $file = $fileInfo->openFile(); $content = ""; +======= + + /** @var \SplFileObject $file */ + $file = $fileInfo->openFile(); + $content = ""; + +>>>>>>> Fix FileDownloader test while (false !== ($char = $file->fgetc())) { $content .= $char; } @@ -359,6 +371,8 @@ class TarArchiveBuilder extends AbstractArchiveBuilder ======= public function buildArchiveResponse() { + $this->tar->setMetadata("comment", "Generated by Thelia v" . Thelia::THELIA_VERSION); + } @@ -397,9 +411,14 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $instance->setFileDownloader($fileDownloader); } +<<<<<<< HEAD $instance->setCacheFile($instance->getCacheFile()) ->copyFile($pathToArchive, $isOnline); >>>>>>> Finish implementing and testing zip +======= + $instance->setCacheFile($instance->generateCacheFile($environment)) + ->copyFile($pathToArchive, $instance->getCacheFile(), $isOnline); +>>>>>>> Fix FileDownloader test /** * This throws TarArchiveBuilderException if diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index cf65ea3d1..1c9bfba8a 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -33,19 +33,26 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase Tlog::getNewInstance(); $this->tar = new TarArchiveBuilder(); +<<<<<<< HEAD <<<<<<< HEAD $this->tar->setEnvironment("dev"); ======= >>>>>>> Finish implementing and testing zip +======= + $this->tar->setEnvironment("dev"); +>>>>>>> Fix FileDownloader test } public function testAddFileAndDirectory() { <<<<<<< HEAD +<<<<<<< HEAD ======= $this->tar->setEnvironment("dev"); >>>>>>> Finish implementing and testing zip +======= +>>>>>>> Fix FileDownloader test /** * File */ @@ -97,9 +104,13 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testAddValidFileFromString() { +<<<<<<< HEAD <<<<<<< HEAD $this->tar->addFileFromString( <<<<<<< HEAD +======= + $this->tar->addFileFromString( +>>>>>>> Fix FileDownloader test "foo", "bar" ); @@ -111,6 +122,7 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase "foo", $this->tar->getFileContent("bar") ); +<<<<<<< HEAD $this->tar->addFileFromString( "foo", "bar", "baz" @@ -308,8 +320,60 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase >>>>>>> Finish implementing and testing zip ======= ======= +>>>>>>> Fix FileDownloader test +======= >>>>>>> Fix FileDownloader test + $this->tar->addFileFromString( + "foo", "bar", "baz" + ); + + $this->assertTrue( + $this->tar->hasFile("baz/bar") + ); + + $this->assertEquals( + "foo", + $this->tar->getFileContent("baz/bar") + ); + } + + /** + * @expectedException \ErrorException + */ + public function testAddNotValidFileFromString() + { + $this->tar->addFileFromString( + "foo", $this + ); + } + + /** + * @expectedException \ErrorException + */ + public function testAddNotValidFileValueFromString() + { + $this->tar->addFileFromString( + $this, "foo" + ); + } + + + public function testDeleteFile() + { + $this->tar->addFileFromString( + "foo", "bar" + ); + + $this->assertTrue( + $this->tar->hasFile("bar") + ); + + $this->tar->deleteFile("bar"); + + $this->assertFalse( + $this->tar->hasFile("bar") + ); } } >>>>>>> Complete zip tests diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php index 94e7170ca..ac0ae7eca 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php @@ -18,9 +18,13 @@ use Thelia\Exception\FileNotFoundException; use Thelia\Exception\HttpUrlException; use Thelia\Log\Tlog; <<<<<<< HEAD +<<<<<<< HEAD use Thelia\Tools\URL; ======= >>>>>>> Define archive builders and formatters +======= +use Thelia\Tools\URL; +>>>>>>> Fix FileDownloader test /** * Class FileDownloader diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 9351bcac4..8ef2b4b31 100644 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -315,11 +315,15 @@ class URL $clean; } +<<<<<<< HEAD <<<<<<< HEAD public static function checkUrl($url, array $protocols = ["http", "https"]) ======= public function checkUrl($url, array $protocols = ["http", "https"]) >>>>>>> Define archive builders and formatters +======= + public static function checkUrl($url, array $protocols = ["http", "https"]) +>>>>>>> Fix FileDownloader test { $pattern = sprintf(UrlValidator::PATTERN, implode('|', $protocols)); From 880626e4dec6bce449ef86a7fdcb8e9a782388a1 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 3 Jul 2014 14:51:20 +0200 Subject: [PATCH 030/158] =?UTF-8?q?Finish=20Tar=20archive=20builder=20=09m?= =?UTF-8?q?odifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/Fil?= =?UTF-8?q?eFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php=20=09modif?= =?UTF-8?q?i=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFo?= =?UTF-8?q?rmat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php=20=09nouv?= =?UTF-8?q?eau=20fichier:=20core/lib/Thelia/Tests/FileFormat/Archive/Archi?= =?UTF-8?q?veBuilder/TestResources/bad=5Fformatted.tar=20=09nouveau=20fich?= =?UTF-8?q?ier:=20core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/?= =?UTF-8?q?TestResources/well=5Fformatted.tar=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Tests/FileFormat/Archive/Arch?= =?UTF-8?q?iveBuilder/ZipArchiveBuilderTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchiveBuilder/TarArchiveBuilder.php | 46 +++++- .../ArchiveBuilder/TarArchiveBuilderTest.php | 139 +++++++++++++++++- .../ArchiveBuilder/ZipArchiveBuilderTest.php | 5 +- 3 files changed, 187 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index d51251499..4387eb728 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -14,6 +14,7 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder; use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException; <<<<<<< HEAD +<<<<<<< HEAD use Thelia\Core\HttpFoundation\Response; use Thelia\Core\Thelia; use Thelia\Core\Translation\Translator; @@ -23,6 +24,12 @@ use Thelia\Core\FileFormat\Archive\ArchiveBuilderInterface; use Thelia\Core\Thelia; use Thelia\Core\Translation\Translator; >>>>>>> Finish implementing and testing zip +======= +use Thelia\Core\HttpFoundation\Response; +use Thelia\Core\Thelia; +use Thelia\Core\Translation\Translator; +use Thelia\Exception\FileNotReadableException; +>>>>>>> Finish Tar archive builder use Thelia\Log\Tlog; use Thelia\Tools\FileDownload\FileDownloaderInterface; @@ -77,8 +84,12 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $this->compression = $compressionType; } +<<<<<<< HEAD /** >>>>>>> Finish implementing and testing zip +======= + +>>>>>>> Finish Tar archive builder public function __destruct() { if ($this->tar instanceof \PharData) { @@ -86,6 +97,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder unlink($this->cacheFile); } } +<<<<<<< HEAD <<<<<<< HEAD } @@ -96,6 +108,9 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * @param bool $isOnline ======= }*/ +======= + } +>>>>>>> Finish Tar archive builder /** * @param string $filePath It is the path to access the file. @@ -147,13 +162,19 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $this->tar->addFile($filePath, $name); <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Finish Tar archive builder /** * And clear the download temp file */ unlink($fileDownloadCache); +<<<<<<< HEAD ======= >>>>>>> Finish implementing and testing zip +======= +>>>>>>> Finish Tar archive builder return $this; } @@ -371,9 +392,32 @@ class TarArchiveBuilder extends AbstractArchiveBuilder ======= public function buildArchiveResponse() { - $this->tar->setMetadata("comment", "Generated by Thelia v" . Thelia::THELIA_VERSION); + $this->tar->setMetadata("Generated by Thelia v" . Thelia::THELIA_VERSION); + if (!is_file($this->cacheFile)) { + $this->throwFileNotFound($this->cacheFile); + } + if (!is_readable($this->cacheFile)) { + throw new FileNotReadableException( + $this->translator->trans( + "The file %file is not readable", + [ + "%file" => $this->cacheFile + ] + ) + ); + } + + $content = file_get_contents($this->cacheFile); + + return new Response( + $content, + 200, + [ + "Content-Type" => $this->getMimeType(), + ] + ); } /** diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index 1c9bfba8a..83689d1fa 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -358,7 +358,6 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase ); } - public function testDeleteFile() { $this->tar->addFileFromString( @@ -375,5 +374,143 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->tar->hasFile("bar") ); } +<<<<<<< HEAD } >>>>>>> Complete zip tests +======= + + public function testLoadValidArchive() + { + $tar = TarArchiveBuilder::loadArchive( + __DIR__ . DS . "TestResources/well_formatted.tar", + "dev" + ); + + $this->assertInstanceOf( + get_class($this->tar), + $tar + ); + + $this->assertTrue( + $tar->hasFile("LICENSE.txt") + ); + } + + /** + * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException + */ + public function testLoadInvalidArchive() + { + $tar = TarArchiveBuilder::loadArchive( + __DIR__ . DS . "TestResources/bad_formatted.tar", + "dev" + ); + } + + public function testFormatDirectoryPath() + { + $this->assertEquals( + "foo/", + $this->tar->formatDirectoryPath("foo") + ); + + $this->assertEquals( + "foo/", + $this->tar->formatDirectoryPath("/foo") + ); + + $this->assertEquals( + "foo/", + $this->tar->formatDirectoryPath("foo/") + ); + + $this->assertEquals( + "foo/", + $this->tar->formatDirectoryPath("/foo/") + ); + + $this->assertEquals( + "foo/bar/", + $this->tar->formatDirectoryPath("foo/bar") + ); + + $this->assertEquals( + "foo/bar/", + $this->tar->formatDirectoryPath("/foo/bar") + ); + + $this->assertEquals( + "foo/bar/", + $this->tar->formatDirectoryPath("/foo//bar/") + ); + + $this->assertEquals( + "foo/bar/", + $this->tar->formatDirectoryPath("/foo/bar/") + ); + + $this->assertEquals( + "foo/bar/baz/", + $this->tar->formatDirectoryPath("foo/bar/baz") + ); + + $this->assertEquals( + "foo/bar/baz/", + $this->tar->formatDirectoryPath("//foo/bar///baz/") + ); + } + + public function testFormatFilePath() + { + $this->assertEquals( + "foo", + $this->tar->formatFilePath("foo") + ); + + $this->assertEquals( + "foo", + $this->tar->formatFilePath("/foo") + ); + + $this->assertEquals( + "foo", + $this->tar->formatFilePath("foo/") + ); + + $this->assertEquals( + "foo", + $this->tar->formatFilePath("/foo/") + ); + + $this->assertEquals( + "foo/bar", + $this->tar->formatFilePath("foo/bar") + ); + + $this->assertEquals( + "foo/bar", + $this->tar->formatFilePath("/foo/bar") + ); + + $this->assertEquals( + "foo/bar", + $this->tar->formatFilePath("/foo//bar/") + ); + + $this->assertEquals( + "foo/bar", + $this->tar->formatFilePath("/foo/bar/") + ); + + $this->assertEquals( + "foo/bar/baz", + $this->tar->formatFilePath("foo/bar/baz") + ); + + $this->assertEquals( + "foo/bar/baz", + $this->tar->formatFilePath("//foo/bar///baz/") + ); + } +} +>>>>>>> Finish Tar archive builder diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index 10558a2c6..cdbe919b2 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -69,7 +69,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase ======= >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources */ - public function testGetFilePath() + public function testFormatFilePath() { $this->assertEquals( "foo", @@ -194,6 +194,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase } public function testFormatDirectoryPath() +<<<<<<< HEAD { $this->assertEquals( "/foo/", @@ -207,6 +208,8 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase } public function testGetDirectoryPath() +======= +>>>>>>> Finish Tar archive builder { $this->assertEquals( "/foo/", From ed3a932f92bfe42b61af1ae0b5d2b7de07c607c8 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 09:00:03 +0200 Subject: [PATCH 031/158] =?UTF-8?q?Finish=20tar,=20tar.gz,=20tar.bz2=20and?= =?UTF-8?q?=20tests=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/?= =?UTF-8?q?Thelia/Config/Resources/config.xml=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Abstr?= =?UTF-8?q?actArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Ta?= =?UTF-8?q?rArchiveBuilder.php=20=09nouveau=20fichier:=20core/lib/Thelia/C?= =?UTF-8?q?ore/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php?= =?UTF-8?q?=20=09nouveau=20fichier:=20core/lib/Thelia/Core/FileFormat/Arch?= =?UTF-8?q?ive/ArchiveBuilder/TarGzArchiveBuilder.php=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Arch?= =?UTF-8?q?ive/ArchiveBuilder/ZipArchiveBuilder.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive?= =?UTF-8?q?/ArchiveBuilderInterface.php=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBui?= =?UTF-8?q?lder/TarArchiveBuilderTest.php=20=09nouveau=20fichier:=20core/l?= =?UTF-8?q?ib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2Archive?= =?UTF-8?q?BuilderTest.php=20=09nouveau=20fichier:=20core/lib/Thelia/Tests?= =?UTF-8?q?/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/T?= =?UTF-8?q?ests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.ph?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/config.xml | 6 +-- .../Archive/AbstractArchiveBuilder.php | 16 ++++++ .../ArchiveBuilder/TarArchiveBuilder.php | 53 +++++++++++++++++++ .../ArchiveBuilder/TarBz2ArchiveBuilder.php | 4 ++ .../ArchiveBuilder/TarGzArchiveBuilder.php | 4 ++ .../ArchiveBuilder/ZipArchiveBuilder.php | 41 ++++++++++++-- .../Archive/ArchiveBuilderInterface.php | 14 ++++- .../ArchiveBuilder/TarArchiveBuilderTest.php | 22 +++++--- .../TarBz2ArchiveBuilderTest.php | 4 ++ .../TarGzArchiveBuilderTest.php | 8 +++ .../ArchiveBuilder/ZipArchiveBuilderTest.php | 43 +++++++++++++++ 11 files changed, 200 insertions(+), 15 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index cfeafe7c7..c2561d2f1 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -150,18 +150,18 @@ - + - + gz - + bz2 diff --git a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php index d709e5525..5c2acf0d7 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php @@ -62,12 +62,18 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder /** @var string */ protected $cacheDir; +<<<<<<< HEAD <<<<<<< HEAD /** @var string */ protected $environment; ======= >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources +======= + /** @var string */ + protected $environment; + +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests public function __construct() { $this->translator = Translator::getInstance(); @@ -244,10 +250,16 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder { return $this->cacheFile; } +<<<<<<< HEAD <<<<<<< HEAD /** * @param string $environment +======= + + /** + * @param string $environment +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests * @return $this * * Sets the execution environment of the Kernel, @@ -257,6 +269,7 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder { $this->environment = $environment; } +<<<<<<< HEAD } ======= } @@ -267,3 +280,6 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder ======= } >>>>>>> Finish implementing and testing zip +======= +} +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index 4387eb728..f61463161 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -60,6 +60,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \Thelia\Log\Tlog */ protected $logger; +<<<<<<< HEAD <<<<<<< HEAD ======= function __construct($compressionType = null) @@ -90,6 +91,8 @@ class TarArchiveBuilder extends AbstractArchiveBuilder ======= >>>>>>> Finish Tar archive builder +======= +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests public function __destruct() { if ($this->tar instanceof \PharData) { @@ -433,6 +436,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * * Loads an archive */ +<<<<<<< HEAD <<<<<<< HEAD public function loadArchive($pathToArchive, $isOnline = false) { @@ -463,11 +467,21 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $instance->setCacheFile($instance->generateCacheFile($environment)) ->copyFile($pathToArchive, $instance->getCacheFile(), $isOnline); >>>>>>> Fix FileDownloader test +======= + public function loadArchive($pathToArchive, $isOnline = false) + { + $tar = clone $this; + + $tar + ->setCacheFile($tar->generateCacheFile($this->environment)) + ->copyFile($pathToArchive, $tar->getCacheFile(), $isOnline); +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests /** * This throws TarArchiveBuilderException if * the archive is not valid. */ +<<<<<<< HEAD <<<<<<< HEAD return $tar->setEnvironment($tar->environment); @@ -476,6 +490,9 @@ class TarArchiveBuilder extends AbstractArchiveBuilder return $instance; >>>>>>> Finish implementing and testing zip +======= + return $tar->setEnvironment($tar->environment); +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests } /** @@ -566,6 +583,9 @@ class TarArchiveBuilder extends AbstractArchiveBuilder public function setEnvironment($environment) { <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests if (empty($environment)) { throw new \ErrorException( $this->translator->trans( @@ -574,8 +594,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder ); } +<<<<<<< HEAD ======= >>>>>>> Finish implementing and testing zip +======= +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests if ($this->cacheFile === null) { $cacheFile = $this->generateCacheFile($environment); @@ -591,6 +614,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder try { $this->tar = new \PharData($cacheFile, null, null, static::PHAR_FORMAT); +<<<<<<< HEAD <<<<<<< HEAD $this->compressionEntryPoint(); @@ -606,6 +630,10 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $cacheFile .= ".bz2"; break; } +======= + $this->compressionEntryPoint(); + +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests } catch(\BadMethodCallException $e) { >>>>>>> Finish implementing and testing zip @@ -633,10 +661,14 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } $this->cacheFile = $cacheFile; +<<<<<<< HEAD <<<<<<< HEAD $this->environment = $environment; ======= >>>>>>> Finish implementing and testing zip +======= + $this->environment = $environment; +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests return $this; } @@ -693,6 +725,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getName() { +<<<<<<< HEAD <<<<<<< HEAD return "tar"; ======= @@ -704,6 +737,9 @@ class TarArchiveBuilder extends AbstractArchiveBuilder return $name; >>>>>>> Finish implementing and testing zip +======= + return "tar"; +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests } /** @@ -717,11 +753,15 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getExtension() { +<<<<<<< HEAD <<<<<<< HEAD return "tar"; ======= return $this->getName(); >>>>>>> Finish implementing and testing zip +======= + return "tar"; +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests } /** @@ -735,6 +775,9 @@ class TarArchiveBuilder extends AbstractArchiveBuilder public function getMimeType() { <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests return "application/x-tar"; } @@ -744,6 +787,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * This method must be overwritten if you want to do some * stuff to compress you archive */ +<<<<<<< HEAD } public function getCompression() @@ -760,3 +804,12 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } >>>>>>> Finish implementing and testing zip +======= + } + + public function getCompression() + { + return $this->compression; + } +} +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php index 774d082df..201c19234 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php @@ -44,4 +44,8 @@ class TarBz2ArchiveBuilder extends TarArchiveBuilder return $this; } +<<<<<<< HEAD } +======= +} +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php index 4722417fa..6ba4cd8cf 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php @@ -49,4 +49,8 @@ class TarGzArchiveBuilder extends TarArchiveBuilder return $this; } +<<<<<<< HEAD } +======= +} +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index 796be2fe1..c4d305382 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -373,6 +373,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * If it's local check if the file exists and if it is redable */ <<<<<<< HEAD +<<<<<<< HEAD >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources if ($isOnline) { $fileDownloadCache = $this->cacheDir . DS . "download"; @@ -403,6 +404,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } ======= $fileDownloadCache = $this->cacheDir . DS . "download.tmp"; +======= + $fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp"; +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests $this->copyFile($filePath, $fileDownloadCache, $isOnline); >>>>>>> Finish implementing and testing zip @@ -421,9 +425,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $this->logger->error($translatedErrorMessage); + // if error delete the cache file + unlink($fileDownloadCache); + throw new \ErrorException($translatedErrorMessage); } + // If not too + unlink($fileDownloadCache); + $this->commit(); return $this; @@ -714,23 +724,30 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * @return ZipArchiveBuilder ======= * @param string $pathToArchive - * @param string $environment * @param bool $isOnline * @param FileDownloaderInterface $fileDownloader +<<<<<<< HEAD * @return $this >>>>>>> Define archive builders and formatters +======= + * @return ZipArchiveBuilder +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException * * Loads an archive */ <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests public function loadArchive($pathToArchive, $isOnline = false) { $back = $this->zip; $this->zip = new \ZipArchive(); $zip = clone $this; $this->zip = $back; +<<<<<<< HEAD $zip->setEnvironment($this->environment); @@ -764,17 +781,29 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if ($fileDownloader !== null) { $instance->setFileDownloader($fileDownloader); } +======= +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests - $instance->copyFile($pathToArchive, $instance->getCacheFile(), $isOnline); + $zip->setEnvironment($this->environment); - if (true !== $return = $zip->open($instance->getCacheFile())) { + $zip->copyFile( + $pathToArchive, + $zip->getCacheFile(), + $isOnline + ); + + if (true !== $return = $zip->getRawZipArchive()->open($zip->getCacheFile())) { throw new ZipArchiveException( - $instance->getZipErrorMessage($return) + $zip->getZipErrorMessage($return) ); } +<<<<<<< HEAD return $instance; >>>>>>> Define archive builders and formatters +======= + return $zip; +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests } /** @@ -837,6 +866,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder public function setEnvironment($environment) { <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD parent::setEnvironment($environment); @@ -874,6 +904,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $cacheFile .= "." . $this->getExtension(); >>>>>>> Define archive builders and formatters ======= +======= + parent::setEnvironment($environment); +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests <<<<<<< HEAD $cacheFileName = md5 (uniqid()); diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php index 1b4cb8688..5b2273889 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -11,7 +11,7 @@ /*************************************************************************************/ namespace Thelia\Core\FileFormat\Archive; -use Thelia\Tools\FileDownload\FileDownloaderInterface; + /** * Interface ArchiveBuilderInterface @@ -150,13 +150,15 @@ interface ArchiveBuilderInterface /** * @param string $pathToArchive - * @param string $environment * @param bool $isOnline <<<<<<< HEAD +<<<<<<< HEAD >>>>>>> Define archive builders and formatters ======= * @param FileDownloaderInterface $fileDownloader >>>>>>> Finish implementing and testing zip +======= +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException @@ -164,6 +166,7 @@ interface ArchiveBuilderInterface * Loads an archive */ <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD public function loadArchive($pathToArchive, $isOnline = false); ======= @@ -172,6 +175,9 @@ interface ArchiveBuilderInterface ======= public static function loadArchive($pathToArchive, $environment, $isOnline = false, FileDownloaderInterface $fileDownloader = null); >>>>>>> Finish implementing and testing zip +======= + public function loadArchive($pathToArchive, $isOnline = false); +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests /** * @param $pathToFile @@ -193,6 +199,7 @@ interface ArchiveBuilderInterface */ public function hasDirectory($directory); +<<<<<<< HEAD <<<<<<< HEAD } ======= @@ -206,3 +213,6 @@ interface ArchiveBuilderInterface public function setEnvironment($environment); } >>>>>>> Define archive builders and formatters +======= +} +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index 83689d1fa..36b57e8be 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -381,9 +381,8 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testLoadValidArchive() { - $tar = TarArchiveBuilder::loadArchive( - __DIR__ . DS . "TestResources/well_formatted.tar", - "dev" + $tar = $this->tar->loadArchive( + __DIR__ . DS . "TestResources/well_formatted.tar" ); $this->assertInstanceOf( @@ -401,9 +400,8 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase */ public function testLoadInvalidArchive() { - $tar = TarArchiveBuilder::loadArchive( - __DIR__ . DS . "TestResources/bad_formatted.tar", - "dev" + $tar = $this->tar->loadArchive( + __DIR__ . DS . "TestResources/bad_formatted.tar" ); } @@ -512,5 +510,17 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->tar->formatFilePath("//foo/bar///baz/") ); } +<<<<<<< HEAD } >>>>>>> Finish Tar archive builder +======= + + public function testCompression() + { + $this->assertEquals( + null, + $this->tar->getCompression() + ); + } +} +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php index a65892424..c4ec0dd3b 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php @@ -35,4 +35,8 @@ class TarBz2ArchiveBuilderTest extends TarArchiveBuilderTest $this->tar->getCompression() ); } +<<<<<<< HEAD } +======= +} +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php index 5b1aded6e..6f6f526cf 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php @@ -12,6 +12,10 @@ namespace Thelia\Tests\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarGzArchiveBuilder; +<<<<<<< HEAD +======= +use Thelia\Core\HttpFoundation\Response; +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests /** * Class TarGzArchiveBuilderTest @@ -35,4 +39,8 @@ class TarGzArchiveBuilderTest extends TarArchiveBuilderTest $this->tar->getCompression() ); } +<<<<<<< HEAD } +======= +} +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index cdbe919b2..52feada77 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -40,6 +40,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->zip = new ZipArchiveBuilder(); +<<<<<<< HEAD <<<<<<< HEAD $this->zip->setEnvironment("dev"); @@ -50,6 +51,12 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase __DIR__ . DS . "TestResources/well_formatted.zip", "dev" >>>>>>> Define archive builders and formatters +======= + $this->zip->setEnvironment("dev"); + + $this->loadedZip = $this->zip->loadArchive( + __DIR__ . DS . "TestResources/well_formatted.zip" +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); } @@ -342,12 +349,16 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testLoadValidZip() { $loadedZip = $this->zip->loadArchive( +<<<<<<< HEAD <<<<<<< HEAD __DIR__ . DS . "TestResources/well_formatted.zip" ======= __DIR__ . DS . "TestResources/well_formatted.zip", "dev" >>>>>>> Define archive builders and formatters +======= + __DIR__ . DS . "TestResources/well_formatted.zip" +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); $this->assertInstanceOf( @@ -371,12 +382,16 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testLoadNotValidZip() { $this->zip->loadArchive( +<<<<<<< HEAD <<<<<<< HEAD __DIR__ . DS . "TestResources/bad_formatted.zip" ======= __DIR__ . DS . "TestResources/bad_formatted.zip", "dev" >>>>>>> Define archive builders and formatters +======= + __DIR__ . DS . "TestResources/bad_formatted.zip" +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); } @@ -386,17 +401,22 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testLoadNotExistingFile() { $this->zip->loadArchive( +<<<<<<< HEAD <<<<<<< HEAD __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip" ======= __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", "dev" >>>>>>> Define archive builders and formatters +======= + __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip" +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); } public function testLoadOnlineAvailableAndValidFile() { +<<<<<<< HEAD <<<<<<< HEAD $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); @@ -410,6 +430,13 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase true, FakeFileDownloader::getInstance() >>>>>>> Define archive builders and formatters +======= + $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); + + $this->zip->loadArchive( + __DIR__ . DS . "TestResources/well_formatted.zip", + true +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); } @@ -427,6 +454,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase */ public function testLoadOnlineAvailableAndNotValidFile() { +<<<<<<< HEAD <<<<<<< HEAD $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); @@ -440,6 +468,13 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase true, FakeFileDownloader::getInstance() >>>>>>> Define archive builders and formatters +======= + $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); + + $this->zip->loadArchive( + __DIR__ . DS . "TestResources/bad_formatted.zip", + true +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); } @@ -448,6 +483,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase */ public function testLoadOnlineNotExistingFile() { +<<<<<<< HEAD <<<<<<< HEAD $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); @@ -461,6 +497,13 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase true, FakeFileDownloader::getInstance() >>>>>>> Define archive builders and formatters +======= + $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); + + $this->zip->loadArchive( + __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", + true +>>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); } From d1a6d55a72e6c1f80168a38b721e83afc7cfb67d Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 09:29:57 +0200 Subject: [PATCH 032/158] =?UTF-8?q?Fix=20services=20=09modifi=C3=A9:=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20core/lib/Thelia/Config/Resources/config.xm?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/config.xml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index c2561d2f1..30968906e 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -138,7 +138,7 @@ <<<<<<< HEAD ======= - + %kernel.environment% @@ -156,17 +156,17 @@ - gz - bz2 + +<<<<<<< HEAD >>>>>>> Add archive builder manager and formatter manager services @@ -199,5 +199,8 @@ +======= + +>>>>>>> Fix services From 0ceecf09c81da505d71bd86178d7b0dde95e5d08 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 09:38:27 +0200 Subject: [PATCH 033/158] =?UTF-8?q?revert=20file=20to=20ccd16dc=20=09modif?= =?UTF-8?q?i=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/Tools/?= =?UTF-8?q?FileManagerTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Tests/Tools/FileManagerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Tests/Tools/FileManagerTest.php b/core/lib/Thelia/Tests/Tools/FileManagerTest.php index 29e4f2966..e611b2c53 100644 --- a/core/lib/Thelia/Tests/Tools/FileManagerTest.php +++ b/core/lib/Thelia/Tests/Tools/FileManagerTest.php @@ -787,7 +787,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->getMock(); $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') - ->disableOriginalConstructor() + ->setConstructorArgs([__DIR__ . '/fixtures/test.xml', 'test.xml']) ->getMock(); $stubUploadedFile->expects($this->any()) ->method('getClientOriginalExtension') @@ -814,7 +814,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->getMock(); $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') - ->disableOriginalConstructor() + ->setConstructorArgs([__DIR__ . '/fixtures/test.xml', 'test.xml']) ->getMock(); $stubUploadedFile->expects($this->any()) ->method('getClientOriginalExtension') From 713637196085f83e1b65314be2cf13f1031a2aa3 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 09:46:21 +0200 Subject: [PATCH 034/158] =?UTF-8?q?Fix=20Zip=20add=20file,=20we=20must=20f?= =?UTF-8?q?irst=20commit=20and=20then=20delete=20the=20temporary=20file=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core?= =?UTF-8?q?/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index c4d305382..5113d2fde 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -431,11 +431,11 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder throw new \ErrorException($translatedErrorMessage); } - // If not too - unlink($fileDownloadCache); - $this->commit(); + // Delete the temp file + unlink($fileDownloadCache); + return $this; >>>>>>> Define archive builders and formatters } From 2e4987a47cfc7385a82c4a46c20cdb5c46f0024a Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 10:01:29 +0200 Subject: [PATCH 035/158] =?UTF-8?q?Fix=20cs=20=09modifi=C3=A9:=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Abstract?= =?UTF-8?q?ArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Excep?= =?UTF-8?q?tion/TarArchiveException.php=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuil?= =?UTF-8?q?der/Exception/ZipArchiveException.php=20=09modifi=C3=A9:=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Ar?= =?UTF-8?q?chiveBuilder/TarArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Archi?= =?UTF-8?q?veBuilder/TarBz2ArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Archi?= =?UTF-8?q?veBuilder/TarGzArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Archi?= =?UTF-8?q?veBuilder/ZipArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveB?= =?UTF-8?q?uilderInterface.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManage?= =?UTF-8?q?r.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/The?= =?UTF-8?q?lia/Core/FileFormat/FormatInterface.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatt?= =?UTF-8?q?er/AbstractFormatter.php=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/Core/FileFormat/Formatter/Exception/Ba?= =?UTF-8?q?dFormattedStringException.php=20=09nouveau=20fichier:=20core/li?= =?UTF-8?q?b/Thelia/Core/FileFormat/Formatter/FormatterData.php=20=09nouve?= =?UTF-8?q?au=20fichier:=20core/lib/Thelia/Core/FileFormat/Formatter/Forma?= =?UTF-8?q?tterInterface.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/T?= =?UTF-8?q?ests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.ph?= =?UTF-8?q?p=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/?= =?UTF-8?q?Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTes?= =?UTF-8?q?t.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/The?= =?UTF-8?q?lia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder?= =?UTF-8?q?Test.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/?= =?UTF-8?q?Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilde?= =?UTF-8?q?rTest.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib?= =?UTF-8?q?/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/T?= =?UTF-8?q?ests/FileFormat/Formatter/FormatterManagerTest.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/Tools/F?= =?UTF-8?q?akeFileDownloader.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Tests/Tools/FileDownloaderTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/AbstractArchiveBuilder.php | 8 ++ .../Exception/TarArchiveException.php | 4 + .../Exception/ZipArchiveException.php | 2 +- .../ArchiveBuilder/TarArchiveBuilder.php | 78 +++++++++++++++++++ .../ArchiveBuilder/TarBz2ArchiveBuilder.php | 4 + .../ArchiveBuilder/TarGzArchiveBuilder.php | 4 + .../ArchiveBuilder/ZipArchiveBuilder.php | 56 ++++++++++++- .../Archive/ArchiveBuilderInterface.php | 28 ++++++- .../Archive/ArchiveBuilderManager.php | 8 ++ .../Core/FileFormat/FormatInterface.php | 4 + .../Formatter/AbstractFormatter.php | 21 +---- .../Exception/BadFormattedStringException.php | 2 +- .../FileFormat/Formatter/FormatterData.php | 23 ++++++ .../Formatter/FormatterInterface.php | 39 ++++++++++ .../FileFormat/Formatter/FormatterManager.php | 4 +- .../ArchiveBuilder/TarArchiveBuilderTest.php | 6 +- .../TarBz2ArchiveBuilderTest.php | 4 + .../TarGzArchiveBuilderTest.php | 7 ++ .../ArchiveBuilder/ZipArchiveBuilderTest.php | 4 + .../Archive/ArchiveBuilderManagerTest.php | 4 + .../Formatter/FormatterManagerTest.php | 2 +- .../Thelia/Tests/Tools/FakeFileDownloader.php | 9 +++ .../Thelia/Tests/Tools/FileDownloaderTest.php | 4 + 23 files changed, 295 insertions(+), 30 deletions(-) create mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php create mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php diff --git a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php index 5c2acf0d7..18b06931c 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php @@ -258,8 +258,12 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder ======= /** +<<<<<<< HEAD * @param string $environment >>>>>>> Finish tar, tar.gz, tar.bz2 and tests +======= + * @param string $environment +>>>>>>> Fix cs * @return $this * * Sets the execution environment of the Kernel, @@ -270,6 +274,7 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder $this->environment = $environment; } <<<<<<< HEAD +<<<<<<< HEAD } ======= } @@ -283,3 +288,6 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder ======= } >>>>>>> Finish tar, tar.gz, tar.bz2 and tests +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php index 9566c4eaa..977860947 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php @@ -20,8 +20,12 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception; class TarArchiveException extends \Exception { +<<<<<<< HEAD <<<<<<< HEAD } ======= } >>>>>>> Finish implementing and testing zip +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php index 24f9ddb37..f69375dec 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php @@ -20,4 +20,4 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception; class ZipArchiveException extends \ErrorException { -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index f61463161..272408b28 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -109,6 +109,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * @param string $directoryInArchive This is the directory where it will be stored in the archive * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name * @param bool $isOnline +<<<<<<< HEAD ======= }*/ ======= @@ -121,6 +122,8 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name * @param bool $isOnline >>>>>>> Finish implementing and testing zip +======= +>>>>>>> Fix cs * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -184,11 +187,15 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** * @param $content * @param $name +<<<<<<< HEAD <<<<<<< HEAD * @param string $directoryInArchive ======= * @param string $directoryInArchive >>>>>>> Finish implementing and testing zip +======= + * @param string $directoryInArchive +>>>>>>> Fix cs * @return mixed * @throws \ErrorException * @@ -213,11 +220,15 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } try { $this->tar->addFromString($name, $content); +<<<<<<< HEAD <<<<<<< HEAD } catch (\Exception $e) { ======= } catch(\Exception $e) { >>>>>>> Finish implementing and testing zip +======= + } catch (\Exception $e) { +>>>>>>> Fix cs throw new \ErrorException( $this->translator->trans( "Error while writing the file into the archive, error message: %errmes", @@ -229,10 +240,13 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } } +<<<<<<< HEAD <<<<<<< HEAD ======= >>>>>>> Finish implementing and testing zip +======= +>>>>>>> Fix cs /** * @param $directoryPath * @return $this @@ -248,11 +262,15 @@ class TarArchiveBuilder extends AbstractArchiveBuilder try { $this->tar->addEmptyDir($directoryInArchive); +<<<<<<< HEAD <<<<<<< HEAD } catch (\Exception $e) { ======= } catch(\Exception $e) { >>>>>>> Finish implementing and testing zip +======= + } catch (\Exception $e) { +>>>>>>> Fix cs throw new \ErrorException( $this->translator->trans( "The directory %dir has not been created in the archive", @@ -268,11 +286,15 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $pathToFile ======= * @param string $pathToFile >>>>>>> Finish implementing and testing zip +======= + * @param string $pathToFile +>>>>>>> Fix cs * @return null|string * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -315,6 +337,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder return $content; } +<<<<<<< HEAD ======= ======= @@ -324,6 +347,8 @@ class TarArchiveBuilder extends AbstractArchiveBuilder >>>>>>> Finish implementing and testing zip +======= +>>>>>>> Fix cs /** * @param $pathInArchive * @return $this @@ -424,11 +449,18 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** +<<<<<<< HEAD * @param string $pathToArchive * @param string $environment * @param bool $isOnline * @param FileDownloaderInterface $fileDownloader >>>>>>> Finish implementing and testing zip +======= + * @param string $pathToArchive + * @param string $environment + * @param bool $isOnline + * @param FileDownloaderInterface $fileDownloader +>>>>>>> Fix cs * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException @@ -483,6 +515,9 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Fix cs return $tar->setEnvironment($tar->environment); ======= @@ -512,31 +547,43 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \PharFileInfo $fileInfo */ $fileInfo = $this->tar[$pathToFile]; +<<<<<<< HEAD <<<<<<< HEAD if ($fileInfo->isFile()) { ======= if($fileInfo->isFile()) { >>>>>>> Finish implementing and testing zip +======= + if ($fileInfo->isFile()) { +>>>>>>> Fix cs $isFile = true; } /** * Catch the exception to avoid its displaying. */ +<<<<<<< HEAD <<<<<<< HEAD } catch (\BadMethodCallException $e) {} ======= } catch(\BadMethodCallException $e) {} >>>>>>> Finish implementing and testing zip +======= + } catch (\BadMethodCallException $e) {} +>>>>>>> Fix cs return $isFile; } /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $directory ======= * @param string $directory >>>>>>> Finish implementing and testing zip +======= + * @param string $directory +>>>>>>> Fix cs * @return bool * * Check if the archive has a directory @@ -550,31 +597,43 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \PharFileInfo $fileInfo */ $fileInfo = $this->tar[$pathToDir]; +<<<<<<< HEAD <<<<<<< HEAD if ($fileInfo->isDir()) { ======= if($fileInfo->isDir()) { >>>>>>> Finish implementing and testing zip +======= + if ($fileInfo->isDir()) { +>>>>>>> Fix cs $isDir = true; } /** * Catch the exception to avoid its displaying. */ +<<<<<<< HEAD <<<<<<< HEAD } catch (\BadMethodCallException $e) {} ======= } catch(\BadMethodCallException $e) {} >>>>>>> Finish implementing and testing zip +======= + } catch (\BadMethodCallException $e) {} +>>>>>>> Fix cs return $isDir; } /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $environment ======= * @param string $environment >>>>>>> Finish implementing and testing zip +======= + * @param string $environment +>>>>>>> Fix cs * @return $this * * Sets the execution environment of the Kernel, @@ -619,6 +678,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $this->compressionEntryPoint(); } catch (\BadMethodCallException $e) { +<<<<<<< HEAD ======= switch ($this->compression) { case "gz": @@ -637,15 +697,21 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } catch(\BadMethodCallException $e) { >>>>>>> Finish implementing and testing zip +======= +>>>>>>> Fix cs /** * This should not happen */ $errorMessage = "You have badly called the method setEnvironment twice for %file"; +<<<<<<< HEAD <<<<<<< HEAD } catch (\UnexpectedValueException $e) { ======= } catch(\UnexpectedValueException $e) { >>>>>>> Finish implementing and testing zip +======= + } catch (\UnexpectedValueException $e) { +>>>>>>> Fix cs $errorMessage = "The file %file is corrupted"; } @@ -674,11 +740,15 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $initialString ======= * @param string $initialString >>>>>>> Finish implementing and testing zip +======= + * @param string $initialString +>>>>>>> Fix cs * @return string * * Gives a valid file path for \ZipArchive @@ -699,11 +769,15 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $initialString ======= * @param string $initialString >>>>>>> Finish implementing and testing zip +======= + * @param string $initialString +>>>>>>> Fix cs * @return string * * Gives a valid directory path for \ZipArchive @@ -811,5 +885,9 @@ class TarArchiveBuilder extends AbstractArchiveBuilder { return $this->compression; } +<<<<<<< HEAD } >>>>>>> Finish tar, tar.gz, tar.bz2 and tests +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php index 201c19234..1b198bd8c 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php @@ -45,7 +45,11 @@ class TarBz2ArchiveBuilder extends TarArchiveBuilder return $this; } <<<<<<< HEAD +<<<<<<< HEAD } ======= } >>>>>>> Finish tar, tar.gz, tar.bz2 and tests +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php index 6ba4cd8cf..5ae97afff 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php @@ -49,8 +49,12 @@ class TarGzArchiveBuilder extends TarArchiveBuilder return $this; } +<<<<<<< HEAD <<<<<<< HEAD } ======= } >>>>>>> Finish tar, tar.gz, tar.bz2 and tests +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index 5113d2fde..9261cba3a 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -94,11 +94,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * On the destruction of the class, * remove the temporary file. */ +<<<<<<< HEAD <<<<<<< HEAD public function __destruct() ======= function __destruct() >>>>>>> Define archive builders and formatters +======= + public function __destruct() +>>>>>>> Fix cs { if ($this->zip instanceof \ZipArchive) { @$this->zip->close(); @@ -126,10 +130,14 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder /** <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Fix cs * @param string $filePath It is the path to access the file. * @param string $directoryInArchive This is the directory where it will be stored in the archive * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name * @param bool $isOnline +<<<<<<< HEAD * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -139,6 +147,8 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * @param string $directoryInArchive This is the directory where it will be stored in the archive * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name * @param bool $isOnline +======= +>>>>>>> Fix cs * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -163,6 +173,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ if (!empty($directoryInArchive)) { +<<<<<<< HEAD $this->addDirectory($directoryInArchive); } @@ -270,6 +281,8 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ if(!empty($directoryInArchive)) { +======= +>>>>>>> Fix cs $this->addDirectory($directoryInArchive); } @@ -443,7 +456,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder /** * @param $content * @param $name - * @param string $directoryInArchive + * @param string $directoryInArchive * @return mixed * @throws \ErrorException * @@ -510,7 +523,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** - * @param string $pathToFile + * @param string $pathToFile * @return null|string * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -540,7 +553,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder /** - * @param string $initialString + * @param string $initialString * @return string * * Gives a valid file path for \ZipArchive @@ -560,11 +573,12 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if (preg_match("#\/?[^\/]+\/[^\/]+\/?#", $initialString)) { $initialString = "/" . $initialString; } + return $initialString; } /** - * @param string $initialString + * @param string $initialString * @return string * * Gives a valid directory path for \ZipArchive @@ -717,6 +731,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $pathToArchive * @param bool $isOnline @@ -730,6 +745,11 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * @return $this >>>>>>> Define archive builders and formatters ======= +======= + * @param string $pathToArchive + * @param bool $isOnline + * @param FileDownloaderInterface $fileDownloader +>>>>>>> Fix cs * @return ZipArchiveBuilder >>>>>>> Finish tar, tar.gz, tar.bz2 and tests * @throws \Thelia\Exception\FileNotFoundException @@ -828,11 +848,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $directory ======= * @param string $directory >>>>>>> Define archive builders and formatters +======= + * @param string $directory +>>>>>>> Fix cs * @return bool * * Checks if the link $directory exists and if it's not a file. @@ -853,11 +877,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $environment ======= * @param string $environment >>>>>>> Define archive builders and formatters +======= + * @param string $environment +>>>>>>> Fix cs * @return $this * * Sets the execution environment of the Kernel, @@ -927,6 +955,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder \ZipArchive::CREATE ); +<<<<<<< HEAD <<<<<<< HEAD if ($opening !== true) { throw new \ErrorException( @@ -934,6 +963,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder "An unknown error append" ======= if($opening !== true) { +======= + if ($opening !== true) { +>>>>>>> Fix cs throw new \ErrorException( $this->translator->trans( <<<<<<< HEAD @@ -1052,11 +1084,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $initialString ======= * @param string $initialString >>>>>>> Define archive builders and formatters +======= + * @param string $initialString +>>>>>>> Fix cs * @return string * * Gives a valid file path for \ZipArchive @@ -1085,18 +1121,26 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $initialString = "/" . $initialString; } <<<<<<< HEAD +<<<<<<< HEAD ======= >>>>>>> Define archive builders and formatters +======= + +>>>>>>> Fix cs return $initialString; } /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $initialString ======= * @param string $initialString >>>>>>> Define archive builders and formatters +======= + * @param string $initialString +>>>>>>> Fix cs * @return string * * Gives a valid directory path for \ZipArchive @@ -1219,6 +1263,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD } ======= @@ -1240,3 +1285,6 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder ======= } >>>>>>> Finish implementing and testing zip +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php index 5b2273889..3eb0aaa84 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -12,7 +12,6 @@ namespace Thelia\Core\FileFormat\Archive; - /** * Interface ArchiveBuilderInterface * @package Thelia\Core\FileFormat\Archive @@ -32,10 +31,14 @@ interface ArchiveBuilderInterface { /** <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Fix cs * @param string $filePath It is the path to access the file. * @param string $directoryInArchive This is the directory where it will be stored in the archive * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name * @param bool $isOnline +<<<<<<< HEAD * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -45,6 +48,8 @@ interface ArchiveBuilderInterface * @param string $directoryInArchive This is the directory where it will be stored in the archive * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name * @param bool $isOnline +======= +>>>>>>> Fix cs * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -69,8 +74,12 @@ interface ArchiveBuilderInterface ======= * @param $content * @param $name +<<<<<<< HEAD * @param string $directoryInArchive >>>>>>> Finish implementing and testing zip +======= + * @param string $directoryInArchive +>>>>>>> Fix cs * @return mixed * @throws \ErrorException * @@ -79,11 +88,15 @@ interface ArchiveBuilderInterface public function addFileFromString($content, $name, $directoryInArchive = "/"); /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $pathToFile ======= * @param string $pathToFile >>>>>>> Finish implementing and testing zip +======= + * @param string $pathToFile +>>>>>>> Fix cs * @return null|string * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -149,6 +162,7 @@ interface ArchiveBuilderInterface public function buildArchiveResponse(); /** +<<<<<<< HEAD * @param string $pathToArchive * @param bool $isOnline <<<<<<< HEAD @@ -159,6 +173,10 @@ interface ArchiveBuilderInterface >>>>>>> Finish implementing and testing zip ======= >>>>>>> Finish tar, tar.gz, tar.bz2 and tests +======= + * @param string $pathToArchive + * @param bool $isOnline +>>>>>>> Fix cs * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException @@ -188,17 +206,22 @@ interface ArchiveBuilderInterface public function hasFile($pathToFile); /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $directory ======= * @param string $directory >>>>>>> Define archive builders and formatters +======= + * @param string $directory +>>>>>>> Fix cs * @return bool * * Check if the archive has a directory */ public function hasDirectory($directory); +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD } @@ -216,3 +239,6 @@ interface ArchiveBuilderInterface ======= } >>>>>>> Finish tar, tar.gz, tar.bz2 and tests +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php index 7e62c2c34..e8a13a20e 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php @@ -34,6 +34,7 @@ class ArchiveBuilderManager $this->environment = $environment; } /** +<<<<<<< HEAD <<<<<<< HEAD * @param AbstractArchiveBuilder $archiveBuilder * @return $this @@ -46,6 +47,9 @@ class ArchiveBuilderManager $this->archiveBuilders[$archiveBuilder->getName()] = $archiveBuilder; ======= * @param AbstractArchiveBuilder $archiveCreator +======= + * @param AbstractArchiveBuilder $archiveCreator +>>>>>>> Fix cs * @return $this */ public function add(AbstractArchiveBuilder $archiveCreator) @@ -143,5 +147,9 @@ class ArchiveBuilderManager { return $this->archiveCreators; } +<<<<<<< HEAD } >>>>>>> Define archive builders and formatters +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/FormatInterface.php b/core/lib/Thelia/Core/FileFormat/FormatInterface.php index f51e35905..290bdabc5 100644 --- a/core/lib/Thelia/Core/FileFormat/FormatInterface.php +++ b/core/lib/Thelia/Core/FileFormat/FormatInterface.php @@ -56,7 +56,11 @@ interface FormatInterface */ public function getMimeType(); <<<<<<< HEAD +<<<<<<< HEAD } ======= } >>>>>>> Define archive builders and formatters +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php index f991535c8..605bc6362 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php @@ -18,24 +18,7 @@ use Thelia\Core\FileFormat\FormatInterface; * @package Thelia\Core\FileFormat\Formatter * @author Benjamin Perche */ -abstract class AbstractFormatter implements FormatInterface +abstract class AbstractFormatter implements FormatInterface, FormatterInterface { - /** - * @param array $data - * @return mixed - * - * Encodes an array to the desired format. - * $data array only contains array and scalar data. - */ - abstract public function encode(array $data); - /** - * @param $data - * @return array - * @throws \Thelia\Core\FileFormat\Formatter\Exception\BadFormattedStringException - * - * this method must do exactly the opposite of encode and return - * an array composed of array and scalar data. - */ - abstract public function decode($data); -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php b/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php index 6d763a01b..18d28bb78 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php @@ -20,4 +20,4 @@ namespace Thelia\Core\FileFormat\Formatter\Exception; class BadFormattedStringException extends \ErrorException { -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php new file mode 100644 index 000000000..689ad0ba6 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php @@ -0,0 +1,23 @@ + + */ +class FormatterData +{ + +} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php new file mode 100644 index 000000000..4d2d2d91e --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php @@ -0,0 +1,39 @@ + + */ +interface FormatterInterface +{ + /** + * @param FormatterData $data + * @return mixed + * + * This method must use a FormatterData object and output + * a formatted value. + */ + public function encode(FormatterData $data); + + /** + * @param $rawData + * @return FormatterData + * + * This must takes raw data as argument and outputs + * a FormatterData object. + */ + public function decode($rawData); +} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php index cc8aad8e4..b8e5d5d66 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php @@ -18,7 +18,7 @@ use Thelia\Core\Translation\Translator; * @package Thelia\Core\FileFormat\Formatter * @author Benjamin Perche */ -class FormatterManager +class FormatterManager { protected $formatters = array(); @@ -66,4 +66,4 @@ class FormatterManager { return $this->formatters; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index 36b57e8be..03490d45a 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -457,7 +457,7 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->tar->formatDirectoryPath("//foo/bar///baz/") ); } - + public function testFormatFilePath() { $this->assertEquals( @@ -522,5 +522,9 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->tar->getCompression() ); } +<<<<<<< HEAD } >>>>>>> Finish tar, tar.gz, tar.bz2 and tests +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php index c4ec0dd3b..47bd9e82d 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php @@ -36,7 +36,11 @@ class TarBz2ArchiveBuilderTest extends TarArchiveBuilderTest ); } <<<<<<< HEAD +<<<<<<< HEAD } ======= } >>>>>>> Finish tar, tar.gz, tar.bz2 and tests +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php index 6f6f526cf..324d5f2dc 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php @@ -13,9 +13,12 @@ namespace Thelia\Tests\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarGzArchiveBuilder; <<<<<<< HEAD +<<<<<<< HEAD ======= use Thelia\Core\HttpFoundation\Response; >>>>>>> Finish tar, tar.gz, tar.bz2 and tests +======= +>>>>>>> Fix cs /** * Class TarGzArchiveBuilderTest @@ -40,7 +43,11 @@ class TarGzArchiveBuilderTest extends TarArchiveBuilderTest ); } <<<<<<< HEAD +<<<<<<< HEAD } ======= } >>>>>>> Finish tar, tar.gz, tar.bz2 and tests +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index 52feada77..fa8ea74d1 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -693,6 +693,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase ); } +<<<<<<< HEAD <<<<<<< HEAD } ======= @@ -701,3 +702,6 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase ======= } >>>>>>> Finish implementing and testing zip +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php index 7e92216bf..f5907f49c 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php @@ -72,8 +72,12 @@ class ArchiveBuilderManagerTest extends \PHPUnit_Framework_TestCase $this->manager->delete("foo"); } +<<<<<<< HEAD <<<<<<< HEAD } ======= } >>>>>>> Define archive builders and formatters +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php index 8759c2fca..39bf06cb3 100644 --- a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php @@ -71,4 +71,4 @@ class FormatterManagerTest extends \PHPUnit_Framework_TestCase { $this->manager->delete("foo"); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php b/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php index eb3a32918..524ef3aa7 100644 --- a/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php +++ b/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php @@ -22,6 +22,7 @@ use Thelia\Tools\FileDownload\FileDownloader; class FakeFileDownloader extends FileDownloader { /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $url * @param string $pathToStore @@ -29,6 +30,10 @@ class FakeFileDownloader extends FileDownloader * @param string $url * @param string $pathToStore >>>>>>> Define archive builders and formatters +======= + * @param string $url + * @param string $pathToStore +>>>>>>> Fix cs * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException * @throws \HttpUrlException @@ -46,8 +51,12 @@ class FakeFileDownloader extends FileDownloader } } +<<<<<<< HEAD <<<<<<< HEAD } ======= } >>>>>>> Define archive builders and formatters +======= +} +>>>>>>> Fix cs diff --git a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php index 263d67db7..2c5a0c2a8 100644 --- a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php +++ b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php @@ -69,7 +69,11 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase $this->downloader->download("https://github.com/thelia/thelia", "php://temp"); } <<<<<<< HEAD +<<<<<<< HEAD } ======= } >>>>>>> Define archive builders and formatters +======= +} +>>>>>>> Fix cs From c2720c9f2f75680661662557c1454f8999692429 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 13:44:28 +0200 Subject: [PATCH 036/158] =?UTF-8?q?Fix=20cs=20and=20add=20get=20method=20i?= =?UTF-8?q?n=20managers=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/?= =?UTF-8?q?lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core?= =?UTF-8?q?/FileFormat/Formatter/FormatterData.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatt?= =?UTF-8?q?er/FormatterManager.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Tools/FileDownload/FileDownloader.php=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tool?= =?UTF-8?q?s/FileDownload/FileDownloaderAwareTrait.php=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tools/FileDownload/F?= =?UTF-8?q?ileDownloaderInterface.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/ArchiveBuilderManager.php | 39 ++++++++++++++++++- .../FileFormat/Formatter/FormatterData.php | 25 ++++++++++++ .../FileFormat/Formatter/FormatterManager.php | 34 ++++++++++++---- .../Tools/FileDownload/FileDownloader.php | 13 +++++++ .../FileDownload/FileDownloaderAwareTrait.php | 8 ++++ .../FileDownload/FileDownloaderInterface.php | 12 ++++++ 6 files changed, 122 insertions(+), 9 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php index e8a13a20e..7c040f1a5 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php @@ -20,12 +20,16 @@ use Thelia\Core\Translation\Translator; */ class ArchiveBuilderManager { +<<<<<<< HEAD <<<<<<< HEAD /** @var array */ protected $archiveBuilders = array(); ======= protected $archiveCreators = array(); >>>>>>> Define archive builders and formatters +======= + protected $archiveBuilders = array(); +>>>>>>> Fix cs and add get method in managers protected $environment; @@ -57,8 +61,12 @@ class ArchiveBuilderManager if (null !== $archiveCreator) { $archiveCreator->setEnvironment($this->environment); +<<<<<<< HEAD $this->archiveCreators[$archiveCreator->getName()] = $archiveCreator; >>>>>>> Define archive builders and formatters +======= + $this->archiveBuilders[$archiveCreator->getName()] = $archiveCreator; +>>>>>>> Fix cs and add get method in managers } return $this; @@ -71,6 +79,7 @@ class ArchiveBuilderManager */ public function delete($name) { +<<<<<<< HEAD <<<<<<< HEAD if (!array_key_exists($name, $this->archiveBuilders)) { $this->throwOutOfBounds($name); @@ -91,6 +100,13 @@ class ArchiveBuilderManager unset($this->archiveCreators[$name]); >>>>>>> Define archive builders and formatters +======= + if (!array_key_exists($name, $this->archiveBuilders)) { + $this->throwOutOfBounds($name); + } + + unset($this->archiveBuilders[$name]); +>>>>>>> Fix cs and add get method in managers return $this; } @@ -145,7 +161,28 @@ class ArchiveBuilderManager */ public function getAll() { - return $this->archiveCreators; + return $this->archiveBuilders; + } + + public function get($name) + { + if (!array_key_exists($name, $this->archiveBuilders)) { + $this->throwOutOfBounds($name); + } + + return $this->archiveBuilders[$name]; + } + + protected function throwOutOfBounds($name) + { + throw new \OutOfBoundsException( + Translator::getInstance()->trans( + "The archive creator %name doesn't exist", + [ + "%name" => $name + ] + ) + ); } <<<<<<< HEAD } diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php index 689ad0ba6..a74ecef90 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php @@ -11,6 +11,8 @@ /*************************************************************************************/ namespace Thelia\Core\FileFormat\Formatter; +use Propel\Runtime\ActiveQuery\ModelCriteria; +use Thelia\Core\Translation\Translator; /** * Class FormatterData @@ -19,5 +21,28 @@ namespace Thelia\Core\FileFormat\Formatter; */ class FormatterData { + /** @var array */ + protected $data; + /** @var Translator */ + protected $translator; + + public function __construct() + { + $this->translator = Translator::getInstance(); + } + + public function loadModelCriteria(ModelCriteria $criteria) + { + + $propelData = + $criteria + ->find() + ; + + if (empty($propelData)) { + return null; + } + + } } diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php index b8e5d5d66..4035927ae 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php @@ -44,14 +44,7 @@ class FormatterManager public function delete($name) { if (!array_key_exists($name, $this->formatters)) { - throw new \OutOfBoundsException( - Translator::getInstance()->trans( - "The formatter %name doesn't exist", - [ - "%name" => $name - ] - ) - ); + $this->throwOutOfBounds($name); } unset($this->formatters[$name]); @@ -59,6 +52,15 @@ class FormatterManager return $this; } + public function get($name) + { + if (!array_key_exists($name, $this->formatters)) { + $this->throwOutOfBounds($name); + } + + return $this->formatters[$name]; + } + /** * @return array[AbstractFormatter] */ @@ -66,4 +68,20 @@ class FormatterManager { return $this->formatters; } + + /** + * @param $name + * @throws \OutOfBoundsException + */ + protected function throwOutOfBounds($name) + { + throw new \OutOfBoundsException( + Translator::getInstance()->trans( + "The formatter %name doesn't exist", + [ + "%name" => $name + ] + ) + ); + } } diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php index ac0ae7eca..95c54465d 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php @@ -52,6 +52,7 @@ class FileDownloader implements FileDownloaderInterface } /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $url * @param string $pathToStore @@ -59,6 +60,10 @@ class FileDownloader implements FileDownloaderInterface * @param string $url * @param string $pathToStore >>>>>>> Define archive builders and formatters +======= + * @param string $url + * @param string $pathToStore +>>>>>>> Fix cs and add get method in managers * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException * @throws \HttpUrlException @@ -137,11 +142,15 @@ class FileDownloader implements FileDownloaderInterface */ $file = @fopen($pathToStore, "w"); +<<<<<<< HEAD <<<<<<< HEAD if ($file === false) { ======= if($file === false) { >>>>>>> Define archive builders and formatters +======= + if ($file === false) { +>>>>>>> Fix cs and add get method in managers $translatedErrorMessage = $this->translator->trans( "Failed to open a writing stream on the file: %file", [ @@ -157,7 +166,11 @@ class FileDownloader implements FileDownloaderInterface fclose($file); } <<<<<<< HEAD +<<<<<<< HEAD } ======= } >>>>>>> Define archive builders and formatters +======= +} +>>>>>>> Fix cs and add get method in managers diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php b/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php index d0472b41d..5ef7880e5 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php @@ -35,11 +35,15 @@ trait FileDownloaderAwareTrait } /** +<<<<<<< HEAD <<<<<<< HEAD * @param FileDownloaderInterface $fileDownloader ======= * @param FileDownloaderInterface $fileDownloader >>>>>>> Define archive builders and formatters +======= + * @param FileDownloaderInterface $fileDownloader +>>>>>>> Fix cs and add get method in managers * @return $this */ public function setFileDownloader(FileDownloaderInterface $fileDownloader) @@ -49,7 +53,11 @@ trait FileDownloaderAwareTrait return $this; } <<<<<<< HEAD +<<<<<<< HEAD } ======= } >>>>>>> Define archive builders and formatters +======= +} +>>>>>>> Fix cs and add get method in managers diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php b/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php index 0f451396b..b9f1eaab3 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php @@ -14,10 +14,13 @@ namespace Thelia\Tools\FileDownload; use Psr\Log\LoggerInterface; use Symfony\Component\Translation\Translator; +<<<<<<< HEAD <<<<<<< HEAD ======= >>>>>>> Define archive builders and formatters +======= +>>>>>>> Fix cs and add get method in managers /** * Class FileDownloader * @package Thelia\Tools\FileDownload @@ -26,6 +29,7 @@ use Symfony\Component\Translation\Translator; interface FileDownloaderInterface { /** +<<<<<<< HEAD <<<<<<< HEAD * @param string $url * @param string $pathToStore @@ -33,6 +37,10 @@ interface FileDownloaderInterface * @param string $url * @param string $pathToStore >>>>>>> Define archive builders and formatters +======= + * @param string $url + * @param string $pathToStore +>>>>>>> Fix cs and add get method in managers * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException * @throws \HttpUrlException @@ -50,7 +58,11 @@ interface FileDownloaderInterface */ public static function getInstance(); <<<<<<< HEAD +<<<<<<< HEAD } ======= } >>>>>>> Define archive builders and formatters +======= +} +>>>>>>> Fix cs and add get method in managers From 169e23658869e8f38789e8ff802bb2b2fc41f3a1 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 14:34:30 +0200 Subject: [PATCH 037/158] =?UTF-8?q?Add=20filename=20in=20build=20archive?= =?UTF-8?q?=20response=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/l?= =?UTF-8?q?ib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuil?= =?UTF-8?q?der.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/T?= =?UTF-8?q?helia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.?= =?UTF-8?q?php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Theli?= =?UTF-8?q?a/Core/FileFormat/Archive/ArchiveBuilderInterface.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/ArchiveBuilder/TarArchiveBuilder.php | 5 +++++ .../Archive/ArchiveBuilder/ZipArchiveBuilder.php | 9 +++++++++ .../FileFormat/Archive/ArchiveBuilderInterface.php | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index 272408b28..d9c150b85 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -380,6 +380,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * * This method return an instance of a Response with the archive as content. */ +<<<<<<< HEAD <<<<<<< HEAD public function buildArchiveResponse($filename) { @@ -419,6 +420,9 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * @param FileDownloaderInterface $fileDownloader ======= public function buildArchiveResponse() +======= + public function buildArchiveResponse($filename) +>>>>>>> Add filename in build archive response { $this->tar->setMetadata("Generated by Thelia v" . Thelia::THELIA_VERSION); @@ -444,6 +448,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder 200, [ "Content-Type" => $this->getMimeType(), + "Content-Disposition" => $filename . "." . $this->getExtension(), ] ); } diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index 9261cba3a..ea2a6a811 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -639,11 +639,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * * This method return an instance of a Response with the archive as content. */ +<<<<<<< HEAD <<<<<<< HEAD public function buildArchiveResponse($filename) ======= public function buildArchiveResponse() >>>>>>> Define archive builders and formatters +======= + public function buildArchiveResponse($filename) +>>>>>>> Add filename in build archive response { $this->zip->comment = "Generated by Thelia v" . Thelia::THELIA_VERSION; @@ -720,12 +724,17 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $content, 200, [ +<<<<<<< HEAD <<<<<<< HEAD "Content-Type" => $this->getMimeType(), "Content-Disposition" => $filename . "." . $this->getExtension(), ======= "Content-Type" => $this->getMimeType() >>>>>>> Define archive builders and formatters +======= + "Content-Type" => $this->getMimeType(), + "Content-Disposition" => $filename . "." . $this->getExtension(), +>>>>>>> Add filename in build archive response ] ); } diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php index 3eb0aaa84..626b7ae87 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -139,6 +139,7 @@ interface ArchiveBuilderInterface * This method creates an empty directory */ public function addDirectory($directoryPath); +<<<<<<< HEAD <<<<<<< HEAD /** @@ -148,10 +149,16 @@ interface ArchiveBuilderInterface ======= /** >>>>>>> Finish implementing and testing zip +======= + + /** + * @params string $filename +>>>>>>> Add filename in build archive response * @return \Thelia\Core\HttpFoundation\Response * * This method return an instance of a Response with the archive as content. */ +<<<<<<< HEAD <<<<<<< HEAD public function buildArchiveResponse($filename); @@ -160,6 +167,9 @@ interface ArchiveBuilderInterface * @param bool $isOnline ======= public function buildArchiveResponse(); +======= + public function buildArchiveResponse($filename); +>>>>>>> Add filename in build archive response /** <<<<<<< HEAD From d82ca5d7673b873090b2ae15ebe64cb31c4f8139 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 14:49:35 +0200 Subject: [PATCH 038/158] =?UTF-8?q?Fix=20Test=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Tests/FileFormat/Archive/Arch?= =?UTF-8?q?iveBuilder/ZipArchiveBuilderTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/ArchiveBuilder/ZipArchiveBuilderTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index fa8ea74d1..f0c6b2385 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -606,11 +606,15 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testBuildArchiveResponse() { $loadedArchiveResponse = $this->loadedZip +<<<<<<< HEAD <<<<<<< HEAD ->buildArchiveResponse("test") ======= ->buildArchiveResponse() >>>>>>> Define archive builders and formatters +======= + ->buildArchiveResponse("test") +>>>>>>> Fix Test ; $loadedArchiveResponseContent = $loadedArchiveResponse->getContent(); From a80a35b5de7c1ee901434c015b96b088fae2993a Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 15:07:07 +0200 Subject: [PATCH 039/158] =?UTF-8?q?Add=20getNames=20methods=20to=20manager?= =?UTF-8?q?s=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/?= =?UTF-8?q?Core/FileFormat/Archive/ArchiveBuilderManager.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Formatter/FormatterManager.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/ArchiveBuilderManager.php | 36 +++++++++++++++++-- .../FileFormat/Formatter/FormatterManager.php | 15 ++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php index 7c040f1a5..0b9e111c5 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php @@ -22,6 +22,9 @@ class ArchiveBuilderManager { <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> Add getNames methods to managers /** @var array */ protected $archiveBuilders = array(); ======= @@ -39,6 +42,7 @@ class ArchiveBuilderManager } /** <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD * @param AbstractArchiveBuilder $archiveBuilder * @return $this @@ -54,19 +58,26 @@ class ArchiveBuilderManager ======= * @param AbstractArchiveBuilder $archiveCreator >>>>>>> Fix cs +======= + * @param AbstractArchiveBuilder $archiveBuilder +>>>>>>> Add getNames methods to managers * @return $this */ - public function add(AbstractArchiveBuilder $archiveCreator) + public function add(AbstractArchiveBuilder $archiveBuilder) { - if (null !== $archiveCreator) { - $archiveCreator->setEnvironment($this->environment); + if (null !== $archiveBuilder) { + $archiveBuilder->setEnvironment($this->environment); +<<<<<<< HEAD <<<<<<< HEAD $this->archiveCreators[$archiveCreator->getName()] = $archiveCreator; >>>>>>> Define archive builders and formatters ======= $this->archiveBuilders[$archiveCreator->getName()] = $archiveCreator; >>>>>>> Fix cs and add get method in managers +======= + $this->archiveBuilders[$archiveBuilder->getName()] = $archiveBuilder; +>>>>>>> Add getNames methods to managers } return $this; @@ -112,6 +123,7 @@ class ArchiveBuilderManager } /** +<<<<<<< HEAD <<<<<<< HEAD * @return array */ @@ -158,12 +170,30 @@ class ArchiveBuilderManager } ======= * @return array[AbstractArchiveBuilder] +======= + * @return array +>>>>>>> Add getNames methods to managers */ public function getAll() { return $this->archiveBuilders; } + /** + * @return array + */ + public function getNames() + { + $names = []; + + /** @var AbstractArchiveBuilder $builder */ + foreach($this->archiveBuilders as $builder) { + $names[] = $builder->getName(); + } + + return $names; + } + public function get($name) { if (!array_key_exists($name, $this->archiveBuilders)) { diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php index 4035927ae..b7801c7a9 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php @@ -69,6 +69,21 @@ class FormatterManager return $this->formatters; } + /** + * @return array + */ + public function getNames() + { + $names = []; + + /** @var AbstractFormatter $formatter */ + foreach($this->formatters as $formatter) { + $names[] = $formatter->getName(); + } + + return $names; + } + /** * @param $name * @throws \OutOfBoundsException From 8d56563dfc54e3d8881224fb8e7ddac8c925fe00 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 4 Jul 2014 16:57:38 +0200 Subject: [PATCH 040/158] =?UTF-8?q?Begin=20FormatterData=20=09modifi=C3=A9?= =?UTF-8?q?:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/For?= =?UTF-8?q?matter/FormatterData.php=20=09nouveau=20fichier:=20core/lib/The?= =?UTF-8?q?lia/Tests/FileFormat/Formatter/FormatterDataTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileFormat/Formatter/FormatterData.php | 28 ++++++-- .../Formatter/FormatterDataTest.php | 70 +++++++++++++++++++ 2 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php index a74ecef90..0a7ed344d 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php @@ -12,6 +12,8 @@ namespace Thelia\Core\FileFormat\Formatter; use Propel\Runtime\ActiveQuery\ModelCriteria; +use Propel\Runtime\Collection\ArrayCollection; +use Propel\Runtime\Collection\ObjectCollection; use Thelia\Core\Translation\Translator; /** @@ -34,15 +36,31 @@ class FormatterData public function loadModelCriteria(ModelCriteria $criteria) { - - $propelData = - $criteria - ->find() - ; + $propelData = $criteria->find(); if (empty($propelData)) { return null; } + $asColumns = $propelData->getFormatter()->getAsColumns(); + + if (empty($asColumns) && $propelData instanceof ObjectCollection) { + /** + * Full request ( without select nor join ) + */ + } elseif (empty($asColumns) && $propelData instanceof ArrayCollection) { + /** + * Request with joins, but without select + */ + } elseif (count($asColumns) > 1) { + /** + * Request with multiple select + */ + } elseif (count($asColumns) === 1) { + /** + * Request with one select + */ + } + } } diff --git a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php new file mode 100644 index 000000000..369e2bc41 --- /dev/null +++ b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php @@ -0,0 +1,70 @@ + + */ +class FormatterDataTest extends \PHPUnit_Framework_TestCase +{ + + protected $data; + + public function setUp() + { + new Translator(new Container()); + $this->data = new FormatterData(); + + $query = ProductQuery::create() + ->filterById([3,4,5], Criteria::IN); + + $this->data->loadModelCriteria($query); + + $query = ProductSaleElementsQuery::create() + ->joinProduct() + ->select(["ProductSaleElements.id", "Product.id"]) + ->filterById([3,4,5], Criteria::IN) + ; + + $this->data->loadModelCriteria($query); + + $query = ProductSaleElementsQuery::create() + ->joinProduct() + ->select(["ProductSaleElements.id"]) + ->filterById([3,4,5], Criteria::IN) + ; + + $this->data->loadModelCriteria($query); + + $query = ProductQuery::create() + ->joinProductSaleElements() + ->filterById([3,4,5], Criteria::IN); + + $this->data->loadModelCriteria($query); + } + + public function testA() + { + + } +} From ab241c8581d2505be0c66df30adac9a27fb772f6 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Mon, 7 Jul 2014 13:42:20 +0200 Subject: [PATCH 041/158] =?UTF-8?q?Add=20some=20tests=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Form?= =?UTF-8?q?atter/FormatterData.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataT?= =?UTF-8?q?est.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileFormat/Formatter/FormatterData.php | 124 ++++++- .../Formatter/FormatterDataTest.php | 314 +++++++++++++++++- 2 files changed, 419 insertions(+), 19 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php index 0a7ed344d..f2aaa8507 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php +++ b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php @@ -11,9 +11,10 @@ /*************************************************************************************/ namespace Thelia\Core\FileFormat\Formatter; +use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\ModelCriteria; -use Propel\Runtime\Collection\ArrayCollection; -use Propel\Runtime\Collection\ObjectCollection; +use Propel\Runtime\ActiveQuery\ModelJoin; +use Propel\Runtime\Map\TableMap; use Thelia\Core\Translation\Translator; /** @@ -26,14 +27,74 @@ class FormatterData /** @var array */ protected $data; + /** @var null|array */ + protected $aliases; + /** @var Translator */ protected $translator; - public function __construct() + /** + * @param array $aliases + * + * $aliases is a associative array where the key represents propel TYPE_PHP_NAME of column if you use + * loadModelCriteria, or your own aliases for setData, and the value + * is the alias. It can be null or empty if you don't want aliases, + * but remember to always define all the fields the you want: + * non aliases fields will be ignored. + */ + public function __construct(array $aliases = null) { $this->translator = Translator::getInstance(); + + if (!is_array($aliases)) { + $aliases = []; + } + + /** + * Lower all the values + */ + foreach ($aliases as $key => $value) { + $lowerKey = strtolower($key); + $lowerValue = strtolower($value); + if ($lowerKey !== $key) { + $aliases[$lowerKey] = $lowerValue; + unset($aliases[$key]); + } else { + $aliases[$key] = $lowerValue; + } + } + + $this->aliases = $aliases; } + /** + * @param array $data + * @return $this + * + * Sets raw data with aliases + */ + public function setData(array $data) + { + if (empty($this->aliases)) { + $this->data = $data; + return $this; + } + + $this->data = $this->applyAliases($data, $this->aliases); + + return $this; + } + + /** + * @param ModelCriteria $criteria + * @return $this|null + * + * Loads a model criteria. + * Warning: if you want to do multi table export, + * you'll have to use you own select and not the joinYourTable method. + * For more details, please see the unit test + * Thelia\Tests\FileFormat\Formatter\FormatterDataTest::testFormatSimpleMultipleTableQuery + */ public function loadModelCriteria(ModelCriteria $criteria) { $propelData = $criteria->find(); @@ -44,23 +105,62 @@ class FormatterData $asColumns = $propelData->getFormatter()->getAsColumns(); - if (empty($asColumns) && $propelData instanceof ObjectCollection) { - /** - * Full request ( without select nor join ) - */ - } elseif (empty($asColumns) && $propelData instanceof ArrayCollection) { - /** - * Request with joins, but without select - */ - } elseif (count($asColumns) > 1) { + /** + * Format it correctly + * After this pass, we MUST have a 2D array. + * The first may be keyed with integers. + */ + $formattedResult = $propelData + ->toArray(null, false, TableMap::TYPE_COLNAME); + + if (count($asColumns) > 1) { /** * Request with multiple select + * Apply propel aliases */ + $formattedResult = $this->applyAliases($formattedResult, $asColumns); } elseif (count($asColumns) === 1) { /** * Request with one select */ + $key = str_replace("\"", "", array_keys($asColumns)[0]); + $formattedResult = [[$key => $formattedResult[0]]]; } + $data = $this->applyAliases($formattedResult, $this->aliases); + + /** + * Then store it + */ + $this->data = $data; + + return $this; + } + + /** + * @param array $data + * @param array $aliases + */ + protected function applyAliases(array $data, array $aliases) + { + $formattedData = []; + + foreach ($data as $key=>$entry) { + $key = strtolower($key); + + if (is_array($entry)) { + $formattedData[$key] = $this->applyAliases($entry, $aliases); + } else { + $alias = isset($aliases[$key]) ? $aliases[$key] : $key; + $formattedData[$alias] = $entry; + } + } + + return $formattedData; + } + + public function getData() + { + return $this->data; } } diff --git a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php index 369e2bc41..31949a60c 100644 --- a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php @@ -11,13 +11,20 @@ /*************************************************************************************/ namespace Thelia\Tests\FileFormat\Formatter; +use Propel\Generator\Builder\Om\QueryBuilder; use Propel\Runtime\ActiveQuery\Criteria; +use Propel\Runtime\DataFetcher\ArrayDataFetcher; +use Propel\Runtime\Formatter\ArrayFormatter; +use Propel\Runtime\Map\TableMap; +use Propel\Runtime\Propel; use Symfony\Component\DependencyInjection\Container; use Thelia\Core\FileFormat\Formatter\FormatterData; +use Thelia\Core\Thelia; use Thelia\Core\Translation\Translator; use Thelia\Model\Base\ProductQuery; use Thelia\Model\Base\ProductSaleElementsQuery; -use Thelia\Model\LangQuery; +use Thelia\Model\ConfigQuery; +use Thelia\Model\Map\ProductTableMap; use Thelia\Model\Product; /** @@ -28,14 +35,11 @@ use Thelia\Model\Product; class FormatterDataTest extends \PHPUnit_Framework_TestCase { - protected $data; - public function setUp() { new Translator(new Container()); - $this->data = new FormatterData(); - $query = ProductQuery::create() + /* ->filterById([3,4,5], Criteria::IN); $this->data->loadModelCriteria($query); @@ -60,11 +64,307 @@ class FormatterDataTest extends \PHPUnit_Framework_TestCase ->joinProductSaleElements() ->filterById([3,4,5], Criteria::IN); - $this->data->loadModelCriteria($query); + $this->data->loadModelCriteria($query);*/ } - public function testA() + public function testFormatSimpleQuery() { + $formatterData = new FormatterData(); + $query = ConfigQuery::create() + ->limit(1) + ; + + $formattedData = $formatterData + ->loadModelCriteria($query) + ->getData() + ; + + /** @var \Thelia\Model\Config $result */ + $result = $query->findOne(); + + $formattedResult = [ + [ + "config.id" => $result->getId(), + "config.name" => $result->getName(), + "config.value" => $result->getValue(), + "config.created_at" => $result->getCreatedAt(), + "config.updated_at" => $result->getUpdatedAt(), + "config.hidden" => $result->getHidden(), + "config.secured" => $result->getHidden(), + ], + ]; + + $this->assertEquals($formattedResult,$formattedData); } + + public function testFormatSimpleQueryWithAliases() + { + /** + * Aliases must not be case sensitive + */ + $aliases = [ + "coNfiG.iD" => "id", + "conFig.NaMe" => "name", + "CoNfIg.Value" => "value", + "config.hidden" => "hidden", + "ConFig.Secured" => "secured", + ]; + + $formatterData = new FormatterData($aliases); + + $query = ConfigQuery::create() + ->limit(1) + ; + + $formattedData = $formatterData + ->loadModelCriteria($query) + ->getData() + ; + + /** @var \Thelia\Model\Config $result */ + $result = $query->findOne(); + + $formattedResult = [ + [ + "id" => $result->getId(), + "name" => $result->getName(), + "value" => $result->getValue(), + "config.created_at" => $result->getCreatedAt(), + "config.updated_at" => $result->getUpdatedAt(), + "hidden" => $result->getHidden(), + "secured" => $result->getHidden(), + ], + ]; + + $this->assertEquals($formattedResult,$formattedData); + } + + public function testFormatSimpleMultipleTableQuery() + { + $formatterData = new FormatterData(); + + + } + + public function testFormatSimpleMultipleTableQueryWithAliases() + { + /** + * Aliases must not be case sensitive + */ + $aliases = [ + "coNfiG.iD" => "id", + "conFig.NaMe" => "name", + "CoNfIg.Value" => "value", + "config.hidden" => "hidden", + "ConFig.Secured" => "secured", + ]; + + $formatterData = new FormatterData($aliases); + + $query = ConfigQuery::create() + ->limit(1) + ; + + $formattedData = $formatterData + ->loadModelCriteria($query) + ->getData() + ; + + /** @var \Thelia\Model\Config $result */ + $result = $query->findOne(); + + $formattedResult = [ + [ + "id" => $result->getId(), + "name" => $result->getName(), + "value" => $result->getValue(), + "config.created_at" => $result->getCreatedAt(), + "config.updated_at" => $result->getUpdatedAt(), + "hidden" => $result->getHidden(), + "secured" => $result->getHidden(), + ], + ]; + + $this->assertEquals($formattedResult,$formattedData); + } + + public function testSetRawDataDepth1() { + $formatterData = new FormatterData(); + + $data = [ + "foo" => "bar", + "baz" => "foo", + ]; + + $formattedData = $formatterData + ->setData($data) + ->getData() + ; + + $this->assertEquals($data,$formattedData); + } + + public function testSetRawDataDepth1WithAliases() { + $aliases = [ + "FoO" => "orange", + "Baz" => "banana", + ]; + + $formatterData = new FormatterData($aliases); + + $data = [ + "fOo" => "bar", + "bAZ" => "foo", + ]; + + $expectedData = [ + "orange" => "bar", + "banana" => "foo", + ]; + + $formattedData = $formatterData + ->setData($data) + ->getData() + ; + + $this->assertEquals($expectedData,$formattedData); + } + + public function testSetRawDataDepth2() { + $formatterData = new FormatterData(); + + $data = [ + [ + "orange" => "banana", + "apple" => "pear", + ], + [ + "strawberry" => "raspberry", + "blackberry" => "cranberry", + ] + ]; + + $formattedData = $formatterData + ->setData($data) + ->getData() + ; + + $this->assertEquals($data,$formattedData); + } + + public function testSetRawDataDepth2WithAliases() { + $aliases = [ + "orange" => "cherry", + "blackberry" => "banana", + ]; + + $formatterData = new FormatterData($aliases); + + $data = [ + [ + "orange" => "banana", + "apple" => "pear", + ], + [ + "strawberry" => "raspberry", + "blackberry" => "cranberry", + ] + ]; + + $expectedData = [ + [ + "cherry" => "banana", + "apple" => "pear", + ], + [ + "strawberry" => "raspberry", + "banana" => "cranberry", + ] + ]; + + $formattedData = $formatterData + ->setData($data) + ->getData() + ; + + $this->assertEquals($expectedData,$formattedData); + } + + public function testSetRawDataMultipleDepth() { + $formatterData = new FormatterData(); + + $data = [ + [ + "orange" => "banana", + "apple" => "pear", + ], + [ + "strawberry" => "raspberry", + "blackberry" => "cranberry", + ] + ]; + + $formattedData = $formatterData + ->setData($data) + ->getData() + ; + + $this->assertEquals($data,$formattedData); + } + + public function testSetRawDataMultipleDepthWithAliases() { + $aliases = [ + "orange" => "cherry", + "blackberry" => "banana", + ]; + + $formatterData = new FormatterData($aliases); + + $data = [ + "orange" => "banana", + "apple" => "pear", + [ + "orange" => "tomato", + "pepper" => "pear", + ], + [ + [ + "strawberry" => "raspberry", + "blackberry" => "cranberry", + ], + [ + "cherry" => "lemon", + "mango" => "cranberry", + ] + ], + ]; + + $expectedData = [ + "cherry" => "banana", + "apple" => "pear", + [ + "cherry" => "tomato", + "pepper" => "pear", + ], + [ + [ + "strawberry" => "raspberry", + "banana" => "cranberry", + ], + [ + "cherry" => "lemon", + "mango" => "cranberry", + ] + ], + ]; + + $formattedData = $formatterData + ->setData($data) + ->getData() + ; + + $this->assertEquals($expectedData,$formattedData); + } + } From 2b19d1fe33db5ba7728c22750dd17e1db7e7a121 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Mon, 7 Jul 2014 16:50:10 +0200 Subject: [PATCH 042/158] =?UTF-8?q?End=20formatter=20data=20and=20refactor?= =?UTF-8?q?=20Thelia\Core\FileFormat\Formatter=20=09renomm=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatter/Abs?= =?UTF-8?q?tractFormatter.php=20->=20core/lib/Thelia/Core/FileFormat/Forma?= =?UTF-8?q?tting/AbstractFormatter.php=20=09renomm=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatter/Exception?= =?UTF-8?q?/BadFormattedStringException.php=20->=20core/lib/Thelia/Core/Fi?= =?UTF-8?q?leFormat/Formatting/Exception/BadFormattedStringException.php?= =?UTF-8?q?=20=09renomm=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/C?= =?UTF-8?q?ore/FileFormat/Formatter/FormatterData.php=20->=20core/lib/Thel?= =?UTF-8?q?ia/Core/FileFormat/Formatting/FormatterData.php=20=09renomm?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Formatter/FormatterInterface.php=20->=20core/lib/Thelia/Core?= =?UTF-8?q?/FileFormat/Formatting/FormatterInterface.php=20=09renomm=C3=A9?= =?UTF-8?q?:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/For?= =?UTF-8?q?matter/FormatterManager.php=20->=20core/lib/Thelia/Core/FileFor?= =?UTF-8?q?mat/Formatting/FormatterManager.php=20=09renomm=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Tests/FileFormat/Formatter/Fo?= =?UTF-8?q?rmatterDataTest.php=20->=20core/lib/Thelia/Tests/FileFormat/For?= =?UTF-8?q?matting/FormatterDataTest.php=20=09renomm=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Tests/FileFormat/Formatter/Formatte?= =?UTF-8?q?rManagerTest.php=20->=20core/lib/Thelia/Tests/FileFormat/Format?= =?UTF-8?q?ting/FormatterManagerTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Formatter/AbstractFormatter.php | 24 -- .../Exception/BadFormattedStringException.php | 23 -- .../FileFormat/Formatter/FormatterData.php | 166 -------- .../Formatter/FormatterInterface.php | 39 -- .../FileFormat/Formatter/FormatterManager.php | 102 ----- .../Formatter/FormatterDataTest.php | 370 ------------------ .../Formatter/FormatterManagerTest.php | 74 ---- 7 files changed, 798 deletions(-) delete mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php delete mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php delete mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php delete mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php delete mode 100644 core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php delete mode 100644 core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php delete mode 100644 core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php deleted file mode 100644 index 605bc6362..000000000 --- a/core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php +++ /dev/null @@ -1,24 +0,0 @@ - - */ -abstract class AbstractFormatter implements FormatInterface, FormatterInterface -{ - -} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php b/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php deleted file mode 100644 index 18d28bb78..000000000 --- a/core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php +++ /dev/null @@ -1,23 +0,0 @@ - - */ -class BadFormattedStringException extends \ErrorException -{ - -} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php deleted file mode 100644 index f2aaa8507..000000000 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php +++ /dev/null @@ -1,166 +0,0 @@ - - */ -class FormatterData -{ - /** @var array */ - protected $data; - - /** @var null|array */ - protected $aliases; - - /** @var Translator */ - protected $translator; - - /** - * @param array $aliases - * - * $aliases is a associative array where the key represents propel TYPE_PHP_NAME of column if you use - * loadModelCriteria, or your own aliases for setData, and the value - * is the alias. It can be null or empty if you don't want aliases, - * but remember to always define all the fields the you want: - * non aliases fields will be ignored. - */ - public function __construct(array $aliases = null) - { - $this->translator = Translator::getInstance(); - - if (!is_array($aliases)) { - $aliases = []; - } - - /** - * Lower all the values - */ - foreach ($aliases as $key => $value) { - $lowerKey = strtolower($key); - $lowerValue = strtolower($value); - if ($lowerKey !== $key) { - $aliases[$lowerKey] = $lowerValue; - unset($aliases[$key]); - } else { - $aliases[$key] = $lowerValue; - } - } - - $this->aliases = $aliases; - } - - /** - * @param array $data - * @return $this - * - * Sets raw data with aliases - */ - public function setData(array $data) - { - if (empty($this->aliases)) { - $this->data = $data; - return $this; - } - - $this->data = $this->applyAliases($data, $this->aliases); - - return $this; - } - - /** - * @param ModelCriteria $criteria - * @return $this|null - * - * Loads a model criteria. - * Warning: if you want to do multi table export, - * you'll have to use you own select and not the joinYourTable method. - * For more details, please see the unit test - * Thelia\Tests\FileFormat\Formatter\FormatterDataTest::testFormatSimpleMultipleTableQuery - */ - public function loadModelCriteria(ModelCriteria $criteria) - { - $propelData = $criteria->find(); - - if (empty($propelData)) { - return null; - } - - $asColumns = $propelData->getFormatter()->getAsColumns(); - - /** - * Format it correctly - * After this pass, we MUST have a 2D array. - * The first may be keyed with integers. - */ - $formattedResult = $propelData - ->toArray(null, false, TableMap::TYPE_COLNAME); - - if (count($asColumns) > 1) { - /** - * Request with multiple select - * Apply propel aliases - */ - $formattedResult = $this->applyAliases($formattedResult, $asColumns); - } elseif (count($asColumns) === 1) { - /** - * Request with one select - */ - $key = str_replace("\"", "", array_keys($asColumns)[0]); - $formattedResult = [[$key => $formattedResult[0]]]; - } - - $data = $this->applyAliases($formattedResult, $this->aliases); - - /** - * Then store it - */ - $this->data = $data; - - return $this; - } - - /** - * @param array $data - * @param array $aliases - */ - protected function applyAliases(array $data, array $aliases) - { - $formattedData = []; - - foreach ($data as $key=>$entry) { - $key = strtolower($key); - - if (is_array($entry)) { - $formattedData[$key] = $this->applyAliases($entry, $aliases); - } else { - $alias = isset($aliases[$key]) ? $aliases[$key] : $key; - $formattedData[$alias] = $entry; - } - } - - return $formattedData; - } - - public function getData() - { - return $this->data; - } -} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php deleted file mode 100644 index 4d2d2d91e..000000000 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ -interface FormatterInterface -{ - /** - * @param FormatterData $data - * @return mixed - * - * This method must use a FormatterData object and output - * a formatted value. - */ - public function encode(FormatterData $data); - - /** - * @param $rawData - * @return FormatterData - * - * This must takes raw data as argument and outputs - * a FormatterData object. - */ - public function decode($rawData); -} diff --git a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php b/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php deleted file mode 100644 index b7801c7a9..000000000 --- a/core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php +++ /dev/null @@ -1,102 +0,0 @@ - - */ -class FormatterManager -{ - - protected $formatters = array(); - - /** - * @param $archiveCreator - * @return $this - */ - public function add(AbstractFormatter $formatter) - { - if (null !== $formatter) { - $this->formatters[$formatter->getName()] = $formatter; - } - - return $this; - } - - /** - * @param $name - * @return $this - * @throws \OutOfBoundsException - */ - public function delete($name) - { - if (!array_key_exists($name, $this->formatters)) { - $this->throwOutOfBounds($name); - } - - unset($this->formatters[$name]); - - return $this; - } - - public function get($name) - { - if (!array_key_exists($name, $this->formatters)) { - $this->throwOutOfBounds($name); - } - - return $this->formatters[$name]; - } - - /** - * @return array[AbstractFormatter] - */ - public function getAll() - { - return $this->formatters; - } - - /** - * @return array - */ - public function getNames() - { - $names = []; - - /** @var AbstractFormatter $formatter */ - foreach($this->formatters as $formatter) { - $names[] = $formatter->getName(); - } - - return $names; - } - - /** - * @param $name - * @throws \OutOfBoundsException - */ - protected function throwOutOfBounds($name) - { - throw new \OutOfBoundsException( - Translator::getInstance()->trans( - "The formatter %name doesn't exist", - [ - "%name" => $name - ] - ) - ); - } -} diff --git a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php deleted file mode 100644 index 31949a60c..000000000 --- a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php +++ /dev/null @@ -1,370 +0,0 @@ - - */ -class FormatterDataTest extends \PHPUnit_Framework_TestCase -{ - - public function setUp() - { - new Translator(new Container()); - - /* - ->filterById([3,4,5], Criteria::IN); - - $this->data->loadModelCriteria($query); - - $query = ProductSaleElementsQuery::create() - ->joinProduct() - ->select(["ProductSaleElements.id", "Product.id"]) - ->filterById([3,4,5], Criteria::IN) - ; - - $this->data->loadModelCriteria($query); - - $query = ProductSaleElementsQuery::create() - ->joinProduct() - ->select(["ProductSaleElements.id"]) - ->filterById([3,4,5], Criteria::IN) - ; - - $this->data->loadModelCriteria($query); - - $query = ProductQuery::create() - ->joinProductSaleElements() - ->filterById([3,4,5], Criteria::IN); - - $this->data->loadModelCriteria($query);*/ - } - - public function testFormatSimpleQuery() - { - $formatterData = new FormatterData(); - - $query = ConfigQuery::create() - ->limit(1) - ; - - $formattedData = $formatterData - ->loadModelCriteria($query) - ->getData() - ; - - /** @var \Thelia\Model\Config $result */ - $result = $query->findOne(); - - $formattedResult = [ - [ - "config.id" => $result->getId(), - "config.name" => $result->getName(), - "config.value" => $result->getValue(), - "config.created_at" => $result->getCreatedAt(), - "config.updated_at" => $result->getUpdatedAt(), - "config.hidden" => $result->getHidden(), - "config.secured" => $result->getHidden(), - ], - ]; - - $this->assertEquals($formattedResult,$formattedData); - } - - public function testFormatSimpleQueryWithAliases() - { - /** - * Aliases must not be case sensitive - */ - $aliases = [ - "coNfiG.iD" => "id", - "conFig.NaMe" => "name", - "CoNfIg.Value" => "value", - "config.hidden" => "hidden", - "ConFig.Secured" => "secured", - ]; - - $formatterData = new FormatterData($aliases); - - $query = ConfigQuery::create() - ->limit(1) - ; - - $formattedData = $formatterData - ->loadModelCriteria($query) - ->getData() - ; - - /** @var \Thelia\Model\Config $result */ - $result = $query->findOne(); - - $formattedResult = [ - [ - "id" => $result->getId(), - "name" => $result->getName(), - "value" => $result->getValue(), - "config.created_at" => $result->getCreatedAt(), - "config.updated_at" => $result->getUpdatedAt(), - "hidden" => $result->getHidden(), - "secured" => $result->getHidden(), - ], - ]; - - $this->assertEquals($formattedResult,$formattedData); - } - - public function testFormatSimpleMultipleTableQuery() - { - $formatterData = new FormatterData(); - - - } - - public function testFormatSimpleMultipleTableQueryWithAliases() - { - /** - * Aliases must not be case sensitive - */ - $aliases = [ - "coNfiG.iD" => "id", - "conFig.NaMe" => "name", - "CoNfIg.Value" => "value", - "config.hidden" => "hidden", - "ConFig.Secured" => "secured", - ]; - - $formatterData = new FormatterData($aliases); - - $query = ConfigQuery::create() - ->limit(1) - ; - - $formattedData = $formatterData - ->loadModelCriteria($query) - ->getData() - ; - - /** @var \Thelia\Model\Config $result */ - $result = $query->findOne(); - - $formattedResult = [ - [ - "id" => $result->getId(), - "name" => $result->getName(), - "value" => $result->getValue(), - "config.created_at" => $result->getCreatedAt(), - "config.updated_at" => $result->getUpdatedAt(), - "hidden" => $result->getHidden(), - "secured" => $result->getHidden(), - ], - ]; - - $this->assertEquals($formattedResult,$formattedData); - } - - public function testSetRawDataDepth1() { - $formatterData = new FormatterData(); - - $data = [ - "foo" => "bar", - "baz" => "foo", - ]; - - $formattedData = $formatterData - ->setData($data) - ->getData() - ; - - $this->assertEquals($data,$formattedData); - } - - public function testSetRawDataDepth1WithAliases() { - $aliases = [ - "FoO" => "orange", - "Baz" => "banana", - ]; - - $formatterData = new FormatterData($aliases); - - $data = [ - "fOo" => "bar", - "bAZ" => "foo", - ]; - - $expectedData = [ - "orange" => "bar", - "banana" => "foo", - ]; - - $formattedData = $formatterData - ->setData($data) - ->getData() - ; - - $this->assertEquals($expectedData,$formattedData); - } - - public function testSetRawDataDepth2() { - $formatterData = new FormatterData(); - - $data = [ - [ - "orange" => "banana", - "apple" => "pear", - ], - [ - "strawberry" => "raspberry", - "blackberry" => "cranberry", - ] - ]; - - $formattedData = $formatterData - ->setData($data) - ->getData() - ; - - $this->assertEquals($data,$formattedData); - } - - public function testSetRawDataDepth2WithAliases() { - $aliases = [ - "orange" => "cherry", - "blackberry" => "banana", - ]; - - $formatterData = new FormatterData($aliases); - - $data = [ - [ - "orange" => "banana", - "apple" => "pear", - ], - [ - "strawberry" => "raspberry", - "blackberry" => "cranberry", - ] - ]; - - $expectedData = [ - [ - "cherry" => "banana", - "apple" => "pear", - ], - [ - "strawberry" => "raspberry", - "banana" => "cranberry", - ] - ]; - - $formattedData = $formatterData - ->setData($data) - ->getData() - ; - - $this->assertEquals($expectedData,$formattedData); - } - - public function testSetRawDataMultipleDepth() { - $formatterData = new FormatterData(); - - $data = [ - [ - "orange" => "banana", - "apple" => "pear", - ], - [ - "strawberry" => "raspberry", - "blackberry" => "cranberry", - ] - ]; - - $formattedData = $formatterData - ->setData($data) - ->getData() - ; - - $this->assertEquals($data,$formattedData); - } - - public function testSetRawDataMultipleDepthWithAliases() { - $aliases = [ - "orange" => "cherry", - "blackberry" => "banana", - ]; - - $formatterData = new FormatterData($aliases); - - $data = [ - "orange" => "banana", - "apple" => "pear", - [ - "orange" => "tomato", - "pepper" => "pear", - ], - [ - [ - "strawberry" => "raspberry", - "blackberry" => "cranberry", - ], - [ - "cherry" => "lemon", - "mango" => "cranberry", - ] - ], - ]; - - $expectedData = [ - "cherry" => "banana", - "apple" => "pear", - [ - "cherry" => "tomato", - "pepper" => "pear", - ], - [ - [ - "strawberry" => "raspberry", - "banana" => "cranberry", - ], - [ - "cherry" => "lemon", - "mango" => "cranberry", - ] - ], - ]; - - $formattedData = $formatterData - ->setData($data) - ->getData() - ; - - $this->assertEquals($expectedData,$formattedData); - } - -} diff --git a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php b/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php deleted file mode 100644 index 39bf06cb3..000000000 --- a/core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php +++ /dev/null @@ -1,74 +0,0 @@ - - */ -class FormatterManagerTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var FormatterManager - */ - protected $manager; - - public function setUp() - { - new Translator( - new Container() - ); - $this->manager = new FormatterManager(); - } - - public function testAddFormatter() - { - /** @var AbstractFormatter $instance */ - $instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatter\\AbstractFormatter"); - - $this->manager->add($instance); - - $archiveBuilders = $this->manager->getAll(); - - $this->assertTrue( - array_key_exists($instance->getName(), $archiveBuilders) - ); - } - - public function testDeleteFormatter() - { - /** @var AbstractFormatter $instance */ - $instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatter\\AbstractFormatter"); - - $this->manager->add($instance); - - $this->manager->delete($instance->getName()); - - $this->assertTrue( - count($this->manager->getAll()) === 0 - ); - } - - /** - * @expectedException \OutOfBoundsException - */ - public function testDeleteNotExistingFormatter() - { - $this->manager->delete("foo"); - } -} From df0ba3676c03c178b1401ddfb287c2fec872e7d7 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Tue, 8 Jul 2014 13:59:13 +0200 Subject: [PATCH 043/158] Readd services --- core/lib/Thelia/Config/Resources/config.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 30968906e..1cda3e289 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -106,6 +106,10 @@ %kernel.debug% +<<<<<<< HEAD +======= + +>>>>>>> Readd services %file_model.classes% @@ -136,7 +140,10 @@ <<<<<<< HEAD +<<<<<<< HEAD ======= +======= +>>>>>>> Readd services @@ -166,6 +173,7 @@ +<<<<<<< HEAD <<<<<<< HEAD >>>>>>> Add archive builder manager and formatter manager services @@ -202,5 +210,8 @@ ======= >>>>>>> Fix services +======= + +>>>>>>> Readd services From 7ccb32badbe12a1fb4abe3c6c4938e1c674242f2 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Tue, 8 Jul 2014 14:07:16 +0200 Subject: [PATCH 044/158] =?UTF-8?q?Remove=20conflicts=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Form?= =?UTF-8?q?atting/AbstractFormatter.php=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatting/Formatte?= =?UTF-8?q?rData.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib?= =?UTF-8?q?/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Formatting/AbstractFormatter.php | 35 ++++++ .../FileFormat/Formatting/FormatterData.php | 84 ++++++++++++++ .../Formatting/FormatterDataTest.php | 105 ++++++++++++++++++ 3 files changed, 224 insertions(+) diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php index 103167d42..8a015f9bb 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php @@ -12,6 +12,11 @@ namespace Thelia\Core\FileFormat\Formatting; use Thelia\Core\FileFormat\FormatInterface; +<<<<<<< HEAD +======= +use Thelia\Core\Translation\Translator; +use Thelia\Log\Tlog; +>>>>>>> Remove conflicts /** * Class AbstractFormatter @@ -20,5 +25,35 @@ use Thelia\Core\FileFormat\FormatInterface; */ abstract class AbstractFormatter implements FormatInterface, FormatterInterface { +<<<<<<< HEAD +======= + /** @var \Thelia\Core\Translation\Translator */ + protected $translator; + + /** @var \Thelia\Log\Tlog */ + protected $logger; + + /** @var array */ + protected $aliases = array(); + + public function __construct() + { + $this->translator = Translator::getInstance(); + + $this->logger = Tlog::getInstance(); + } + + public function setAliases(array $aliases) + { + $this->aliases = $aliases; + + return $this; + } + + public function getAliases() + { + return $this->aliases; + } +>>>>>>> Remove conflicts } diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php index 103e3d616..bba78c6b2 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php @@ -16,7 +16,11 @@ use Propel\Runtime\ActiveQuery\ModelCriteria; use Propel\Runtime\ActiveQuery\ModelJoin; use Propel\Runtime\Map\TableMap; use Thelia\Core\Translation\Translator; +<<<<<<< HEAD +======= +use Thelia\Model\Map\ProductTableMap; +>>>>>>> Remove conflicts /** * Class FormatterData * @package Thelia\Core\FileFormat\Formatting @@ -25,7 +29,11 @@ use Thelia\Core\Translation\Translator; class FormatterData { /** @var array */ +<<<<<<< HEAD protected $data; +======= + protected $data = array(); +>>>>>>> Remove conflicts /** @var null|array */ protected $aliases; @@ -72,6 +80,10 @@ class FormatterData * @return $this * * Sets raw data with aliases +<<<<<<< HEAD +======= + * may bug with some formatter +>>>>>>> Remove conflicts */ public function setData(array $data) { @@ -158,8 +170,80 @@ class FormatterData return $formattedData; } +<<<<<<< HEAD +======= + /** + * @param array $row + * @return $this + */ + public function addRow(array $row) + { + $this->data += [$this->applyAliases($row, $this->aliases)]; + + return $this; + } + + /** + * @param int $index + * @return array|bool + */ + public function popRow($index = 0) + { + $row = $this->getRow($index); + + if (false !== $row) { + unset($this->data[$index]); + } + + return $row; + } + + /** + * @param int $index + * @return array|bool + * @throws \OutOfBoundsException + */ + public function getRow($index = 0) + { + if (empty($this->data)) { + return false; + } elseif (!isset($this->data[$index])) { + throw new \OutOfBoundsException( + $this->translator->trans( + "Bad index value %idx", + [ + "%idx" => $index + ] + ) + ); + } + + $row = $this->reverseAliases($this->data[$index], $this->aliases); + + return $row; + } + + /** + * @param array $data + * @param array $aliases + * @return array + */ + protected function reverseAliases(array $data, array $aliases) + { + return $this->applyAliases($data, array_flip($aliases)); + } + +>>>>>>> Remove conflicts public function getData() { return $this->data; } +<<<<<<< HEAD +======= + + public function getDataReverseAliases() + { + return $this->reverseAliases($this->data, $this->aliases); + } +>>>>>>> Remove conflicts } diff --git a/core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php b/core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php index d5747ef33..f2ae7542f 100644 --- a/core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php @@ -359,4 +359,109 @@ class FormatterDataTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedData,$formattedData); } +<<<<<<< HEAD +======= + public function testSetRawDataMultipleDepthWithReverseAliases() { + $aliases = [ + "orange" => "foo", + "blackberry" => "banana", + ]; + + $formatterData = new FormatterData($aliases); + + $data = [ + "orange" => "banana", + "apple" => "pear", + [ + "orange" => "tomato", + "pepper" => "pear", + ], + [ + [ + "strawberry" => "raspberry", + "blackberry" => "cranberry", + ], + [ + "cherry" => "lemon", + "mango" => "cranberry", + ] + ], + ]; + + $formattedData = $formatterData + ->setData($data) + ->getDataReverseAliases() + ; + + $this->assertEquals($data,$formattedData); + } + + /** + * That's why an alias MUST not be the same as a present value + */ + public function testSetRawDataMultipleDepthWithReverseAliasesFail() { + $aliases = [ + "orange" => "cherry", + "blackberry" => "banana", + ]; + + $formatterData = new FormatterData($aliases); + + $data = [ + "orange" => "banana", + "apple" => "pear", + [ + "orange" => "tomato", + "pepper" => "pear", + ], + [ + [ + "strawberry" => "raspberry", + "blackberry" => "cranberry", + ], + [ + "cherry" => "lemon", + "mango" => "cranberry", + ] + ], + ]; + + $formattedData = $formatterData + ->setData($data) + ->getDataReverseAliases() + ; + + $this->assertNotEquals($data,$formattedData); + } + + public function testAddRow() + { + $data = new FormatterData(); + + $row = [ + "title" => "A super book", + "author" => "Manu", + ]; + + $data->addRow($row); + + $this->assertEquals([$row], $data->getData()); + $this->assertEquals($row, $data->getRow()); + } + + public function testPopRow() + { + $data = new FormatterData(); + + $row = [ + "title" => "A super book", + "author" => "Manu", + ]; + + $data->addRow($row); + + $this->assertEquals($row, $data->popRow()); + $this->assertFalse($data->getRow()); + } +>>>>>>> Remove conflicts } From 5c9d3909fa472f515e1fb19eaa7d9d7b62c20c7b Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Tue, 8 Jul 2014 16:07:57 +0200 Subject: [PATCH 045/158] =?UTF-8?q?Restore=20=09modifi=C3=A9:=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatting/Forma?= =?UTF-8?q?tterData.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php index bba78c6b2..285dd1de4 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php @@ -11,16 +11,17 @@ /*************************************************************************************/ namespace Thelia\Core\FileFormat\Formatting; -use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\ModelCriteria; -use Propel\Runtime\ActiveQuery\ModelJoin; use Propel\Runtime\Map\TableMap; use Thelia\Core\Translation\Translator; <<<<<<< HEAD +<<<<<<< HEAD ======= use Thelia\Model\Map\ProductTableMap; >>>>>>> Remove conflicts +======= +>>>>>>> Restore /** * Class FormatterData * @package Thelia\Core\FileFormat\Formatting From 168cb31253b22033f767cba84819908a931a02f1 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Tue, 8 Jul 2014 16:23:30 +0200 Subject: [PATCH 046/158] =?UTF-8?q?Remove=20FileManagerTest=20=09supprim?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/Tools/File?= =?UTF-8?q?ManagerTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Thelia/Tests/Tools/FileManagerTest.php | 900 ------------------ 1 file changed, 900 deletions(-) delete mode 100644 core/lib/Thelia/Tests/Tools/FileManagerTest.php diff --git a/core/lib/Thelia/Tests/Tools/FileManagerTest.php b/core/lib/Thelia/Tests/Tools/FileManagerTest.php deleted file mode 100644 index e611b2c53..000000000 --- a/core/lib/Thelia/Tests/Tools/FileManagerTest.php +++ /dev/null @@ -1,900 +0,0 @@ -markTestIncomplete( - 'This test has not been implemented yet : Mock issue' - ); - - $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - $stubTranslator->expects($this->any()) - ->method('trans') - ->will($this->returnValue('translated')); - - $stubRequest = $this->getMockBuilder('\Thelia\Core\HttpFoundation\Request') - ->disableOriginalConstructor() - ->getMock(); - - $stubSecurity = $this->getMockBuilder('\Thelia\Core\Security\SecurityContext') - ->disableOriginalConstructor() - ->getMock(); - $stubSecurity->expects($this->any()) - ->method('getAdminUser') - ->will($this->returnValue(new Admin())); - - // Create a map of arguments to return values. - $map = array( - array('thelia.translator', $stubTranslator), - array('request', $stubRequest), - array('thelia.securityContext', $stubSecurity) - ); - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - $stubContainer->expects($this->any()) - ->method('get') - ->will($this->returnValueMap($map)); - - $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage') - ->disableOriginalConstructor() - ->getMock(); - $stubProductImage->expects($this->any()) - ->method('getUploadDir') - ->will($this->returnValue(THELIA_LOCAL_DIR . 'media/images/product')); - $stubProductImage->expects($this->any()) - ->method('getId') - ->will($this->returnValue(42)); - $stubProductImage->expects($this->any()) - ->method('setFile') - ->will($this->returnValue(true)); - $stubProductImage->expects($this->any()) - ->method('save') - ->will($this->returnValue(0)); - - $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') - ->disableOriginalConstructor() - ->getMock(); - $stubUploadedFile->expects($this->any()) - ->method('getClientOriginalName') - ->will($this->returnValue('goodName')); - $stubUploadedFile->expects($this->any()) - ->method('getClientOriginalExtension') - ->will($this->returnValue('png')); - $stubUploadedFile->expects($this->any()) - ->method('move') - ->will($this->returnValue($stubUploadedFile)); - - $fileManager = new FileManager($stubContainer); - - $newUploadedFiles = array(); - - $actual = $fileManager->copyUploadedFile(24, FileManager::TYPE_PRODUCT, $stubProductImage, $stubUploadedFile, $newUploadedFiles, FileManager::FILE_TYPE_IMAGES); - - $this->assertCount(1, $actual); - }*/ - - /** - * @covers Thelia\Tools\FileManager::copyUploadedFile - * @expectedException \Thelia\Exception\ImageException - */ - /*public function testCopyUploadedFileExceptionImageException() - { - $this->markTestIncomplete( - 'This test has not been implemented yet : Mock issue' - ); - - $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - $stubTranslator->expects($this->any()) - ->method('trans') - ->will($this->returnValue('translated')); - - $stubRequest = $this->getMockBuilder('\Thelia\Core\HttpFoundation\Request') - ->disableOriginalConstructor() - ->getMock(); - - $stubSecurity = $this->getMockBuilder('\Thelia\Core\Security\SecurityContext') - ->disableOriginalConstructor() - ->getMock(); - $stubSecurity->expects($this->any()) - ->method('getAdminUser') - ->will($this->returnValue(new Admin())); - - // Create a map of arguments to return values. - $map = array( - array('thelia.translator', $stubTranslator), - array('request', $stubRequest), - array('thelia.securityContext', $stubSecurity) - ); - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - $stubContainer->expects($this->any()) - ->method('get') - ->will($this->returnValueMap($map)); - - $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage') - ->disableOriginalConstructor() - ->getMock(); - $stubProductImage->expects($this->any()) - ->method('getUploadDir') - ->will($this->returnValue(THELIA_LOCAL_DIR . 'media/images/product')); - $stubProductImage->expects($this->any()) - ->method('getId') - ->will($this->returnValue(42)); - $stubProductImage->expects($this->any()) - ->method('setFile') - ->will($this->returnValue(true)); - $stubProductImage->expects($this->any()) - ->method('save') - ->will($this->returnValue(0)); - - $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') - ->disableOriginalConstructor() - ->getMock(); - $stubUploadedFile->expects($this->any()) - ->method('getClientOriginalName') - ->will($this->returnValue('goodName')); - $stubUploadedFile->expects($this->any()) - ->method('getClientOriginalExtension') - ->will($this->returnValue('png')); - $stubUploadedFile->expects($this->any()) - ->method('move') - ->will($this->returnValue($stubUploadedFile)); - - $fileManager = new FileManager($stubContainer); - - $newUploadedFiles = array(); - - $actual = $fileManager->copyUploadedFile(24, FileManager::TYPE_PRODUCT, $stubProductImage, $stubUploadedFile, $newUploadedFiles, FileManager::FILE_TYPE_DOCUMENTS); - - }*/ - - /** - * @covers Thelia\Tools\FileManager::saveImage - */ - public function testSaveImageProductImage() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage') - ->disableOriginalConstructor() - ->getMock(); - $stubProductImage->expects($this->any()) - ->method('save') - ->will($this->returnValue(10)); - $stubProductImage->expects($this->any()) - ->method('getFile') - ->will($this->returnValue('file')); - - $fileManager = new FileManager(); - - $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24); - - $expected = 10; - $actual = $fileManager->saveImage($event, $stubProductImage); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::saveDocument - */ - public function testSaveDocumentProductDocument() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $stubProductDocument = $this->getMockBuilder('\Thelia\Model\ProductDocument') - ->disableOriginalConstructor() - ->getMock(); - $stubProductDocument->expects($this->any()) - ->method('save') - ->will($this->returnValue(10)); - $stubProductDocument->expects($this->any()) - ->method('getFile') - ->will($this->returnValue('file')); - - $fileManager = new FileManager(); - - $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24); - - $expected = 10; - $actual = $fileManager->saveDocument($event, $stubProductDocument); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::saveImage - */ - public function testSaveImageCategoryImage() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $stubCategoryImage = $this->getMockBuilder('\Thelia\Model\CategoryImage') - ->disableOriginalConstructor() - ->getMock(); - $stubCategoryImage->expects($this->any()) - ->method('save') - ->will($this->returnValue(10)); - $stubCategoryImage->expects($this->any()) - ->method('getFile') - ->will($this->returnValue('file')); - - $fileManager = new FileManager(); - - $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_CATEGORY, 24); - - $expected = 10; - $actual = $fileManager->saveImage($event, $stubCategoryImage); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::saveDocument - */ - public function testSaveDocumentCategoryDocument() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $stubCategoryDocument = $this->getMockBuilder('\Thelia\Model\CategoryDocument') - ->disableOriginalConstructor() - ->getMock(); - $stubCategoryDocument->expects($this->any()) - ->method('save') - ->will($this->returnValue(10)); - $stubCategoryDocument->expects($this->any()) - ->method('getFile') - ->will($this->returnValue('file')); - - $fileManager = new FileManager(); - - $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_CATEGORY, 24); - - $expected = 10; - $actual = $fileManager->saveDocument($event, $stubCategoryDocument); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::saveImage - */ - public function testSaveImageFolderImage() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $stubFolderImage = $this->getMockBuilder('\Thelia\Model\FolderImage') - ->disableOriginalConstructor() - ->getMock(); - $stubFolderImage->expects($this->any()) - ->method('save') - ->will($this->returnValue(10)); - $stubFolderImage->expects($this->any()) - ->method('getFile') - ->will($this->returnValue('file')); - - $fileManager = new FileManager(); - - $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_FOLDER, 24); - - $expected = 10; - $actual = $fileManager->saveImage($event, $stubFolderImage); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::saveDocument - */ - public function testSaveDocumentFolderDocument() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $stubFolderDocument = $this->getMockBuilder('\Thelia\Model\FolderDocument') - ->disableOriginalConstructor() - ->getMock(); - $stubFolderDocument->expects($this->any()) - ->method('save') - ->will($this->returnValue(10)); - $stubFolderDocument->expects($this->any()) - ->method('getFile') - ->will($this->returnValue('file')); - - $fileManager = new FileManager(); - - $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_FOLDER, 24); - - $expected = 10; - $actual = $fileManager->saveDocument($event, $stubFolderDocument); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::saveImage - */ - public function testSaveImageContentImage() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $stubContentImage = $this->getMockBuilder('\Thelia\Model\ContentImage') - ->disableOriginalConstructor() - ->getMock(); - $stubContentImage->expects($this->any()) - ->method('save') - ->will($this->returnValue(10)); - $stubContentImage->expects($this->any()) - ->method('getFile') - ->will($this->returnValue('file')); - - $fileManager = new FileManager(); - - $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_CONTENT, 24); - - $expected = 10; - $actual = $fileManager->saveImage($event, $stubContentImage); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::saveDocument - */ - public function testSaveDocumentContentDocument() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $stubContentDocument = $this->getMockBuilder('\Thelia\Model\ContentDocument') - ->disableOriginalConstructor() - ->getMock(); - $stubContentDocument->expects($this->any()) - ->method('save') - ->will($this->returnValue(10)); - $stubContentDocument->expects($this->any()) - ->method('getFile') - ->will($this->returnValue('file')); - - $fileManager = new FileManager(); - - $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_CONTENT, 24); - - $expected = 10; - $actual = $fileManager->saveDocument($event, $stubContentDocument); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::saveImage - * @expectedException \Thelia\Exception\ImageException - */ - public function testSaveImageExceptionImageException() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - $fileManager = new FileManager(); - - $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage') - ->disableOriginalConstructor() - ->getMock(); - $stubProductImage->expects($this->any()) - ->method('save') - ->will($this->returnValue(10)); - $stubProductImage->expects($this->any()) - ->method('getFile') - ->will($this->returnValue('file')); - - $event = new ImageCreateOrUpdateEvent('bad', 24); - - $fileManager->saveImage($event, $stubProductImage); - } - - /** - * @covers Thelia\Tools\FileManager::saveDocument - * @expectedException \Thelia\Model\Exception\InvalidArgumentException - */ - public function testSaveDocumentExceptionDocumentException() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - $fileManager = new FileManager(); - - $stubProductDocument = $this->getMockBuilder('\Thelia\Model\ProductDocument') - ->disableOriginalConstructor() - ->getMock(); - $stubProductDocument->expects($this->any()) - ->method('save') - ->will($this->returnValue(10)); - $stubProductDocument->expects($this->any()) - ->method('getFile') - ->will($this->returnValue('file')); - - $event = new DocumentCreateOrUpdateEvent('bad', 24); - - $fileManager->saveDocument($event, $stubProductDocument); - } - - /** - * @covers Thelia\Tools\FileManager::saveImage - * @expectedException \Thelia\Exception\ImageException - */ - public function testSaveImageExceptionImageException2() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - $fileManager = new FileManager(); - - $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage') - ->disableOriginalConstructor() - ->getMock(); - $stubProductImage->expects($this->any()) - ->method('save') - ->will($this->returnValue(0)); - $stubProductImage->expects($this->any()) - ->method('getFile') - ->will($this->returnValue('file')); - - $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24); - - $fileManager->saveImage($event, $stubProductImage); - } - - /** - * @covers Thelia\Tools\FileManager::saveDocument - * @expectedException \Thelia\Model\Exception\InvalidArgumentException - */ - public function testSaveDocumentExceptionDocumentException2() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - $fileManager = new FileManager(); - - $stubProductDocument = $this->getMockBuilder('\Thelia\Model\ProductDocument') - ->disableOriginalConstructor() - ->getMock(); - $stubProductDocument->expects($this->any()) - ->method('save') - ->will($this->returnValue(0)); - $stubProductDocument->expects($this->any()) - ->method('getFile') - ->will($this->returnValue('file')); - - $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24); - - $fileManager->saveDocument($event, $stubProductDocument); - } - - /** - * @covers Thelia\Tools\FileManager::sanitizeFileName - */ - public function testSanitizeFileName() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $fileManager = new FileManager(); - $badFileName = 'a/ze\érà~çè§^"$*+-_°)(&é<>@#ty2/[\/:*?"<>|]/fi?.fUPPERile.exel../e*'; - - $expected = 'azer-_ty2fi.fupperile.exel..e'; - $actual = $fileManager->sanitizeFileName($badFileName); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::getImageModel - */ - public function testGetImageModel() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $fileManager = new FileManager(); - $actual = $fileManager->getImageModel(FileManager::TYPE_PRODUCT); - $this->assertInstanceOf('\Thelia\Model\ProductImage', $actual); - $actual = $fileManager->getImageModel(FileManager::TYPE_CATEGORY); - $this->assertInstanceOf('\Thelia\Model\CategoryImage', $actual); - $actual = $fileManager->getImageModel(FileManager::TYPE_CONTENT); - $this->assertInstanceOf('\Thelia\Model\ContentImage', $actual); - $actual = $fileManager->getImageModel(FileManager::TYPE_FOLDER); - $this->assertInstanceOf('\Thelia\Model\FolderImage', $actual); - $actual = $fileManager->getImageModel('bad'); - $this->assertNull($actual); - } - - /** - * @covers Thelia\Tools\FileManager::getDocumentModel - */ - public function testGetDocumentModel() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $fileManager = new FileManager(); - $actual = $fileManager->getDocumentModel(FileManager::TYPE_PRODUCT); - $this->assertInstanceOf('\Thelia\Model\ProductDocument', $actual); - $actual = $fileManager->getDocumentModel(FileManager::TYPE_CATEGORY); - $this->assertInstanceOf('\Thelia\Model\CategoryDocument', $actual); - $actual = $fileManager->getDocumentModel(FileManager::TYPE_CONTENT); - $this->assertInstanceOf('\Thelia\Model\ContentDocument', $actual); - $actual = $fileManager->getDocumentModel(FileManager::TYPE_FOLDER); - $this->assertInstanceOf('\Thelia\Model\FolderDocument', $actual); - $actual = $fileManager->getDocumentModel('bad'); - $this->assertNull($actual); - } - - /** - * @covers Thelia\Tools\FileManager::getImageModelQuery - */ - public function testGetImageModelQuery() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $fileManager = new FileManager(); - $actual = $fileManager->getImageModelQuery(FileManager::TYPE_PRODUCT); - $this->assertInstanceOf('\Thelia\Model\ProductImageQuery', $actual); - $actual = $fileManager->getImageModelQuery(FileManager::TYPE_CATEGORY); - $this->assertInstanceOf('\Thelia\Model\CategoryImageQuery', $actual); - $actual = $fileManager->getImageModelQuery(FileManager::TYPE_CONTENT); - $this->assertInstanceOf('\Thelia\Model\ContentImageQuery', $actual); - $actual = $fileManager->getImageModelQuery(FileManager::TYPE_FOLDER); - $this->assertInstanceOf('\Thelia\Model\FolderImageQuery', $actual); - $actual = $fileManager->getImageModelQuery('bad'); - $this->assertNull($actual); - } - - /** - * @covers Thelia\Tools\FileManager::getDocumentModelQuery - */ - public function testGetDocumentModelQuery() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $fileManager = new FileManager(); - $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_PRODUCT); - $this->assertInstanceOf('\Thelia\Model\ProductDocumentQuery', $actual); - $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_CATEGORY); - $this->assertInstanceOf('\Thelia\Model\CategoryDocumentQuery', $actual); - $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_CONTENT); - $this->assertInstanceOf('\Thelia\Model\ContentDocumentQuery', $actual); - $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_FOLDER); - $this->assertInstanceOf('\Thelia\Model\FolderDocumentQuery', $actual); - $actual = $fileManager->getDocumentModelQuery('bad'); - $this->assertNull($actual); - } - - /** - * @covers Thelia\Tools\FileManager::getParentFileModel - */ - public function testGetParentFileModel() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $fileManager = new FileManager(); - $actual = $fileManager->getParentFileModel(FileManager::TYPE_PRODUCT, ProductQuery::create()->findOne()->getId()); - $this->assertInstanceOf('\Thelia\Model\Product', $actual); - $actual = $fileManager->getParentFileModel(FileManager::TYPE_CATEGORY, CategoryQuery::create()->findOne()->getId()); - $this->assertInstanceOf('\Thelia\Model\Category', $actual); - $actual = $fileManager->getParentFileModel(FileManager::TYPE_CONTENT, ContentQuery::create()->findOne()->getId()); - $this->assertInstanceOf('\Thelia\Model\Content', $actual); - $actual = $fileManager->getParentFileModel(FileManager::TYPE_FOLDER, FolderQuery::create()->findOne()->getId()); - $this->assertInstanceOf('\Thelia\Model\Folder', $actual, 1); - $actual = $fileManager->getParentFileModel('bad', 1); - $this->assertNull($actual); - } - - /** - * @covers Thelia\Tools\FileManager::getImageForm - */ - /* public function testGetImageForm() - { - // Mock issue - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - }*/ - /** - * @covers Thelia\Tools\FileManager::getDocumentForm - */ - /* public function testGetDocumentForm() - { - // Mock issue - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - }*/ - - /** - * @covers Thelia\Tools\FileManager::getUploadDir - */ - public function testGetUploadDir() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $fileManager = new FileManager(); - - $actual = $fileManager->getUploadDir(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/product', $actual); - $actual = $fileManager->getUploadDir(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/category', $actual); - $actual = $fileManager->getUploadDir(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/content', $actual); - $actual = $fileManager->getUploadDir(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/folder', $actual); - $actual = $fileManager->getUploadDir('bad', FileManager::FILE_TYPE_IMAGES); - $this->assertEquals(false, $actual); - - $actual = $fileManager->getUploadDir(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals(THELIA_LOCAL_DIR . 'media/documents/product', $actual); - $actual = $fileManager->getUploadDir(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals(THELIA_LOCAL_DIR . 'media/documents/category', $actual); - $actual = $fileManager->getUploadDir(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals(THELIA_LOCAL_DIR . 'media/documents/content', $actual); - $actual = $fileManager->getUploadDir(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals(THELIA_LOCAL_DIR . 'media/documents/folder', $actual); - $actual = $fileManager->getUploadDir('bad', FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals(false, $actual); - - $actual = $fileManager->getUploadDir(FileManager::TYPE_FOLDER, 'bad'); - $this->assertEquals(false, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::getRedirectionUrl - */ - public function testGetRedirectionUrl() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $fileManager = new FileManager(); - - $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_PRODUCT, 1, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals('/admin/products/update?product_id=1¤t_tab=images', $actual); - $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_CATEGORY, 1, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals('/admin/categories/update?category_id=1¤t_tab=images', $actual); - $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_CONTENT, 1, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals('/admin/content/update/1?current_tab=images', $actual); - $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_FOLDER, 1, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals('/admin/folders/update/1?current_tab=images', $actual); - $actual = $fileManager->getRedirectionUrl('bad', 1, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals(false, $actual); - - $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_PRODUCT, 1, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals('/admin/products/update?product_id=1¤t_tab=documents', $actual); - $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_CATEGORY, 1, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals('/admin/categories/update?category_id=1¤t_tab=documents', $actual); - $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_CONTENT, 1, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals('/admin/content/update/1?current_tab=documents', $actual); - $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_FOLDER, 1, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals('/admin/folders/update/1?current_tab=documents', $actual); - $actual = $fileManager->getRedirectionUrl('bad', 1, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals(false, $actual); - - $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_FOLDER, 1, 'bad'); - $this->assertEquals(false, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::getFormId - */ - public function testGetFormId() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $fileManager = new FileManager(); - - $actual = $fileManager->getFormId(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals('thelia.admin.product.image.modification', $actual); - $actual = $fileManager->getFormId(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals('thelia.admin.category.image.modification', $actual); - $actual = $fileManager->getFormId(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals('thelia.admin.content.image.modification', $actual); - $actual = $fileManager->getFormId(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_IMAGES); - $this->assertEquals('thelia.admin.folder.image.modification', $actual); - $actual = $fileManager->getFormId('bad', FileManager::FILE_TYPE_IMAGES); - $this->assertEquals(false, $actual); - - $actual = $fileManager->getFormId(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals('thelia.admin.product.document.modification', $actual); - $actual = $fileManager->getFormId(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals('thelia.admin.category.document.modification', $actual); - $actual = $fileManager->getFormId(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals('thelia.admin.content.document.modification', $actual); - $actual = $fileManager->getFormId(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals('thelia.admin.folder.document.modification', $actual); - $actual = $fileManager->getFormId('bad', FileManager::FILE_TYPE_DOCUMENTS); - $this->assertEquals(false, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::renameFile - */ - public function testRenameFile() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') - ->setConstructorArgs([__DIR__ . '/fixtures/test.xml', 'test.xml']) - ->getMock(); - $stubUploadedFile->expects($this->any()) - ->method('getClientOriginalExtension') - ->will($this->returnValue('yml')); - $stubUploadedFile->expects($this->any()) - ->method('getClientOriginalName') - ->will($this->returnValue('or1-g_n?al*/&é"filen@me#')); - - $fileManager = new FileManager(); - - $expected = 'or1-g_nalfilenme-1.yml'; - $actual = $fileManager->renameFile(1, $stubUploadedFile); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::renameFile - */ - public function testRenameFileWithoutExtension() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile') - ->setConstructorArgs([__DIR__ . '/fixtures/test.xml', 'test.xml']) - ->getMock(); - $stubUploadedFile->expects($this->any()) - ->method('getClientOriginalExtension') - ->will($this->returnValue('')); - $stubUploadedFile->expects($this->any()) - ->method('getClientOriginalName') - ->will($this->returnValue('or1-g_n?al*/&é"filen@me#')); - - $fileManager = new FileManager(); - - $expected = 'or1-g_nalfilenme-1'; - $actual = $fileManager->renameFile(1, $stubUploadedFile); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::isImage - */ - public function testIsImage() - { - $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') - ->disableOriginalConstructor() - ->getMock(); - - $fileManager = new FileManager(); - - $actual = $fileManager->isImage('image/jpeg'); - $this->assertTrue($actual); - $actual = $fileManager->isImage('image/png'); - $this->assertTrue($actual); - $actual = $fileManager->isImage('image/gif'); - $this->assertTrue($actual); - - $actual = $fileManager->isImage('bad'); - $this->assertFalse($actual); - $actual = $fileManager->isImage('image/jpg'); - $this->assertFalse($actual); - $actual = $fileManager->isImage('application/x-msdownload'); - $this->assertFalse($actual); - $actual = $fileManager->isImage('application/x-sh'); - $this->assertFalse($actual); - - } - - /** - * @covers Thelia\Tools\FileManager::getAvailableTypes - */ - public function testGetAvailableTypes() - { - $expected = array( - FileManager::TYPE_CATEGORY, - FileManager::TYPE_CONTENT, - FileManager::TYPE_FOLDER, - FileManager::TYPE_PRODUCT, - FileManager::TYPE_MODULE, - ); - $actual = FileManager::getAvailableTypes(); - - $this->assertEquals($expected, $actual); - } - - /** - * @covers Thelia\Tools\FileManager::adminLogAppend - */ - /* public function testAdminLogAppend() - { - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - }*/ - - /** - * @covers Thelia\Tools\FileManager::deleteFile - */ - /* public function testDeleteFile() - { - // @todo see http://tech.vg.no/2011/03/09/mocking-the-file-system-using-phpunit-and-vfsstream/ - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - }*/ -} From d1f5087d00c963c26971022c361ffc46f21cc471 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Wed, 9 Jul 2014 15:57:23 +0200 Subject: [PATCH 047/158] =?UTF-8?q?Begin=20import=20export=20management=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Conf?= =?UTF-8?q?ig/Resources/config.xml=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Config/Resources/form.xml=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Config/Resour?= =?UTF-8?q?ces/loop.xml=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/?= =?UTF-8?q?lib/Thelia/Config/Resources/routing/admin.xml=20=09renomm=C3=A9?= =?UTF-8?q?:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Form/ImportExport/B?= =?UTF-8?q?aseExportForm.php=20->=20core/lib/Thelia/Controller/Admin/Custo?= =?UTF-8?q?merExportController.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Controller/Admin/ExportController.php=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core?= =?UTF-8?q?/DependencyInjection/Compiler/RegisterArchiveBuilderPass.php=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core?= =?UTF-8?q?/DependencyInjection/Compiler/RegisterFormatterPass.php=20=09no?= =?UTF-8?q?uveau=20fichier:=20core/lib/Thelia/Core/Template/Loop/ArchiveBu?= =?UTF-8?q?ilder.php=20=09nouveau=20fichier:=20core/lib/Thelia/Core/Templa?= =?UTF-8?q?te/Loop/Formatter.php=20=09nouveau=20fichier:=20core/lib/Thelia?= =?UTF-8?q?/Model/Base/ImportExportCategory.php=20=09nouveau=20fichier:=20?= =?UTF-8?q?core/lib/Thelia/Model/Base/ImportExportCategoryI18n.php=20=09no?= =?UTF-8?q?uveau=20fichier:=20core/lib/Thelia/Model/Base/ImportExportCateg?= =?UTF-8?q?oryI18nQuery.php=20=09nouveau=20fichier:=20core/lib/Thelia/Mode?= =?UTF-8?q?l/Base/ImportExportCategoryQuery.php=20=09nouveau=20fichier:=20?= =?UTF-8?q?core/lib/Thelia/Model/Base/ImportExportType.php=20=09nouveau=20?= =?UTF-8?q?fichier:=20core/lib/Thelia/Model/Base/ImportExportTypeI18n.php?= =?UTF-8?q?=20=09nouveau=20fichier:=20core/lib/Thelia/Model/Base/ImportExp?= =?UTF-8?q?ortTypeI18nQuery.php=20=09nouveau=20fichier:=20core/lib/Thelia/?= =?UTF-8?q?Model/Base/ImportExportTypeQuery.php=20=09nouveau=20fichier:=20?= =?UTF-8?q?core/lib/Thelia/Model/ImportExportCategory.php=20=09nouveau=20f?= =?UTF-8?q?ichier:=20core/lib/Thelia/Model/ImportExportCategoryI18n.php=20?= =?UTF-8?q?=09nouveau=20fichier:=20core/lib/Thelia/Model/ImportExportCateg?= =?UTF-8?q?oryI18nQuery.php=20=09nouveau=20fichier:=20core/lib/Thelia/Mode?= =?UTF-8?q?l/ImportExportCategoryQuery.php=20=09nouveau=20fichier:=20core/?= =?UTF-8?q?lib/Thelia/Model/ImportExportType.php=20=09nouveau=20fichier:?= =?UTF-8?q?=20core/lib/Thelia/Model/ImportExportTypeI18n.php=20=09nouveau?= =?UTF-8?q?=20fichier:=20core/lib/Thelia/Model/ImportExportTypeI18nQuery.p?= =?UTF-8?q?hp=20=09nouveau=20fichier:=20core/lib/Thelia/Model/ImportExport?= =?UTF-8?q?TypeQuery.php=20=09nouveau=20fichier:=20core/lib/Thelia/Model/M?= =?UTF-8?q?ap/ImportExportCategoryI18nTableMap.php=20=09nouveau=20fichier:?= =?UTF-8?q?=20core/lib/Thelia/Model/Map/ImportExportCategoryTableMap.php?= =?UTF-8?q?=20=09nouveau=20fichier:=20core/lib/Thelia/Model/Map/ImportExpo?= =?UTF-8?q?rtTypeI18nTableMap.php=20=09nouveau=20fichier:=20core/lib/Theli?= =?UTF-8?q?a/Model/Map/ImportExportTypeTableMap.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20local/config/schema.xml=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20setup/thelia.sql=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20templates/backOffice/default/?= =?UTF-8?q?export.html=20=09nouveau=20fichier:=20templates/backOffice/defa?= =?UTF-8?q?ult/includes/export-form-definition.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/config.xml | 28 +- core/lib/Thelia/Config/Resources/form.xml | 2 + core/lib/Thelia/Config/Resources/loop.xml | 2 + .../Thelia/Config/Resources/routing/admin.xml | 5 +- .../Admin/CustomerExportController.php | 45 +- .../Controller/Admin/ExportController.php | 5 + .../Compiler/RegisterArchiveBuilderPass.php | 2 +- .../Compiler/RegisterFormatterPass.php | 2 +- .../Core/Template/Loop/ArchiveBuilder.php | 134 ++ .../Thelia/Core/Template/Loop/Formatter.php | 132 ++ .../Model/Base/ImportExportCategory.php | 1989 +++++++++++++++++ .../Model/Base/ImportExportCategoryI18n.php | 1268 +++++++++++ .../Base/ImportExportCategoryI18nQuery.php | 508 +++++ .../Model/Base/ImportExportCategoryQuery.php | 764 +++++++ .../Thelia/Model/Base/ImportExportType.php | 1717 ++++++++++++++ .../Model/Base/ImportExportTypeI18n.php | 1326 +++++++++++ .../Model/Base/ImportExportTypeI18nQuery.php | 541 +++++ .../Model/Base/ImportExportTypeQuery.php | 641 ++++++ .../lib/Thelia/Model/ImportExportCategory.php | 10 + .../Thelia/Model/ImportExportCategoryI18n.php | 10 + .../Model/ImportExportCategoryI18nQuery.php | 21 + .../Model/ImportExportCategoryQuery.php | 21 + core/lib/Thelia/Model/ImportExportType.php | 10 + .../lib/Thelia/Model/ImportExportTypeI18n.php | 10 + .../Model/ImportExportTypeI18nQuery.php | 21 + .../Thelia/Model/ImportExportTypeQuery.php | 21 + .../Map/ImportExportCategoryI18nTableMap.php | 474 ++++ .../Map/ImportExportCategoryTableMap.php | 461 ++++ .../Map/ImportExportTypeI18nTableMap.php | 482 ++++ .../Model/Map/ImportExportTypeTableMap.php | 451 ++++ local/config/schema.xml | 25 + setup/thelia.sql | 72 + templates/backOffice/default/export.html | 92 +- .../includes/export-form-definition.html | 96 + 34 files changed, 11313 insertions(+), 75 deletions(-) create mode 100644 core/lib/Thelia/Core/Template/Loop/ArchiveBuilder.php create mode 100644 core/lib/Thelia/Core/Template/Loop/Formatter.php create mode 100644 core/lib/Thelia/Model/Base/ImportExportCategory.php create mode 100644 core/lib/Thelia/Model/Base/ImportExportCategoryI18n.php create mode 100644 core/lib/Thelia/Model/Base/ImportExportCategoryI18nQuery.php create mode 100644 core/lib/Thelia/Model/Base/ImportExportCategoryQuery.php create mode 100644 core/lib/Thelia/Model/Base/ImportExportType.php create mode 100644 core/lib/Thelia/Model/Base/ImportExportTypeI18n.php create mode 100644 core/lib/Thelia/Model/Base/ImportExportTypeI18nQuery.php create mode 100644 core/lib/Thelia/Model/Base/ImportExportTypeQuery.php create mode 100644 core/lib/Thelia/Model/ImportExportCategory.php create mode 100644 core/lib/Thelia/Model/ImportExportCategoryI18n.php create mode 100644 core/lib/Thelia/Model/ImportExportCategoryI18nQuery.php create mode 100644 core/lib/Thelia/Model/ImportExportCategoryQuery.php create mode 100644 core/lib/Thelia/Model/ImportExportType.php create mode 100644 core/lib/Thelia/Model/ImportExportTypeI18n.php create mode 100644 core/lib/Thelia/Model/ImportExportTypeI18nQuery.php create mode 100644 core/lib/Thelia/Model/ImportExportTypeQuery.php create mode 100644 core/lib/Thelia/Model/Map/ImportExportCategoryI18nTableMap.php create mode 100644 core/lib/Thelia/Model/Map/ImportExportCategoryTableMap.php create mode 100644 core/lib/Thelia/Model/Map/ImportExportTypeI18nTableMap.php create mode 100644 core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php create mode 100644 templates/backOffice/default/includes/export-form-definition.html diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 1cda3e289..1f043374a 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -152,26 +152,27 @@ - - + + - - + + - - + + - - + + +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD @@ -213,5 +214,16 @@ ======= >>>>>>> Readd services +======= + + + + + + + + + +>>>>>>> Begin import export management diff --git a/core/lib/Thelia/Config/Resources/form.xml b/core/lib/Thelia/Config/Resources/form.xml index 758f2c926..9dbb59253 100644 --- a/core/lib/Thelia/Config/Resources/form.xml +++ b/core/lib/Thelia/Config/Resources/form.xml @@ -133,6 +133,8 @@
+ + diff --git a/core/lib/Thelia/Config/Resources/loop.xml b/core/lib/Thelia/Config/Resources/loop.xml index 743f33853..90678a5e0 100644 --- a/core/lib/Thelia/Config/Resources/loop.xml +++ b/core/lib/Thelia/Config/Resources/loop.xml @@ -55,6 +55,8 @@ + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 42696a22c..7a2da4a57 100644 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -1164,8 +1164,9 @@ Thelia\Controller\Admin\ExportController::indexAction - - Thelia\Controller\Admin\CustomerExportController::newsletterExportAction + + Thelia\Controller\Admin\ExportController::export + .+ diff --git a/core/lib/Thelia/Controller/Admin/CustomerExportController.php b/core/lib/Thelia/Controller/Admin/CustomerExportController.php index 0036f2d53..901e3c305 100644 --- a/core/lib/Thelia/Controller/Admin/CustomerExportController.php +++ b/core/lib/Thelia/Controller/Admin/CustomerExportController.php @@ -24,43 +24,18 @@ use Thelia\Model\NewsletterQuery; */ class CustomerExportController extends BaseAdminController { - - public function newsletterExportAction() + public function newsletterSubscribers() { - if (null !== $response = $this->checkAuth([AdminResources::EXPORT_CUSTOMER_NEWSLETTER], [], [AccessManager::VIEW])) { - return $response; - } - - $data = NewsletterQuery::create() - ->select([ - 'email', - 'firstname', - 'lastname', - 'locale' - ]) - ->find(); - - $handle = fopen('php://memory', 'r+'); - - fputcsv($handle, ['email','firstname','lastname','locale'], ';', '"'); - - foreach ($data->toArray() as $customer) { - fputcsv($handle, $customer, ';', '"'); - } - - rewind($handle); - $content = stream_get_contents($handle); - fclose($handle); - - return Response::create( - $content, - 200, - array( - "Content-Type"=>"application/csv-tab-delimited-table", - "Content-disposition"=>"filename=export_customer_newsletter.csv" - ) - ); } + public function customers() + { + + } + + public function mailing() + { + + } } diff --git a/core/lib/Thelia/Controller/Admin/ExportController.php b/core/lib/Thelia/Controller/Admin/ExportController.php index 279ed8b4c..90c79dc23 100644 --- a/core/lib/Thelia/Controller/Admin/ExportController.php +++ b/core/lib/Thelia/Controller/Admin/ExportController.php @@ -31,4 +31,9 @@ class ExportController extends BaseAdminController return $this->render('export'); } + + public function export($exportType) + { + + } } diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterArchiveBuilderPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterArchiveBuilderPass.php index 590e307d7..82cc9bbd8 100644 --- a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterArchiveBuilderPass.php +++ b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterArchiveBuilderPass.php @@ -24,7 +24,7 @@ class RegisterArchiveBuilderPass implements CompilerPassInterface { const MANAGER_DEFINITION = "thelia.manager.archive_builder_manager"; - const SERVICE_TAG = "thelia.manager.archive_builder"; + const SERVICE_TAG = "thelia.archive_builder"; /** * You can modify the container here before it is dumped to PHP code. diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterFormatterPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterFormatterPass.php index c10fb8dde..d6ae4dda5 100644 --- a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterFormatterPass.php +++ b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterFormatterPass.php @@ -24,7 +24,7 @@ class RegisterFormatterPass implements CompilerPassInterface { const MANAGER_DEFINITION = "thelia.manager.formatter_manager"; - const SERVICE_TAG = "thelia.manager.formatter"; + const SERVICE_TAG = "thelia.formatter"; /** * You can modify the container here before it is dumped to PHP code. diff --git a/core/lib/Thelia/Core/Template/Loop/ArchiveBuilder.php b/core/lib/Thelia/Core/Template/Loop/ArchiveBuilder.php new file mode 100644 index 000000000..59a2b712a --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/ArchiveBuilder.php @@ -0,0 +1,134 @@ + + */ +class ArchiveBuilder extends BaseLoop implements ArraySearchLoopInterface +{ + /** + * this method returns an array + * + * @return array + */ + public function buildArray() + { + /** @var \Thelia\Core\FileFormat\Archive\archiveBuilderManager $service */ + $service = $this->container->get("thelia.manager.archive_builder_manager"); + + $rawArchiveBuilders = array_change_key_case($service->getAll()); + + + $allowedArchiveBuilder = $this->getAllowed_archive_builder(); + $archiveBuilders = []; + + if ($allowedArchiveBuilder !== null) { + $allowedArchiveBuilder = explode(",", $allowedArchiveBuilder); + + + foreach($allowedArchiveBuilder as $archiveBuilder) { + $archiveBuilder = trim(strtolower($archiveBuilder)); + + if (isset($rawArchiveBuilders[$archiveBuilder])) { + $archiveBuilders[$archiveBuilder] = $rawArchiveBuilders[$archiveBuilder]; + } + } + } else { + $archiveBuilders = $rawArchiveBuilders; + } + + switch ($this->getOrder()) { + case "alpha": + ksort($archiveBuilders); + break; + case "alpha_reverse": + krsort($archiveBuilders); + break; + } + + return $archiveBuilders; + } + + /** + * @param LoopResult $loopResult + * + * @return LoopResult + */ + public function parseResults(LoopResult $loopResult) + { + /** @var \Thelia\Core\FileFormat\Archive\AbstractarchiveBuilder $archiveBuilder */ + foreach ($loopResult->getResultDataCollection() as $archiveBuilder) { + $loopResultRow = new LoopResultRow(); + + $loopResultRow + ->set("NAME", $archiveBuilder->getName()) + ->set("EXTENSION", $archiveBuilder->getExtension()) + ->set("MIME_TYPE", $archiveBuilder->getMimeType()) + ; + + $loopResult->addRow($loopResultRow); + + } + + return $loopResult; + } + + /** + * Definition of loop arguments + * + * example : + * + * public function getArgDefinitions() + * { + * return new ArgumentCollection( + * + * Argument::createIntListTypeArgument('id'), + * new Argument( + * 'ref', + * new TypeCollection( + * new Type\AlphaNumStringListType() + * ) + * ), + * Argument::createIntListTypeArgument('category'), + * Argument::createBooleanTypeArgument('new'), + * ... + * ); + * } + * + * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createAnyTypeArgument("allowed_archive_builder"), + new Argument( + "order", + new TypeCollection( + new EnumType(["alpha", "alpha_reverse"]) + ), + "alpha" + ) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/Formatter.php b/core/lib/Thelia/Core/Template/Loop/Formatter.php new file mode 100644 index 000000000..0c77e4de6 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Formatter.php @@ -0,0 +1,132 @@ + + */ +class Formatter extends BaseLoop implements ArraySearchLoopInterface +{ + /** + * this method returns an array + * + * @return array + */ + public function buildArray() + { + /** @var \Thelia\Core\FileFormat\Formatting\FormatterManager $service */ + $service = $this->container->get("thelia.manager.formatter_manager"); + + $rawFormatters = array_change_key_case($service->getAll()); + + $allowedFormatter = $this->getAllowed_formatter(); + $formatters = []; + if ($allowedFormatter !== null) { + $allowedFormatter = explode(",", $allowedFormatter); + + + foreach($allowedFormatter as $formatter) { + $formatter = trim(strtolower($formatter)); + + if (isset($rawFormatters[$formatter])) { + $formatters[$formatter] = $rawFormatters[$formatter]; + } + } + } else { + $formatters = $rawFormatters; + } + + switch ($this->getOrder()) { + case "alpha": + ksort($formatters); + break; + case "alpha_reverse": + krsort($formatters); + break; + } + + return $formatters; + } + + /** + * @param LoopResult $loopResult + * + * @return LoopResult + */ + public function parseResults(LoopResult $loopResult) + { + /** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */ + foreach ($loopResult->getResultDataCollection() as $formatter) { + $loopResultRow = new LoopResultRow(); + + $loopResultRow + ->set("NAME", $formatter->getName()) + ->set("EXTENSION", $formatter->getExtension()) + ->set("MIME_TYPE", $formatter->getMimeType()) + ; + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } + + /** + * Definition of loop arguments + * + * example : + * + * public function getArgDefinitions() + * { + * return new ArgumentCollection( + * + * Argument::createIntListTypeArgument('id'), + * new Argument( + * 'ref', + * new TypeCollection( + * new Type\AlphaNumStringListType() + * ) + * ), + * Argument::createIntListTypeArgument('category'), + * Argument::createBooleanTypeArgument('new'), + * ... + * ); + * } + * + * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createAnyTypeArgument("allowed_formatter"), + new Argument( + "order", + new TypeCollection( + new EnumType(["alpha", "alpha_reverse"]) + ), + "alpha" + ) + ); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Model/Base/ImportExportCategory.php b/core/lib/Thelia/Model/Base/ImportExportCategory.php new file mode 100644 index 000000000..ed0e5007c --- /dev/null +++ b/core/lib/Thelia/Model/Base/ImportExportCategory.php @@ -0,0 +1,1989 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another ImportExportCategory instance. If + * obj is an instance of ImportExportCategory, delegates to + * equals(ImportExportCategory). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return ImportExportCategory The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return ImportExportCategory The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [position] column value. + * + * @return int + */ + public function getPosition() + { + + return $this->position; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; + } + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \Thelia\Model\ImportExportCategory The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[ImportExportCategoryTableMap::ID] = true; + } + + + return $this; + } // setId() + + /** + * Set the value of [position] column. + * + * @param int $v new value + * @return \Thelia\Model\ImportExportCategory The current object (for fluent API support) + */ + public function setPosition($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->position !== $v) { + $this->position = $v; + $this->modifiedColumns[ImportExportCategoryTableMap::POSITION] = true; + } + + + return $this; + } // setPosition() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\ImportExportCategory The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[ImportExportCategoryTableMap::CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\ImportExportCategory The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[ImportExportCategoryTableMap::UPDATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ImportExportCategoryTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ImportExportCategoryTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; + $this->position = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportExportCategoryTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportExportCategoryTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 4; // 4 = ImportExportCategoryTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\ImportExportCategory object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ImportExportCategoryTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildImportExportCategoryQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->collImportExportTypes = null; + + $this->collImportExportCategoryI18ns = null; + + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see ImportExportCategory::setDeleted() + * @see ImportExportCategory::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildImportExportCategoryQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(ImportExportCategoryTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(ImportExportCategoryTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(ImportExportCategoryTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + ImportExportCategoryTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + if ($this->importExportTypesScheduledForDeletion !== null) { + if (!$this->importExportTypesScheduledForDeletion->isEmpty()) { + \Thelia\Model\ImportExportTypeQuery::create() + ->filterByPrimaryKeys($this->importExportTypesScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->importExportTypesScheduledForDeletion = null; + } + } + + if ($this->collImportExportTypes !== null) { + foreach ($this->collImportExportTypes as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + if ($this->importExportCategoryI18nsScheduledForDeletion !== null) { + if (!$this->importExportCategoryI18nsScheduledForDeletion->isEmpty()) { + \Thelia\Model\ImportExportCategoryI18nQuery::create() + ->filterByPrimaryKeys($this->importExportCategoryI18nsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->importExportCategoryI18nsScheduledForDeletion = null; + } + } + + if ($this->collImportExportCategoryI18ns !== null) { + foreach ($this->collImportExportCategoryI18ns as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[ImportExportCategoryTableMap::ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . ImportExportCategoryTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(ImportExportCategoryTableMap::ID)) { + $modifiedColumns[':p' . $index++] = '`ID`'; + } + if ($this->isColumnModified(ImportExportCategoryTableMap::POSITION)) { + $modifiedColumns[':p' . $index++] = '`POSITION`'; + } + if ($this->isColumnModified(ImportExportCategoryTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = '`CREATED_AT`'; + } + if ($this->isColumnModified(ImportExportCategoryTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = '`UPDATED_AT`'; + } + + $sql = sprintf( + 'INSERT INTO `import_export_category` (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case '`ID`': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case '`POSITION`': + $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); + break; + case '`CREATED_AT`': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case '`UPDATED_AT`': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = ImportExportCategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getPosition(); + break; + case 2: + return $this->getCreatedAt(); + break; + case 3: + return $this->getUpdatedAt(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['ImportExportCategory'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['ImportExportCategory'][$this->getPrimaryKey()] = true; + $keys = ImportExportCategoryTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getPosition(), + $keys[2] => $this->getCreatedAt(), + $keys[3] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->collImportExportTypes) { + $result['ImportExportTypes'] = $this->collImportExportTypes->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + if (null !== $this->collImportExportCategoryI18ns) { + $result['ImportExportCategoryI18ns'] = $this->collImportExportCategoryI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = ImportExportCategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setPosition($value); + break; + case 2: + $this->setCreatedAt($value); + break; + case 3: + $this->setUpdatedAt($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = ImportExportCategoryTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setPosition($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setCreatedAt($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setUpdatedAt($arr[$keys[3]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(ImportExportCategoryTableMap::DATABASE_NAME); + + if ($this->isColumnModified(ImportExportCategoryTableMap::ID)) $criteria->add(ImportExportCategoryTableMap::ID, $this->id); + if ($this->isColumnModified(ImportExportCategoryTableMap::POSITION)) $criteria->add(ImportExportCategoryTableMap::POSITION, $this->position); + if ($this->isColumnModified(ImportExportCategoryTableMap::CREATED_AT)) $criteria->add(ImportExportCategoryTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(ImportExportCategoryTableMap::UPDATED_AT)) $criteria->add(ImportExportCategoryTableMap::UPDATED_AT, $this->updated_at); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(ImportExportCategoryTableMap::DATABASE_NAME); + $criteria->add(ImportExportCategoryTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Thelia\Model\ImportExportCategory (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setPosition($this->getPosition()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + + if ($deepCopy) { + // important: temporarily setNew(false) because this affects the behavior of + // the getter/setter methods for fkey referrer objects. + $copyObj->setNew(false); + + foreach ($this->getImportExportTypes() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addImportExportType($relObj->copy($deepCopy)); + } + } + + foreach ($this->getImportExportCategoryI18ns() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addImportExportCategoryI18n($relObj->copy($deepCopy)); + } + } + + } // if ($deepCopy) + + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Thelia\Model\ImportExportCategory Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + + /** + * Initializes a collection based on the name of a relation. + * Avoids crafting an 'init[$relationName]s' method name + * that wouldn't work when StandardEnglishPluralizer is used. + * + * @param string $relationName The name of the relation to initialize + * @return void + */ + public function initRelation($relationName) + { + if ('ImportExportType' == $relationName) { + return $this->initImportExportTypes(); + } + if ('ImportExportCategoryI18n' == $relationName) { + return $this->initImportExportCategoryI18ns(); + } + } + + /** + * Clears out the collImportExportTypes collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addImportExportTypes() + */ + public function clearImportExportTypes() + { + $this->collImportExportTypes = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collImportExportTypes collection loaded partially. + */ + public function resetPartialImportExportTypes($v = true) + { + $this->collImportExportTypesPartial = $v; + } + + /** + * Initializes the collImportExportTypes collection. + * + * By default this just sets the collImportExportTypes collection to an empty array (like clearcollImportExportTypes()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initImportExportTypes($overrideExisting = true) + { + if (null !== $this->collImportExportTypes && !$overrideExisting) { + return; + } + $this->collImportExportTypes = new ObjectCollection(); + $this->collImportExportTypes->setModel('\Thelia\Model\ImportExportType'); + } + + /** + * Gets an array of ChildImportExportType objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildImportExportCategory is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildImportExportType[] List of ChildImportExportType objects + * @throws PropelException + */ + public function getImportExportTypes($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collImportExportTypesPartial && !$this->isNew(); + if (null === $this->collImportExportTypes || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collImportExportTypes) { + // return empty collection + $this->initImportExportTypes(); + } else { + $collImportExportTypes = ChildImportExportTypeQuery::create(null, $criteria) + ->filterByImportExportCategory($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collImportExportTypesPartial && count($collImportExportTypes)) { + $this->initImportExportTypes(false); + + foreach ($collImportExportTypes as $obj) { + if (false == $this->collImportExportTypes->contains($obj)) { + $this->collImportExportTypes->append($obj); + } + } + + $this->collImportExportTypesPartial = true; + } + + reset($collImportExportTypes); + + return $collImportExportTypes; + } + + if ($partial && $this->collImportExportTypes) { + foreach ($this->collImportExportTypes as $obj) { + if ($obj->isNew()) { + $collImportExportTypes[] = $obj; + } + } + } + + $this->collImportExportTypes = $collImportExportTypes; + $this->collImportExportTypesPartial = false; + } + } + + return $this->collImportExportTypes; + } + + /** + * Sets a collection of ImportExportType objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $importExportTypes A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildImportExportCategory The current object (for fluent API support) + */ + public function setImportExportTypes(Collection $importExportTypes, ConnectionInterface $con = null) + { + $importExportTypesToDelete = $this->getImportExportTypes(new Criteria(), $con)->diff($importExportTypes); + + + $this->importExportTypesScheduledForDeletion = $importExportTypesToDelete; + + foreach ($importExportTypesToDelete as $importExportTypeRemoved) { + $importExportTypeRemoved->setImportExportCategory(null); + } + + $this->collImportExportTypes = null; + foreach ($importExportTypes as $importExportType) { + $this->addImportExportType($importExportType); + } + + $this->collImportExportTypes = $importExportTypes; + $this->collImportExportTypesPartial = false; + + return $this; + } + + /** + * Returns the number of related ImportExportType objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related ImportExportType objects. + * @throws PropelException + */ + public function countImportExportTypes(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collImportExportTypesPartial && !$this->isNew(); + if (null === $this->collImportExportTypes || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collImportExportTypes) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getImportExportTypes()); + } + + $query = ChildImportExportTypeQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByImportExportCategory($this) + ->count($con); + } + + return count($this->collImportExportTypes); + } + + /** + * Method called to associate a ChildImportExportType object to this object + * through the ChildImportExportType foreign key attribute. + * + * @param ChildImportExportType $l ChildImportExportType + * @return \Thelia\Model\ImportExportCategory The current object (for fluent API support) + */ + public function addImportExportType(ChildImportExportType $l) + { + if ($this->collImportExportTypes === null) { + $this->initImportExportTypes(); + $this->collImportExportTypesPartial = true; + } + + if (!in_array($l, $this->collImportExportTypes->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddImportExportType($l); + } + + return $this; + } + + /** + * @param ImportExportType $importExportType The importExportType object to add. + */ + protected function doAddImportExportType($importExportType) + { + $this->collImportExportTypes[]= $importExportType; + $importExportType->setImportExportCategory($this); + } + + /** + * @param ImportExportType $importExportType The importExportType object to remove. + * @return ChildImportExportCategory The current object (for fluent API support) + */ + public function removeImportExportType($importExportType) + { + if ($this->getImportExportTypes()->contains($importExportType)) { + $this->collImportExportTypes->remove($this->collImportExportTypes->search($importExportType)); + if (null === $this->importExportTypesScheduledForDeletion) { + $this->importExportTypesScheduledForDeletion = clone $this->collImportExportTypes; + $this->importExportTypesScheduledForDeletion->clear(); + } + $this->importExportTypesScheduledForDeletion[]= clone $importExportType; + $importExportType->setImportExportCategory(null); + } + + return $this; + } + + /** + * Clears out the collImportExportCategoryI18ns collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addImportExportCategoryI18ns() + */ + public function clearImportExportCategoryI18ns() + { + $this->collImportExportCategoryI18ns = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collImportExportCategoryI18ns collection loaded partially. + */ + public function resetPartialImportExportCategoryI18ns($v = true) + { + $this->collImportExportCategoryI18nsPartial = $v; + } + + /** + * Initializes the collImportExportCategoryI18ns collection. + * + * By default this just sets the collImportExportCategoryI18ns collection to an empty array (like clearcollImportExportCategoryI18ns()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initImportExportCategoryI18ns($overrideExisting = true) + { + if (null !== $this->collImportExportCategoryI18ns && !$overrideExisting) { + return; + } + $this->collImportExportCategoryI18ns = new ObjectCollection(); + $this->collImportExportCategoryI18ns->setModel('\Thelia\Model\ImportExportCategoryI18n'); + } + + /** + * Gets an array of ChildImportExportCategoryI18n objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildImportExportCategory is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildImportExportCategoryI18n[] List of ChildImportExportCategoryI18n objects + * @throws PropelException + */ + public function getImportExportCategoryI18ns($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collImportExportCategoryI18nsPartial && !$this->isNew(); + if (null === $this->collImportExportCategoryI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collImportExportCategoryI18ns) { + // return empty collection + $this->initImportExportCategoryI18ns(); + } else { + $collImportExportCategoryI18ns = ChildImportExportCategoryI18nQuery::create(null, $criteria) + ->filterByImportExportCategory($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collImportExportCategoryI18nsPartial && count($collImportExportCategoryI18ns)) { + $this->initImportExportCategoryI18ns(false); + + foreach ($collImportExportCategoryI18ns as $obj) { + if (false == $this->collImportExportCategoryI18ns->contains($obj)) { + $this->collImportExportCategoryI18ns->append($obj); + } + } + + $this->collImportExportCategoryI18nsPartial = true; + } + + reset($collImportExportCategoryI18ns); + + return $collImportExportCategoryI18ns; + } + + if ($partial && $this->collImportExportCategoryI18ns) { + foreach ($this->collImportExportCategoryI18ns as $obj) { + if ($obj->isNew()) { + $collImportExportCategoryI18ns[] = $obj; + } + } + } + + $this->collImportExportCategoryI18ns = $collImportExportCategoryI18ns; + $this->collImportExportCategoryI18nsPartial = false; + } + } + + return $this->collImportExportCategoryI18ns; + } + + /** + * Sets a collection of ImportExportCategoryI18n objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $importExportCategoryI18ns A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildImportExportCategory The current object (for fluent API support) + */ + public function setImportExportCategoryI18ns(Collection $importExportCategoryI18ns, ConnectionInterface $con = null) + { + $importExportCategoryI18nsToDelete = $this->getImportExportCategoryI18ns(new Criteria(), $con)->diff($importExportCategoryI18ns); + + + //since at least one column in the foreign key is at the same time a PK + //we can not just set a PK to NULL in the lines below. We have to store + //a backup of all values, so we are able to manipulate these items based on the onDelete value later. + $this->importExportCategoryI18nsScheduledForDeletion = clone $importExportCategoryI18nsToDelete; + + foreach ($importExportCategoryI18nsToDelete as $importExportCategoryI18nRemoved) { + $importExportCategoryI18nRemoved->setImportExportCategory(null); + } + + $this->collImportExportCategoryI18ns = null; + foreach ($importExportCategoryI18ns as $importExportCategoryI18n) { + $this->addImportExportCategoryI18n($importExportCategoryI18n); + } + + $this->collImportExportCategoryI18ns = $importExportCategoryI18ns; + $this->collImportExportCategoryI18nsPartial = false; + + return $this; + } + + /** + * Returns the number of related ImportExportCategoryI18n objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related ImportExportCategoryI18n objects. + * @throws PropelException + */ + public function countImportExportCategoryI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collImportExportCategoryI18nsPartial && !$this->isNew(); + if (null === $this->collImportExportCategoryI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collImportExportCategoryI18ns) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getImportExportCategoryI18ns()); + } + + $query = ChildImportExportCategoryI18nQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByImportExportCategory($this) + ->count($con); + } + + return count($this->collImportExportCategoryI18ns); + } + + /** + * Method called to associate a ChildImportExportCategoryI18n object to this object + * through the ChildImportExportCategoryI18n foreign key attribute. + * + * @param ChildImportExportCategoryI18n $l ChildImportExportCategoryI18n + * @return \Thelia\Model\ImportExportCategory The current object (for fluent API support) + */ + public function addImportExportCategoryI18n(ChildImportExportCategoryI18n $l) + { + if ($l && $locale = $l->getLocale()) { + $this->setLocale($locale); + $this->currentTranslations[$locale] = $l; + } + if ($this->collImportExportCategoryI18ns === null) { + $this->initImportExportCategoryI18ns(); + $this->collImportExportCategoryI18nsPartial = true; + } + + if (!in_array($l, $this->collImportExportCategoryI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddImportExportCategoryI18n($l); + } + + return $this; + } + + /** + * @param ImportExportCategoryI18n $importExportCategoryI18n The importExportCategoryI18n object to add. + */ + protected function doAddImportExportCategoryI18n($importExportCategoryI18n) + { + $this->collImportExportCategoryI18ns[]= $importExportCategoryI18n; + $importExportCategoryI18n->setImportExportCategory($this); + } + + /** + * @param ImportExportCategoryI18n $importExportCategoryI18n The importExportCategoryI18n object to remove. + * @return ChildImportExportCategory The current object (for fluent API support) + */ + public function removeImportExportCategoryI18n($importExportCategoryI18n) + { + if ($this->getImportExportCategoryI18ns()->contains($importExportCategoryI18n)) { + $this->collImportExportCategoryI18ns->remove($this->collImportExportCategoryI18ns->search($importExportCategoryI18n)); + if (null === $this->importExportCategoryI18nsScheduledForDeletion) { + $this->importExportCategoryI18nsScheduledForDeletion = clone $this->collImportExportCategoryI18ns; + $this->importExportCategoryI18nsScheduledForDeletion->clear(); + } + $this->importExportCategoryI18nsScheduledForDeletion[]= clone $importExportCategoryI18n; + $importExportCategoryI18n->setImportExportCategory(null); + } + + return $this; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->position = null; + $this->created_at = null; + $this->updated_at = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + if ($this->collImportExportTypes) { + foreach ($this->collImportExportTypes as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collImportExportCategoryI18ns) { + foreach ($this->collImportExportCategoryI18ns as $o) { + $o->clearAllReferences($deep); + } + } + } // if ($deep) + + // i18n behavior + $this->currentLocale = 'en_US'; + $this->currentTranslations = null; + + $this->collImportExportTypes = null; + $this->collImportExportCategoryI18ns = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(ImportExportCategoryTableMap::DEFAULT_STRING_FORMAT); + } + + // i18n behavior + + /** + * Sets the locale for translations + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * + * @return ChildImportExportCategory The current object (for fluent API support) + */ + public function setLocale($locale = 'en_US') + { + $this->currentLocale = $locale; + + return $this; + } + + /** + * Gets the locale for translations + * + * @return string $locale Locale to use for the translation, e.g. 'fr_FR' + */ + public function getLocale() + { + return $this->currentLocale; + } + + /** + * Returns the current translation for a given locale + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * @param ConnectionInterface $con an optional connection object + * + * @return ChildImportExportCategoryI18n */ + public function getTranslation($locale = 'en_US', ConnectionInterface $con = null) + { + if (!isset($this->currentTranslations[$locale])) { + if (null !== $this->collImportExportCategoryI18ns) { + foreach ($this->collImportExportCategoryI18ns as $translation) { + if ($translation->getLocale() == $locale) { + $this->currentTranslations[$locale] = $translation; + + return $translation; + } + } + } + if ($this->isNew()) { + $translation = new ChildImportExportCategoryI18n(); + $translation->setLocale($locale); + } else { + $translation = ChildImportExportCategoryI18nQuery::create() + ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->findOneOrCreate($con); + $this->currentTranslations[$locale] = $translation; + } + $this->addImportExportCategoryI18n($translation); + } + + return $this->currentTranslations[$locale]; + } + + /** + * Remove the translation for a given locale + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * @param ConnectionInterface $con an optional connection object + * + * @return ChildImportExportCategory The current object (for fluent API support) + */ + public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null) + { + if (!$this->isNew()) { + ChildImportExportCategoryI18nQuery::create() + ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->delete($con); + } + if (isset($this->currentTranslations[$locale])) { + unset($this->currentTranslations[$locale]); + } + foreach ($this->collImportExportCategoryI18ns as $key => $translation) { + if ($translation->getLocale() == $locale) { + unset($this->collImportExportCategoryI18ns[$key]); + break; + } + } + + return $this; + } + + /** + * Returns the current translation + * + * @param ConnectionInterface $con an optional connection object + * + * @return ChildImportExportCategoryI18n */ + public function getCurrentTranslation(ConnectionInterface $con = null) + { + return $this->getTranslation($this->getLocale(), $con); + } + + + /** + * Get the [title] column value. + * + * @return string + */ + public function getTitle() + { + return $this->getCurrentTranslation()->getTitle(); + } + + + /** + * Set the value of [title] column. + * + * @param string $v new value + * @return \Thelia\Model\ImportExportCategoryI18n The current object (for fluent API support) + */ + public function setTitle($v) + { $this->getCurrentTranslation()->setTitle($v); + + return $this; + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildImportExportCategory The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[ImportExportCategoryTableMap::UPDATED_AT] = true; + + return $this; + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/core/lib/Thelia/Model/Base/ImportExportCategoryI18n.php b/core/lib/Thelia/Model/Base/ImportExportCategoryI18n.php new file mode 100644 index 000000000..53519dc56 --- /dev/null +++ b/core/lib/Thelia/Model/Base/ImportExportCategoryI18n.php @@ -0,0 +1,1268 @@ +locale = 'en_US'; + } + + /** + * Initializes internal state of Thelia\Model\Base\ImportExportCategoryI18n object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !!$this->modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another ImportExportCategoryI18n instance. If + * obj is an instance of ImportExportCategoryI18n, delegates to + * equals(ImportExportCategoryI18n). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return ImportExportCategoryI18n The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return ImportExportCategoryI18n The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [locale] column value. + * + * @return string + */ + public function getLocale() + { + + return $this->locale; + } + + /** + * Get the [title] column value. + * + * @return string + */ + public function getTitle() + { + + return $this->title; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \Thelia\Model\ImportExportCategoryI18n The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[ImportExportCategoryI18nTableMap::ID] = true; + } + + if ($this->aImportExportCategory !== null && $this->aImportExportCategory->getId() !== $v) { + $this->aImportExportCategory = null; + } + + + return $this; + } // setId() + + /** + * Set the value of [locale] column. + * + * @param string $v new value + * @return \Thelia\Model\ImportExportCategoryI18n The current object (for fluent API support) + */ + public function setLocale($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->locale !== $v) { + $this->locale = $v; + $this->modifiedColumns[ImportExportCategoryI18nTableMap::LOCALE] = true; + } + + + return $this; + } // setLocale() + + /** + * Set the value of [title] column. + * + * @param string $v new value + * @return \Thelia\Model\ImportExportCategoryI18n The current object (for fluent API support) + */ + public function setTitle($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->title !== $v) { + $this->title = $v; + $this->modifiedColumns[ImportExportCategoryI18nTableMap::TITLE] = true; + } + + + return $this; + } // setTitle() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + if ($this->locale !== 'en_US') { + return false; + } + + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ImportExportCategoryI18nTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ImportExportCategoryI18nTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; + $this->locale = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportExportCategoryI18nTableMap::translateFieldName('Title', TableMap::TYPE_PHPNAME, $indexType)]; + $this->title = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 3; // 3 = ImportExportCategoryI18nTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\ImportExportCategoryI18n object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aImportExportCategory !== null && $this->id !== $this->aImportExportCategory->getId()) { + $this->aImportExportCategory = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildImportExportCategoryI18nQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aImportExportCategory = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see ImportExportCategoryI18n::setDeleted() + * @see ImportExportCategoryI18n::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildImportExportCategoryI18nQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + ImportExportCategoryI18nTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aImportExportCategory !== null) { + if ($this->aImportExportCategory->isModified() || $this->aImportExportCategory->isNew()) { + $affectedRows += $this->aImportExportCategory->save($con); + } + $this->setImportExportCategory($this->aImportExportCategory); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(ImportExportCategoryI18nTableMap::ID)) { + $modifiedColumns[':p' . $index++] = '`ID`'; + } + if ($this->isColumnModified(ImportExportCategoryI18nTableMap::LOCALE)) { + $modifiedColumns[':p' . $index++] = '`LOCALE`'; + } + if ($this->isColumnModified(ImportExportCategoryI18nTableMap::TITLE)) { + $modifiedColumns[':p' . $index++] = '`TITLE`'; + } + + $sql = sprintf( + 'INSERT INTO `import_export_category_i18n` (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case '`ID`': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case '`LOCALE`': + $stmt->bindValue($identifier, $this->locale, PDO::PARAM_STR); + break; + case '`TITLE`': + $stmt->bindValue($identifier, $this->title, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = ImportExportCategoryI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getLocale(); + break; + case 2: + return $this->getTitle(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['ImportExportCategoryI18n'][serialize($this->getPrimaryKey())])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['ImportExportCategoryI18n'][serialize($this->getPrimaryKey())] = true; + $keys = ImportExportCategoryI18nTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getLocale(), + $keys[2] => $this->getTitle(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aImportExportCategory) { + $result['ImportExportCategory'] = $this->aImportExportCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = ImportExportCategoryI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setLocale($value); + break; + case 2: + $this->setTitle($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = ImportExportCategoryI18nTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setLocale($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setTitle($arr[$keys[2]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(ImportExportCategoryI18nTableMap::DATABASE_NAME); + + if ($this->isColumnModified(ImportExportCategoryI18nTableMap::ID)) $criteria->add(ImportExportCategoryI18nTableMap::ID, $this->id); + if ($this->isColumnModified(ImportExportCategoryI18nTableMap::LOCALE)) $criteria->add(ImportExportCategoryI18nTableMap::LOCALE, $this->locale); + if ($this->isColumnModified(ImportExportCategoryI18nTableMap::TITLE)) $criteria->add(ImportExportCategoryI18nTableMap::TITLE, $this->title); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(ImportExportCategoryI18nTableMap::DATABASE_NAME); + $criteria->add(ImportExportCategoryI18nTableMap::ID, $this->id); + $criteria->add(ImportExportCategoryI18nTableMap::LOCALE, $this->locale); + + return $criteria; + } + + /** + * Returns the composite primary key for this object. + * The array elements will be in same order as specified in XML. + * @return array + */ + public function getPrimaryKey() + { + $pks = array(); + $pks[0] = $this->getId(); + $pks[1] = $this->getLocale(); + + return $pks; + } + + /** + * Set the [composite] primary key. + * + * @param array $keys The elements of the composite key (order must match the order in XML file). + * @return void + */ + public function setPrimaryKey($keys) + { + $this->setId($keys[0]); + $this->setLocale($keys[1]); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return (null === $this->getId()) && (null === $this->getLocale()); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Thelia\Model\ImportExportCategoryI18n (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setLocale($this->getLocale()); + $copyObj->setTitle($this->getTitle()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Thelia\Model\ImportExportCategoryI18n Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildImportExportCategory object. + * + * @param ChildImportExportCategory $v + * @return \Thelia\Model\ImportExportCategoryI18n The current object (for fluent API support) + * @throws PropelException + */ + public function setImportExportCategory(ChildImportExportCategory $v = null) + { + if ($v === null) { + $this->setId(NULL); + } else { + $this->setId($v->getId()); + } + + $this->aImportExportCategory = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildImportExportCategory object, it will not be re-added. + if ($v !== null) { + $v->addImportExportCategoryI18n($this); + } + + + return $this; + } + + + /** + * Get the associated ChildImportExportCategory object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildImportExportCategory The associated ChildImportExportCategory object. + * @throws PropelException + */ + public function getImportExportCategory(ConnectionInterface $con = null) + { + if ($this->aImportExportCategory === null && ($this->id !== null)) { + $this->aImportExportCategory = ChildImportExportCategoryQuery::create()->findPk($this->id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aImportExportCategory->addImportExportCategoryI18ns($this); + */ + } + + return $this->aImportExportCategory; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->locale = null; + $this->title = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aImportExportCategory = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(ImportExportCategoryI18nTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/core/lib/Thelia/Model/Base/ImportExportCategoryI18nQuery.php b/core/lib/Thelia/Model/Base/ImportExportCategoryI18nQuery.php new file mode 100644 index 000000000..05ee2eb89 --- /dev/null +++ b/core/lib/Thelia/Model/Base/ImportExportCategoryI18nQuery.php @@ -0,0 +1,508 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(array(12, 34), $con); + * + * + * @param array[$id, $locale] $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildImportExportCategoryI18n|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = ImportExportCategoryI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildImportExportCategoryI18n A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT `ID`, `LOCALE`, `TITLE` FROM `import_export_category_i18n` WHERE `ID` = :p0 AND `LOCALE` = :p1'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); + $stmt->bindValue(':p1', $key[1], PDO::PARAM_STR); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildImportExportCategoryI18n(); + $obj->hydrate($row); + ImportExportCategoryI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildImportExportCategoryI18n|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + $this->addUsingAlias(ImportExportCategoryI18nTableMap::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(ImportExportCategoryI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + + return $this; + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + if (empty($keys)) { + return $this->add(null, '1<>1', Criteria::CUSTOM); + } + foreach ($keys as $key) { + $cton0 = $this->getNewCriterion(ImportExportCategoryI18nTableMap::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(ImportExportCategoryI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $this->addOr($cton0); + } + + return $this; + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @see filterByImportExportCategory() + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(ImportExportCategoryI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(ImportExportCategoryI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ImportExportCategoryI18nTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the locale column + * + * Example usage: + * + * $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue' + * $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%' + * + * + * @param string $locale The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + */ + public function filterByLocale($locale = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($locale)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $locale)) { + $locale = str_replace('*', '%', $locale); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ImportExportCategoryI18nTableMap::LOCALE, $locale, $comparison); + } + + /** + * Filter the query on the title column + * + * Example usage: + * + * $query->filterByTitle('fooValue'); // WHERE title = 'fooValue' + * $query->filterByTitle('%fooValue%'); // WHERE title LIKE '%fooValue%' + * + * + * @param string $title The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + */ + public function filterByTitle($title = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($title)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $title)) { + $title = str_replace('*', '%', $title); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ImportExportCategoryI18nTableMap::TITLE, $title, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\ImportExportCategory object + * + * @param \Thelia\Model\ImportExportCategory|ObjectCollection $importExportCategory The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + */ + public function filterByImportExportCategory($importExportCategory, $comparison = null) + { + if ($importExportCategory instanceof \Thelia\Model\ImportExportCategory) { + return $this + ->addUsingAlias(ImportExportCategoryI18nTableMap::ID, $importExportCategory->getId(), $comparison); + } elseif ($importExportCategory instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(ImportExportCategoryI18nTableMap::ID, $importExportCategory->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByImportExportCategory() only accepts arguments of type \Thelia\Model\ImportExportCategory or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the ImportExportCategory relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + */ + public function joinImportExportCategory($relationAlias = null, $joinType = 'LEFT JOIN') + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('ImportExportCategory'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'ImportExportCategory'); + } + + return $this; + } + + /** + * Use the ImportExportCategory relation ImportExportCategory object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ImportExportCategoryQuery A secondary query class using the current class as primary query + */ + public function useImportExportCategoryQuery($relationAlias = null, $joinType = 'LEFT JOIN') + { + return $this + ->joinImportExportCategory($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ImportExportCategory', '\Thelia\Model\ImportExportCategoryQuery'); + } + + /** + * Exclude object from result + * + * @param ChildImportExportCategoryI18n $importExportCategoryI18n Object to remove from the list of results + * + * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + */ + public function prune($importExportCategoryI18n = null) + { + if ($importExportCategoryI18n) { + $this->addCond('pruneCond0', $this->getAliasedColName(ImportExportCategoryI18nTableMap::ID), $importExportCategoryI18n->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(ImportExportCategoryI18nTableMap::LOCALE), $importExportCategoryI18n->getLocale(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); + } + + return $this; + } + + /** + * Deletes all rows from the import_export_category_i18n table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + ImportExportCategoryI18nTableMap::clearInstancePool(); + ImportExportCategoryI18nTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildImportExportCategoryI18n or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildImportExportCategoryI18n object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(ImportExportCategoryI18nTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + ImportExportCategoryI18nTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + ImportExportCategoryI18nTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // ImportExportCategoryI18nQuery diff --git a/core/lib/Thelia/Model/Base/ImportExportCategoryQuery.php b/core/lib/Thelia/Model/Base/ImportExportCategoryQuery.php new file mode 100644 index 000000000..535ad75ac --- /dev/null +++ b/core/lib/Thelia/Model/Base/ImportExportCategoryQuery.php @@ -0,0 +1,764 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildImportExportCategory|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = ImportExportCategoryTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ImportExportCategoryTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildImportExportCategory A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT `ID`, `POSITION`, `CREATED_AT`, `UPDATED_AT` FROM `import_export_category` WHERE `ID` = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildImportExportCategory(); + $obj->hydrate($row); + ImportExportCategoryTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildImportExportCategory|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(ImportExportCategoryTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(ImportExportCategoryTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(ImportExportCategoryTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(ImportExportCategoryTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ImportExportCategoryTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the position column + * + * Example usage: + * + * $query->filterByPosition(1234); // WHERE position = 1234 + * $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34) + * $query->filterByPosition(array('min' => 12)); // WHERE position > 12 + * + * + * @param mixed $position The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function filterByPosition($position = null, $comparison = null) + { + if (is_array($position)) { + $useMinMax = false; + if (isset($position['min'])) { + $this->addUsingAlias(ImportExportCategoryTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($position['max'])) { + $this->addUsingAlias(ImportExportCategoryTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ImportExportCategoryTableMap::POSITION, $position, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(ImportExportCategoryTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(ImportExportCategoryTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ImportExportCategoryTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(ImportExportCategoryTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(ImportExportCategoryTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ImportExportCategoryTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\ImportExportType object + * + * @param \Thelia\Model\ImportExportType|ObjectCollection $importExportType the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function filterByImportExportType($importExportType, $comparison = null) + { + if ($importExportType instanceof \Thelia\Model\ImportExportType) { + return $this + ->addUsingAlias(ImportExportCategoryTableMap::ID, $importExportType->getImportExportCategoryId(), $comparison); + } elseif ($importExportType instanceof ObjectCollection) { + return $this + ->useImportExportTypeQuery() + ->filterByPrimaryKeys($importExportType->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByImportExportType() only accepts arguments of type \Thelia\Model\ImportExportType or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the ImportExportType relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function joinImportExportType($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('ImportExportType'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'ImportExportType'); + } + + return $this; + } + + /** + * Use the ImportExportType relation ImportExportType object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ImportExportTypeQuery A secondary query class using the current class as primary query + */ + public function useImportExportTypeQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinImportExportType($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ImportExportType', '\Thelia\Model\ImportExportTypeQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\ImportExportCategoryI18n object + * + * @param \Thelia\Model\ImportExportCategoryI18n|ObjectCollection $importExportCategoryI18n the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function filterByImportExportCategoryI18n($importExportCategoryI18n, $comparison = null) + { + if ($importExportCategoryI18n instanceof \Thelia\Model\ImportExportCategoryI18n) { + return $this + ->addUsingAlias(ImportExportCategoryTableMap::ID, $importExportCategoryI18n->getId(), $comparison); + } elseif ($importExportCategoryI18n instanceof ObjectCollection) { + return $this + ->useImportExportCategoryI18nQuery() + ->filterByPrimaryKeys($importExportCategoryI18n->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByImportExportCategoryI18n() only accepts arguments of type \Thelia\Model\ImportExportCategoryI18n or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the ImportExportCategoryI18n relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function joinImportExportCategoryI18n($relationAlias = null, $joinType = 'LEFT JOIN') + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('ImportExportCategoryI18n'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'ImportExportCategoryI18n'); + } + + return $this; + } + + /** + * Use the ImportExportCategoryI18n relation ImportExportCategoryI18n object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ImportExportCategoryI18nQuery A secondary query class using the current class as primary query + */ + public function useImportExportCategoryI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') + { + return $this + ->joinImportExportCategoryI18n($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ImportExportCategoryI18n', '\Thelia\Model\ImportExportCategoryI18nQuery'); + } + + /** + * Exclude object from result + * + * @param ChildImportExportCategory $importExportCategory Object to remove from the list of results + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function prune($importExportCategory = null) + { + if ($importExportCategory) { + $this->addUsingAlias(ImportExportCategoryTableMap::ID, $importExportCategory->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the import_export_category table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + ImportExportCategoryTableMap::clearInstancePool(); + ImportExportCategoryTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildImportExportCategory or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildImportExportCategory object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(ImportExportCategoryTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + ImportExportCategoryTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + ImportExportCategoryTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // i18n behavior + + /** + * Adds a JOIN clause to the query using the i18n relation + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function joinI18n($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $relationName = $relationAlias ? $relationAlias : 'ImportExportCategoryI18n'; + + return $this + ->joinImportExportCategoryI18n($relationAlias, $joinType) + ->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale); + } + + /** + * Adds a JOIN clause to the query and hydrates the related I18n object. + * Shortcut for $c->joinI18n($locale)->with() + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function joinWithI18n($locale = 'en_US', $joinType = Criteria::LEFT_JOIN) + { + $this + ->joinI18n($locale, null, $joinType) + ->with('ImportExportCategoryI18n'); + $this->with['ImportExportCategoryI18n']->setIsWithOneToMany(false); + + return $this; + } + + /** + * Use the I18n relation query object + * + * @see useQuery() + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildImportExportCategoryI18nQuery A secondary query class using the current class as primary query + */ + public function useI18nQuery($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinI18n($locale, $relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ImportExportCategoryI18n', '\Thelia\Model\ImportExportCategoryI18nQuery'); + } + + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(ImportExportCategoryTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(ImportExportCategoryTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(ImportExportCategoryTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(ImportExportCategoryTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(ImportExportCategoryTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildImportExportCategoryQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(ImportExportCategoryTableMap::CREATED_AT); + } + +} // ImportExportCategoryQuery diff --git a/core/lib/Thelia/Model/Base/ImportExportType.php b/core/lib/Thelia/Model/Base/ImportExportType.php new file mode 100644 index 000000000..5107ed58a --- /dev/null +++ b/core/lib/Thelia/Model/Base/ImportExportType.php @@ -0,0 +1,1717 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another ImportExportType instance. If + * obj is an instance of ImportExportType, delegates to + * equals(ImportExportType). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return ImportExportType The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return ImportExportType The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [url_action] column value. + * + * @return string + */ + public function getUrlAction() + { + + return $this->url_action; + } + + /** + * Get the [import_export_category_id] column value. + * + * @return int + */ + public function getImportExportCategoryId() + { + + return $this->import_export_category_id; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[ImportExportTypeTableMap::ID] = true; + } + + + return $this; + } // setId() + + /** + * Set the value of [url_action] column. + * + * @param string $v new value + * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + */ + public function setUrlAction($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->url_action !== $v) { + $this->url_action = $v; + $this->modifiedColumns[ImportExportTypeTableMap::URL_ACTION] = true; + } + + + return $this; + } // setUrlAction() + + /** + * Set the value of [import_export_category_id] column. + * + * @param int $v new value + * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + */ + public function setImportExportCategoryId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->import_export_category_id !== $v) { + $this->import_export_category_id = $v; + $this->modifiedColumns[ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID] = true; + } + + if ($this->aImportExportCategory !== null && $this->aImportExportCategory->getId() !== $v) { + $this->aImportExportCategory = null; + } + + + return $this; + } // setImportExportCategoryId() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ImportExportTypeTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ImportExportTypeTableMap::translateFieldName('UrlAction', TableMap::TYPE_PHPNAME, $indexType)]; + $this->url_action = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportExportTypeTableMap::translateFieldName('ImportExportCategoryId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->import_export_category_id = (null !== $col) ? (int) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 3; // 3 = ImportExportTypeTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\ImportExportType object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aImportExportCategory !== null && $this->import_export_category_id !== $this->aImportExportCategory->getId()) { + $this->aImportExportCategory = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ImportExportTypeTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildImportExportTypeQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aImportExportCategory = null; + $this->collImportExportTypeI18ns = null; + + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see ImportExportType::setDeleted() + * @see ImportExportType::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildImportExportTypeQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + ImportExportTypeTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aImportExportCategory !== null) { + if ($this->aImportExportCategory->isModified() || $this->aImportExportCategory->isNew()) { + $affectedRows += $this->aImportExportCategory->save($con); + } + $this->setImportExportCategory($this->aImportExportCategory); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + if ($this->importExportTypeI18nsScheduledForDeletion !== null) { + if (!$this->importExportTypeI18nsScheduledForDeletion->isEmpty()) { + \Thelia\Model\ImportExportTypeI18nQuery::create() + ->filterByPrimaryKeys($this->importExportTypeI18nsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->importExportTypeI18nsScheduledForDeletion = null; + } + } + + if ($this->collImportExportTypeI18ns !== null) { + foreach ($this->collImportExportTypeI18ns as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[ImportExportTypeTableMap::ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . ImportExportTypeTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(ImportExportTypeTableMap::ID)) { + $modifiedColumns[':p' . $index++] = '`ID`'; + } + if ($this->isColumnModified(ImportExportTypeTableMap::URL_ACTION)) { + $modifiedColumns[':p' . $index++] = '`URL_ACTION`'; + } + if ($this->isColumnModified(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID)) { + $modifiedColumns[':p' . $index++] = '`IMPORT_EXPORT_CATEGORY_ID`'; + } + + $sql = sprintf( + 'INSERT INTO `import_export_type` (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case '`ID`': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case '`URL_ACTION`': + $stmt->bindValue($identifier, $this->url_action, PDO::PARAM_STR); + break; + case '`IMPORT_EXPORT_CATEGORY_ID`': + $stmt->bindValue($identifier, $this->import_export_category_id, PDO::PARAM_INT); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = ImportExportTypeTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getUrlAction(); + break; + case 2: + return $this->getImportExportCategoryId(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['ImportExportType'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['ImportExportType'][$this->getPrimaryKey()] = true; + $keys = ImportExportTypeTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getUrlAction(), + $keys[2] => $this->getImportExportCategoryId(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aImportExportCategory) { + $result['ImportExportCategory'] = $this->aImportExportCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->collImportExportTypeI18ns) { + $result['ImportExportTypeI18ns'] = $this->collImportExportTypeI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = ImportExportTypeTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setUrlAction($value); + break; + case 2: + $this->setImportExportCategoryId($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = ImportExportTypeTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setUrlAction($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setImportExportCategoryId($arr[$keys[2]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(ImportExportTypeTableMap::DATABASE_NAME); + + if ($this->isColumnModified(ImportExportTypeTableMap::ID)) $criteria->add(ImportExportTypeTableMap::ID, $this->id); + if ($this->isColumnModified(ImportExportTypeTableMap::URL_ACTION)) $criteria->add(ImportExportTypeTableMap::URL_ACTION, $this->url_action); + if ($this->isColumnModified(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID)) $criteria->add(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $this->import_export_category_id); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(ImportExportTypeTableMap::DATABASE_NAME); + $criteria->add(ImportExportTypeTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Thelia\Model\ImportExportType (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setUrlAction($this->getUrlAction()); + $copyObj->setImportExportCategoryId($this->getImportExportCategoryId()); + + if ($deepCopy) { + // important: temporarily setNew(false) because this affects the behavior of + // the getter/setter methods for fkey referrer objects. + $copyObj->setNew(false); + + foreach ($this->getImportExportTypeI18ns() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addImportExportTypeI18n($relObj->copy($deepCopy)); + } + } + + } // if ($deepCopy) + + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Thelia\Model\ImportExportType Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildImportExportCategory object. + * + * @param ChildImportExportCategory $v + * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + * @throws PropelException + */ + public function setImportExportCategory(ChildImportExportCategory $v = null) + { + if ($v === null) { + $this->setImportExportCategoryId(NULL); + } else { + $this->setImportExportCategoryId($v->getId()); + } + + $this->aImportExportCategory = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildImportExportCategory object, it will not be re-added. + if ($v !== null) { + $v->addImportExportType($this); + } + + + return $this; + } + + + /** + * Get the associated ChildImportExportCategory object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildImportExportCategory The associated ChildImportExportCategory object. + * @throws PropelException + */ + public function getImportExportCategory(ConnectionInterface $con = null) + { + if ($this->aImportExportCategory === null && ($this->import_export_category_id !== null)) { + $this->aImportExportCategory = ChildImportExportCategoryQuery::create()->findPk($this->import_export_category_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aImportExportCategory->addImportExportTypes($this); + */ + } + + return $this->aImportExportCategory; + } + + + /** + * Initializes a collection based on the name of a relation. + * Avoids crafting an 'init[$relationName]s' method name + * that wouldn't work when StandardEnglishPluralizer is used. + * + * @param string $relationName The name of the relation to initialize + * @return void + */ + public function initRelation($relationName) + { + if ('ImportExportTypeI18n' == $relationName) { + return $this->initImportExportTypeI18ns(); + } + } + + /** + * Clears out the collImportExportTypeI18ns collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addImportExportTypeI18ns() + */ + public function clearImportExportTypeI18ns() + { + $this->collImportExportTypeI18ns = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collImportExportTypeI18ns collection loaded partially. + */ + public function resetPartialImportExportTypeI18ns($v = true) + { + $this->collImportExportTypeI18nsPartial = $v; + } + + /** + * Initializes the collImportExportTypeI18ns collection. + * + * By default this just sets the collImportExportTypeI18ns collection to an empty array (like clearcollImportExportTypeI18ns()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initImportExportTypeI18ns($overrideExisting = true) + { + if (null !== $this->collImportExportTypeI18ns && !$overrideExisting) { + return; + } + $this->collImportExportTypeI18ns = new ObjectCollection(); + $this->collImportExportTypeI18ns->setModel('\Thelia\Model\ImportExportTypeI18n'); + } + + /** + * Gets an array of ChildImportExportTypeI18n objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildImportExportType is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildImportExportTypeI18n[] List of ChildImportExportTypeI18n objects + * @throws PropelException + */ + public function getImportExportTypeI18ns($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collImportExportTypeI18nsPartial && !$this->isNew(); + if (null === $this->collImportExportTypeI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collImportExportTypeI18ns) { + // return empty collection + $this->initImportExportTypeI18ns(); + } else { + $collImportExportTypeI18ns = ChildImportExportTypeI18nQuery::create(null, $criteria) + ->filterByImportExportType($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collImportExportTypeI18nsPartial && count($collImportExportTypeI18ns)) { + $this->initImportExportTypeI18ns(false); + + foreach ($collImportExportTypeI18ns as $obj) { + if (false == $this->collImportExportTypeI18ns->contains($obj)) { + $this->collImportExportTypeI18ns->append($obj); + } + } + + $this->collImportExportTypeI18nsPartial = true; + } + + reset($collImportExportTypeI18ns); + + return $collImportExportTypeI18ns; + } + + if ($partial && $this->collImportExportTypeI18ns) { + foreach ($this->collImportExportTypeI18ns as $obj) { + if ($obj->isNew()) { + $collImportExportTypeI18ns[] = $obj; + } + } + } + + $this->collImportExportTypeI18ns = $collImportExportTypeI18ns; + $this->collImportExportTypeI18nsPartial = false; + } + } + + return $this->collImportExportTypeI18ns; + } + + /** + * Sets a collection of ImportExportTypeI18n objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $importExportTypeI18ns A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildImportExportType The current object (for fluent API support) + */ + public function setImportExportTypeI18ns(Collection $importExportTypeI18ns, ConnectionInterface $con = null) + { + $importExportTypeI18nsToDelete = $this->getImportExportTypeI18ns(new Criteria(), $con)->diff($importExportTypeI18ns); + + + //since at least one column in the foreign key is at the same time a PK + //we can not just set a PK to NULL in the lines below. We have to store + //a backup of all values, so we are able to manipulate these items based on the onDelete value later. + $this->importExportTypeI18nsScheduledForDeletion = clone $importExportTypeI18nsToDelete; + + foreach ($importExportTypeI18nsToDelete as $importExportTypeI18nRemoved) { + $importExportTypeI18nRemoved->setImportExportType(null); + } + + $this->collImportExportTypeI18ns = null; + foreach ($importExportTypeI18ns as $importExportTypeI18n) { + $this->addImportExportTypeI18n($importExportTypeI18n); + } + + $this->collImportExportTypeI18ns = $importExportTypeI18ns; + $this->collImportExportTypeI18nsPartial = false; + + return $this; + } + + /** + * Returns the number of related ImportExportTypeI18n objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related ImportExportTypeI18n objects. + * @throws PropelException + */ + public function countImportExportTypeI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collImportExportTypeI18nsPartial && !$this->isNew(); + if (null === $this->collImportExportTypeI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collImportExportTypeI18ns) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getImportExportTypeI18ns()); + } + + $query = ChildImportExportTypeI18nQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByImportExportType($this) + ->count($con); + } + + return count($this->collImportExportTypeI18ns); + } + + /** + * Method called to associate a ChildImportExportTypeI18n object to this object + * through the ChildImportExportTypeI18n foreign key attribute. + * + * @param ChildImportExportTypeI18n $l ChildImportExportTypeI18n + * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + */ + public function addImportExportTypeI18n(ChildImportExportTypeI18n $l) + { + if ($l && $locale = $l->getLocale()) { + $this->setLocale($locale); + $this->currentTranslations[$locale] = $l; + } + if ($this->collImportExportTypeI18ns === null) { + $this->initImportExportTypeI18ns(); + $this->collImportExportTypeI18nsPartial = true; + } + + if (!in_array($l, $this->collImportExportTypeI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddImportExportTypeI18n($l); + } + + return $this; + } + + /** + * @param ImportExportTypeI18n $importExportTypeI18n The importExportTypeI18n object to add. + */ + protected function doAddImportExportTypeI18n($importExportTypeI18n) + { + $this->collImportExportTypeI18ns[]= $importExportTypeI18n; + $importExportTypeI18n->setImportExportType($this); + } + + /** + * @param ImportExportTypeI18n $importExportTypeI18n The importExportTypeI18n object to remove. + * @return ChildImportExportType The current object (for fluent API support) + */ + public function removeImportExportTypeI18n($importExportTypeI18n) + { + if ($this->getImportExportTypeI18ns()->contains($importExportTypeI18n)) { + $this->collImportExportTypeI18ns->remove($this->collImportExportTypeI18ns->search($importExportTypeI18n)); + if (null === $this->importExportTypeI18nsScheduledForDeletion) { + $this->importExportTypeI18nsScheduledForDeletion = clone $this->collImportExportTypeI18ns; + $this->importExportTypeI18nsScheduledForDeletion->clear(); + } + $this->importExportTypeI18nsScheduledForDeletion[]= clone $importExportTypeI18n; + $importExportTypeI18n->setImportExportType(null); + } + + return $this; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->url_action = null; + $this->import_export_category_id = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + if ($this->collImportExportTypeI18ns) { + foreach ($this->collImportExportTypeI18ns as $o) { + $o->clearAllReferences($deep); + } + } + } // if ($deep) + + // i18n behavior + $this->currentLocale = 'en_US'; + $this->currentTranslations = null; + + $this->collImportExportTypeI18ns = null; + $this->aImportExportCategory = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(ImportExportTypeTableMap::DEFAULT_STRING_FORMAT); + } + + // i18n behavior + + /** + * Sets the locale for translations + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * + * @return ChildImportExportType The current object (for fluent API support) + */ + public function setLocale($locale = 'en_US') + { + $this->currentLocale = $locale; + + return $this; + } + + /** + * Gets the locale for translations + * + * @return string $locale Locale to use for the translation, e.g. 'fr_FR' + */ + public function getLocale() + { + return $this->currentLocale; + } + + /** + * Returns the current translation for a given locale + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * @param ConnectionInterface $con an optional connection object + * + * @return ChildImportExportTypeI18n */ + public function getTranslation($locale = 'en_US', ConnectionInterface $con = null) + { + if (!isset($this->currentTranslations[$locale])) { + if (null !== $this->collImportExportTypeI18ns) { + foreach ($this->collImportExportTypeI18ns as $translation) { + if ($translation->getLocale() == $locale) { + $this->currentTranslations[$locale] = $translation; + + return $translation; + } + } + } + if ($this->isNew()) { + $translation = new ChildImportExportTypeI18n(); + $translation->setLocale($locale); + } else { + $translation = ChildImportExportTypeI18nQuery::create() + ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->findOneOrCreate($con); + $this->currentTranslations[$locale] = $translation; + } + $this->addImportExportTypeI18n($translation); + } + + return $this->currentTranslations[$locale]; + } + + /** + * Remove the translation for a given locale + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * @param ConnectionInterface $con an optional connection object + * + * @return ChildImportExportType The current object (for fluent API support) + */ + public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null) + { + if (!$this->isNew()) { + ChildImportExportTypeI18nQuery::create() + ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->delete($con); + } + if (isset($this->currentTranslations[$locale])) { + unset($this->currentTranslations[$locale]); + } + foreach ($this->collImportExportTypeI18ns as $key => $translation) { + if ($translation->getLocale() == $locale) { + unset($this->collImportExportTypeI18ns[$key]); + break; + } + } + + return $this; + } + + /** + * Returns the current translation + * + * @param ConnectionInterface $con an optional connection object + * + * @return ChildImportExportTypeI18n */ + public function getCurrentTranslation(ConnectionInterface $con = null) + { + return $this->getTranslation($this->getLocale(), $con); + } + + + /** + * Get the [title] column value. + * + * @return string + */ + public function getTitle() + { + return $this->getCurrentTranslation()->getTitle(); + } + + + /** + * Set the value of [title] column. + * + * @param string $v new value + * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + */ + public function setTitle($v) + { $this->getCurrentTranslation()->setTitle($v); + + return $this; + } + + + /** + * Get the [description] column value. + * + * @return string + */ + public function getDescription() + { + return $this->getCurrentTranslation()->getDescription(); + } + + + /** + * Set the value of [description] column. + * + * @param string $v new value + * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + */ + public function setDescription($v) + { $this->getCurrentTranslation()->setDescription($v); + + return $this; + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/core/lib/Thelia/Model/Base/ImportExportTypeI18n.php b/core/lib/Thelia/Model/Base/ImportExportTypeI18n.php new file mode 100644 index 000000000..0aca83a7f --- /dev/null +++ b/core/lib/Thelia/Model/Base/ImportExportTypeI18n.php @@ -0,0 +1,1326 @@ +locale = 'en_US'; + } + + /** + * Initializes internal state of Thelia\Model\Base\ImportExportTypeI18n object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !!$this->modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another ImportExportTypeI18n instance. If + * obj is an instance of ImportExportTypeI18n, delegates to + * equals(ImportExportTypeI18n). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return ImportExportTypeI18n The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return ImportExportTypeI18n The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [locale] column value. + * + * @return string + */ + public function getLocale() + { + + return $this->locale; + } + + /** + * Get the [title] column value. + * + * @return string + */ + public function getTitle() + { + + return $this->title; + } + + /** + * Get the [description] column value. + * + * @return string + */ + public function getDescription() + { + + return $this->description; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[ImportExportTypeI18nTableMap::ID] = true; + } + + if ($this->aImportExportType !== null && $this->aImportExportType->getId() !== $v) { + $this->aImportExportType = null; + } + + + return $this; + } // setId() + + /** + * Set the value of [locale] column. + * + * @param string $v new value + * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + */ + public function setLocale($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->locale !== $v) { + $this->locale = $v; + $this->modifiedColumns[ImportExportTypeI18nTableMap::LOCALE] = true; + } + + + return $this; + } // setLocale() + + /** + * Set the value of [title] column. + * + * @param string $v new value + * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + */ + public function setTitle($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->title !== $v) { + $this->title = $v; + $this->modifiedColumns[ImportExportTypeI18nTableMap::TITLE] = true; + } + + + return $this; + } // setTitle() + + /** + * Set the value of [description] column. + * + * @param string $v new value + * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + */ + public function setDescription($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->description !== $v) { + $this->description = $v; + $this->modifiedColumns[ImportExportTypeI18nTableMap::DESCRIPTION] = true; + } + + + return $this; + } // setDescription() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + if ($this->locale !== 'en_US') { + return false; + } + + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ImportExportTypeI18nTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ImportExportTypeI18nTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; + $this->locale = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportExportTypeI18nTableMap::translateFieldName('Title', TableMap::TYPE_PHPNAME, $indexType)]; + $this->title = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportExportTypeI18nTableMap::translateFieldName('Description', TableMap::TYPE_PHPNAME, $indexType)]; + $this->description = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 4; // 4 = ImportExportTypeI18nTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\ImportExportTypeI18n object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aImportExportType !== null && $this->id !== $this->aImportExportType->getId()) { + $this->aImportExportType = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildImportExportTypeI18nQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aImportExportType = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see ImportExportTypeI18n::setDeleted() + * @see ImportExportTypeI18n::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildImportExportTypeI18nQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + ImportExportTypeI18nTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aImportExportType !== null) { + if ($this->aImportExportType->isModified() || $this->aImportExportType->isNew()) { + $affectedRows += $this->aImportExportType->save($con); + } + $this->setImportExportType($this->aImportExportType); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(ImportExportTypeI18nTableMap::ID)) { + $modifiedColumns[':p' . $index++] = '`ID`'; + } + if ($this->isColumnModified(ImportExportTypeI18nTableMap::LOCALE)) { + $modifiedColumns[':p' . $index++] = '`LOCALE`'; + } + if ($this->isColumnModified(ImportExportTypeI18nTableMap::TITLE)) { + $modifiedColumns[':p' . $index++] = '`TITLE`'; + } + if ($this->isColumnModified(ImportExportTypeI18nTableMap::DESCRIPTION)) { + $modifiedColumns[':p' . $index++] = '`DESCRIPTION`'; + } + + $sql = sprintf( + 'INSERT INTO `import_export_type_i18n` (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case '`ID`': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case '`LOCALE`': + $stmt->bindValue($identifier, $this->locale, PDO::PARAM_STR); + break; + case '`TITLE`': + $stmt->bindValue($identifier, $this->title, PDO::PARAM_STR); + break; + case '`DESCRIPTION`': + $stmt->bindValue($identifier, $this->description, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = ImportExportTypeI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getLocale(); + break; + case 2: + return $this->getTitle(); + break; + case 3: + return $this->getDescription(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['ImportExportTypeI18n'][serialize($this->getPrimaryKey())])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['ImportExportTypeI18n'][serialize($this->getPrimaryKey())] = true; + $keys = ImportExportTypeI18nTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getLocale(), + $keys[2] => $this->getTitle(), + $keys[3] => $this->getDescription(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aImportExportType) { + $result['ImportExportType'] = $this->aImportExportType->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = ImportExportTypeI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setLocale($value); + break; + case 2: + $this->setTitle($value); + break; + case 3: + $this->setDescription($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = ImportExportTypeI18nTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setLocale($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setTitle($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setDescription($arr[$keys[3]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(ImportExportTypeI18nTableMap::DATABASE_NAME); + + if ($this->isColumnModified(ImportExportTypeI18nTableMap::ID)) $criteria->add(ImportExportTypeI18nTableMap::ID, $this->id); + if ($this->isColumnModified(ImportExportTypeI18nTableMap::LOCALE)) $criteria->add(ImportExportTypeI18nTableMap::LOCALE, $this->locale); + if ($this->isColumnModified(ImportExportTypeI18nTableMap::TITLE)) $criteria->add(ImportExportTypeI18nTableMap::TITLE, $this->title); + if ($this->isColumnModified(ImportExportTypeI18nTableMap::DESCRIPTION)) $criteria->add(ImportExportTypeI18nTableMap::DESCRIPTION, $this->description); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(ImportExportTypeI18nTableMap::DATABASE_NAME); + $criteria->add(ImportExportTypeI18nTableMap::ID, $this->id); + $criteria->add(ImportExportTypeI18nTableMap::LOCALE, $this->locale); + + return $criteria; + } + + /** + * Returns the composite primary key for this object. + * The array elements will be in same order as specified in XML. + * @return array + */ + public function getPrimaryKey() + { + $pks = array(); + $pks[0] = $this->getId(); + $pks[1] = $this->getLocale(); + + return $pks; + } + + /** + * Set the [composite] primary key. + * + * @param array $keys The elements of the composite key (order must match the order in XML file). + * @return void + */ + public function setPrimaryKey($keys) + { + $this->setId($keys[0]); + $this->setLocale($keys[1]); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return (null === $this->getId()) && (null === $this->getLocale()); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Thelia\Model\ImportExportTypeI18n (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setLocale($this->getLocale()); + $copyObj->setTitle($this->getTitle()); + $copyObj->setDescription($this->getDescription()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Thelia\Model\ImportExportTypeI18n Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildImportExportType object. + * + * @param ChildImportExportType $v + * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + * @throws PropelException + */ + public function setImportExportType(ChildImportExportType $v = null) + { + if ($v === null) { + $this->setId(NULL); + } else { + $this->setId($v->getId()); + } + + $this->aImportExportType = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildImportExportType object, it will not be re-added. + if ($v !== null) { + $v->addImportExportTypeI18n($this); + } + + + return $this; + } + + + /** + * Get the associated ChildImportExportType object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildImportExportType The associated ChildImportExportType object. + * @throws PropelException + */ + public function getImportExportType(ConnectionInterface $con = null) + { + if ($this->aImportExportType === null && ($this->id !== null)) { + $this->aImportExportType = ChildImportExportTypeQuery::create()->findPk($this->id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aImportExportType->addImportExportTypeI18ns($this); + */ + } + + return $this->aImportExportType; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->locale = null; + $this->title = null; + $this->description = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aImportExportType = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(ImportExportTypeI18nTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/core/lib/Thelia/Model/Base/ImportExportTypeI18nQuery.php b/core/lib/Thelia/Model/Base/ImportExportTypeI18nQuery.php new file mode 100644 index 000000000..2d5176307 --- /dev/null +++ b/core/lib/Thelia/Model/Base/ImportExportTypeI18nQuery.php @@ -0,0 +1,541 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(array(12, 34), $con); + * + * + * @param array[$id, $locale] $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildImportExportTypeI18n|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = ImportExportTypeI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildImportExportTypeI18n A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT `ID`, `LOCALE`, `TITLE`, `DESCRIPTION` FROM `import_export_type_i18n` WHERE `ID` = :p0 AND `LOCALE` = :p1'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); + $stmt->bindValue(':p1', $key[1], PDO::PARAM_STR); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildImportExportTypeI18n(); + $obj->hydrate($row); + ImportExportTypeI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildImportExportTypeI18n|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + $this->addUsingAlias(ImportExportTypeI18nTableMap::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(ImportExportTypeI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + + return $this; + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + if (empty($keys)) { + return $this->add(null, '1<>1', Criteria::CUSTOM); + } + foreach ($keys as $key) { + $cton0 = $this->getNewCriterion(ImportExportTypeI18nTableMap::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(ImportExportTypeI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $this->addOr($cton0); + } + + return $this; + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @see filterByImportExportType() + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(ImportExportTypeI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(ImportExportTypeI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ImportExportTypeI18nTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the locale column + * + * Example usage: + * + * $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue' + * $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%' + * + * + * @param string $locale The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + */ + public function filterByLocale($locale = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($locale)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $locale)) { + $locale = str_replace('*', '%', $locale); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ImportExportTypeI18nTableMap::LOCALE, $locale, $comparison); + } + + /** + * Filter the query on the title column + * + * Example usage: + * + * $query->filterByTitle('fooValue'); // WHERE title = 'fooValue' + * $query->filterByTitle('%fooValue%'); // WHERE title LIKE '%fooValue%' + * + * + * @param string $title The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + */ + public function filterByTitle($title = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($title)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $title)) { + $title = str_replace('*', '%', $title); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ImportExportTypeI18nTableMap::TITLE, $title, $comparison); + } + + /** + * Filter the query on the description column + * + * Example usage: + * + * $query->filterByDescription('fooValue'); // WHERE description = 'fooValue' + * $query->filterByDescription('%fooValue%'); // WHERE description LIKE '%fooValue%' + * + * + * @param string $description The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + */ + public function filterByDescription($description = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($description)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $description)) { + $description = str_replace('*', '%', $description); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ImportExportTypeI18nTableMap::DESCRIPTION, $description, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\ImportExportType object + * + * @param \Thelia\Model\ImportExportType|ObjectCollection $importExportType The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + */ + public function filterByImportExportType($importExportType, $comparison = null) + { + if ($importExportType instanceof \Thelia\Model\ImportExportType) { + return $this + ->addUsingAlias(ImportExportTypeI18nTableMap::ID, $importExportType->getId(), $comparison); + } elseif ($importExportType instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(ImportExportTypeI18nTableMap::ID, $importExportType->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByImportExportType() only accepts arguments of type \Thelia\Model\ImportExportType or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the ImportExportType relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + */ + public function joinImportExportType($relationAlias = null, $joinType = 'LEFT JOIN') + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('ImportExportType'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'ImportExportType'); + } + + return $this; + } + + /** + * Use the ImportExportType relation ImportExportType object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ImportExportTypeQuery A secondary query class using the current class as primary query + */ + public function useImportExportTypeQuery($relationAlias = null, $joinType = 'LEFT JOIN') + { + return $this + ->joinImportExportType($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ImportExportType', '\Thelia\Model\ImportExportTypeQuery'); + } + + /** + * Exclude object from result + * + * @param ChildImportExportTypeI18n $importExportTypeI18n Object to remove from the list of results + * + * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + */ + public function prune($importExportTypeI18n = null) + { + if ($importExportTypeI18n) { + $this->addCond('pruneCond0', $this->getAliasedColName(ImportExportTypeI18nTableMap::ID), $importExportTypeI18n->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(ImportExportTypeI18nTableMap::LOCALE), $importExportTypeI18n->getLocale(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); + } + + return $this; + } + + /** + * Deletes all rows from the import_export_type_i18n table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + ImportExportTypeI18nTableMap::clearInstancePool(); + ImportExportTypeI18nTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildImportExportTypeI18n or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildImportExportTypeI18n object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(ImportExportTypeI18nTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + ImportExportTypeI18nTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + ImportExportTypeI18nTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // ImportExportTypeI18nQuery diff --git a/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php b/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php new file mode 100644 index 000000000..d55d40194 --- /dev/null +++ b/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php @@ -0,0 +1,641 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildImportExportType|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = ImportExportTypeTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ImportExportTypeTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildImportExportType A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT `ID`, `URL_ACTION`, `IMPORT_EXPORT_CATEGORY_ID` FROM `import_export_type` WHERE `ID` = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildImportExportType(); + $obj->hydrate($row); + ImportExportTypeTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildImportExportType|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(ImportExportTypeTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(ImportExportTypeTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(ImportExportTypeTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(ImportExportTypeTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ImportExportTypeTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the url_action column + * + * Example usage: + * + * $query->filterByUrlAction('fooValue'); // WHERE url_action = 'fooValue' + * $query->filterByUrlAction('%fooValue%'); // WHERE url_action LIKE '%fooValue%' + * + * + * @param string $urlAction The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function filterByUrlAction($urlAction = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($urlAction)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $urlAction)) { + $urlAction = str_replace('*', '%', $urlAction); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ImportExportTypeTableMap::URL_ACTION, $urlAction, $comparison); + } + + /** + * Filter the query on the import_export_category_id column + * + * Example usage: + * + * $query->filterByImportExportCategoryId(1234); // WHERE import_export_category_id = 1234 + * $query->filterByImportExportCategoryId(array(12, 34)); // WHERE import_export_category_id IN (12, 34) + * $query->filterByImportExportCategoryId(array('min' => 12)); // WHERE import_export_category_id > 12 + * + * + * @see filterByImportExportCategory() + * + * @param mixed $importExportCategoryId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function filterByImportExportCategoryId($importExportCategoryId = null, $comparison = null) + { + if (is_array($importExportCategoryId)) { + $useMinMax = false; + if (isset($importExportCategoryId['min'])) { + $this->addUsingAlias(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $importExportCategoryId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($importExportCategoryId['max'])) { + $this->addUsingAlias(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $importExportCategoryId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $importExportCategoryId, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\ImportExportCategory object + * + * @param \Thelia\Model\ImportExportCategory|ObjectCollection $importExportCategory The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function filterByImportExportCategory($importExportCategory, $comparison = null) + { + if ($importExportCategory instanceof \Thelia\Model\ImportExportCategory) { + return $this + ->addUsingAlias(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $importExportCategory->getId(), $comparison); + } elseif ($importExportCategory instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $importExportCategory->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByImportExportCategory() only accepts arguments of type \Thelia\Model\ImportExportCategory or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the ImportExportCategory relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function joinImportExportCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('ImportExportCategory'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'ImportExportCategory'); + } + + return $this; + } + + /** + * Use the ImportExportCategory relation ImportExportCategory object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ImportExportCategoryQuery A secondary query class using the current class as primary query + */ + public function useImportExportCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinImportExportCategory($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ImportExportCategory', '\Thelia\Model\ImportExportCategoryQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\ImportExportTypeI18n object + * + * @param \Thelia\Model\ImportExportTypeI18n|ObjectCollection $importExportTypeI18n the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function filterByImportExportTypeI18n($importExportTypeI18n, $comparison = null) + { + if ($importExportTypeI18n instanceof \Thelia\Model\ImportExportTypeI18n) { + return $this + ->addUsingAlias(ImportExportTypeTableMap::ID, $importExportTypeI18n->getId(), $comparison); + } elseif ($importExportTypeI18n instanceof ObjectCollection) { + return $this + ->useImportExportTypeI18nQuery() + ->filterByPrimaryKeys($importExportTypeI18n->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByImportExportTypeI18n() only accepts arguments of type \Thelia\Model\ImportExportTypeI18n or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the ImportExportTypeI18n relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function joinImportExportTypeI18n($relationAlias = null, $joinType = 'LEFT JOIN') + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('ImportExportTypeI18n'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'ImportExportTypeI18n'); + } + + return $this; + } + + /** + * Use the ImportExportTypeI18n relation ImportExportTypeI18n object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ImportExportTypeI18nQuery A secondary query class using the current class as primary query + */ + public function useImportExportTypeI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') + { + return $this + ->joinImportExportTypeI18n($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ImportExportTypeI18n', '\Thelia\Model\ImportExportTypeI18nQuery'); + } + + /** + * Exclude object from result + * + * @param ChildImportExportType $importExportType Object to remove from the list of results + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function prune($importExportType = null) + { + if ($importExportType) { + $this->addUsingAlias(ImportExportTypeTableMap::ID, $importExportType->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the import_export_type table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + ImportExportTypeTableMap::clearInstancePool(); + ImportExportTypeTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildImportExportType or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildImportExportType object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(ImportExportTypeTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + ImportExportTypeTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + ImportExportTypeTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // i18n behavior + + /** + * Adds a JOIN clause to the query using the i18n relation + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function joinI18n($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $relationName = $relationAlias ? $relationAlias : 'ImportExportTypeI18n'; + + return $this + ->joinImportExportTypeI18n($relationAlias, $joinType) + ->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale); + } + + /** + * Adds a JOIN clause to the query and hydrates the related I18n object. + * Shortcut for $c->joinI18n($locale)->with() + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function joinWithI18n($locale = 'en_US', $joinType = Criteria::LEFT_JOIN) + { + $this + ->joinI18n($locale, null, $joinType) + ->with('ImportExportTypeI18n'); + $this->with['ImportExportTypeI18n']->setIsWithOneToMany(false); + + return $this; + } + + /** + * Use the I18n relation query object + * + * @see useQuery() + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildImportExportTypeI18nQuery A secondary query class using the current class as primary query + */ + public function useI18nQuery($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinI18n($locale, $relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ImportExportTypeI18n', '\Thelia\Model\ImportExportTypeI18nQuery'); + } + +} // ImportExportTypeQuery diff --git a/core/lib/Thelia/Model/ImportExportCategory.php b/core/lib/Thelia/Model/ImportExportCategory.php new file mode 100644 index 000000000..f4e8c393b --- /dev/null +++ b/core/lib/Thelia/Model/ImportExportCategory.php @@ -0,0 +1,10 @@ + array('Id', 'Locale', 'Title', ), + self::TYPE_STUDLYPHPNAME => array('id', 'locale', 'title', ), + self::TYPE_COLNAME => array(ImportExportCategoryI18nTableMap::ID, ImportExportCategoryI18nTableMap::LOCALE, ImportExportCategoryI18nTableMap::TITLE, ), + self::TYPE_RAW_COLNAME => array('ID', 'LOCALE', 'TITLE', ), + self::TYPE_FIELDNAME => array('id', 'locale', 'title', ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Locale' => 1, 'Title' => 2, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'locale' => 1, 'title' => 2, ), + self::TYPE_COLNAME => array(ImportExportCategoryI18nTableMap::ID => 0, ImportExportCategoryI18nTableMap::LOCALE => 1, ImportExportCategoryI18nTableMap::TITLE => 2, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'LOCALE' => 1, 'TITLE' => 2, ), + self::TYPE_FIELDNAME => array('id' => 0, 'locale' => 1, 'title' => 2, ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('import_export_category_i18n'); + $this->setPhpName('ImportExportCategoryI18n'); + $this->setClassName('\\Thelia\\Model\\ImportExportCategoryI18n'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'import_export_category', 'ID', true, null, null); + $this->addPrimaryKey('LOCALE', 'Locale', 'VARCHAR', true, 5, 'en_US'); + $this->addColumn('TITLE', 'Title', 'VARCHAR', true, 255, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('ImportExportCategory', '\\Thelia\\Model\\ImportExportCategory', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', null); + } // buildRelations() + + /** + * Adds an object to the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases you may need to explicitly add objects + * to the cache in order to ensure that the same objects are always returned by find*() + * and findPk*() calls. + * + * @param \Thelia\Model\ImportExportCategoryI18n $obj A \Thelia\Model\ImportExportCategoryI18n object. + * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). + */ + public static function addInstanceToPool($obj, $key = null) + { + if (Propel::isInstancePoolingEnabled()) { + if (null === $key) { + $key = serialize(array((string) $obj->getId(), (string) $obj->getLocale())); + } // if key === null + self::$instances[$key] = $obj; + } + } + + /** + * Removes an object from the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases -- especially when you override doDelete + * methods in your stub classes -- you may need to explicitly remove objects + * from the cache in order to prevent returning objects that no longer exist. + * + * @param mixed $value A \Thelia\Model\ImportExportCategoryI18n object or a primary key value. + */ + public static function removeInstanceFromPool($value) + { + if (Propel::isInstancePoolingEnabled() && null !== $value) { + if (is_object($value) && $value instanceof \Thelia\Model\ImportExportCategoryI18n) { + $key = serialize(array((string) $value->getId(), (string) $value->getLocale())); + + } elseif (is_array($value) && count($value) === 2) { + // assume we've been passed a primary key"; + $key = serialize(array((string) $value[0], (string) $value[1])); + } elseif ($value instanceof Criteria) { + self::$instances = []; + + return; + } else { + $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Thelia\Model\ImportExportCategoryI18n object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); + throw $e; + } + + unset(self::$instances[$key]); + } + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)])); + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return $pks; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? ImportExportCategoryI18nTableMap::CLASS_DEFAULT : ImportExportCategoryI18nTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (ImportExportCategoryI18n object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = ImportExportCategoryI18nTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ImportExportCategoryI18nTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + ImportExportCategoryI18nTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = ImportExportCategoryI18nTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + ImportExportCategoryI18nTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = ImportExportCategoryI18nTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ImportExportCategoryI18nTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + ImportExportCategoryI18nTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(ImportExportCategoryI18nTableMap::ID); + $criteria->addSelectColumn(ImportExportCategoryI18nTableMap::LOCALE); + $criteria->addSelectColumn(ImportExportCategoryI18nTableMap::TITLE); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.LOCALE'); + $criteria->addSelectColumn($alias . '.TITLE'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(ImportExportCategoryI18nTableMap::DATABASE_NAME)->getTable(ImportExportCategoryI18nTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ImportExportCategoryI18nTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ImportExportCategoryI18nTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ImportExportCategoryI18nTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a ImportExportCategoryI18n or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ImportExportCategoryI18n object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\ImportExportCategoryI18n) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(ImportExportCategoryI18nTableMap::DATABASE_NAME); + // primary key is composite; we therefore, expect + // the primary key passed to be an array of pkey values + if (count($values) == count($values, COUNT_RECURSIVE)) { + // array is not multi-dimensional + $values = array($values); + } + foreach ($values as $value) { + $criterion = $criteria->getNewCriterion(ImportExportCategoryI18nTableMap::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(ImportExportCategoryI18nTableMap::LOCALE, $value[1])); + $criteria->addOr($criterion); + } + } + + $query = ImportExportCategoryI18nQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { ImportExportCategoryI18nTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { ImportExportCategoryI18nTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the import_export_category_i18n table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return ImportExportCategoryI18nQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a ImportExportCategoryI18n or Criteria object. + * + * @param mixed $criteria Criteria or ImportExportCategoryI18n object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from ImportExportCategoryI18n object + } + + + // Set the correct dbName + $query = ImportExportCategoryI18nQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // ImportExportCategoryI18nTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +ImportExportCategoryI18nTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/ImportExportCategoryTableMap.php b/core/lib/Thelia/Model/Map/ImportExportCategoryTableMap.php new file mode 100644 index 000000000..96a0d768c --- /dev/null +++ b/core/lib/Thelia/Model/Map/ImportExportCategoryTableMap.php @@ -0,0 +1,461 @@ + array('Id', 'Position', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'position', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(ImportExportCategoryTableMap::ID, ImportExportCategoryTableMap::POSITION, ImportExportCategoryTableMap::CREATED_AT, ImportExportCategoryTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'position', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Position' => 1, 'CreatedAt' => 2, 'UpdatedAt' => 3, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'position' => 1, 'createdAt' => 2, 'updatedAt' => 3, ), + self::TYPE_COLNAME => array(ImportExportCategoryTableMap::ID => 0, ImportExportCategoryTableMap::POSITION => 1, ImportExportCategoryTableMap::CREATED_AT => 2, ImportExportCategoryTableMap::UPDATED_AT => 3, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'POSITION' => 1, 'CREATED_AT' => 2, 'UPDATED_AT' => 3, ), + self::TYPE_FIELDNAME => array('id' => 0, 'position' => 1, 'created_at' => 2, 'updated_at' => 3, ), + self::TYPE_NUM => array(0, 1, 2, 3, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('import_export_category'); + $this->setPhpName('ImportExportCategory'); + $this->setClassName('\\Thelia\\Model\\ImportExportCategory'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addColumn('POSITION', 'Position', 'INTEGER', true, null, null); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('ImportExportType', '\\Thelia\\Model\\ImportExportType', RelationMap::ONE_TO_MANY, array('id' => 'import_export_category_id', ), 'CASCADE', 'RESTRICT', 'ImportExportTypes'); + $this->addRelation('ImportExportCategoryI18n', '\\Thelia\\Model\\ImportExportCategoryI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ImportExportCategoryI18ns'); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'i18n' => array('i18n_table' => '%TABLE%_i18n', 'i18n_phpname' => '%PHPNAME%I18n', 'i18n_columns' => 'title', 'locale_column' => 'locale', 'locale_length' => '5', 'default_locale' => '', 'locale_alias' => '', ), + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + ); + } // getBehaviors() + /** + * Method to invalidate the instance pool of all tables related to import_export_category * by a foreign key with ON DELETE CASCADE + */ + public static function clearRelatedInstancePool() + { + // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, + // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. + ImportExportTypeTableMap::clearInstancePool(); + ImportExportCategoryI18nTableMap::clearInstancePool(); + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? ImportExportCategoryTableMap::CLASS_DEFAULT : ImportExportCategoryTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (ImportExportCategory object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = ImportExportCategoryTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ImportExportCategoryTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + ImportExportCategoryTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = ImportExportCategoryTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + ImportExportCategoryTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = ImportExportCategoryTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ImportExportCategoryTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + ImportExportCategoryTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(ImportExportCategoryTableMap::ID); + $criteria->addSelectColumn(ImportExportCategoryTableMap::POSITION); + $criteria->addSelectColumn(ImportExportCategoryTableMap::CREATED_AT); + $criteria->addSelectColumn(ImportExportCategoryTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.POSITION'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(ImportExportCategoryTableMap::DATABASE_NAME)->getTable(ImportExportCategoryTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ImportExportCategoryTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ImportExportCategoryTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ImportExportCategoryTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a ImportExportCategory or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ImportExportCategory object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\ImportExportCategory) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(ImportExportCategoryTableMap::DATABASE_NAME); + $criteria->add(ImportExportCategoryTableMap::ID, (array) $values, Criteria::IN); + } + + $query = ImportExportCategoryQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { ImportExportCategoryTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { ImportExportCategoryTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the import_export_category table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return ImportExportCategoryQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a ImportExportCategory or Criteria object. + * + * @param mixed $criteria Criteria or ImportExportCategory object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from ImportExportCategory object + } + + if ($criteria->containsKey(ImportExportCategoryTableMap::ID) && $criteria->keyContainsValue(ImportExportCategoryTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.ImportExportCategoryTableMap::ID.')'); + } + + + // Set the correct dbName + $query = ImportExportCategoryQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // ImportExportCategoryTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +ImportExportCategoryTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/ImportExportTypeI18nTableMap.php b/core/lib/Thelia/Model/Map/ImportExportTypeI18nTableMap.php new file mode 100644 index 000000000..291ccf906 --- /dev/null +++ b/core/lib/Thelia/Model/Map/ImportExportTypeI18nTableMap.php @@ -0,0 +1,482 @@ + array('Id', 'Locale', 'Title', 'Description', ), + self::TYPE_STUDLYPHPNAME => array('id', 'locale', 'title', 'description', ), + self::TYPE_COLNAME => array(ImportExportTypeI18nTableMap::ID, ImportExportTypeI18nTableMap::LOCALE, ImportExportTypeI18nTableMap::TITLE, ImportExportTypeI18nTableMap::DESCRIPTION, ), + self::TYPE_RAW_COLNAME => array('ID', 'LOCALE', 'TITLE', 'DESCRIPTION', ), + self::TYPE_FIELDNAME => array('id', 'locale', 'title', 'description', ), + self::TYPE_NUM => array(0, 1, 2, 3, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Locale' => 1, 'Title' => 2, 'Description' => 3, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'locale' => 1, 'title' => 2, 'description' => 3, ), + self::TYPE_COLNAME => array(ImportExportTypeI18nTableMap::ID => 0, ImportExportTypeI18nTableMap::LOCALE => 1, ImportExportTypeI18nTableMap::TITLE => 2, ImportExportTypeI18nTableMap::DESCRIPTION => 3, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'LOCALE' => 1, 'TITLE' => 2, 'DESCRIPTION' => 3, ), + self::TYPE_FIELDNAME => array('id' => 0, 'locale' => 1, 'title' => 2, 'description' => 3, ), + self::TYPE_NUM => array(0, 1, 2, 3, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('import_export_type_i18n'); + $this->setPhpName('ImportExportTypeI18n'); + $this->setClassName('\\Thelia\\Model\\ImportExportTypeI18n'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'import_export_type', 'ID', true, null, null); + $this->addPrimaryKey('LOCALE', 'Locale', 'VARCHAR', true, 5, 'en_US'); + $this->addColumn('TITLE', 'Title', 'VARCHAR', true, 255, null); + $this->addColumn('DESCRIPTION', 'Description', 'CLOB', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('ImportExportType', '\\Thelia\\Model\\ImportExportType', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', null); + } // buildRelations() + + /** + * Adds an object to the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases you may need to explicitly add objects + * to the cache in order to ensure that the same objects are always returned by find*() + * and findPk*() calls. + * + * @param \Thelia\Model\ImportExportTypeI18n $obj A \Thelia\Model\ImportExportTypeI18n object. + * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). + */ + public static function addInstanceToPool($obj, $key = null) + { + if (Propel::isInstancePoolingEnabled()) { + if (null === $key) { + $key = serialize(array((string) $obj->getId(), (string) $obj->getLocale())); + } // if key === null + self::$instances[$key] = $obj; + } + } + + /** + * Removes an object from the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases -- especially when you override doDelete + * methods in your stub classes -- you may need to explicitly remove objects + * from the cache in order to prevent returning objects that no longer exist. + * + * @param mixed $value A \Thelia\Model\ImportExportTypeI18n object or a primary key value. + */ + public static function removeInstanceFromPool($value) + { + if (Propel::isInstancePoolingEnabled() && null !== $value) { + if (is_object($value) && $value instanceof \Thelia\Model\ImportExportTypeI18n) { + $key = serialize(array((string) $value->getId(), (string) $value->getLocale())); + + } elseif (is_array($value) && count($value) === 2) { + // assume we've been passed a primary key"; + $key = serialize(array((string) $value[0], (string) $value[1])); + } elseif ($value instanceof Criteria) { + self::$instances = []; + + return; + } else { + $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Thelia\Model\ImportExportTypeI18n object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); + throw $e; + } + + unset(self::$instances[$key]); + } + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)])); + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return $pks; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? ImportExportTypeI18nTableMap::CLASS_DEFAULT : ImportExportTypeI18nTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (ImportExportTypeI18n object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = ImportExportTypeI18nTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ImportExportTypeI18nTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + ImportExportTypeI18nTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = ImportExportTypeI18nTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + ImportExportTypeI18nTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = ImportExportTypeI18nTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ImportExportTypeI18nTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + ImportExportTypeI18nTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(ImportExportTypeI18nTableMap::ID); + $criteria->addSelectColumn(ImportExportTypeI18nTableMap::LOCALE); + $criteria->addSelectColumn(ImportExportTypeI18nTableMap::TITLE); + $criteria->addSelectColumn(ImportExportTypeI18nTableMap::DESCRIPTION); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.LOCALE'); + $criteria->addSelectColumn($alias . '.TITLE'); + $criteria->addSelectColumn($alias . '.DESCRIPTION'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(ImportExportTypeI18nTableMap::DATABASE_NAME)->getTable(ImportExportTypeI18nTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ImportExportTypeI18nTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ImportExportTypeI18nTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ImportExportTypeI18nTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a ImportExportTypeI18n or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ImportExportTypeI18n object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\ImportExportTypeI18n) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(ImportExportTypeI18nTableMap::DATABASE_NAME); + // primary key is composite; we therefore, expect + // the primary key passed to be an array of pkey values + if (count($values) == count($values, COUNT_RECURSIVE)) { + // array is not multi-dimensional + $values = array($values); + } + foreach ($values as $value) { + $criterion = $criteria->getNewCriterion(ImportExportTypeI18nTableMap::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(ImportExportTypeI18nTableMap::LOCALE, $value[1])); + $criteria->addOr($criterion); + } + } + + $query = ImportExportTypeI18nQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { ImportExportTypeI18nTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { ImportExportTypeI18nTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the import_export_type_i18n table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return ImportExportTypeI18nQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a ImportExportTypeI18n or Criteria object. + * + * @param mixed $criteria Criteria or ImportExportTypeI18n object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from ImportExportTypeI18n object + } + + + // Set the correct dbName + $query = ImportExportTypeI18nQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // ImportExportTypeI18nTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +ImportExportTypeI18nTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php b/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php new file mode 100644 index 000000000..d464ef15f --- /dev/null +++ b/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php @@ -0,0 +1,451 @@ + array('Id', 'UrlAction', 'ImportExportCategoryId', ), + self::TYPE_STUDLYPHPNAME => array('id', 'urlAction', 'importExportCategoryId', ), + self::TYPE_COLNAME => array(ImportExportTypeTableMap::ID, ImportExportTypeTableMap::URL_ACTION, ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, ), + self::TYPE_RAW_COLNAME => array('ID', 'URL_ACTION', 'IMPORT_EXPORT_CATEGORY_ID', ), + self::TYPE_FIELDNAME => array('id', 'url_action', 'import_export_category_id', ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'UrlAction' => 1, 'ImportExportCategoryId' => 2, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'urlAction' => 1, 'importExportCategoryId' => 2, ), + self::TYPE_COLNAME => array(ImportExportTypeTableMap::ID => 0, ImportExportTypeTableMap::URL_ACTION => 1, ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID => 2, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'URL_ACTION' => 1, 'IMPORT_EXPORT_CATEGORY_ID' => 2, ), + self::TYPE_FIELDNAME => array('id' => 0, 'url_action' => 1, 'import_export_category_id' => 2, ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('import_export_type'); + $this->setPhpName('ImportExportType'); + $this->setClassName('\\Thelia\\Model\\ImportExportType'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addColumn('URL_ACTION', 'UrlAction', 'VARCHAR', true, 255, null); + $this->addForeignKey('IMPORT_EXPORT_CATEGORY_ID', 'ImportExportCategoryId', 'INTEGER', 'import_export_category', 'ID', true, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('ImportExportCategory', '\\Thelia\\Model\\ImportExportCategory', RelationMap::MANY_TO_ONE, array('import_export_category_id' => 'id', ), 'CASCADE', 'RESTRICT'); + $this->addRelation('ImportExportTypeI18n', '\\Thelia\\Model\\ImportExportTypeI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ImportExportTypeI18ns'); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'i18n' => array('i18n_table' => '%TABLE%_i18n', 'i18n_phpname' => '%PHPNAME%I18n', 'i18n_columns' => 'title, description', 'locale_column' => 'locale', 'locale_length' => '5', 'default_locale' => '', 'locale_alias' => '', ), + ); + } // getBehaviors() + /** + * Method to invalidate the instance pool of all tables related to import_export_type * by a foreign key with ON DELETE CASCADE + */ + public static function clearRelatedInstancePool() + { + // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, + // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. + ImportExportTypeI18nTableMap::clearInstancePool(); + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? ImportExportTypeTableMap::CLASS_DEFAULT : ImportExportTypeTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (ImportExportType object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = ImportExportTypeTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ImportExportTypeTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + ImportExportTypeTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = ImportExportTypeTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + ImportExportTypeTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = ImportExportTypeTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ImportExportTypeTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + ImportExportTypeTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(ImportExportTypeTableMap::ID); + $criteria->addSelectColumn(ImportExportTypeTableMap::URL_ACTION); + $criteria->addSelectColumn(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.URL_ACTION'); + $criteria->addSelectColumn($alias . '.IMPORT_EXPORT_CATEGORY_ID'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(ImportExportTypeTableMap::DATABASE_NAME)->getTable(ImportExportTypeTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ImportExportTypeTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ImportExportTypeTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ImportExportTypeTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a ImportExportType or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ImportExportType object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\ImportExportType) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(ImportExportTypeTableMap::DATABASE_NAME); + $criteria->add(ImportExportTypeTableMap::ID, (array) $values, Criteria::IN); + } + + $query = ImportExportTypeQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { ImportExportTypeTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { ImportExportTypeTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the import_export_type table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return ImportExportTypeQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a ImportExportType or Criteria object. + * + * @param mixed $criteria Criteria or ImportExportType object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from ImportExportType object + } + + if ($criteria->containsKey(ImportExportTypeTableMap::ID) && $criteria->keyContainsValue(ImportExportTypeTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.ImportExportTypeTableMap::ID.')'); + } + + + // Set the correct dbName + $query = ImportExportTypeQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // ImportExportTypeTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +ImportExportTypeTableMap::buildTableMap(); diff --git a/local/config/schema.xml b/local/config/schema.xml index f65b90d57..b86124f25 100644 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1512,4 +1512,29 @@ + + + + + + + + +
+ + + + + + + + + + + + + + + +
diff --git a/setup/thelia.sql b/setup/thelia.sql index 024809a76..8b46f23be 100644 --- a/setup/thelia.sql +++ b/setup/thelia.sql @@ -1873,6 +1873,41 @@ CREATE TABLE `form_firewall` INDEX `idx_form_firewall_ip_address` (`ip_address`) ) ENGINE=InnoDB; +-- --------------------------------------------------------------------- +-- import_export_category +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `import_export_category`; + +CREATE TABLE `import_export_category` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `position` INTEGER NOT NULL, + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`) +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- import_export_type +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `import_export_type`; + +CREATE TABLE `import_export_type` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `url_action` VARCHAR(255) NOT NULL, + `import_export_category_id` INTEGER NOT NULL, + PRIMARY KEY (`id`), + INDEX `idx_import_export_type_import_export_category_id` (`import_export_category_id`), + CONSTRAINT `fk_import_export_type_import_export_category_id` + FOREIGN KEY (`import_export_category_id`) + REFERENCES `import_export_category` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + -- --------------------------------------------------------------------- -- category_i18n -- --------------------------------------------------------------------- @@ -2568,6 +2603,43 @@ CREATE TABLE `brand_image_i18n` ON DELETE CASCADE ) ENGINE=InnoDB; +-- --------------------------------------------------------------------- +-- import_export_category_i18n +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `import_export_category_i18n`; + +CREATE TABLE `import_export_category_i18n` +( + `id` INTEGER NOT NULL, + `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, + `title` VARCHAR(255) NOT NULL, + PRIMARY KEY (`id`,`locale`), + CONSTRAINT `import_export_category_i18n_FK_1` + FOREIGN KEY (`id`) + REFERENCES `import_export_category` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- import_export_type_i18n +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `import_export_type_i18n`; + +CREATE TABLE `import_export_type_i18n` +( + `id` INTEGER NOT NULL, + `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, + `title` VARCHAR(255) NOT NULL, + `description` LONGTEXT, + PRIMARY KEY (`id`,`locale`), + CONSTRAINT `import_export_type_i18n_FK_1` + FOREIGN KEY (`id`) + REFERENCES `import_export_type` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + -- --------------------------------------------------------------------- -- category_version -- --------------------------------------------------------------------- diff --git a/templates/backOffice/default/export.html b/templates/backOffice/default/export.html index 7bc7efd2e..ed1360a2a 100644 --- a/templates/backOffice/default/export.html +++ b/templates/backOffice/default/export.html @@ -10,49 +10,85 @@ {block name="check-access"}view{/block} {block name="main-content"} -
-
+ {form name="thelia.admin.export"} + +
- +
- {module_include location='tools_top'} + -
+ {module_include location='tools_top'} -
-
-
- {module_include location='configuration_bottom'} + {module_include location='configuration_bottom'} +
-
+ + {/form} + +{/block} + + +{block name="javascript-initialization"} + {javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} + + {/javascripts} {/block} {block name="javascript-last-call"} + + {module_include location='configuration-js'} {/block} \ No newline at end of file diff --git a/templates/backOffice/default/includes/export-form-definition.html b/templates/backOffice/default/includes/export-form-definition.html new file mode 100644 index 000000000..61a2062cd --- /dev/null +++ b/templates/backOffice/default/includes/export-form-definition.html @@ -0,0 +1,96 @@ +{* + + This file defines the fields used for export configuration: + - Export format + - With images ? documents ? + - archive format ? + +*} + +
+
+
+
+ {intl l="Export options"} +
+
+ {ifloop rel="export-formatters"} +
+ +
+
+ {custom_render_form_field form=$form field="formatter"} + + {/custom_render_form_field} +
+ +
+
+
+ +
+ +
+
+
+
+
+ {custom_render_form_field form=$form field="archive_builder"} + + {/custom_render_form_field} +
+
+
+ +
+ {form_field form=$form field="images"} + + +
+ +
+ {/form_field} +
+
+ {form_field form=$form field="documents"} + + +
+ +
+ {/form_field} +
+
+
+
+ {/ifloop} + {elseloop rel="export-formatters"} +
+
+
+ {intl l="You can't do exports, you don't have any formatter"} +
+
+
+ {/elseloop} +
+
+
\ No newline at end of file From 5a6ede991bf8d94e4b99d62c50706cb472f3ff6d Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Wed, 9 Jul 2014 16:01:16 +0200 Subject: [PATCH 048/158] =?UTF-8?q?Add=20timestampable=20behavior=20in=20i?= =?UTF-8?q?mport=5Fexport=5Ftype=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Model/Base/ImportExportType.php=20=09modi?= =?UTF-8?q?fi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Model/Base/?= =?UTF-8?q?ImportExportTypeQuery.php=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20local/config/sche?= =?UTF-8?q?ma.xml=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20setup/theli?= =?UTF-8?q?a.sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Thelia/Model/Base/ImportExportType.php | 169 +++++++++++++++++- .../Model/Base/ImportExportTypeQuery.php | 162 ++++++++++++++++- .../Model/Map/ImportExportTypeTableMap.php | 45 +++-- local/config/schema.xml | 1 + setup/thelia.sql | 2 + 5 files changed, 363 insertions(+), 16 deletions(-) diff --git a/core/lib/Thelia/Model/Base/ImportExportType.php b/core/lib/Thelia/Model/Base/ImportExportType.php index 5107ed58a..c15281a34 100644 --- a/core/lib/Thelia/Model/Base/ImportExportType.php +++ b/core/lib/Thelia/Model/Base/ImportExportType.php @@ -2,6 +2,7 @@ namespace Thelia\Model\Base; +use \DateTime; use \Exception; use \PDO; use Propel\Runtime\Propel; @@ -15,6 +16,7 @@ use Propel\Runtime\Exception\BadMethodCallException; use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Parser\AbstractParser; +use Propel\Runtime\Util\PropelDateTime; use Thelia\Model\ImportExportCategory as ChildImportExportCategory; use Thelia\Model\ImportExportCategoryQuery as ChildImportExportCategoryQuery; use Thelia\Model\ImportExportType as ChildImportExportType; @@ -75,6 +77,18 @@ abstract class ImportExportType implements ActiveRecordInterface */ protected $import_export_category_id; + /** + * The value for the created_at field. + * @var string + */ + protected $created_at; + + /** + * The value for the updated_at field. + * @var string + */ + protected $updated_at; + /** * @var ImportExportCategory */ @@ -405,6 +419,46 @@ abstract class ImportExportType implements ActiveRecordInterface return $this->import_export_category_id; } + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; + } + } + /** * Set the value of [id] column. * @@ -472,6 +526,48 @@ abstract class ImportExportType implements ActiveRecordInterface return $this; } // setImportExportCategoryId() + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[ImportExportTypeTableMap::CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[ImportExportTypeTableMap::UPDATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + /** * Indicates whether the columns in this object are only set to default values. * @@ -517,6 +613,18 @@ abstract class ImportExportType implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportExportTypeTableMap::translateFieldName('ImportExportCategoryId', TableMap::TYPE_PHPNAME, $indexType)]; $this->import_export_category_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportExportTypeTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ImportExportTypeTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; $this->resetModified(); $this->setNew(false); @@ -525,7 +633,7 @@ abstract class ImportExportType implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 3; // 3 = ImportExportTypeTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 5; // 5 = ImportExportTypeTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\ImportExportType object", 0, $e); @@ -662,8 +770,19 @@ abstract class ImportExportType implements ActiveRecordInterface $ret = $this->preSave($con); if ($isInsert) { $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(ImportExportTypeTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(ImportExportTypeTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } } else { $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(ImportExportTypeTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } } if ($ret) { $affectedRows = $this->doSave($con); @@ -778,6 +897,12 @@ abstract class ImportExportType implements ActiveRecordInterface if ($this->isColumnModified(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID)) { $modifiedColumns[':p' . $index++] = '`IMPORT_EXPORT_CATEGORY_ID`'; } + if ($this->isColumnModified(ImportExportTypeTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = '`CREATED_AT`'; + } + if ($this->isColumnModified(ImportExportTypeTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = '`UPDATED_AT`'; + } $sql = sprintf( 'INSERT INTO `import_export_type` (%s) VALUES (%s)', @@ -798,6 +923,12 @@ abstract class ImportExportType implements ActiveRecordInterface case '`IMPORT_EXPORT_CATEGORY_ID`': $stmt->bindValue($identifier, $this->import_export_category_id, PDO::PARAM_INT); break; + case '`CREATED_AT`': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case '`UPDATED_AT`': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; } } $stmt->execute(); @@ -869,6 +1000,12 @@ abstract class ImportExportType implements ActiveRecordInterface case 2: return $this->getImportExportCategoryId(); break; + case 3: + return $this->getCreatedAt(); + break; + case 4: + return $this->getUpdatedAt(); + break; default: return null; break; @@ -901,6 +1038,8 @@ abstract class ImportExportType implements ActiveRecordInterface $keys[0] => $this->getId(), $keys[1] => $this->getUrlAction(), $keys[2] => $this->getImportExportCategoryId(), + $keys[3] => $this->getCreatedAt(), + $keys[4] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { @@ -957,6 +1096,12 @@ abstract class ImportExportType implements ActiveRecordInterface case 2: $this->setImportExportCategoryId($value); break; + case 3: + $this->setCreatedAt($value); + break; + case 4: + $this->setUpdatedAt($value); + break; } // switch() } @@ -984,6 +1129,8 @@ abstract class ImportExportType implements ActiveRecordInterface if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setUrlAction($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setImportExportCategoryId($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]); } /** @@ -998,6 +1145,8 @@ abstract class ImportExportType implements ActiveRecordInterface if ($this->isColumnModified(ImportExportTypeTableMap::ID)) $criteria->add(ImportExportTypeTableMap::ID, $this->id); if ($this->isColumnModified(ImportExportTypeTableMap::URL_ACTION)) $criteria->add(ImportExportTypeTableMap::URL_ACTION, $this->url_action); if ($this->isColumnModified(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID)) $criteria->add(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $this->import_export_category_id); + if ($this->isColumnModified(ImportExportTypeTableMap::CREATED_AT)) $criteria->add(ImportExportTypeTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(ImportExportTypeTableMap::UPDATED_AT)) $criteria->add(ImportExportTypeTableMap::UPDATED_AT, $this->updated_at); return $criteria; } @@ -1063,6 +1212,8 @@ abstract class ImportExportType implements ActiveRecordInterface { $copyObj->setUrlAction($this->getUrlAction()); $copyObj->setImportExportCategoryId($this->getImportExportCategoryId()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); if ($deepCopy) { // important: temporarily setNew(false) because this affects the behavior of @@ -1405,6 +1556,8 @@ abstract class ImportExportType implements ActiveRecordInterface $this->id = null; $this->url_action = null; $this->import_export_category_id = null; + $this->created_at = null; + $this->updated_at = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); @@ -1596,6 +1749,20 @@ abstract class ImportExportType implements ActiveRecordInterface return $this; } + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildImportExportType The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[ImportExportTypeTableMap::UPDATED_AT] = true; + + return $this; + } + /** * Code to be run before persisting the object * @param ConnectionInterface $con diff --git a/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php b/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php index d55d40194..68adab4a0 100644 --- a/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php +++ b/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php @@ -25,10 +25,14 @@ use Thelia\Model\Map\ImportExportTypeTableMap; * @method ChildImportExportTypeQuery orderById($order = Criteria::ASC) Order by the id column * @method ChildImportExportTypeQuery orderByUrlAction($order = Criteria::ASC) Order by the url_action column * @method ChildImportExportTypeQuery orderByImportExportCategoryId($order = Criteria::ASC) Order by the import_export_category_id column + * @method ChildImportExportTypeQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column + * @method ChildImportExportTypeQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * * @method ChildImportExportTypeQuery groupById() Group by the id column * @method ChildImportExportTypeQuery groupByUrlAction() Group by the url_action column * @method ChildImportExportTypeQuery groupByImportExportCategoryId() Group by the import_export_category_id column + * @method ChildImportExportTypeQuery groupByCreatedAt() Group by the created_at column + * @method ChildImportExportTypeQuery groupByUpdatedAt() Group by the updated_at column * * @method ChildImportExportTypeQuery leftJoin($relation) Adds a LEFT JOIN clause to the query * @method ChildImportExportTypeQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query @@ -48,10 +52,14 @@ use Thelia\Model\Map\ImportExportTypeTableMap; * @method ChildImportExportType findOneById(int $id) Return the first ChildImportExportType filtered by the id column * @method ChildImportExportType findOneByUrlAction(string $url_action) Return the first ChildImportExportType filtered by the url_action column * @method ChildImportExportType findOneByImportExportCategoryId(int $import_export_category_id) Return the first ChildImportExportType filtered by the import_export_category_id column + * @method ChildImportExportType findOneByCreatedAt(string $created_at) Return the first ChildImportExportType filtered by the created_at column + * @method ChildImportExportType findOneByUpdatedAt(string $updated_at) Return the first ChildImportExportType filtered by the updated_at column * * @method array findById(int $id) Return ChildImportExportType objects filtered by the id column * @method array findByUrlAction(string $url_action) Return ChildImportExportType objects filtered by the url_action column * @method array findByImportExportCategoryId(int $import_export_category_id) Return ChildImportExportType objects filtered by the import_export_category_id column + * @method array findByCreatedAt(string $created_at) Return ChildImportExportType objects filtered by the created_at column + * @method array findByUpdatedAt(string $updated_at) Return ChildImportExportType objects filtered by the updated_at column * */ abstract class ImportExportTypeQuery extends ModelCriteria @@ -140,7 +148,7 @@ abstract class ImportExportTypeQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT `ID`, `URL_ACTION`, `IMPORT_EXPORT_CATEGORY_ID` FROM `import_export_type` WHERE `ID` = :p0'; + $sql = 'SELECT `ID`, `URL_ACTION`, `IMPORT_EXPORT_CATEGORY_ID`, `CREATED_AT`, `UPDATED_AT` FROM `import_export_type` WHERE `ID` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -342,6 +350,92 @@ abstract class ImportExportTypeQuery extends ModelCriteria return $this->addUsingAlias(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $importExportCategoryId, $comparison); } + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(ImportExportTypeTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(ImportExportTypeTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ImportExportTypeTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(ImportExportTypeTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(ImportExportTypeTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ImportExportTypeTableMap::UPDATED_AT, $updatedAt, $comparison); + } + /** * Filter the query by a related \Thelia\Model\ImportExportCategory object * @@ -638,4 +732,70 @@ abstract class ImportExportTypeQuery extends ModelCriteria ->useQuery($relationAlias ? $relationAlias : 'ImportExportTypeI18n', '\Thelia\Model\ImportExportTypeI18nQuery'); } + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(ImportExportTypeTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(ImportExportTypeTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(ImportExportTypeTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(ImportExportTypeTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(ImportExportTypeTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(ImportExportTypeTableMap::CREATED_AT); + } + } // ImportExportTypeQuery diff --git a/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php b/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php index d464ef15f..bfca378c5 100644 --- a/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php +++ b/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php @@ -58,7 +58,7 @@ class ImportExportTypeTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 3; + const NUM_COLUMNS = 5; /** * The number of lazy-loaded columns @@ -68,7 +68,7 @@ class ImportExportTypeTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 3; + const NUM_HYDRATE_COLUMNS = 5; /** * the column name for the ID field @@ -85,6 +85,16 @@ class ImportExportTypeTableMap extends TableMap */ const IMPORT_EXPORT_CATEGORY_ID = 'import_export_type.IMPORT_EXPORT_CATEGORY_ID'; + /** + * the column name for the CREATED_AT field + */ + const CREATED_AT = 'import_export_type.CREATED_AT'; + + /** + * the column name for the UPDATED_AT field + */ + const UPDATED_AT = 'import_export_type.UPDATED_AT'; + /** * The default string format for model objects of the related table */ @@ -106,12 +116,12 @@ class ImportExportTypeTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'UrlAction', 'ImportExportCategoryId', ), - self::TYPE_STUDLYPHPNAME => array('id', 'urlAction', 'importExportCategoryId', ), - self::TYPE_COLNAME => array(ImportExportTypeTableMap::ID, ImportExportTypeTableMap::URL_ACTION, ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, ), - self::TYPE_RAW_COLNAME => array('ID', 'URL_ACTION', 'IMPORT_EXPORT_CATEGORY_ID', ), - self::TYPE_FIELDNAME => array('id', 'url_action', 'import_export_category_id', ), - self::TYPE_NUM => array(0, 1, 2, ) + self::TYPE_PHPNAME => array('Id', 'UrlAction', 'ImportExportCategoryId', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'urlAction', 'importExportCategoryId', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(ImportExportTypeTableMap::ID, ImportExportTypeTableMap::URL_ACTION, ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, ImportExportTypeTableMap::CREATED_AT, ImportExportTypeTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'URL_ACTION', 'IMPORT_EXPORT_CATEGORY_ID', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'url_action', 'import_export_category_id', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, ) ); /** @@ -121,12 +131,12 @@ class ImportExportTypeTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'UrlAction' => 1, 'ImportExportCategoryId' => 2, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'urlAction' => 1, 'importExportCategoryId' => 2, ), - self::TYPE_COLNAME => array(ImportExportTypeTableMap::ID => 0, ImportExportTypeTableMap::URL_ACTION => 1, ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID => 2, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'URL_ACTION' => 1, 'IMPORT_EXPORT_CATEGORY_ID' => 2, ), - self::TYPE_FIELDNAME => array('id' => 0, 'url_action' => 1, 'import_export_category_id' => 2, ), - self::TYPE_NUM => array(0, 1, 2, ) + self::TYPE_PHPNAME => array('Id' => 0, 'UrlAction' => 1, 'ImportExportCategoryId' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'urlAction' => 1, 'importExportCategoryId' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), + self::TYPE_COLNAME => array(ImportExportTypeTableMap::ID => 0, ImportExportTypeTableMap::URL_ACTION => 1, ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID => 2, ImportExportTypeTableMap::CREATED_AT => 3, ImportExportTypeTableMap::UPDATED_AT => 4, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'URL_ACTION' => 1, 'IMPORT_EXPORT_CATEGORY_ID' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), + self::TYPE_FIELDNAME => array('id' => 0, 'url_action' => 1, 'import_export_category_id' => 2, 'created_at' => 3, 'updated_at' => 4, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, ) ); /** @@ -148,6 +158,8 @@ class ImportExportTypeTableMap extends TableMap $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addColumn('URL_ACTION', 'UrlAction', 'VARCHAR', true, 255, null); $this->addForeignKey('IMPORT_EXPORT_CATEGORY_ID', 'ImportExportCategoryId', 'INTEGER', 'import_export_category', 'ID', true, null, null); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() /** @@ -169,6 +181,7 @@ class ImportExportTypeTableMap extends TableMap { return array( 'i18n' => array('i18n_table' => '%TABLE%_i18n', 'i18n_phpname' => '%PHPNAME%I18n', 'i18n_columns' => 'title, description', 'locale_column' => 'locale', 'locale_length' => '5', 'default_locale' => '', 'locale_alias' => '', ), + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), ); } // getBehaviors() /** @@ -322,10 +335,14 @@ class ImportExportTypeTableMap extends TableMap $criteria->addSelectColumn(ImportExportTypeTableMap::ID); $criteria->addSelectColumn(ImportExportTypeTableMap::URL_ACTION); $criteria->addSelectColumn(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID); + $criteria->addSelectColumn(ImportExportTypeTableMap::CREATED_AT); + $criteria->addSelectColumn(ImportExportTypeTableMap::UPDATED_AT); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.URL_ACTION'); $criteria->addSelectColumn($alias . '.IMPORT_EXPORT_CATEGORY_ID'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); } } diff --git a/local/config/schema.xml b/local/config/schema.xml index b86124f25..f9e62b9ed 100644 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1536,5 +1536,6 @@ + diff --git a/setup/thelia.sql b/setup/thelia.sql index 8b46f23be..d46b81c98 100644 --- a/setup/thelia.sql +++ b/setup/thelia.sql @@ -1899,6 +1899,8 @@ CREATE TABLE `import_export_type` `id` INTEGER NOT NULL AUTO_INCREMENT, `url_action` VARCHAR(255) NOT NULL, `import_export_category_id` INTEGER NOT NULL, + `created_at` DATETIME, + `updated_at` DATETIME, PRIMARY KEY (`id`), INDEX `idx_import_export_type_import_export_category_id` (`import_export_category_id`), CONSTRAINT `fk_import_export_type_import_export_category_id` From 0cb0e893824b8c69f413eeda0b58c2980ad8f090 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Wed, 9 Jul 2014 16:48:04 +0200 Subject: [PATCH 049/158] =?UTF-8?q?Continue=20import=20export=20management?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/C?= =?UTF-8?q?onfig/Resources/loop.xml=20=09nouveau=20fichier:=20core/lib/The?= =?UTF-8?q?lia/Core/Template/Loop/ImportExportCategory.php=20=09nouveau=20?= =?UTF-8?q?fichier:=20core/lib/Thelia/Core/Template/Loop/ImportExportType.?= =?UTF-8?q?php=20=09nouveau=20fichier:=20core/lib/Thelia/Form/ExportForm.p?= =?UTF-8?q?hp=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia?= =?UTF-8?q?/Model/Base/ImportExportType.php=20=09modifi=C3=A9:=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20core/lib/Thelia/Model/Base/ImportExportTypeQuery?= =?UTF-8?q?.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thel?= =?UTF-8?q?ia/Model/Map/ImportExportTypeTableMap.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20local/config/schema.xml=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20setup/thelia.sql=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20templates/backOffice/default/?= =?UTF-8?q?export.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/loop.xml | 1 + .../Template/Loop/ImportExportCategory.php | 136 ++++++++++++++++++ .../Core/Template/Loop/ImportExportType.php | 87 +++++++++++ core/lib/Thelia/Form/ExportForm.php | 99 +++++++++++++ .../Thelia/Model/Base/ImportExportType.php | 76 ++++++++-- .../Model/Base/ImportExportTypeQuery.php | 47 +++++- .../Model/Map/ImportExportTypeTableMap.php | 36 +++-- local/config/schema.xml | 1 + setup/thelia.sql | 1 + templates/backOffice/default/export.html | 56 +++++--- 10 files changed, 495 insertions(+), 45 deletions(-) create mode 100644 core/lib/Thelia/Core/Template/Loop/ImportExportCategory.php create mode 100644 core/lib/Thelia/Core/Template/Loop/ImportExportType.php create mode 100644 core/lib/Thelia/Form/ExportForm.php diff --git a/core/lib/Thelia/Config/Resources/loop.xml b/core/lib/Thelia/Config/Resources/loop.xml index 90678a5e0..3588e3787 100644 --- a/core/lib/Thelia/Config/Resources/loop.xml +++ b/core/lib/Thelia/Config/Resources/loop.xml @@ -57,6 +57,7 @@ + diff --git a/core/lib/Thelia/Core/Template/Loop/ImportExportCategory.php b/core/lib/Thelia/Core/Template/Loop/ImportExportCategory.php new file mode 100644 index 000000000..f20c38bf6 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/ImportExportCategory.php @@ -0,0 +1,136 @@ + + */ +class ImportExportCategory extends BaseLoop implements PropelSearchLoopInterface +{ + protected $timestampable = true; + + /** + * @param LoopResult $loopResult + * + * @return LoopResult + */ + public function parseResults(LoopResult $loopResult) + { + /** @var \Thelia\Model\ImportExportCategory $category */ + foreach ($loopResult->getResultDataCollection() as $category) + { + $loopResultRow = new LoopResultRow($category); + + $loopResultRow + ->set("ID", $category->getId()) + ->set("TITLE", $category->getTitle()) + ->set("POSITION", $category->getPosition()) + ; + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } + + /** + * this method returns a Propel ModelCriteria + * + * @return \Propel\Runtime\ActiveQuery\ModelCriteria + */ + public function buildModelCriteria() + { + $query = ImportExportCategoryQuery::create(); + + if (null !== $ids = $this->getId()) { + $query->filterById($ids, Criteria::IN); + } + + if (null !== $orders = $this->getOrder()) { + foreach ($orders as $order) { + switch($order) { + case "id": + $query->orderById(); + break; + case "id_reverse": + $query->orderById(Criteria::DESC); + break; + case "alpha": + $query->addAscendingOrderByColumn("i18n_TITLE"); + break; + case "alpha_reverse": + $query->addDescendingOrderByColumn("i18n_TITLE"); + break; + case "manual": + $query->orderByPosition(); + break; + case "manual_reverse": + $query->orderByPosition(Criteria::DESC); + break; + } + } + } + + return $query; + } + + /** + * Definition of loop arguments + * + * example : + * + * public function getArgDefinitions() + * { + * return new ArgumentCollection( + * + * Argument::createIntListTypeArgument('id'), + * new Argument( + * 'ref', + * new TypeCollection( + * new Type\AlphaNumStringListType() + * ) + * ), + * Argument::createIntListTypeArgument('category'), + * Argument::createBooleanTypeArgument('new'), + * ... + * ); + * } + * + * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntListTypeArgument('id'), + new Argument( + "order", + new TypeCollection( + new EnumListType(["id", "id_reverse", "alpha", "alpha_reverse", "manual", "manual_reverse"]) + ), + "manual" + ) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/ImportExportType.php b/core/lib/Thelia/Core/Template/Loop/ImportExportType.php new file mode 100644 index 000000000..7990a4a6b --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/ImportExportType.php @@ -0,0 +1,87 @@ + + */ +class ImportExportType extends BaseLoop implements PropelSearchLoopInterface +{ + /** + * @param LoopResult $loopResult + * + * @return LoopResult + */ + public function parseResults(LoopResult $loopResult) + { + // TODO: Implement parseResults() method. + } + + + /** + * this method returns a Propel ModelCriteria + * + * @return \Propel\Runtime\ActiveQuery\ModelCriteria + */ + public function buildModelCriteria() + { + // TODO: Implement buildModelCriteria() method. + } + + /** + * Definition of loop arguments + * + * example : + * + * public function getArgDefinitions() + * { + * return new ArgumentCollection( + * + * Argument::createIntListTypeArgument('id'), + * new Argument( + * 'ref', + * new TypeCollection( + * new Type\AlphaNumStringListType() + * ) + * ), + * Argument::createIntListTypeArgument('category'), + * Argument::createBooleanTypeArgument('new'), + * ... + * ); + * } + * + * @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntListTypeArgument('id'), + new Argument( + "order", + new TypeCollection( + new EnumListType(["id", "id_reverse", "alpha", "alpha_reverse", "manual", "manual_reverse"]) + ), + "manual" + ) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Form/ExportForm.php b/core/lib/Thelia/Form/ExportForm.php new file mode 100644 index 000000000..33fb8e029 --- /dev/null +++ b/core/lib/Thelia/Form/ExportForm.php @@ -0,0 +1,99 @@ + + */ +class ExportForm extends BaseForm +{ + protected $archiveBuilderManager = array(); + + protected $formattersNames = array(); + + protected $exportTypes = array(); + + protected $translator; + + public function __construct(Request $request, $type= "form", $data = array(), $options = array()) + { + $this->translator = Translator::getInstance(); + + parent::__construct($request, $type, $data, $options); + } + + protected function buildForm() + { + $this->formBuilder + ->add("formatter", "choice", array( + "label" => $this->translator->trans("File format"), + "label_attr" => ["for" => "formatter"], + "required" => true, + "multiple" => false, + "choices" => $this->formattersNames, + )) + ->add("archive_builder", "choice", array( + "label" => $this->translator->trans("Archive Format"), + "label_attr" => ["for" => "archive_builder"], + "required" => true, + "multiple" => false, + "choices" => $this->archiveBuilderManager, + )) + ->add("images", "checkbox", array( + "label" => $this->translator->trans("Include images"), + "label_attr" => ["for" => "with_images"], + "required" => false, + )) + ->add("documents", "checkbox", array( + "label" => $this->translator->trans("Include documents"), + "label_attr" => ["for" => "with_documents"], + "required" => false, + )) + ->add("export_type", "choice", array( + "required" => true, + "choices" => $this->exportTypes, + )) + ; + } + + + public function setFormatters(array $formattersNames) { + $this->formattersNames = $formattersNames; + + return $this; + } + + public function setArchiveBuilderNames(array $archiveBuildersNames) + { + $this->archiveBuilderManager += $archiveBuildersNames; + + return $this; + } + + public function setExportTypes(array $exportType) + { + $this->exportTypes = $exportType; + + return $this; + } + + public function getName() + { + return "thelia_export"; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Model/Base/ImportExportType.php b/core/lib/Thelia/Model/Base/ImportExportType.php index c15281a34..47595ded9 100644 --- a/core/lib/Thelia/Model/Base/ImportExportType.php +++ b/core/lib/Thelia/Model/Base/ImportExportType.php @@ -77,6 +77,12 @@ abstract class ImportExportType implements ActiveRecordInterface */ protected $import_export_category_id; + /** + * The value for the position field. + * @var int + */ + protected $position; + /** * The value for the created_at field. * @var string @@ -419,6 +425,17 @@ abstract class ImportExportType implements ActiveRecordInterface return $this->import_export_category_id; } + /** + * Get the [position] column value. + * + * @return int + */ + public function getPosition() + { + + return $this->position; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -526,6 +543,27 @@ abstract class ImportExportType implements ActiveRecordInterface return $this; } // setImportExportCategoryId() + /** + * Set the value of [position] column. + * + * @param int $v new value + * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + */ + public function setPosition($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->position !== $v) { + $this->position = $v; + $this->modifiedColumns[ImportExportTypeTableMap::POSITION] = true; + } + + + return $this; + } // setPosition() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -614,13 +652,16 @@ abstract class ImportExportType implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportExportTypeTableMap::translateFieldName('ImportExportCategoryId', TableMap::TYPE_PHPNAME, $indexType)]; $this->import_export_category_id = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportExportTypeTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportExportTypeTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; + $this->position = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ImportExportTypeTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ImportExportTypeTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ImportExportTypeTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -633,7 +674,7 @@ abstract class ImportExportType implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 5; // 5 = ImportExportTypeTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 6; // 6 = ImportExportTypeTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\ImportExportType object", 0, $e); @@ -897,6 +938,9 @@ abstract class ImportExportType implements ActiveRecordInterface if ($this->isColumnModified(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID)) { $modifiedColumns[':p' . $index++] = '`IMPORT_EXPORT_CATEGORY_ID`'; } + if ($this->isColumnModified(ImportExportTypeTableMap::POSITION)) { + $modifiedColumns[':p' . $index++] = '`POSITION`'; + } if ($this->isColumnModified(ImportExportTypeTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = '`CREATED_AT`'; } @@ -923,6 +967,9 @@ abstract class ImportExportType implements ActiveRecordInterface case '`IMPORT_EXPORT_CATEGORY_ID`': $stmt->bindValue($identifier, $this->import_export_category_id, PDO::PARAM_INT); break; + case '`POSITION`': + $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); + break; case '`CREATED_AT`': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; @@ -1001,9 +1048,12 @@ abstract class ImportExportType implements ActiveRecordInterface return $this->getImportExportCategoryId(); break; case 3: - return $this->getCreatedAt(); + return $this->getPosition(); break; case 4: + return $this->getCreatedAt(); + break; + case 5: return $this->getUpdatedAt(); break; default: @@ -1038,8 +1088,9 @@ abstract class ImportExportType implements ActiveRecordInterface $keys[0] => $this->getId(), $keys[1] => $this->getUrlAction(), $keys[2] => $this->getImportExportCategoryId(), - $keys[3] => $this->getCreatedAt(), - $keys[4] => $this->getUpdatedAt(), + $keys[3] => $this->getPosition(), + $keys[4] => $this->getCreatedAt(), + $keys[5] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { @@ -1097,9 +1148,12 @@ abstract class ImportExportType implements ActiveRecordInterface $this->setImportExportCategoryId($value); break; case 3: - $this->setCreatedAt($value); + $this->setPosition($value); break; case 4: + $this->setCreatedAt($value); + break; + case 5: $this->setUpdatedAt($value); break; } // switch() @@ -1129,8 +1183,9 @@ abstract class ImportExportType implements ActiveRecordInterface if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setUrlAction($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setImportExportCategoryId($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]); + if (array_key_exists($keys[3], $arr)) $this->setPosition($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setUpdatedAt($arr[$keys[5]]); } /** @@ -1145,6 +1200,7 @@ abstract class ImportExportType implements ActiveRecordInterface if ($this->isColumnModified(ImportExportTypeTableMap::ID)) $criteria->add(ImportExportTypeTableMap::ID, $this->id); if ($this->isColumnModified(ImportExportTypeTableMap::URL_ACTION)) $criteria->add(ImportExportTypeTableMap::URL_ACTION, $this->url_action); if ($this->isColumnModified(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID)) $criteria->add(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $this->import_export_category_id); + if ($this->isColumnModified(ImportExportTypeTableMap::POSITION)) $criteria->add(ImportExportTypeTableMap::POSITION, $this->position); if ($this->isColumnModified(ImportExportTypeTableMap::CREATED_AT)) $criteria->add(ImportExportTypeTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(ImportExportTypeTableMap::UPDATED_AT)) $criteria->add(ImportExportTypeTableMap::UPDATED_AT, $this->updated_at); @@ -1212,6 +1268,7 @@ abstract class ImportExportType implements ActiveRecordInterface { $copyObj->setUrlAction($this->getUrlAction()); $copyObj->setImportExportCategoryId($this->getImportExportCategoryId()); + $copyObj->setPosition($this->getPosition()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); @@ -1556,6 +1613,7 @@ abstract class ImportExportType implements ActiveRecordInterface $this->id = null; $this->url_action = null; $this->import_export_category_id = null; + $this->position = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php b/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php index 68adab4a0..953591923 100644 --- a/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php +++ b/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php @@ -25,12 +25,14 @@ use Thelia\Model\Map\ImportExportTypeTableMap; * @method ChildImportExportTypeQuery orderById($order = Criteria::ASC) Order by the id column * @method ChildImportExportTypeQuery orderByUrlAction($order = Criteria::ASC) Order by the url_action column * @method ChildImportExportTypeQuery orderByImportExportCategoryId($order = Criteria::ASC) Order by the import_export_category_id column + * @method ChildImportExportTypeQuery orderByPosition($order = Criteria::ASC) Order by the position column * @method ChildImportExportTypeQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildImportExportTypeQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * * @method ChildImportExportTypeQuery groupById() Group by the id column * @method ChildImportExportTypeQuery groupByUrlAction() Group by the url_action column * @method ChildImportExportTypeQuery groupByImportExportCategoryId() Group by the import_export_category_id column + * @method ChildImportExportTypeQuery groupByPosition() Group by the position column * @method ChildImportExportTypeQuery groupByCreatedAt() Group by the created_at column * @method ChildImportExportTypeQuery groupByUpdatedAt() Group by the updated_at column * @@ -52,12 +54,14 @@ use Thelia\Model\Map\ImportExportTypeTableMap; * @method ChildImportExportType findOneById(int $id) Return the first ChildImportExportType filtered by the id column * @method ChildImportExportType findOneByUrlAction(string $url_action) Return the first ChildImportExportType filtered by the url_action column * @method ChildImportExportType findOneByImportExportCategoryId(int $import_export_category_id) Return the first ChildImportExportType filtered by the import_export_category_id column + * @method ChildImportExportType findOneByPosition(int $position) Return the first ChildImportExportType filtered by the position column * @method ChildImportExportType findOneByCreatedAt(string $created_at) Return the first ChildImportExportType filtered by the created_at column * @method ChildImportExportType findOneByUpdatedAt(string $updated_at) Return the first ChildImportExportType filtered by the updated_at column * * @method array findById(int $id) Return ChildImportExportType objects filtered by the id column * @method array findByUrlAction(string $url_action) Return ChildImportExportType objects filtered by the url_action column * @method array findByImportExportCategoryId(int $import_export_category_id) Return ChildImportExportType objects filtered by the import_export_category_id column + * @method array findByPosition(int $position) Return ChildImportExportType objects filtered by the position column * @method array findByCreatedAt(string $created_at) Return ChildImportExportType objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildImportExportType objects filtered by the updated_at column * @@ -148,7 +152,7 @@ abstract class ImportExportTypeQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT `ID`, `URL_ACTION`, `IMPORT_EXPORT_CATEGORY_ID`, `CREATED_AT`, `UPDATED_AT` FROM `import_export_type` WHERE `ID` = :p0'; + $sql = 'SELECT `ID`, `URL_ACTION`, `IMPORT_EXPORT_CATEGORY_ID`, `POSITION`, `CREATED_AT`, `UPDATED_AT` FROM `import_export_type` WHERE `ID` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -350,6 +354,47 @@ abstract class ImportExportTypeQuery extends ModelCriteria return $this->addUsingAlias(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $importExportCategoryId, $comparison); } + /** + * Filter the query on the position column + * + * Example usage: + * + * $query->filterByPosition(1234); // WHERE position = 1234 + * $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34) + * $query->filterByPosition(array('min' => 12)); // WHERE position > 12 + * + * + * @param mixed $position The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportExportTypeQuery The current query, for fluid interface + */ + public function filterByPosition($position = null, $comparison = null) + { + if (is_array($position)) { + $useMinMax = false; + if (isset($position['min'])) { + $this->addUsingAlias(ImportExportTypeTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($position['max'])) { + $this->addUsingAlias(ImportExportTypeTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ImportExportTypeTableMap::POSITION, $position, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php b/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php index bfca378c5..5533343fd 100644 --- a/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php +++ b/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php @@ -58,7 +58,7 @@ class ImportExportTypeTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 5; + const NUM_COLUMNS = 6; /** * The number of lazy-loaded columns @@ -68,7 +68,7 @@ class ImportExportTypeTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 5; + const NUM_HYDRATE_COLUMNS = 6; /** * the column name for the ID field @@ -85,6 +85,11 @@ class ImportExportTypeTableMap extends TableMap */ const IMPORT_EXPORT_CATEGORY_ID = 'import_export_type.IMPORT_EXPORT_CATEGORY_ID'; + /** + * the column name for the POSITION field + */ + const POSITION = 'import_export_type.POSITION'; + /** * the column name for the CREATED_AT field */ @@ -116,12 +121,12 @@ class ImportExportTypeTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'UrlAction', 'ImportExportCategoryId', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'urlAction', 'importExportCategoryId', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(ImportExportTypeTableMap::ID, ImportExportTypeTableMap::URL_ACTION, ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, ImportExportTypeTableMap::CREATED_AT, ImportExportTypeTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'URL_ACTION', 'IMPORT_EXPORT_CATEGORY_ID', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'url_action', 'import_export_category_id', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + self::TYPE_PHPNAME => array('Id', 'UrlAction', 'ImportExportCategoryId', 'Position', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'urlAction', 'importExportCategoryId', 'position', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(ImportExportTypeTableMap::ID, ImportExportTypeTableMap::URL_ACTION, ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, ImportExportTypeTableMap::POSITION, ImportExportTypeTableMap::CREATED_AT, ImportExportTypeTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'URL_ACTION', 'IMPORT_EXPORT_CATEGORY_ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'url_action', 'import_export_category_id', 'position', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) ); /** @@ -131,12 +136,12 @@ class ImportExportTypeTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'UrlAction' => 1, 'ImportExportCategoryId' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'urlAction' => 1, 'importExportCategoryId' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), - self::TYPE_COLNAME => array(ImportExportTypeTableMap::ID => 0, ImportExportTypeTableMap::URL_ACTION => 1, ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID => 2, ImportExportTypeTableMap::CREATED_AT => 3, ImportExportTypeTableMap::UPDATED_AT => 4, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'URL_ACTION' => 1, 'IMPORT_EXPORT_CATEGORY_ID' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), - self::TYPE_FIELDNAME => array('id' => 0, 'url_action' => 1, 'import_export_category_id' => 2, 'created_at' => 3, 'updated_at' => 4, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + self::TYPE_PHPNAME => array('Id' => 0, 'UrlAction' => 1, 'ImportExportCategoryId' => 2, 'Position' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'urlAction' => 1, 'importExportCategoryId' => 2, 'position' => 3, 'createdAt' => 4, 'updatedAt' => 5, ), + self::TYPE_COLNAME => array(ImportExportTypeTableMap::ID => 0, ImportExportTypeTableMap::URL_ACTION => 1, ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID => 2, ImportExportTypeTableMap::POSITION => 3, ImportExportTypeTableMap::CREATED_AT => 4, ImportExportTypeTableMap::UPDATED_AT => 5, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'URL_ACTION' => 1, 'IMPORT_EXPORT_CATEGORY_ID' => 2, 'POSITION' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ), + self::TYPE_FIELDNAME => array('id' => 0, 'url_action' => 1, 'import_export_category_id' => 2, 'position' => 3, 'created_at' => 4, 'updated_at' => 5, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) ); /** @@ -158,6 +163,7 @@ class ImportExportTypeTableMap extends TableMap $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addColumn('URL_ACTION', 'UrlAction', 'VARCHAR', true, 255, null); $this->addForeignKey('IMPORT_EXPORT_CATEGORY_ID', 'ImportExportCategoryId', 'INTEGER', 'import_export_category', 'ID', true, null, null); + $this->addColumn('POSITION', 'Position', 'INTEGER', true, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -335,12 +341,14 @@ class ImportExportTypeTableMap extends TableMap $criteria->addSelectColumn(ImportExportTypeTableMap::ID); $criteria->addSelectColumn(ImportExportTypeTableMap::URL_ACTION); $criteria->addSelectColumn(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID); + $criteria->addSelectColumn(ImportExportTypeTableMap::POSITION); $criteria->addSelectColumn(ImportExportTypeTableMap::CREATED_AT); $criteria->addSelectColumn(ImportExportTypeTableMap::UPDATED_AT); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.URL_ACTION'); $criteria->addSelectColumn($alias . '.IMPORT_EXPORT_CATEGORY_ID'); + $criteria->addSelectColumn($alias . '.POSITION'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/local/config/schema.xml b/local/config/schema.xml index f9e62b9ed..0738419ee 100644 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1527,6 +1527,7 @@ + diff --git a/setup/thelia.sql b/setup/thelia.sql index d46b81c98..d5d300552 100644 --- a/setup/thelia.sql +++ b/setup/thelia.sql @@ -1899,6 +1899,7 @@ CREATE TABLE `import_export_type` `id` INTEGER NOT NULL AUTO_INCREMENT, `url_action` VARCHAR(255) NOT NULL, `import_export_category_id` INTEGER NOT NULL, + `position` INTEGER NOT NULL, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), diff --git a/templates/backOffice/default/export.html b/templates/backOffice/default/export.html index ed1360a2a..6cafbd178 100644 --- a/templates/backOffice/default/export.html +++ b/templates/backOffice/default/export.html @@ -27,31 +27,45 @@ {module_include location='tools_top'} - {include file='includes/export-form-definition.html' form=$form} -
+ {loop name="import-export-category" type="import-export-category"} + {if $LOOP_COUNT % 3} +
+ {/if} -
- + {if $LOOP_COUNT % 3} +
+ {/if} + {/loop} + + {module_include location='configuration_bottom'}
From 658c848171e5638e467a8d6cb641fa27f69f0c25 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 10 Jul 2014 10:31:57 +0200 Subject: [PATCH 050/158] =?UTF-8?q?Split=20import=20export=20management=20?= =?UTF-8?q?in=20two=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/?= =?UTF-8?q?Thelia/Config/Resources/config.xml=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Config/Resources/loop.xml=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Conf?= =?UTF-8?q?ig/Resources/routing/admin.xml=20=09nouveau=20fichier:=20core/l?= =?UTF-8?q?ib/Thelia/Controller/Admin/ImportExportController.php=20=09nouv?= =?UTF-8?q?eau=20fichier:=20core/lib/Thelia/Core/Template/Loop/Export.php?= =?UTF-8?q?=20=09nouveau=20fichier:=20core/lib/Thelia/Core/Template/Loop/E?= =?UTF-8?q?xportCategory.php=20=09nouveau=20fichier:=20core/lib/Thelia/Cor?= =?UTF-8?q?e/Template/Loop/Import.php=20=09nouveau=20fichier:=20core/lib/T?= =?UTF-8?q?helia/Core/Template/Loop/ImportCategory.php=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/Template/Loop/I?= =?UTF-8?q?mportExportCategory.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Core/Template/Loop/ImportExportType.php?= =?UTF-8?q?=20=09nouveau=20fichier:=20core/lib/Thelia/Model/Base/Export.ph?= =?UTF-8?q?p=20=09nouveau=20fichier:=20core/lib/Thelia/Model/Base/ExportCa?= =?UTF-8?q?tegory.php=20=09nouveau=20fichier:=20core/lib/Thelia/Model/Base?= =?UTF-8?q?/ExportCategoryI18n.php=20=09nouveau=20fichier:=20core/lib/Thel?= =?UTF-8?q?ia/Model/Base/ExportCategoryI18nQuery.php=20=09nouveau=20fichie?= =?UTF-8?q?r:=20core/lib/Thelia/Model/Base/ExportCategoryQuery.php=20=09no?= =?UTF-8?q?uveau=20fichier:=20core/lib/Thelia/Model/Base/ExportI18n.php=20?= =?UTF-8?q?=09nouveau=20fichier:=20core/lib/Thelia/Model/Base/ExportI18nQu?= =?UTF-8?q?ery.php=20=09nouveau=20fichier:=20core/lib/Thelia/Model/Base/Ex?= =?UTF-8?q?portQuery.php=20=09renomm=C3=A9:=20=20=20=20=20=20=20=20=20core?= =?UTF-8?q?/lib/Thelia/Model/Base/ImportExportType.php=20->=20core/lib/The?= =?UTF-8?q?lia/Model/Base/Import.php=20=09renomm=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/Model/Base/ImportExportCategory.php=20?= =?UTF-8?q?->=20core/lib/Thelia/Model/Base/ImportCategory.php=20=09renomm?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Model/Base/Im?= =?UTF-8?q?portExportCategoryI18n.php=20->=20core/lib/Thelia/Model/Base/Im?= =?UTF-8?q?portCategoryI18n.php=20=09renomm=C3=A9:=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20core/lib/Thelia/Model/Base/ImportExportCategoryI18nQuery.php?= =?UTF-8?q?=20->=20core/lib/Thelia/Model/Base/ImportCategoryI18nQuery.php?= =?UTF-8?q?=20=09renomm=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/M?= =?UTF-8?q?odel/Base/ImportExportCategoryQuery.php=20->=20core/lib/Thelia/?= =?UTF-8?q?Model/Base/ImportCategoryQuery.php=20=09renomm=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Model/Base/ImportExportTypeI1?= =?UTF-8?q?8n.php=20->=20core/lib/Thelia/Model/Base/ImportI18n.php=20=09re?= =?UTF-8?q?nomm=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Model/Bas?= =?UTF-8?q?e/ImportExportTypeI18nQuery.php=20->=20core/lib/Thelia/Model/Ba?= =?UTF-8?q?se/ImportI18nQuery.php=20=09renomm=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Model/Base/ImportExportTypeQuery.php=20->?= =?UTF-8?q?=20core/lib/Thelia/Model/Base/ImportQuery.php=20=09nouveau=20fi?= =?UTF-8?q?chier:=20core/lib/Thelia/Model/Export.php=20=09nouveau=20fichie?= =?UTF-8?q?r:=20core/lib/Thelia/Model/ExportCategory.php=20=09nouveau=20fi?= =?UTF-8?q?chier:=20core/lib/Thelia/Model/ExportCategoryI18n.php=20=09reno?= =?UTF-8?q?mm=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Model/Impor?= =?UTF-8?q?tExportCategoryQuery.php=20->=20core/lib/Thelia/Model/ExportCat?= =?UTF-8?q?egoryI18nQuery.php=20=09renomm=C3=A9:=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20core/lib/Thelia/Model/ImportExportTypeQuery.php=20->=20core/?= =?UTF-8?q?lib/Thelia/Model/ExportCategoryQuery.php=20=09nouveau=20fichier?= =?UTF-8?q?:=20core/lib/Thelia/Model/ExportI18n.php=20=09renomm=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Model/ImportExportTypeI?= =?UTF-8?q?18nQuery.php=20->=20core/lib/Thelia/Model/ExportI18nQuery.php?= =?UTF-8?q?=20=09renomm=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/M?= =?UTF-8?q?odel/ImportExportCategoryI18nQuery.php=20->=20core/lib/Thelia/M?= =?UTF-8?q?odel/ExportQuery.php=20=09nouveau=20fichier:=20core/lib/Thelia/?= =?UTF-8?q?Model/Import.php=20=09nouveau=20fichier:=20core/lib/Thelia/Mode?= =?UTF-8?q?l/ImportCategory.php=20=09nouveau=20fichier:=20core/lib/Thelia/?= =?UTF-8?q?Model/ImportCategoryI18n.php=20=09nouveau=20fichier:=20core/lib?= =?UTF-8?q?/Thelia/Model/ImportCategoryI18nQuery.php=20=09nouveau=20fichie?= =?UTF-8?q?r:=20core/lib/Thelia/Model/ImportCategoryQuery.php=20=09supprim?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20core/lib/Thelia/Model/ImportExpo?= =?UTF-8?q?rtCategory.php=20=09supprim=C3=A9:=20=20=20=20=20=20=20=20core/?= =?UTF-8?q?lib/Thelia/Model/ImportExportCategoryI18n.php=20=09supprim?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20core/lib/Thelia/Model/ImportExpo?= =?UTF-8?q?rtType.php=20=09supprim=C3=A9:=20=20=20=20=20=20=20=20core/lib/?= =?UTF-8?q?Thelia/Model/ImportExportTypeI18n.php=20=09nouveau=20fichier:?= =?UTF-8?q?=20core/lib/Thelia/Model/ImportI18n.php=20=09nouveau=20fichier:?= =?UTF-8?q?=20core/lib/Thelia/Model/ImportI18nQuery.php=20=09nouveau=20fic?= =?UTF-8?q?hier:=20core/lib/Thelia/Model/ImportQuery.php=20=09nouveau=20fi?= =?UTF-8?q?chier:=20core/lib/Thelia/Model/Map/ExportCategoryI18nTableMap.p?= =?UTF-8?q?hp=20=09nouveau=20fichier:=20core/lib/Thelia/Model/Map/ExportCa?= =?UTF-8?q?tegoryTableMap.php=20=09nouveau=20fichier:=20core/lib/Thelia/Mo?= =?UTF-8?q?del/Map/ExportI18nTableMap.php=20=09nouveau=20fichier:=20core/l?= =?UTF-8?q?ib/Thelia/Model/Map/ExportTableMap.php=20=09renomm=C3=A9:=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20core/lib/Thelia/Model/Map/ImportExportCate?= =?UTF-8?q?goryI18nTableMap.php=20->=20core/lib/Thelia/Model/Map/ImportCat?= =?UTF-8?q?egoryI18nTableMap.php=20=09renomm=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Model/Map/ImportExportCategoryTableMap.ph?= =?UTF-8?q?p=20->=20core/lib/Thelia/Model/Map/ImportCategoryTableMap.php?= =?UTF-8?q?=20=09renomm=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/M?= =?UTF-8?q?odel/Map/ImportExportTypeI18nTableMap.php=20->=20core/lib/Theli?= =?UTF-8?q?a/Model/Map/ImportI18nTableMap.php=20=09renomm=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Model/Map/ImportExportTypeTab?= =?UTF-8?q?leMap.php=20->=20core/lib/Thelia/Model/Map/ImportTableMap.php?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20local/config/sche?= =?UTF-8?q?ma.xml=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20setup/theli?= =?UTF-8?q?a.sql=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20templates/ba?= =?UTF-8?q?ckOffice/default/export.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/config.xml | 2 + core/lib/Thelia/Config/Resources/loop.xml | 5 +- .../Thelia/Config/Resources/routing/admin.xml | 11 +- .../Admin/ImportExportController.php | 31 + core/lib/Thelia/Core/Template/Loop/Export.php | 38 + .../Core/Template/Loop/ExportCategory.php | 28 + core/lib/Thelia/Core/Template/Loop/Import.php | 37 + .../Core/Template/Loop/ImportCategory.php | 27 + .../Template/Loop/ImportExportCategory.php | 8 +- .../Core/Template/Loop/ImportExportType.php | 73 +- core/lib/Thelia/Model/Base/Export.php | 1884 ++++++++++++++++ core/lib/Thelia/Model/Base/ExportCategory.php | 1989 +++++++++++++++++ .../Thelia/Model/Base/ExportCategoryI18n.php | 1268 +++++++++++ .../Model/Base/ExportCategoryI18nQuery.php | 508 +++++ .../Thelia/Model/Base/ExportCategoryQuery.php | 764 +++++++ core/lib/Thelia/Model/Base/ExportI18n.php | 1326 +++++++++++ .../lib/Thelia/Model/Base/ExportI18nQuery.php | 541 +++++ core/lib/Thelia/Model/Base/ExportQuery.php | 813 +++++++ .../Base/{ImportExportType.php => Import.php} | 558 +++-- ...tExportCategory.php => ImportCategory.php} | 578 ++--- ...ategoryI18n.php => ImportCategoryI18n.php} | 158 +- ...nQuery.php => ImportCategoryI18nQuery.php} | 180 +- ...egoryQuery.php => ImportCategoryQuery.php} | 286 +-- ...mportExportTypeI18n.php => ImportI18n.php} | 168 +- ...tTypeI18nQuery.php => ImportI18nQuery.php} | 192 +- ...ortExportTypeQuery.php => ImportQuery.php} | 353 ++- core/lib/Thelia/Model/Export.php | 10 + core/lib/Thelia/Model/ExportCategory.php | 10 + core/lib/Thelia/Model/ExportCategoryI18n.php | 10 + ...yQuery.php => ExportCategoryI18nQuery.php} | 8 +- ...tTypeQuery.php => ExportCategoryQuery.php} | 8 +- core/lib/Thelia/Model/ExportI18n.php | 10 + ...tTypeI18nQuery.php => ExportI18nQuery.php} | 8 +- ...tCategoryI18nQuery.php => ExportQuery.php} | 8 +- core/lib/Thelia/Model/Import.php | 10 + core/lib/Thelia/Model/ImportCategory.php | 10 + core/lib/Thelia/Model/ImportCategoryI18n.php | 10 + .../Thelia/Model/ImportCategoryI18nQuery.php | 21 + core/lib/Thelia/Model/ImportCategoryQuery.php | 21 + .../lib/Thelia/Model/ImportExportCategory.php | 10 - .../Thelia/Model/ImportExportCategoryI18n.php | 10 - core/lib/Thelia/Model/ImportExportType.php | 10 - .../lib/Thelia/Model/ImportExportTypeI18n.php | 10 - core/lib/Thelia/Model/ImportI18n.php | 10 + core/lib/Thelia/Model/ImportI18nQuery.php | 21 + core/lib/Thelia/Model/ImportQuery.php | 21 + .../Model/Map/ExportCategoryI18nTableMap.php | 474 ++++ .../Model/Map/ExportCategoryTableMap.php | 461 ++++ .../Thelia/Model/Map/ExportI18nTableMap.php | 482 ++++ core/lib/Thelia/Model/Map/ExportTableMap.php | 468 ++++ ...Map.php => ImportCategoryI18nTableMap.php} | 116 +- ...ableMap.php => ImportCategoryTableMap.php} | 120 +- ...18nTableMap.php => ImportI18nTableMap.php} | 120 +- ...ortTypeTableMap.php => ImportTableMap.php} | 160 +- local/config/schema.xml | 41 +- setup/thelia.sql | 117 +- templates/backOffice/default/export.html | 10 +- 57 files changed, 12983 insertions(+), 1648 deletions(-) create mode 100644 core/lib/Thelia/Controller/Admin/ImportExportController.php create mode 100644 core/lib/Thelia/Core/Template/Loop/Export.php create mode 100644 core/lib/Thelia/Core/Template/Loop/ExportCategory.php create mode 100644 core/lib/Thelia/Core/Template/Loop/Import.php create mode 100644 core/lib/Thelia/Core/Template/Loop/ImportCategory.php create mode 100644 core/lib/Thelia/Model/Base/Export.php create mode 100644 core/lib/Thelia/Model/Base/ExportCategory.php create mode 100644 core/lib/Thelia/Model/Base/ExportCategoryI18n.php create mode 100644 core/lib/Thelia/Model/Base/ExportCategoryI18nQuery.php create mode 100644 core/lib/Thelia/Model/Base/ExportCategoryQuery.php create mode 100644 core/lib/Thelia/Model/Base/ExportI18n.php create mode 100644 core/lib/Thelia/Model/Base/ExportI18nQuery.php create mode 100644 core/lib/Thelia/Model/Base/ExportQuery.php rename core/lib/Thelia/Model/Base/{ImportExportType.php => Import.php} (69%) rename core/lib/Thelia/Model/Base/{ImportExportCategory.php => ImportCategory.php} (68%) rename core/lib/Thelia/Model/Base/{ImportExportCategoryI18n.php => ImportCategoryI18n.php} (84%) rename core/lib/Thelia/Model/Base/{ImportExportCategoryI18nQuery.php => ImportCategoryI18nQuery.php} (60%) rename core/lib/Thelia/Model/Base/{ImportExportCategoryQuery.php => ImportCategoryQuery.php} (59%) rename core/lib/Thelia/Model/Base/{ImportExportTypeI18n.php => ImportI18n.php} (84%) rename core/lib/Thelia/Model/Base/{ImportExportTypeI18nQuery.php => ImportI18nQuery.php} (61%) rename core/lib/Thelia/Model/Base/{ImportExportTypeQuery.php => ImportQuery.php} (54%) create mode 100644 core/lib/Thelia/Model/Export.php create mode 100644 core/lib/Thelia/Model/ExportCategory.php create mode 100644 core/lib/Thelia/Model/ExportCategoryI18n.php rename core/lib/Thelia/Model/{ImportExportCategoryQuery.php => ExportCategoryI18nQuery.php} (58%) rename core/lib/Thelia/Model/{ImportExportTypeQuery.php => ExportCategoryQuery.php} (61%) create mode 100644 core/lib/Thelia/Model/ExportI18n.php rename core/lib/Thelia/Model/{ImportExportTypeI18nQuery.php => ExportI18nQuery.php} (58%) rename core/lib/Thelia/Model/{ImportExportCategoryI18nQuery.php => ExportQuery.php} (55%) create mode 100644 core/lib/Thelia/Model/Import.php create mode 100644 core/lib/Thelia/Model/ImportCategory.php create mode 100644 core/lib/Thelia/Model/ImportCategoryI18n.php create mode 100644 core/lib/Thelia/Model/ImportCategoryI18nQuery.php create mode 100644 core/lib/Thelia/Model/ImportCategoryQuery.php delete mode 100644 core/lib/Thelia/Model/ImportExportCategory.php delete mode 100644 core/lib/Thelia/Model/ImportExportCategoryI18n.php delete mode 100644 core/lib/Thelia/Model/ImportExportType.php delete mode 100644 core/lib/Thelia/Model/ImportExportTypeI18n.php create mode 100644 core/lib/Thelia/Model/ImportI18n.php create mode 100644 core/lib/Thelia/Model/ImportI18nQuery.php create mode 100644 core/lib/Thelia/Model/ImportQuery.php create mode 100644 core/lib/Thelia/Model/Map/ExportCategoryI18nTableMap.php create mode 100644 core/lib/Thelia/Model/Map/ExportCategoryTableMap.php create mode 100644 core/lib/Thelia/Model/Map/ExportI18nTableMap.php create mode 100644 core/lib/Thelia/Model/Map/ExportTableMap.php rename core/lib/Thelia/Model/Map/{ImportExportCategoryI18nTableMap.php => ImportCategoryI18nTableMap.php} (76%) rename core/lib/Thelia/Model/Map/{ImportExportCategoryTableMap.php => ImportCategoryTableMap.php} (74%) rename core/lib/Thelia/Model/Map/{ImportExportTypeI18nTableMap.php => ImportI18nTableMap.php} (77%) rename core/lib/Thelia/Model/Map/{ImportExportTypeTableMap.php => ImportTableMap.php} (65%) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 1f043374a..0013941be 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -34,6 +34,8 @@ Thelia\Model\BrandImage + /admin/import + /admin/export diff --git a/core/lib/Thelia/Config/Resources/loop.xml b/core/lib/Thelia/Config/Resources/loop.xml index 3588e3787..bca98a6f3 100644 --- a/core/lib/Thelia/Config/Resources/loop.xml +++ b/core/lib/Thelia/Config/Resources/loop.xml @@ -57,7 +57,10 @@ - + + + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 7a2da4a57..31823709f 100644 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -1160,13 +1160,14 @@ - - Thelia\Controller\Admin\ExportController::indexAction + + Thelia\Controller\Admin\ImportExportController::export + \d+ - - Thelia\Controller\Admin\ExportController::export - .+ + + Thelia\Controller\Admin\ImportExportController::import + \d+ diff --git a/core/lib/Thelia/Controller/Admin/ImportExportController.php b/core/lib/Thelia/Controller/Admin/ImportExportController.php new file mode 100644 index 000000000..4e35fa0bf --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/ImportExportController.php @@ -0,0 +1,31 @@ + + */ +class ImportExportController extends BaseAdminController +{ + public function import() + { + + } + + public function export() + { + + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/Export.php b/core/lib/Thelia/Core/Template/Loop/Export.php new file mode 100644 index 000000000..1815b15d5 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Export.php @@ -0,0 +1,38 @@ + + */ +class Export extends ImportExportType +{ + protected function getBaseUrl() + { + return $this->container->getParameter("export.base_url"); + } + + protected function getQueryModel() + { + return ExportQuery::create(); + } + + protected function getCategoryName() + { + return "ExportCategoryId"; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/ExportCategory.php b/core/lib/Thelia/Core/Template/Loop/ExportCategory.php new file mode 100644 index 000000000..3fc425a77 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/ExportCategory.php @@ -0,0 +1,28 @@ + + */ +class ExportCategory extends ImportExportCategory +{ + protected function getQueryModel() + { + return ExportCategoryQuery::create(); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/Import.php b/core/lib/Thelia/Core/Template/Loop/Import.php new file mode 100644 index 000000000..e15ec49b7 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Import.php @@ -0,0 +1,37 @@ + + */ +class Import extends ImportExportType +{ + protected function getBaseUrl() + { + return $this->container->getParameter("export.base_url"); + } + + protected function getQueryModel() + { + return ImportQuery::create(); + } + + protected function getCategoryName() + { + return "ImportCategoryId"; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/ImportCategory.php b/core/lib/Thelia/Core/Template/Loop/ImportCategory.php new file mode 100644 index 000000000..9b7b5f57d --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/ImportCategory.php @@ -0,0 +1,27 @@ + + */ +class ImportCategory extends ImportExportCategory +{ + protected function getQueryModel() + { + return ImportCategoryQuery::create(); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/ImportExportCategory.php b/core/lib/Thelia/Core/Template/Loop/ImportExportCategory.php index f20c38bf6..d04094db2 100644 --- a/core/lib/Thelia/Core/Template/Loop/ImportExportCategory.php +++ b/core/lib/Thelia/Core/Template/Loop/ImportExportCategory.php @@ -18,7 +18,6 @@ use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\PropelSearchLoopInterface; use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; -use Thelia\Model\Base\ImportExportCategoryQuery; use Thelia\Type\EnumListType; use Thelia\Type\TypeCollection; @@ -27,7 +26,7 @@ use Thelia\Type\TypeCollection; * @package Thelia\Core\Template\Loop * @author Benjamin Perche */ -class ImportExportCategory extends BaseLoop implements PropelSearchLoopInterface +abstract class ImportExportCategory extends BaseLoop implements PropelSearchLoopInterface { protected $timestampable = true; @@ -38,7 +37,6 @@ class ImportExportCategory extends BaseLoop implements PropelSearchLoopInterface */ public function parseResults(LoopResult $loopResult) { - /** @var \Thelia\Model\ImportExportCategory $category */ foreach ($loopResult->getResultDataCollection() as $category) { $loopResultRow = new LoopResultRow($category); @@ -62,7 +60,7 @@ class ImportExportCategory extends BaseLoop implements PropelSearchLoopInterface */ public function buildModelCriteria() { - $query = ImportExportCategoryQuery::create(); + $query = $this->getQueryModel(); if (null !== $ids = $this->getId()) { $query->filterById($ids, Criteria::IN); @@ -133,4 +131,6 @@ class ImportExportCategory extends BaseLoop implements PropelSearchLoopInterface ) ); } + + abstract protected function getQueryModel(); } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/ImportExportType.php b/core/lib/Thelia/Core/Template/Loop/ImportExportType.php index 7990a4a6b..ae02e6854 100644 --- a/core/lib/Thelia/Core/Template/Loop/ImportExportType.php +++ b/core/lib/Thelia/Core/Template/Loop/ImportExportType.php @@ -11,11 +11,14 @@ /*************************************************************************************/ namespace Thelia\Core\Template\Loop; +use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\LoopResult; +use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\PropelSearchLoopInterface; use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Tools\URL; use Thelia\Type\EnumListType; use Thelia\Type\TypeCollection; @@ -24,8 +27,10 @@ use Thelia\Type\TypeCollection; * @package Thelia\Core\Template\Loop * @author Benjamin Perche */ -class ImportExportType extends BaseLoop implements PropelSearchLoopInterface +abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInterface { + protected $timestampable = true; + /** * @param LoopResult $loopResult * @@ -33,9 +38,27 @@ class ImportExportType extends BaseLoop implements PropelSearchLoopInterface */ public function parseResults(LoopResult $loopResult) { - // TODO: Implement parseResults() method. - } + foreach ($loopResult->getResultDataCollection() as $type) { + $loopResultRow = new LoopResultRow($type); + $url = URL::getInstance()->absoluteUrl( + $this->getBaseUrl() . DS . $type->getId() + ); + + $loopResultRow + ->set("ID", $type->getId()) + ->set("TITLE", $type->getTitle()) + ->set("DESCRIPTION", $type->getDescription()) + ->set("URL", $type->isImport() ? $url : null) + ->set("POSITION", $type->getPosition()) + ->set("CATEGORY_ID", $type->getImportExportCategoryId()) + ; + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } /** * this method returns a Propel ModelCriteria @@ -44,7 +67,42 @@ class ImportExportType extends BaseLoop implements PropelSearchLoopInterface */ public function buildModelCriteria() { - // TODO: Implement buildModelCriteria() method. + $query = $this->getQueryModel(); + + if (null !== $ids = $this->getId()) { + $query->filterById($ids); + } + + if (null !== $categories = $this->getCategory()) { + $query->filterBy($this->getCategoryName(), $categories, Criteria::IN); + } + + if (null !== $orders = $this->getOrder()) { + foreach ($orders as $order) { + switch($order) { + case "id": + $query->orderById(); + break; + case "id_reverse": + $query->orderById(Criteria::DESC); + break; + case "alpha": + $query->addAscendingOrderByColumn("i18n_TITLE"); + break; + case "alpha_reverse": + $query->addDescendingOrderByColumn("i18n_TITLE"); + break; + case "manual": + $query->orderByPosition(); + break; + case "manual_reverse": + $query->orderByPosition(Criteria::DESC); + break; + } + } + } + + return $query; } /** @@ -75,6 +133,7 @@ class ImportExportType extends BaseLoop implements PropelSearchLoopInterface { return new ArgumentCollection( Argument::createIntListTypeArgument('id'), + Argument::createIntListTypeArgument('category'), new Argument( "order", new TypeCollection( @@ -84,4 +143,10 @@ class ImportExportType extends BaseLoop implements PropelSearchLoopInterface ) ); } + + abstract protected function getBaseUrl(); + + abstract protected function getQueryModel(); + + abstract protected function getCategoryName(); } \ No newline at end of file diff --git a/core/lib/Thelia/Model/Base/Export.php b/core/lib/Thelia/Model/Base/Export.php new file mode 100644 index 000000000..b5902b177 --- /dev/null +++ b/core/lib/Thelia/Model/Base/Export.php @@ -0,0 +1,1884 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another Export instance. If + * obj is an instance of Export, delegates to + * equals(Export). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return Export The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return Export The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [export_category_id] column value. + * + * @return int + */ + public function getExportCategoryId() + { + + return $this->export_category_id; + } + + /** + * Get the [position] column value. + * + * @return int + */ + public function getPosition() + { + + return $this->position; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; + } + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \Thelia\Model\Export The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[ExportTableMap::ID] = true; + } + + + return $this; + } // setId() + + /** + * Set the value of [export_category_id] column. + * + * @param int $v new value + * @return \Thelia\Model\Export The current object (for fluent API support) + */ + public function setExportCategoryId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->export_category_id !== $v) { + $this->export_category_id = $v; + $this->modifiedColumns[ExportTableMap::EXPORT_CATEGORY_ID] = true; + } + + if ($this->aExportCategory !== null && $this->aExportCategory->getId() !== $v) { + $this->aExportCategory = null; + } + + + return $this; + } // setExportCategoryId() + + /** + * Set the value of [position] column. + * + * @param int $v new value + * @return \Thelia\Model\Export The current object (for fluent API support) + */ + public function setPosition($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->position !== $v) { + $this->position = $v; + $this->modifiedColumns[ExportTableMap::POSITION] = true; + } + + + return $this; + } // setPosition() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\Export The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[ExportTableMap::CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\Export The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[ExportTableMap::UPDATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ExportTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ExportTableMap::translateFieldName('ExportCategoryId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->export_category_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ExportTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; + $this->position = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ExportTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ExportTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 5; // 5 = ExportTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\Export object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aExportCategory !== null && $this->export_category_id !== $this->aExportCategory->getId()) { + $this->aExportCategory = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ExportTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildExportQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aExportCategory = null; + $this->collExportI18ns = null; + + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see Export::setDeleted() + * @see Export::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildExportQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(ExportTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(ExportTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(ExportTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + ExportTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aExportCategory !== null) { + if ($this->aExportCategory->isModified() || $this->aExportCategory->isNew()) { + $affectedRows += $this->aExportCategory->save($con); + } + $this->setExportCategory($this->aExportCategory); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + if ($this->exportI18nsScheduledForDeletion !== null) { + if (!$this->exportI18nsScheduledForDeletion->isEmpty()) { + \Thelia\Model\ExportI18nQuery::create() + ->filterByPrimaryKeys($this->exportI18nsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->exportI18nsScheduledForDeletion = null; + } + } + + if ($this->collExportI18ns !== null) { + foreach ($this->collExportI18ns as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[ExportTableMap::ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . ExportTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(ExportTableMap::ID)) { + $modifiedColumns[':p' . $index++] = '`ID`'; + } + if ($this->isColumnModified(ExportTableMap::EXPORT_CATEGORY_ID)) { + $modifiedColumns[':p' . $index++] = '`EXPORT_CATEGORY_ID`'; + } + if ($this->isColumnModified(ExportTableMap::POSITION)) { + $modifiedColumns[':p' . $index++] = '`POSITION`'; + } + if ($this->isColumnModified(ExportTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = '`CREATED_AT`'; + } + if ($this->isColumnModified(ExportTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = '`UPDATED_AT`'; + } + + $sql = sprintf( + 'INSERT INTO `export` (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case '`ID`': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case '`EXPORT_CATEGORY_ID`': + $stmt->bindValue($identifier, $this->export_category_id, PDO::PARAM_INT); + break; + case '`POSITION`': + $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); + break; + case '`CREATED_AT`': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case '`UPDATED_AT`': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = ExportTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getExportCategoryId(); + break; + case 2: + return $this->getPosition(); + break; + case 3: + return $this->getCreatedAt(); + break; + case 4: + return $this->getUpdatedAt(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['Export'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['Export'][$this->getPrimaryKey()] = true; + $keys = ExportTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getExportCategoryId(), + $keys[2] => $this->getPosition(), + $keys[3] => $this->getCreatedAt(), + $keys[4] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aExportCategory) { + $result['ExportCategory'] = $this->aExportCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->collExportI18ns) { + $result['ExportI18ns'] = $this->collExportI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = ExportTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setExportCategoryId($value); + break; + case 2: + $this->setPosition($value); + break; + case 3: + $this->setCreatedAt($value); + break; + case 4: + $this->setUpdatedAt($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = ExportTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setExportCategoryId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setPosition($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(ExportTableMap::DATABASE_NAME); + + if ($this->isColumnModified(ExportTableMap::ID)) $criteria->add(ExportTableMap::ID, $this->id); + if ($this->isColumnModified(ExportTableMap::EXPORT_CATEGORY_ID)) $criteria->add(ExportTableMap::EXPORT_CATEGORY_ID, $this->export_category_id); + if ($this->isColumnModified(ExportTableMap::POSITION)) $criteria->add(ExportTableMap::POSITION, $this->position); + if ($this->isColumnModified(ExportTableMap::CREATED_AT)) $criteria->add(ExportTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(ExportTableMap::UPDATED_AT)) $criteria->add(ExportTableMap::UPDATED_AT, $this->updated_at); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(ExportTableMap::DATABASE_NAME); + $criteria->add(ExportTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Thelia\Model\Export (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setExportCategoryId($this->getExportCategoryId()); + $copyObj->setPosition($this->getPosition()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + + if ($deepCopy) { + // important: temporarily setNew(false) because this affects the behavior of + // the getter/setter methods for fkey referrer objects. + $copyObj->setNew(false); + + foreach ($this->getExportI18ns() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addExportI18n($relObj->copy($deepCopy)); + } + } + + } // if ($deepCopy) + + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Thelia\Model\Export Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildExportCategory object. + * + * @param ChildExportCategory $v + * @return \Thelia\Model\Export The current object (for fluent API support) + * @throws PropelException + */ + public function setExportCategory(ChildExportCategory $v = null) + { + if ($v === null) { + $this->setExportCategoryId(NULL); + } else { + $this->setExportCategoryId($v->getId()); + } + + $this->aExportCategory = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildExportCategory object, it will not be re-added. + if ($v !== null) { + $v->addExport($this); + } + + + return $this; + } + + + /** + * Get the associated ChildExportCategory object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildExportCategory The associated ChildExportCategory object. + * @throws PropelException + */ + public function getExportCategory(ConnectionInterface $con = null) + { + if ($this->aExportCategory === null && ($this->export_category_id !== null)) { + $this->aExportCategory = ChildExportCategoryQuery::create()->findPk($this->export_category_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aExportCategory->addExports($this); + */ + } + + return $this->aExportCategory; + } + + + /** + * Initializes a collection based on the name of a relation. + * Avoids crafting an 'init[$relationName]s' method name + * that wouldn't work when StandardEnglishPluralizer is used. + * + * @param string $relationName The name of the relation to initialize + * @return void + */ + public function initRelation($relationName) + { + if ('ExportI18n' == $relationName) { + return $this->initExportI18ns(); + } + } + + /** + * Clears out the collExportI18ns collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addExportI18ns() + */ + public function clearExportI18ns() + { + $this->collExportI18ns = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collExportI18ns collection loaded partially. + */ + public function resetPartialExportI18ns($v = true) + { + $this->collExportI18nsPartial = $v; + } + + /** + * Initializes the collExportI18ns collection. + * + * By default this just sets the collExportI18ns collection to an empty array (like clearcollExportI18ns()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initExportI18ns($overrideExisting = true) + { + if (null !== $this->collExportI18ns && !$overrideExisting) { + return; + } + $this->collExportI18ns = new ObjectCollection(); + $this->collExportI18ns->setModel('\Thelia\Model\ExportI18n'); + } + + /** + * Gets an array of ChildExportI18n objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildExport is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildExportI18n[] List of ChildExportI18n objects + * @throws PropelException + */ + public function getExportI18ns($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collExportI18nsPartial && !$this->isNew(); + if (null === $this->collExportI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collExportI18ns) { + // return empty collection + $this->initExportI18ns(); + } else { + $collExportI18ns = ChildExportI18nQuery::create(null, $criteria) + ->filterByExport($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collExportI18nsPartial && count($collExportI18ns)) { + $this->initExportI18ns(false); + + foreach ($collExportI18ns as $obj) { + if (false == $this->collExportI18ns->contains($obj)) { + $this->collExportI18ns->append($obj); + } + } + + $this->collExportI18nsPartial = true; + } + + reset($collExportI18ns); + + return $collExportI18ns; + } + + if ($partial && $this->collExportI18ns) { + foreach ($this->collExportI18ns as $obj) { + if ($obj->isNew()) { + $collExportI18ns[] = $obj; + } + } + } + + $this->collExportI18ns = $collExportI18ns; + $this->collExportI18nsPartial = false; + } + } + + return $this->collExportI18ns; + } + + /** + * Sets a collection of ExportI18n objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $exportI18ns A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildExport The current object (for fluent API support) + */ + public function setExportI18ns(Collection $exportI18ns, ConnectionInterface $con = null) + { + $exportI18nsToDelete = $this->getExportI18ns(new Criteria(), $con)->diff($exportI18ns); + + + //since at least one column in the foreign key is at the same time a PK + //we can not just set a PK to NULL in the lines below. We have to store + //a backup of all values, so we are able to manipulate these items based on the onDelete value later. + $this->exportI18nsScheduledForDeletion = clone $exportI18nsToDelete; + + foreach ($exportI18nsToDelete as $exportI18nRemoved) { + $exportI18nRemoved->setExport(null); + } + + $this->collExportI18ns = null; + foreach ($exportI18ns as $exportI18n) { + $this->addExportI18n($exportI18n); + } + + $this->collExportI18ns = $exportI18ns; + $this->collExportI18nsPartial = false; + + return $this; + } + + /** + * Returns the number of related ExportI18n objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related ExportI18n objects. + * @throws PropelException + */ + public function countExportI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collExportI18nsPartial && !$this->isNew(); + if (null === $this->collExportI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collExportI18ns) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getExportI18ns()); + } + + $query = ChildExportI18nQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByExport($this) + ->count($con); + } + + return count($this->collExportI18ns); + } + + /** + * Method called to associate a ChildExportI18n object to this object + * through the ChildExportI18n foreign key attribute. + * + * @param ChildExportI18n $l ChildExportI18n + * @return \Thelia\Model\Export The current object (for fluent API support) + */ + public function addExportI18n(ChildExportI18n $l) + { + if ($l && $locale = $l->getLocale()) { + $this->setLocale($locale); + $this->currentTranslations[$locale] = $l; + } + if ($this->collExportI18ns === null) { + $this->initExportI18ns(); + $this->collExportI18nsPartial = true; + } + + if (!in_array($l, $this->collExportI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddExportI18n($l); + } + + return $this; + } + + /** + * @param ExportI18n $exportI18n The exportI18n object to add. + */ + protected function doAddExportI18n($exportI18n) + { + $this->collExportI18ns[]= $exportI18n; + $exportI18n->setExport($this); + } + + /** + * @param ExportI18n $exportI18n The exportI18n object to remove. + * @return ChildExport The current object (for fluent API support) + */ + public function removeExportI18n($exportI18n) + { + if ($this->getExportI18ns()->contains($exportI18n)) { + $this->collExportI18ns->remove($this->collExportI18ns->search($exportI18n)); + if (null === $this->exportI18nsScheduledForDeletion) { + $this->exportI18nsScheduledForDeletion = clone $this->collExportI18ns; + $this->exportI18nsScheduledForDeletion->clear(); + } + $this->exportI18nsScheduledForDeletion[]= clone $exportI18n; + $exportI18n->setExport(null); + } + + return $this; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->export_category_id = null; + $this->position = null; + $this->created_at = null; + $this->updated_at = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + if ($this->collExportI18ns) { + foreach ($this->collExportI18ns as $o) { + $o->clearAllReferences($deep); + } + } + } // if ($deep) + + // i18n behavior + $this->currentLocale = 'en_US'; + $this->currentTranslations = null; + + $this->collExportI18ns = null; + $this->aExportCategory = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(ExportTableMap::DEFAULT_STRING_FORMAT); + } + + // i18n behavior + + /** + * Sets the locale for translations + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * + * @return ChildExport The current object (for fluent API support) + */ + public function setLocale($locale = 'en_US') + { + $this->currentLocale = $locale; + + return $this; + } + + /** + * Gets the locale for translations + * + * @return string $locale Locale to use for the translation, e.g. 'fr_FR' + */ + public function getLocale() + { + return $this->currentLocale; + } + + /** + * Returns the current translation for a given locale + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * @param ConnectionInterface $con an optional connection object + * + * @return ChildExportI18n */ + public function getTranslation($locale = 'en_US', ConnectionInterface $con = null) + { + if (!isset($this->currentTranslations[$locale])) { + if (null !== $this->collExportI18ns) { + foreach ($this->collExportI18ns as $translation) { + if ($translation->getLocale() == $locale) { + $this->currentTranslations[$locale] = $translation; + + return $translation; + } + } + } + if ($this->isNew()) { + $translation = new ChildExportI18n(); + $translation->setLocale($locale); + } else { + $translation = ChildExportI18nQuery::create() + ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->findOneOrCreate($con); + $this->currentTranslations[$locale] = $translation; + } + $this->addExportI18n($translation); + } + + return $this->currentTranslations[$locale]; + } + + /** + * Remove the translation for a given locale + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * @param ConnectionInterface $con an optional connection object + * + * @return ChildExport The current object (for fluent API support) + */ + public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null) + { + if (!$this->isNew()) { + ChildExportI18nQuery::create() + ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->delete($con); + } + if (isset($this->currentTranslations[$locale])) { + unset($this->currentTranslations[$locale]); + } + foreach ($this->collExportI18ns as $key => $translation) { + if ($translation->getLocale() == $locale) { + unset($this->collExportI18ns[$key]); + break; + } + } + + return $this; + } + + /** + * Returns the current translation + * + * @param ConnectionInterface $con an optional connection object + * + * @return ChildExportI18n */ + public function getCurrentTranslation(ConnectionInterface $con = null) + { + return $this->getTranslation($this->getLocale(), $con); + } + + + /** + * Get the [title] column value. + * + * @return string + */ + public function getTitle() + { + return $this->getCurrentTranslation()->getTitle(); + } + + + /** + * Set the value of [title] column. + * + * @param string $v new value + * @return \Thelia\Model\ExportI18n The current object (for fluent API support) + */ + public function setTitle($v) + { $this->getCurrentTranslation()->setTitle($v); + + return $this; + } + + + /** + * Get the [description] column value. + * + * @return string + */ + public function getDescription() + { + return $this->getCurrentTranslation()->getDescription(); + } + + + /** + * Set the value of [description] column. + * + * @param string $v new value + * @return \Thelia\Model\ExportI18n The current object (for fluent API support) + */ + public function setDescription($v) + { $this->getCurrentTranslation()->setDescription($v); + + return $this; + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildExport The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[ExportTableMap::UPDATED_AT] = true; + + return $this; + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/core/lib/Thelia/Model/Base/ExportCategory.php b/core/lib/Thelia/Model/Base/ExportCategory.php new file mode 100644 index 000000000..c100fc5b9 --- /dev/null +++ b/core/lib/Thelia/Model/Base/ExportCategory.php @@ -0,0 +1,1989 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another ExportCategory instance. If + * obj is an instance of ExportCategory, delegates to + * equals(ExportCategory). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return ExportCategory The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return ExportCategory The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [position] column value. + * + * @return int + */ + public function getPosition() + { + + return $this->position; + } + + /** + * Get the [optionally formatted] temporal [created_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getCreatedAt($format = NULL) + { + if ($format === null) { + return $this->created_at; + } else { + return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; + } + } + + /** + * Get the [optionally formatted] temporal [updated_at] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw \DateTime object will be returned. + * + * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 + * + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getUpdatedAt($format = NULL) + { + if ($format === null) { + return $this->updated_at; + } else { + return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; + } + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \Thelia\Model\ExportCategory The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[ExportCategoryTableMap::ID] = true; + } + + + return $this; + } // setId() + + /** + * Set the value of [position] column. + * + * @param int $v new value + * @return \Thelia\Model\ExportCategory The current object (for fluent API support) + */ + public function setPosition($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->position !== $v) { + $this->position = $v; + $this->modifiedColumns[ExportCategoryTableMap::POSITION] = true; + } + + + return $this; + } // setPosition() + + /** + * Sets the value of [created_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\ExportCategory The current object (for fluent API support) + */ + public function setCreatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->created_at !== null || $dt !== null) { + if ($dt !== $this->created_at) { + $this->created_at = $dt; + $this->modifiedColumns[ExportCategoryTableMap::CREATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setCreatedAt() + + /** + * Sets the value of [updated_at] column to a normalized version of the date/time value specified. + * + * @param mixed $v string, integer (timestamp), or \DateTime value. + * Empty strings are treated as NULL. + * @return \Thelia\Model\ExportCategory The current object (for fluent API support) + */ + public function setUpdatedAt($v) + { + $dt = PropelDateTime::newInstance($v, null, '\DateTime'); + if ($this->updated_at !== null || $dt !== null) { + if ($dt !== $this->updated_at) { + $this->updated_at = $dt; + $this->modifiedColumns[ExportCategoryTableMap::UPDATED_AT] = true; + } + } // if either are not null + + + return $this; + } // setUpdatedAt() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ExportCategoryTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ExportCategoryTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; + $this->position = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ExportCategoryTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ExportCategoryTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + if ($col === '0000-00-00 00:00:00') { + $col = null; + } + $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 4; // 4 = ExportCategoryTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\ExportCategory object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ExportCategoryTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildExportCategoryQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->collExports = null; + + $this->collExportCategoryI18ns = null; + + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see ExportCategory::setDeleted() + * @see ExportCategory::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildExportCategoryQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + // timestampable behavior + if (!$this->isColumnModified(ExportCategoryTableMap::CREATED_AT)) { + $this->setCreatedAt(time()); + } + if (!$this->isColumnModified(ExportCategoryTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } else { + $ret = $ret && $this->preUpdate($con); + // timestampable behavior + if ($this->isModified() && !$this->isColumnModified(ExportCategoryTableMap::UPDATED_AT)) { + $this->setUpdatedAt(time()); + } + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + ExportCategoryTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + if ($this->exportsScheduledForDeletion !== null) { + if (!$this->exportsScheduledForDeletion->isEmpty()) { + \Thelia\Model\ExportQuery::create() + ->filterByPrimaryKeys($this->exportsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->exportsScheduledForDeletion = null; + } + } + + if ($this->collExports !== null) { + foreach ($this->collExports as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + if ($this->exportCategoryI18nsScheduledForDeletion !== null) { + if (!$this->exportCategoryI18nsScheduledForDeletion->isEmpty()) { + \Thelia\Model\ExportCategoryI18nQuery::create() + ->filterByPrimaryKeys($this->exportCategoryI18nsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->exportCategoryI18nsScheduledForDeletion = null; + } + } + + if ($this->collExportCategoryI18ns !== null) { + foreach ($this->collExportCategoryI18ns as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[ExportCategoryTableMap::ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . ExportCategoryTableMap::ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(ExportCategoryTableMap::ID)) { + $modifiedColumns[':p' . $index++] = '`ID`'; + } + if ($this->isColumnModified(ExportCategoryTableMap::POSITION)) { + $modifiedColumns[':p' . $index++] = '`POSITION`'; + } + if ($this->isColumnModified(ExportCategoryTableMap::CREATED_AT)) { + $modifiedColumns[':p' . $index++] = '`CREATED_AT`'; + } + if ($this->isColumnModified(ExportCategoryTableMap::UPDATED_AT)) { + $modifiedColumns[':p' . $index++] = '`UPDATED_AT`'; + } + + $sql = sprintf( + 'INSERT INTO `export_category` (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case '`ID`': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case '`POSITION`': + $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); + break; + case '`CREATED_AT`': + $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + case '`UPDATED_AT`': + $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = ExportCategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getPosition(); + break; + case 2: + return $this->getCreatedAt(); + break; + case 3: + return $this->getUpdatedAt(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['ExportCategory'][$this->getPrimaryKey()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['ExportCategory'][$this->getPrimaryKey()] = true; + $keys = ExportCategoryTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getPosition(), + $keys[2] => $this->getCreatedAt(), + $keys[3] => $this->getUpdatedAt(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->collExports) { + $result['Exports'] = $this->collExports->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + if (null !== $this->collExportCategoryI18ns) { + $result['ExportCategoryI18ns'] = $this->collExportCategoryI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = ExportCategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setPosition($value); + break; + case 2: + $this->setCreatedAt($value); + break; + case 3: + $this->setUpdatedAt($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = ExportCategoryTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setPosition($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setCreatedAt($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setUpdatedAt($arr[$keys[3]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(ExportCategoryTableMap::DATABASE_NAME); + + if ($this->isColumnModified(ExportCategoryTableMap::ID)) $criteria->add(ExportCategoryTableMap::ID, $this->id); + if ($this->isColumnModified(ExportCategoryTableMap::POSITION)) $criteria->add(ExportCategoryTableMap::POSITION, $this->position); + if ($this->isColumnModified(ExportCategoryTableMap::CREATED_AT)) $criteria->add(ExportCategoryTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(ExportCategoryTableMap::UPDATED_AT)) $criteria->add(ExportCategoryTableMap::UPDATED_AT, $this->updated_at); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(ExportCategoryTableMap::DATABASE_NAME); + $criteria->add(ExportCategoryTableMap::ID, $this->id); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Thelia\Model\ExportCategory (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setPosition($this->getPosition()); + $copyObj->setCreatedAt($this->getCreatedAt()); + $copyObj->setUpdatedAt($this->getUpdatedAt()); + + if ($deepCopy) { + // important: temporarily setNew(false) because this affects the behavior of + // the getter/setter methods for fkey referrer objects. + $copyObj->setNew(false); + + foreach ($this->getExports() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addExport($relObj->copy($deepCopy)); + } + } + + foreach ($this->getExportCategoryI18ns() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addExportCategoryI18n($relObj->copy($deepCopy)); + } + } + + } // if ($deepCopy) + + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Thelia\Model\ExportCategory Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + + /** + * Initializes a collection based on the name of a relation. + * Avoids crafting an 'init[$relationName]s' method name + * that wouldn't work when StandardEnglishPluralizer is used. + * + * @param string $relationName The name of the relation to initialize + * @return void + */ + public function initRelation($relationName) + { + if ('Export' == $relationName) { + return $this->initExports(); + } + if ('ExportCategoryI18n' == $relationName) { + return $this->initExportCategoryI18ns(); + } + } + + /** + * Clears out the collExports collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addExports() + */ + public function clearExports() + { + $this->collExports = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collExports collection loaded partially. + */ + public function resetPartialExports($v = true) + { + $this->collExportsPartial = $v; + } + + /** + * Initializes the collExports collection. + * + * By default this just sets the collExports collection to an empty array (like clearcollExports()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initExports($overrideExisting = true) + { + if (null !== $this->collExports && !$overrideExisting) { + return; + } + $this->collExports = new ObjectCollection(); + $this->collExports->setModel('\Thelia\Model\Export'); + } + + /** + * Gets an array of ChildExport objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildExportCategory is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildExport[] List of ChildExport objects + * @throws PropelException + */ + public function getExports($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collExportsPartial && !$this->isNew(); + if (null === $this->collExports || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collExports) { + // return empty collection + $this->initExports(); + } else { + $collExports = ChildExportQuery::create(null, $criteria) + ->filterByExportCategory($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collExportsPartial && count($collExports)) { + $this->initExports(false); + + foreach ($collExports as $obj) { + if (false == $this->collExports->contains($obj)) { + $this->collExports->append($obj); + } + } + + $this->collExportsPartial = true; + } + + reset($collExports); + + return $collExports; + } + + if ($partial && $this->collExports) { + foreach ($this->collExports as $obj) { + if ($obj->isNew()) { + $collExports[] = $obj; + } + } + } + + $this->collExports = $collExports; + $this->collExportsPartial = false; + } + } + + return $this->collExports; + } + + /** + * Sets a collection of Export objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $exports A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildExportCategory The current object (for fluent API support) + */ + public function setExports(Collection $exports, ConnectionInterface $con = null) + { + $exportsToDelete = $this->getExports(new Criteria(), $con)->diff($exports); + + + $this->exportsScheduledForDeletion = $exportsToDelete; + + foreach ($exportsToDelete as $exportRemoved) { + $exportRemoved->setExportCategory(null); + } + + $this->collExports = null; + foreach ($exports as $export) { + $this->addExport($export); + } + + $this->collExports = $exports; + $this->collExportsPartial = false; + + return $this; + } + + /** + * Returns the number of related Export objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related Export objects. + * @throws PropelException + */ + public function countExports(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collExportsPartial && !$this->isNew(); + if (null === $this->collExports || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collExports) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getExports()); + } + + $query = ChildExportQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByExportCategory($this) + ->count($con); + } + + return count($this->collExports); + } + + /** + * Method called to associate a ChildExport object to this object + * through the ChildExport foreign key attribute. + * + * @param ChildExport $l ChildExport + * @return \Thelia\Model\ExportCategory The current object (for fluent API support) + */ + public function addExport(ChildExport $l) + { + if ($this->collExports === null) { + $this->initExports(); + $this->collExportsPartial = true; + } + + if (!in_array($l, $this->collExports->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddExport($l); + } + + return $this; + } + + /** + * @param Export $export The export object to add. + */ + protected function doAddExport($export) + { + $this->collExports[]= $export; + $export->setExportCategory($this); + } + + /** + * @param Export $export The export object to remove. + * @return ChildExportCategory The current object (for fluent API support) + */ + public function removeExport($export) + { + if ($this->getExports()->contains($export)) { + $this->collExports->remove($this->collExports->search($export)); + if (null === $this->exportsScheduledForDeletion) { + $this->exportsScheduledForDeletion = clone $this->collExports; + $this->exportsScheduledForDeletion->clear(); + } + $this->exportsScheduledForDeletion[]= clone $export; + $export->setExportCategory(null); + } + + return $this; + } + + /** + * Clears out the collExportCategoryI18ns collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addExportCategoryI18ns() + */ + public function clearExportCategoryI18ns() + { + $this->collExportCategoryI18ns = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collExportCategoryI18ns collection loaded partially. + */ + public function resetPartialExportCategoryI18ns($v = true) + { + $this->collExportCategoryI18nsPartial = $v; + } + + /** + * Initializes the collExportCategoryI18ns collection. + * + * By default this just sets the collExportCategoryI18ns collection to an empty array (like clearcollExportCategoryI18ns()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initExportCategoryI18ns($overrideExisting = true) + { + if (null !== $this->collExportCategoryI18ns && !$overrideExisting) { + return; + } + $this->collExportCategoryI18ns = new ObjectCollection(); + $this->collExportCategoryI18ns->setModel('\Thelia\Model\ExportCategoryI18n'); + } + + /** + * Gets an array of ChildExportCategoryI18n objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildExportCategory is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return Collection|ChildExportCategoryI18n[] List of ChildExportCategoryI18n objects + * @throws PropelException + */ + public function getExportCategoryI18ns($criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collExportCategoryI18nsPartial && !$this->isNew(); + if (null === $this->collExportCategoryI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collExportCategoryI18ns) { + // return empty collection + $this->initExportCategoryI18ns(); + } else { + $collExportCategoryI18ns = ChildExportCategoryI18nQuery::create(null, $criteria) + ->filterByExportCategory($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collExportCategoryI18nsPartial && count($collExportCategoryI18ns)) { + $this->initExportCategoryI18ns(false); + + foreach ($collExportCategoryI18ns as $obj) { + if (false == $this->collExportCategoryI18ns->contains($obj)) { + $this->collExportCategoryI18ns->append($obj); + } + } + + $this->collExportCategoryI18nsPartial = true; + } + + reset($collExportCategoryI18ns); + + return $collExportCategoryI18ns; + } + + if ($partial && $this->collExportCategoryI18ns) { + foreach ($this->collExportCategoryI18ns as $obj) { + if ($obj->isNew()) { + $collExportCategoryI18ns[] = $obj; + } + } + } + + $this->collExportCategoryI18ns = $collExportCategoryI18ns; + $this->collExportCategoryI18nsPartial = false; + } + } + + return $this->collExportCategoryI18ns; + } + + /** + * Sets a collection of ExportCategoryI18n objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $exportCategoryI18ns A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return ChildExportCategory The current object (for fluent API support) + */ + public function setExportCategoryI18ns(Collection $exportCategoryI18ns, ConnectionInterface $con = null) + { + $exportCategoryI18nsToDelete = $this->getExportCategoryI18ns(new Criteria(), $con)->diff($exportCategoryI18ns); + + + //since at least one column in the foreign key is at the same time a PK + //we can not just set a PK to NULL in the lines below. We have to store + //a backup of all values, so we are able to manipulate these items based on the onDelete value later. + $this->exportCategoryI18nsScheduledForDeletion = clone $exportCategoryI18nsToDelete; + + foreach ($exportCategoryI18nsToDelete as $exportCategoryI18nRemoved) { + $exportCategoryI18nRemoved->setExportCategory(null); + } + + $this->collExportCategoryI18ns = null; + foreach ($exportCategoryI18ns as $exportCategoryI18n) { + $this->addExportCategoryI18n($exportCategoryI18n); + } + + $this->collExportCategoryI18ns = $exportCategoryI18ns; + $this->collExportCategoryI18nsPartial = false; + + return $this; + } + + /** + * Returns the number of related ExportCategoryI18n objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related ExportCategoryI18n objects. + * @throws PropelException + */ + public function countExportCategoryI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collExportCategoryI18nsPartial && !$this->isNew(); + if (null === $this->collExportCategoryI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collExportCategoryI18ns) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getExportCategoryI18ns()); + } + + $query = ChildExportCategoryI18nQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByExportCategory($this) + ->count($con); + } + + return count($this->collExportCategoryI18ns); + } + + /** + * Method called to associate a ChildExportCategoryI18n object to this object + * through the ChildExportCategoryI18n foreign key attribute. + * + * @param ChildExportCategoryI18n $l ChildExportCategoryI18n + * @return \Thelia\Model\ExportCategory The current object (for fluent API support) + */ + public function addExportCategoryI18n(ChildExportCategoryI18n $l) + { + if ($l && $locale = $l->getLocale()) { + $this->setLocale($locale); + $this->currentTranslations[$locale] = $l; + } + if ($this->collExportCategoryI18ns === null) { + $this->initExportCategoryI18ns(); + $this->collExportCategoryI18nsPartial = true; + } + + if (!in_array($l, $this->collExportCategoryI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddExportCategoryI18n($l); + } + + return $this; + } + + /** + * @param ExportCategoryI18n $exportCategoryI18n The exportCategoryI18n object to add. + */ + protected function doAddExportCategoryI18n($exportCategoryI18n) + { + $this->collExportCategoryI18ns[]= $exportCategoryI18n; + $exportCategoryI18n->setExportCategory($this); + } + + /** + * @param ExportCategoryI18n $exportCategoryI18n The exportCategoryI18n object to remove. + * @return ChildExportCategory The current object (for fluent API support) + */ + public function removeExportCategoryI18n($exportCategoryI18n) + { + if ($this->getExportCategoryI18ns()->contains($exportCategoryI18n)) { + $this->collExportCategoryI18ns->remove($this->collExportCategoryI18ns->search($exportCategoryI18n)); + if (null === $this->exportCategoryI18nsScheduledForDeletion) { + $this->exportCategoryI18nsScheduledForDeletion = clone $this->collExportCategoryI18ns; + $this->exportCategoryI18nsScheduledForDeletion->clear(); + } + $this->exportCategoryI18nsScheduledForDeletion[]= clone $exportCategoryI18n; + $exportCategoryI18n->setExportCategory(null); + } + + return $this; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->position = null; + $this->created_at = null; + $this->updated_at = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + if ($this->collExports) { + foreach ($this->collExports as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collExportCategoryI18ns) { + foreach ($this->collExportCategoryI18ns as $o) { + $o->clearAllReferences($deep); + } + } + } // if ($deep) + + // i18n behavior + $this->currentLocale = 'en_US'; + $this->currentTranslations = null; + + $this->collExports = null; + $this->collExportCategoryI18ns = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(ExportCategoryTableMap::DEFAULT_STRING_FORMAT); + } + + // i18n behavior + + /** + * Sets the locale for translations + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * + * @return ChildExportCategory The current object (for fluent API support) + */ + public function setLocale($locale = 'en_US') + { + $this->currentLocale = $locale; + + return $this; + } + + /** + * Gets the locale for translations + * + * @return string $locale Locale to use for the translation, e.g. 'fr_FR' + */ + public function getLocale() + { + return $this->currentLocale; + } + + /** + * Returns the current translation for a given locale + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * @param ConnectionInterface $con an optional connection object + * + * @return ChildExportCategoryI18n */ + public function getTranslation($locale = 'en_US', ConnectionInterface $con = null) + { + if (!isset($this->currentTranslations[$locale])) { + if (null !== $this->collExportCategoryI18ns) { + foreach ($this->collExportCategoryI18ns as $translation) { + if ($translation->getLocale() == $locale) { + $this->currentTranslations[$locale] = $translation; + + return $translation; + } + } + } + if ($this->isNew()) { + $translation = new ChildExportCategoryI18n(); + $translation->setLocale($locale); + } else { + $translation = ChildExportCategoryI18nQuery::create() + ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->findOneOrCreate($con); + $this->currentTranslations[$locale] = $translation; + } + $this->addExportCategoryI18n($translation); + } + + return $this->currentTranslations[$locale]; + } + + /** + * Remove the translation for a given locale + * + * @param string $locale Locale to use for the translation, e.g. 'fr_FR' + * @param ConnectionInterface $con an optional connection object + * + * @return ChildExportCategory The current object (for fluent API support) + */ + public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null) + { + if (!$this->isNew()) { + ChildExportCategoryI18nQuery::create() + ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) + ->delete($con); + } + if (isset($this->currentTranslations[$locale])) { + unset($this->currentTranslations[$locale]); + } + foreach ($this->collExportCategoryI18ns as $key => $translation) { + if ($translation->getLocale() == $locale) { + unset($this->collExportCategoryI18ns[$key]); + break; + } + } + + return $this; + } + + /** + * Returns the current translation + * + * @param ConnectionInterface $con an optional connection object + * + * @return ChildExportCategoryI18n */ + public function getCurrentTranslation(ConnectionInterface $con = null) + { + return $this->getTranslation($this->getLocale(), $con); + } + + + /** + * Get the [title] column value. + * + * @return string + */ + public function getTitle() + { + return $this->getCurrentTranslation()->getTitle(); + } + + + /** + * Set the value of [title] column. + * + * @param string $v new value + * @return \Thelia\Model\ExportCategoryI18n The current object (for fluent API support) + */ + public function setTitle($v) + { $this->getCurrentTranslation()->setTitle($v); + + return $this; + } + + // timestampable behavior + + /** + * Mark the current object so that the update date doesn't get updated during next save + * + * @return ChildExportCategory The current object (for fluent API support) + */ + public function keepUpdateDateUnchanged() + { + $this->modifiedColumns[ExportCategoryTableMap::UPDATED_AT] = true; + + return $this; + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/core/lib/Thelia/Model/Base/ExportCategoryI18n.php b/core/lib/Thelia/Model/Base/ExportCategoryI18n.php new file mode 100644 index 000000000..761f8239c --- /dev/null +++ b/core/lib/Thelia/Model/Base/ExportCategoryI18n.php @@ -0,0 +1,1268 @@ +locale = 'en_US'; + } + + /** + * Initializes internal state of Thelia\Model\Base\ExportCategoryI18n object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !!$this->modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another ExportCategoryI18n instance. If + * obj is an instance of ExportCategoryI18n, delegates to + * equals(ExportCategoryI18n). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return ExportCategoryI18n The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return ExportCategoryI18n The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [locale] column value. + * + * @return string + */ + public function getLocale() + { + + return $this->locale; + } + + /** + * Get the [title] column value. + * + * @return string + */ + public function getTitle() + { + + return $this->title; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \Thelia\Model\ExportCategoryI18n The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[ExportCategoryI18nTableMap::ID] = true; + } + + if ($this->aExportCategory !== null && $this->aExportCategory->getId() !== $v) { + $this->aExportCategory = null; + } + + + return $this; + } // setId() + + /** + * Set the value of [locale] column. + * + * @param string $v new value + * @return \Thelia\Model\ExportCategoryI18n The current object (for fluent API support) + */ + public function setLocale($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->locale !== $v) { + $this->locale = $v; + $this->modifiedColumns[ExportCategoryI18nTableMap::LOCALE] = true; + } + + + return $this; + } // setLocale() + + /** + * Set the value of [title] column. + * + * @param string $v new value + * @return \Thelia\Model\ExportCategoryI18n The current object (for fluent API support) + */ + public function setTitle($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->title !== $v) { + $this->title = $v; + $this->modifiedColumns[ExportCategoryI18nTableMap::TITLE] = true; + } + + + return $this; + } // setTitle() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + if ($this->locale !== 'en_US') { + return false; + } + + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ExportCategoryI18nTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ExportCategoryI18nTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; + $this->locale = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ExportCategoryI18nTableMap::translateFieldName('Title', TableMap::TYPE_PHPNAME, $indexType)]; + $this->title = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 3; // 3 = ExportCategoryI18nTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\ExportCategoryI18n object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aExportCategory !== null && $this->id !== $this->aExportCategory->getId()) { + $this->aExportCategory = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ExportCategoryI18nTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildExportCategoryI18nQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aExportCategory = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see ExportCategoryI18n::setDeleted() + * @see ExportCategoryI18n::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryI18nTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildExportCategoryI18nQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryI18nTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + ExportCategoryI18nTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aExportCategory !== null) { + if ($this->aExportCategory->isModified() || $this->aExportCategory->isNew()) { + $affectedRows += $this->aExportCategory->save($con); + } + $this->setExportCategory($this->aExportCategory); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(ExportCategoryI18nTableMap::ID)) { + $modifiedColumns[':p' . $index++] = '`ID`'; + } + if ($this->isColumnModified(ExportCategoryI18nTableMap::LOCALE)) { + $modifiedColumns[':p' . $index++] = '`LOCALE`'; + } + if ($this->isColumnModified(ExportCategoryI18nTableMap::TITLE)) { + $modifiedColumns[':p' . $index++] = '`TITLE`'; + } + + $sql = sprintf( + 'INSERT INTO `export_category_i18n` (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case '`ID`': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case '`LOCALE`': + $stmt->bindValue($identifier, $this->locale, PDO::PARAM_STR); + break; + case '`TITLE`': + $stmt->bindValue($identifier, $this->title, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = ExportCategoryI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getLocale(); + break; + case 2: + return $this->getTitle(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['ExportCategoryI18n'][serialize($this->getPrimaryKey())])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['ExportCategoryI18n'][serialize($this->getPrimaryKey())] = true; + $keys = ExportCategoryI18nTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getLocale(), + $keys[2] => $this->getTitle(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aExportCategory) { + $result['ExportCategory'] = $this->aExportCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = ExportCategoryI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setLocale($value); + break; + case 2: + $this->setTitle($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = ExportCategoryI18nTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setLocale($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setTitle($arr[$keys[2]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(ExportCategoryI18nTableMap::DATABASE_NAME); + + if ($this->isColumnModified(ExportCategoryI18nTableMap::ID)) $criteria->add(ExportCategoryI18nTableMap::ID, $this->id); + if ($this->isColumnModified(ExportCategoryI18nTableMap::LOCALE)) $criteria->add(ExportCategoryI18nTableMap::LOCALE, $this->locale); + if ($this->isColumnModified(ExportCategoryI18nTableMap::TITLE)) $criteria->add(ExportCategoryI18nTableMap::TITLE, $this->title); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(ExportCategoryI18nTableMap::DATABASE_NAME); + $criteria->add(ExportCategoryI18nTableMap::ID, $this->id); + $criteria->add(ExportCategoryI18nTableMap::LOCALE, $this->locale); + + return $criteria; + } + + /** + * Returns the composite primary key for this object. + * The array elements will be in same order as specified in XML. + * @return array + */ + public function getPrimaryKey() + { + $pks = array(); + $pks[0] = $this->getId(); + $pks[1] = $this->getLocale(); + + return $pks; + } + + /** + * Set the [composite] primary key. + * + * @param array $keys The elements of the composite key (order must match the order in XML file). + * @return void + */ + public function setPrimaryKey($keys) + { + $this->setId($keys[0]); + $this->setLocale($keys[1]); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return (null === $this->getId()) && (null === $this->getLocale()); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Thelia\Model\ExportCategoryI18n (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setLocale($this->getLocale()); + $copyObj->setTitle($this->getTitle()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Thelia\Model\ExportCategoryI18n Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildExportCategory object. + * + * @param ChildExportCategory $v + * @return \Thelia\Model\ExportCategoryI18n The current object (for fluent API support) + * @throws PropelException + */ + public function setExportCategory(ChildExportCategory $v = null) + { + if ($v === null) { + $this->setId(NULL); + } else { + $this->setId($v->getId()); + } + + $this->aExportCategory = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildExportCategory object, it will not be re-added. + if ($v !== null) { + $v->addExportCategoryI18n($this); + } + + + return $this; + } + + + /** + * Get the associated ChildExportCategory object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildExportCategory The associated ChildExportCategory object. + * @throws PropelException + */ + public function getExportCategory(ConnectionInterface $con = null) + { + if ($this->aExportCategory === null && ($this->id !== null)) { + $this->aExportCategory = ChildExportCategoryQuery::create()->findPk($this->id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aExportCategory->addExportCategoryI18ns($this); + */ + } + + return $this->aExportCategory; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->locale = null; + $this->title = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aExportCategory = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(ExportCategoryI18nTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/core/lib/Thelia/Model/Base/ExportCategoryI18nQuery.php b/core/lib/Thelia/Model/Base/ExportCategoryI18nQuery.php new file mode 100644 index 000000000..5dfc31870 --- /dev/null +++ b/core/lib/Thelia/Model/Base/ExportCategoryI18nQuery.php @@ -0,0 +1,508 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(array(12, 34), $con); + * + * + * @param array[$id, $locale] $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildExportCategoryI18n|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = ExportCategoryI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ExportCategoryI18nTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildExportCategoryI18n A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT `ID`, `LOCALE`, `TITLE` FROM `export_category_i18n` WHERE `ID` = :p0 AND `LOCALE` = :p1'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); + $stmt->bindValue(':p1', $key[1], PDO::PARAM_STR); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildExportCategoryI18n(); + $obj->hydrate($row); + ExportCategoryI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildExportCategoryI18n|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildExportCategoryI18nQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + $this->addUsingAlias(ExportCategoryI18nTableMap::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(ExportCategoryI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + + return $this; + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildExportCategoryI18nQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + if (empty($keys)) { + return $this->add(null, '1<>1', Criteria::CUSTOM); + } + foreach ($keys as $key) { + $cton0 = $this->getNewCriterion(ExportCategoryI18nTableMap::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(ExportCategoryI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $this->addOr($cton0); + } + + return $this; + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @see filterByExportCategory() + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportCategoryI18nQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(ExportCategoryI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(ExportCategoryI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ExportCategoryI18nTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the locale column + * + * Example usage: + * + * $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue' + * $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%' + * + * + * @param string $locale The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportCategoryI18nQuery The current query, for fluid interface + */ + public function filterByLocale($locale = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($locale)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $locale)) { + $locale = str_replace('*', '%', $locale); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ExportCategoryI18nTableMap::LOCALE, $locale, $comparison); + } + + /** + * Filter the query on the title column + * + * Example usage: + * + * $query->filterByTitle('fooValue'); // WHERE title = 'fooValue' + * $query->filterByTitle('%fooValue%'); // WHERE title LIKE '%fooValue%' + * + * + * @param string $title The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportCategoryI18nQuery The current query, for fluid interface + */ + public function filterByTitle($title = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($title)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $title)) { + $title = str_replace('*', '%', $title); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ExportCategoryI18nTableMap::TITLE, $title, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\ExportCategory object + * + * @param \Thelia\Model\ExportCategory|ObjectCollection $exportCategory The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportCategoryI18nQuery The current query, for fluid interface + */ + public function filterByExportCategory($exportCategory, $comparison = null) + { + if ($exportCategory instanceof \Thelia\Model\ExportCategory) { + return $this + ->addUsingAlias(ExportCategoryI18nTableMap::ID, $exportCategory->getId(), $comparison); + } elseif ($exportCategory instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(ExportCategoryI18nTableMap::ID, $exportCategory->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByExportCategory() only accepts arguments of type \Thelia\Model\ExportCategory or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the ExportCategory relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildExportCategoryI18nQuery The current query, for fluid interface + */ + public function joinExportCategory($relationAlias = null, $joinType = 'LEFT JOIN') + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('ExportCategory'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'ExportCategory'); + } + + return $this; + } + + /** + * Use the ExportCategory relation ExportCategory object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ExportCategoryQuery A secondary query class using the current class as primary query + */ + public function useExportCategoryQuery($relationAlias = null, $joinType = 'LEFT JOIN') + { + return $this + ->joinExportCategory($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ExportCategory', '\Thelia\Model\ExportCategoryQuery'); + } + + /** + * Exclude object from result + * + * @param ChildExportCategoryI18n $exportCategoryI18n Object to remove from the list of results + * + * @return ChildExportCategoryI18nQuery The current query, for fluid interface + */ + public function prune($exportCategoryI18n = null) + { + if ($exportCategoryI18n) { + $this->addCond('pruneCond0', $this->getAliasedColName(ExportCategoryI18nTableMap::ID), $exportCategoryI18n->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(ExportCategoryI18nTableMap::LOCALE), $exportCategoryI18n->getLocale(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); + } + + return $this; + } + + /** + * Deletes all rows from the export_category_i18n table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryI18nTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + ExportCategoryI18nTableMap::clearInstancePool(); + ExportCategoryI18nTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildExportCategoryI18n or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildExportCategoryI18n object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryI18nTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(ExportCategoryI18nTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + ExportCategoryI18nTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + ExportCategoryI18nTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // ExportCategoryI18nQuery diff --git a/core/lib/Thelia/Model/Base/ExportCategoryQuery.php b/core/lib/Thelia/Model/Base/ExportCategoryQuery.php new file mode 100644 index 000000000..af24f3f5a --- /dev/null +++ b/core/lib/Thelia/Model/Base/ExportCategoryQuery.php @@ -0,0 +1,764 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildExportCategory|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = ExportCategoryTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ExportCategoryTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildExportCategory A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT `ID`, `POSITION`, `CREATED_AT`, `UPDATED_AT` FROM `export_category` WHERE `ID` = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildExportCategory(); + $obj->hydrate($row); + ExportCategoryTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildExportCategory|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(ExportCategoryTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(ExportCategoryTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(ExportCategoryTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(ExportCategoryTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ExportCategoryTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the position column + * + * Example usage: + * + * $query->filterByPosition(1234); // WHERE position = 1234 + * $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34) + * $query->filterByPosition(array('min' => 12)); // WHERE position > 12 + * + * + * @param mixed $position The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function filterByPosition($position = null, $comparison = null) + { + if (is_array($position)) { + $useMinMax = false; + if (isset($position['min'])) { + $this->addUsingAlias(ExportCategoryTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($position['max'])) { + $this->addUsingAlias(ExportCategoryTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ExportCategoryTableMap::POSITION, $position, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(ExportCategoryTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(ExportCategoryTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ExportCategoryTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(ExportCategoryTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(ExportCategoryTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ExportCategoryTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Export object + * + * @param \Thelia\Model\Export|ObjectCollection $export the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function filterByExport($export, $comparison = null) + { + if ($export instanceof \Thelia\Model\Export) { + return $this + ->addUsingAlias(ExportCategoryTableMap::ID, $export->getExportCategoryId(), $comparison); + } elseif ($export instanceof ObjectCollection) { + return $this + ->useExportQuery() + ->filterByPrimaryKeys($export->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByExport() only accepts arguments of type \Thelia\Model\Export or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Export relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function joinExport($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Export'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Export'); + } + + return $this; + } + + /** + * Use the Export relation Export object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ExportQuery A secondary query class using the current class as primary query + */ + public function useExportQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinExport($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Export', '\Thelia\Model\ExportQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\ExportCategoryI18n object + * + * @param \Thelia\Model\ExportCategoryI18n|ObjectCollection $exportCategoryI18n the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function filterByExportCategoryI18n($exportCategoryI18n, $comparison = null) + { + if ($exportCategoryI18n instanceof \Thelia\Model\ExportCategoryI18n) { + return $this + ->addUsingAlias(ExportCategoryTableMap::ID, $exportCategoryI18n->getId(), $comparison); + } elseif ($exportCategoryI18n instanceof ObjectCollection) { + return $this + ->useExportCategoryI18nQuery() + ->filterByPrimaryKeys($exportCategoryI18n->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByExportCategoryI18n() only accepts arguments of type \Thelia\Model\ExportCategoryI18n or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the ExportCategoryI18n relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function joinExportCategoryI18n($relationAlias = null, $joinType = 'LEFT JOIN') + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('ExportCategoryI18n'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'ExportCategoryI18n'); + } + + return $this; + } + + /** + * Use the ExportCategoryI18n relation ExportCategoryI18n object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ExportCategoryI18nQuery A secondary query class using the current class as primary query + */ + public function useExportCategoryI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') + { + return $this + ->joinExportCategoryI18n($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ExportCategoryI18n', '\Thelia\Model\ExportCategoryI18nQuery'); + } + + /** + * Exclude object from result + * + * @param ChildExportCategory $exportCategory Object to remove from the list of results + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function prune($exportCategory = null) + { + if ($exportCategory) { + $this->addUsingAlias(ExportCategoryTableMap::ID, $exportCategory->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the export_category table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + ExportCategoryTableMap::clearInstancePool(); + ExportCategoryTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildExportCategory or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildExportCategory object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(ExportCategoryTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + ExportCategoryTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + ExportCategoryTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // i18n behavior + + /** + * Adds a JOIN clause to the query using the i18n relation + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function joinI18n($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $relationName = $relationAlias ? $relationAlias : 'ExportCategoryI18n'; + + return $this + ->joinExportCategoryI18n($relationAlias, $joinType) + ->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale); + } + + /** + * Adds a JOIN clause to the query and hydrates the related I18n object. + * Shortcut for $c->joinI18n($locale)->with() + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function joinWithI18n($locale = 'en_US', $joinType = Criteria::LEFT_JOIN) + { + $this + ->joinI18n($locale, null, $joinType) + ->with('ExportCategoryI18n'); + $this->with['ExportCategoryI18n']->setIsWithOneToMany(false); + + return $this; + } + + /** + * Use the I18n relation query object + * + * @see useQuery() + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildExportCategoryI18nQuery A secondary query class using the current class as primary query + */ + public function useI18nQuery($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinI18n($locale, $relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ExportCategoryI18n', '\Thelia\Model\ExportCategoryI18nQuery'); + } + + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(ExportCategoryTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(ExportCategoryTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(ExportCategoryTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(ExportCategoryTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(ExportCategoryTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildExportCategoryQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(ExportCategoryTableMap::CREATED_AT); + } + +} // ExportCategoryQuery diff --git a/core/lib/Thelia/Model/Base/ExportI18n.php b/core/lib/Thelia/Model/Base/ExportI18n.php new file mode 100644 index 000000000..e8271f18a --- /dev/null +++ b/core/lib/Thelia/Model/Base/ExportI18n.php @@ -0,0 +1,1326 @@ +locale = 'en_US'; + } + + /** + * Initializes internal state of Thelia\Model\Base\ExportI18n object. + * @see applyDefaults() + */ + public function __construct() + { + $this->applyDefaultValues(); + } + + /** + * Returns whether the object has been modified. + * + * @return boolean True if the object has been modified. + */ + public function isModified() + { + return !!$this->modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (Boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (Boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another ExportI18n instance. If + * obj is an instance of ExportI18n, delegates to + * equals(ExportI18n). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + $thisclazz = get_class($this); + if (!is_object($obj) || !($obj instanceof $thisclazz)) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() + || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + if (null !== $this->getPrimaryKey()) { + return crc32(serialize($this->getPrimaryKey())); + } + + return crc32(serialize(clone $this)); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return ExportI18n The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * + * @return ExportI18n The current object, for fluid interface + */ + public function importFrom($parser, $data) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); + + return $this; + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + return array_keys(get_object_vars($this)); + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + + return $this->id; + } + + /** + * Get the [locale] column value. + * + * @return string + */ + public function getLocale() + { + + return $this->locale; + } + + /** + * Get the [title] column value. + * + * @return string + */ + public function getTitle() + { + + return $this->title; + } + + /** + * Get the [description] column value. + * + * @return string + */ + public function getDescription() + { + + return $this->description; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return \Thelia\Model\ExportI18n The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[ExportI18nTableMap::ID] = true; + } + + if ($this->aExport !== null && $this->aExport->getId() !== $v) { + $this->aExport = null; + } + + + return $this; + } // setId() + + /** + * Set the value of [locale] column. + * + * @param string $v new value + * @return \Thelia\Model\ExportI18n The current object (for fluent API support) + */ + public function setLocale($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->locale !== $v) { + $this->locale = $v; + $this->modifiedColumns[ExportI18nTableMap::LOCALE] = true; + } + + + return $this; + } // setLocale() + + /** + * Set the value of [title] column. + * + * @param string $v new value + * @return \Thelia\Model\ExportI18n The current object (for fluent API support) + */ + public function setTitle($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->title !== $v) { + $this->title = $v; + $this->modifiedColumns[ExportI18nTableMap::TITLE] = true; + } + + + return $this; + } // setTitle() + + /** + * Set the value of [description] column. + * + * @param string $v new value + * @return \Thelia\Model\ExportI18n The current object (for fluent API support) + */ + public function setDescription($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->description !== $v) { + $this->description = $v; + $this->modifiedColumns[ExportI18nTableMap::DESCRIPTION] = true; + } + + + return $this; + } // setDescription() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + if ($this->locale !== 'en_US') { + return false; + } + + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ExportI18nTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ExportI18nTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; + $this->locale = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ExportI18nTableMap::translateFieldName('Title', TableMap::TYPE_PHPNAME, $indexType)]; + $this->title = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ExportI18nTableMap::translateFieldName('Description', TableMap::TYPE_PHPNAME, $indexType)]; + $this->description = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 4; // 4 = ExportI18nTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException("Error populating \Thelia\Model\ExportI18n object", 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aExport !== null && $this->id !== $this->aExport->getId()) { + $this->aExport = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ExportI18nTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildExportI18nQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aExport = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see ExportI18n::setDeleted() + * @see ExportI18n::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportI18nTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + try { + $deleteQuery = ChildExportI18nQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $con->commit(); + $this->setDeleted(true); + } else { + $con->commit(); + } + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportI18nTableMap::DATABASE_NAME); + } + + $con->beginTransaction(); + $isInsert = $this->isNew(); + try { + $ret = $this->preSave($con); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + ExportI18nTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + $con->commit(); + + return $affectedRows; + } catch (Exception $e) { + $con->rollBack(); + throw $e; + } + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aExport !== null) { + if ($this->aExport->isModified() || $this->aExport->isNew()) { + $affectedRows += $this->aExport->save($con); + } + $this->setExport($this->aExport); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + } else { + $this->doUpdate($con); + } + $affectedRows += 1; + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(ExportI18nTableMap::ID)) { + $modifiedColumns[':p' . $index++] = '`ID`'; + } + if ($this->isColumnModified(ExportI18nTableMap::LOCALE)) { + $modifiedColumns[':p' . $index++] = '`LOCALE`'; + } + if ($this->isColumnModified(ExportI18nTableMap::TITLE)) { + $modifiedColumns[':p' . $index++] = '`TITLE`'; + } + if ($this->isColumnModified(ExportI18nTableMap::DESCRIPTION)) { + $modifiedColumns[':p' . $index++] = '`DESCRIPTION`'; + } + + $sql = sprintf( + 'INSERT INTO `export_i18n` (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case '`ID`': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case '`LOCALE`': + $stmt->bindValue($identifier, $this->locale, PDO::PARAM_STR); + break; + case '`TITLE`': + $stmt->bindValue($identifier, $this->title, PDO::PARAM_STR); + break; + case '`DESCRIPTION`': + $stmt->bindValue($identifier, $this->description, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = ExportI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getLocale(); + break; + case 2: + return $this->getTitle(); + break; + case 3: + return $this->getDescription(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + if (isset($alreadyDumpedObjects['ExportI18n'][serialize($this->getPrimaryKey())])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['ExportI18n'][serialize($this->getPrimaryKey())] = true; + $keys = ExportI18nTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getLocale(), + $keys[2] => $this->getTitle(), + $keys[3] => $this->getDescription(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aExport) { + $result['Export'] = $this->aExport->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return void + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = ExportI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setLocale($value); + break; + case 2: + $this->setTitle($value); + break; + case 3: + $this->setDescription($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = ExportI18nTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); + if (array_key_exists($keys[1], $arr)) $this->setLocale($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setTitle($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setDescription($arr[$keys[3]]); + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(ExportI18nTableMap::DATABASE_NAME); + + if ($this->isColumnModified(ExportI18nTableMap::ID)) $criteria->add(ExportI18nTableMap::ID, $this->id); + if ($this->isColumnModified(ExportI18nTableMap::LOCALE)) $criteria->add(ExportI18nTableMap::LOCALE, $this->locale); + if ($this->isColumnModified(ExportI18nTableMap::TITLE)) $criteria->add(ExportI18nTableMap::TITLE, $this->title); + if ($this->isColumnModified(ExportI18nTableMap::DESCRIPTION)) $criteria->add(ExportI18nTableMap::DESCRIPTION, $this->description); + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(ExportI18nTableMap::DATABASE_NAME); + $criteria->add(ExportI18nTableMap::ID, $this->id); + $criteria->add(ExportI18nTableMap::LOCALE, $this->locale); + + return $criteria; + } + + /** + * Returns the composite primary key for this object. + * The array elements will be in same order as specified in XML. + * @return array + */ + public function getPrimaryKey() + { + $pks = array(); + $pks[0] = $this->getId(); + $pks[1] = $this->getLocale(); + + return $pks; + } + + /** + * Set the [composite] primary key. + * + * @param array $keys The elements of the composite key (order must match the order in XML file). + * @return void + */ + public function setPrimaryKey($keys) + { + $this->setId($keys[0]); + $this->setLocale($keys[1]); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + + return (null === $this->getId()) && (null === $this->getLocale()); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Thelia\Model\ExportI18n (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setId($this->getId()); + $copyObj->setLocale($this->getLocale()); + $copyObj->setTitle($this->getTitle()); + $copyObj->setDescription($this->getDescription()); + if ($makeNew) { + $copyObj->setNew(true); + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Thelia\Model\ExportI18n Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildExport object. + * + * @param ChildExport $v + * @return \Thelia\Model\ExportI18n The current object (for fluent API support) + * @throws PropelException + */ + public function setExport(ChildExport $v = null) + { + if ($v === null) { + $this->setId(NULL); + } else { + $this->setId($v->getId()); + } + + $this->aExport = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildExport object, it will not be re-added. + if ($v !== null) { + $v->addExportI18n($this); + } + + + return $this; + } + + + /** + * Get the associated ChildExport object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildExport The associated ChildExport object. + * @throws PropelException + */ + public function getExport(ConnectionInterface $con = null) + { + if ($this->aExport === null && ($this->id !== null)) { + $this->aExport = ChildExportQuery::create()->findPk($this->id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aExport->addExportI18ns($this); + */ + } + + return $this->aExport; + } + + /** + * Clears the current object and sets all attributes to their default values + */ + public function clear() + { + $this->id = null; + $this->locale = null; + $this->title = null; + $this->description = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->applyDefaultValues(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references to other model objects or collections of model objects. + * + * This method is a user-space workaround for PHP's inability to garbage collect + * objects with circular references (even in PHP 5.3). This is currently necessary + * when using Propel in certain daemon or large-volume/high-memory operations. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aExport = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(ExportI18nTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/core/lib/Thelia/Model/Base/ExportI18nQuery.php b/core/lib/Thelia/Model/Base/ExportI18nQuery.php new file mode 100644 index 000000000..4c0956f12 --- /dev/null +++ b/core/lib/Thelia/Model/Base/ExportI18nQuery.php @@ -0,0 +1,541 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(array(12, 34), $con); + * + * + * @param array[$id, $locale] $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildExportI18n|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = ExportI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ExportI18nTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildExportI18n A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT `ID`, `LOCALE`, `TITLE`, `DESCRIPTION` FROM `export_i18n` WHERE `ID` = :p0 AND `LOCALE` = :p1'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); + $stmt->bindValue(':p1', $key[1], PDO::PARAM_STR); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildExportI18n(); + $obj->hydrate($row); + ExportI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildExportI18n|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildExportI18nQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + $this->addUsingAlias(ExportI18nTableMap::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(ExportI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + + return $this; + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildExportI18nQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + if (empty($keys)) { + return $this->add(null, '1<>1', Criteria::CUSTOM); + } + foreach ($keys as $key) { + $cton0 = $this->getNewCriterion(ExportI18nTableMap::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(ExportI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + $cton0->addAnd($cton1); + $this->addOr($cton0); + } + + return $this; + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @see filterByExport() + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportI18nQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(ExportI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(ExportI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ExportI18nTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the locale column + * + * Example usage: + * + * $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue' + * $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%' + * + * + * @param string $locale The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportI18nQuery The current query, for fluid interface + */ + public function filterByLocale($locale = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($locale)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $locale)) { + $locale = str_replace('*', '%', $locale); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ExportI18nTableMap::LOCALE, $locale, $comparison); + } + + /** + * Filter the query on the title column + * + * Example usage: + * + * $query->filterByTitle('fooValue'); // WHERE title = 'fooValue' + * $query->filterByTitle('%fooValue%'); // WHERE title LIKE '%fooValue%' + * + * + * @param string $title The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportI18nQuery The current query, for fluid interface + */ + public function filterByTitle($title = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($title)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $title)) { + $title = str_replace('*', '%', $title); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ExportI18nTableMap::TITLE, $title, $comparison); + } + + /** + * Filter the query on the description column + * + * Example usage: + * + * $query->filterByDescription('fooValue'); // WHERE description = 'fooValue' + * $query->filterByDescription('%fooValue%'); // WHERE description LIKE '%fooValue%' + * + * + * @param string $description The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportI18nQuery The current query, for fluid interface + */ + public function filterByDescription($description = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($description)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $description)) { + $description = str_replace('*', '%', $description); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ExportI18nTableMap::DESCRIPTION, $description, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\Export object + * + * @param \Thelia\Model\Export|ObjectCollection $export The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportI18nQuery The current query, for fluid interface + */ + public function filterByExport($export, $comparison = null) + { + if ($export instanceof \Thelia\Model\Export) { + return $this + ->addUsingAlias(ExportI18nTableMap::ID, $export->getId(), $comparison); + } elseif ($export instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(ExportI18nTableMap::ID, $export->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByExport() only accepts arguments of type \Thelia\Model\Export or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Export relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildExportI18nQuery The current query, for fluid interface + */ + public function joinExport($relationAlias = null, $joinType = 'LEFT JOIN') + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Export'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Export'); + } + + return $this; + } + + /** + * Use the Export relation Export object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ExportQuery A secondary query class using the current class as primary query + */ + public function useExportQuery($relationAlias = null, $joinType = 'LEFT JOIN') + { + return $this + ->joinExport($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Export', '\Thelia\Model\ExportQuery'); + } + + /** + * Exclude object from result + * + * @param ChildExportI18n $exportI18n Object to remove from the list of results + * + * @return ChildExportI18nQuery The current query, for fluid interface + */ + public function prune($exportI18n = null) + { + if ($exportI18n) { + $this->addCond('pruneCond0', $this->getAliasedColName(ExportI18nTableMap::ID), $exportI18n->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(ExportI18nTableMap::LOCALE), $exportI18n->getLocale(), Criteria::NOT_EQUAL); + $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); + } + + return $this; + } + + /** + * Deletes all rows from the export_i18n table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportI18nTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + ExportI18nTableMap::clearInstancePool(); + ExportI18nTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildExportI18n or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildExportI18n object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportI18nTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(ExportI18nTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + ExportI18nTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + ExportI18nTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + +} // ExportI18nQuery diff --git a/core/lib/Thelia/Model/Base/ExportQuery.php b/core/lib/Thelia/Model/Base/ExportQuery.php new file mode 100644 index 000000000..1a34da44f --- /dev/null +++ b/core/lib/Thelia/Model/Base/ExportQuery.php @@ -0,0 +1,813 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildExport|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, $con = null) + { + if ($key === null) { + return null; + } + if ((null !== ($obj = ExportTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + // the object is already in the instance pool + return $obj; + } + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(ExportTableMap::DATABASE_NAME); + } + $this->basePreSelect($con); + if ($this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins) { + return $this->findPkComplex($key, $con); + } else { + return $this->findPkSimple($key, $con); + } + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildExport A model object, or null if the key is not found + */ + protected function findPkSimple($key, $con) + { + $sql = 'SELECT `ID`, `EXPORT_CATEGORY_ID`, `POSITION`, `CREATED_AT`, `UPDATED_AT` FROM `export` WHERE `ID` = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + $obj = new ChildExport(); + $obj->hydrate($row); + ExportTableMap::addInstanceToPool($obj, (string) $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildExport|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(ExportTableMap::ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(ExportTableMap::ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(ExportTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(ExportTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ExportTableMap::ID, $id, $comparison); + } + + /** + * Filter the query on the export_category_id column + * + * Example usage: + * + * $query->filterByExportCategoryId(1234); // WHERE export_category_id = 1234 + * $query->filterByExportCategoryId(array(12, 34)); // WHERE export_category_id IN (12, 34) + * $query->filterByExportCategoryId(array('min' => 12)); // WHERE export_category_id > 12 + * + * + * @see filterByExportCategory() + * + * @param mixed $exportCategoryId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function filterByExportCategoryId($exportCategoryId = null, $comparison = null) + { + if (is_array($exportCategoryId)) { + $useMinMax = false; + if (isset($exportCategoryId['min'])) { + $this->addUsingAlias(ExportTableMap::EXPORT_CATEGORY_ID, $exportCategoryId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($exportCategoryId['max'])) { + $this->addUsingAlias(ExportTableMap::EXPORT_CATEGORY_ID, $exportCategoryId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ExportTableMap::EXPORT_CATEGORY_ID, $exportCategoryId, $comparison); + } + + /** + * Filter the query on the position column + * + * Example usage: + * + * $query->filterByPosition(1234); // WHERE position = 1234 + * $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34) + * $query->filterByPosition(array('min' => 12)); // WHERE position > 12 + * + * + * @param mixed $position The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function filterByPosition($position = null, $comparison = null) + { + if (is_array($position)) { + $useMinMax = false; + if (isset($position['min'])) { + $this->addUsingAlias(ExportTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($position['max'])) { + $this->addUsingAlias(ExportTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ExportTableMap::POSITION, $position, $comparison); + } + + /** + * Filter the query on the created_at column + * + * Example usage: + * + * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' + * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' + * + * + * @param mixed $createdAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function filterByCreatedAt($createdAt = null, $comparison = null) + { + if (is_array($createdAt)) { + $useMinMax = false; + if (isset($createdAt['min'])) { + $this->addUsingAlias(ExportTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($createdAt['max'])) { + $this->addUsingAlias(ExportTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ExportTableMap::CREATED_AT, $createdAt, $comparison); + } + + /** + * Filter the query on the updated_at column + * + * Example usage: + * + * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' + * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' + * + * + * @param mixed $updatedAt The value to use as filter. + * Values can be integers (unix timestamps), DateTime objects, or strings. + * Empty strings are treated as NULL. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function filterByUpdatedAt($updatedAt = null, $comparison = null) + { + if (is_array($updatedAt)) { + $useMinMax = false; + if (isset($updatedAt['min'])) { + $this->addUsingAlias(ExportTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($updatedAt['max'])) { + $this->addUsingAlias(ExportTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(ExportTableMap::UPDATED_AT, $updatedAt, $comparison); + } + + /** + * Filter the query by a related \Thelia\Model\ExportCategory object + * + * @param \Thelia\Model\ExportCategory|ObjectCollection $exportCategory The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function filterByExportCategory($exportCategory, $comparison = null) + { + if ($exportCategory instanceof \Thelia\Model\ExportCategory) { + return $this + ->addUsingAlias(ExportTableMap::EXPORT_CATEGORY_ID, $exportCategory->getId(), $comparison); + } elseif ($exportCategory instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(ExportTableMap::EXPORT_CATEGORY_ID, $exportCategory->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByExportCategory() only accepts arguments of type \Thelia\Model\ExportCategory or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the ExportCategory relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function joinExportCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('ExportCategory'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'ExportCategory'); + } + + return $this; + } + + /** + * Use the ExportCategory relation ExportCategory object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ExportCategoryQuery A secondary query class using the current class as primary query + */ + public function useExportCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinExportCategory($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ExportCategory', '\Thelia\Model\ExportCategoryQuery'); + } + + /** + * Filter the query by a related \Thelia\Model\ExportI18n object + * + * @param \Thelia\Model\ExportI18n|ObjectCollection $exportI18n the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function filterByExportI18n($exportI18n, $comparison = null) + { + if ($exportI18n instanceof \Thelia\Model\ExportI18n) { + return $this + ->addUsingAlias(ExportTableMap::ID, $exportI18n->getId(), $comparison); + } elseif ($exportI18n instanceof ObjectCollection) { + return $this + ->useExportI18nQuery() + ->filterByPrimaryKeys($exportI18n->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByExportI18n() only accepts arguments of type \Thelia\Model\ExportI18n or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the ExportI18n relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function joinExportI18n($relationAlias = null, $joinType = 'LEFT JOIN') + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('ExportI18n'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'ExportI18n'); + } + + return $this; + } + + /** + * Use the ExportI18n relation ExportI18n object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \Thelia\Model\ExportI18nQuery A secondary query class using the current class as primary query + */ + public function useExportI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') + { + return $this + ->joinExportI18n($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ExportI18n', '\Thelia\Model\ExportI18nQuery'); + } + + /** + * Exclude object from result + * + * @param ChildExport $export Object to remove from the list of results + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function prune($export = null) + { + if ($export) { + $this->addUsingAlias(ExportTableMap::ID, $export->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the export table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportTableMap::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + ExportTableMap::clearInstancePool(); + ExportTableMap::clearRelatedInstancePool(); + + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $affectedRows; + } + + /** + * Performs a DELETE on the database, given a ChildExport or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ChildExport object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(ExportTableMap::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->beginTransaction(); + + + ExportTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + ExportTableMap::clearRelatedInstancePool(); + $con->commit(); + + return $affectedRows; + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + } + + // i18n behavior + + /** + * Adds a JOIN clause to the query using the i18n relation + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function joinI18n($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $relationName = $relationAlias ? $relationAlias : 'ExportI18n'; + + return $this + ->joinExportI18n($relationAlias, $joinType) + ->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale); + } + + /** + * Adds a JOIN clause to the query and hydrates the related I18n object. + * Shortcut for $c->joinI18n($locale)->with() + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function joinWithI18n($locale = 'en_US', $joinType = Criteria::LEFT_JOIN) + { + $this + ->joinI18n($locale, null, $joinType) + ->with('ExportI18n'); + $this->with['ExportI18n']->setIsWithOneToMany(false); + + return $this; + } + + /** + * Use the I18n relation query object + * + * @see useQuery() + * + * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. + * + * @return ChildExportI18nQuery A secondary query class using the current class as primary query + */ + public function useI18nQuery($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinI18n($locale, $relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ExportI18n', '\Thelia\Model\ExportI18nQuery'); + } + + // timestampable behavior + + /** + * Filter by the latest updated + * + * @param int $nbDays Maximum age of the latest update in days + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function recentlyUpdated($nbDays = 7) + { + return $this->addUsingAlias(ExportTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Filter by the latest created + * + * @param int $nbDays Maximum age of in days + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function recentlyCreated($nbDays = 7) + { + return $this->addUsingAlias(ExportTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + } + + /** + * Order by update date desc + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function lastUpdatedFirst() + { + return $this->addDescendingOrderByColumn(ExportTableMap::UPDATED_AT); + } + + /** + * Order by update date asc + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function firstUpdatedFirst() + { + return $this->addAscendingOrderByColumn(ExportTableMap::UPDATED_AT); + } + + /** + * Order by create date desc + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function lastCreatedFirst() + { + return $this->addDescendingOrderByColumn(ExportTableMap::CREATED_AT); + } + + /** + * Order by create date asc + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function firstCreatedFirst() + { + return $this->addAscendingOrderByColumn(ExportTableMap::CREATED_AT); + } + +} // ExportQuery diff --git a/core/lib/Thelia/Model/Base/ImportExportType.php b/core/lib/Thelia/Model/Base/Import.php similarity index 69% rename from core/lib/Thelia/Model/Base/ImportExportType.php rename to core/lib/Thelia/Model/Base/Import.php index 47595ded9..e2b0e3cd6 100644 --- a/core/lib/Thelia/Model/Base/ImportExportType.php +++ b/core/lib/Thelia/Model/Base/Import.php @@ -17,20 +17,20 @@ use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Parser\AbstractParser; use Propel\Runtime\Util\PropelDateTime; -use Thelia\Model\ImportExportCategory as ChildImportExportCategory; -use Thelia\Model\ImportExportCategoryQuery as ChildImportExportCategoryQuery; -use Thelia\Model\ImportExportType as ChildImportExportType; -use Thelia\Model\ImportExportTypeI18n as ChildImportExportTypeI18n; -use Thelia\Model\ImportExportTypeI18nQuery as ChildImportExportTypeI18nQuery; -use Thelia\Model\ImportExportTypeQuery as ChildImportExportTypeQuery; -use Thelia\Model\Map\ImportExportTypeTableMap; +use Thelia\Model\Import as ChildImport; +use Thelia\Model\ImportCategory as ChildImportCategory; +use Thelia\Model\ImportCategoryQuery as ChildImportCategoryQuery; +use Thelia\Model\ImportI18n as ChildImportI18n; +use Thelia\Model\ImportI18nQuery as ChildImportI18nQuery; +use Thelia\Model\ImportQuery as ChildImportQuery; +use Thelia\Model\Map\ImportTableMap; -abstract class ImportExportType implements ActiveRecordInterface +abstract class Import implements ActiveRecordInterface { /** * TableMap class name */ - const TABLE_MAP = '\\Thelia\\Model\\Map\\ImportExportTypeTableMap'; + const TABLE_MAP = '\\Thelia\\Model\\Map\\ImportTableMap'; /** @@ -66,16 +66,10 @@ abstract class ImportExportType implements ActiveRecordInterface protected $id; /** - * The value for the url_action field. - * @var string - */ - protected $url_action; - - /** - * The value for the import_export_category_id field. + * The value for the import_category_id field. * @var int */ - protected $import_export_category_id; + protected $import_category_id; /** * The value for the position field. @@ -96,15 +90,15 @@ abstract class ImportExportType implements ActiveRecordInterface protected $updated_at; /** - * @var ImportExportCategory + * @var ImportCategory */ - protected $aImportExportCategory; + protected $aImportCategory; /** - * @var ObjectCollection|ChildImportExportTypeI18n[] Collection to store aggregation of ChildImportExportTypeI18n objects. + * @var ObjectCollection|ChildImportI18n[] Collection to store aggregation of ChildImportI18n objects. */ - protected $collImportExportTypeI18ns; - protected $collImportExportTypeI18nsPartial; + protected $collImportI18ns; + protected $collImportI18nsPartial; /** * Flag to prevent endless save loop, if this object is referenced @@ -124,7 +118,7 @@ abstract class ImportExportType implements ActiveRecordInterface /** * Current translation objects - * @var array[ChildImportExportTypeI18n] + * @var array[ChildImportI18n] */ protected $currentTranslations; @@ -132,10 +126,10 @@ abstract class ImportExportType implements ActiveRecordInterface * An array of objects scheduled for deletion. * @var ObjectCollection */ - protected $importExportTypeI18nsScheduledForDeletion = null; + protected $importI18nsScheduledForDeletion = null; /** - * Initializes internal state of Thelia\Model\Base\ImportExportType object. + * Initializes internal state of Thelia\Model\Base\Import object. */ public function __construct() { @@ -230,9 +224,9 @@ abstract class ImportExportType implements ActiveRecordInterface } /** - * Compares this with another ImportExportType instance. If - * obj is an instance of ImportExportType, delegates to - * equals(ImportExportType). Otherwise, returns false. + * Compares this with another Import instance. If + * obj is an instance of Import, delegates to + * equals(Import). Otherwise, returns false. * * @param mixed $obj The object to compare to. * @return boolean Whether equal to the object specified. @@ -315,7 +309,7 @@ abstract class ImportExportType implements ActiveRecordInterface * @param string $name The virtual column name * @param mixed $value The value to give to the virtual column * - * @return ImportExportType The current object, for fluid interface + * @return Import The current object, for fluid interface */ public function setVirtualColumn($name, $value) { @@ -347,7 +341,7 @@ abstract class ImportExportType implements ActiveRecordInterface * or a format name ('XML', 'YAML', 'JSON', 'CSV') * @param string $data The source data to import from * - * @return ImportExportType The current object, for fluid interface + * @return Import The current object, for fluid interface */ public function importFrom($parser, $data) { @@ -404,25 +398,14 @@ abstract class ImportExportType implements ActiveRecordInterface } /** - * Get the [url_action] column value. - * - * @return string - */ - public function getUrlAction() - { - - return $this->url_action; - } - - /** - * Get the [import_export_category_id] column value. + * Get the [import_category_id] column value. * * @return int */ - public function getImportExportCategoryId() + public function getImportCategoryId() { - return $this->import_export_category_id; + return $this->import_category_id; } /** @@ -480,7 +463,7 @@ abstract class ImportExportType implements ActiveRecordInterface * Set the value of [id] column. * * @param int $v new value - * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + * @return \Thelia\Model\Import The current object (for fluent API support) */ public function setId($v) { @@ -490,7 +473,7 @@ abstract class ImportExportType implements ActiveRecordInterface if ($this->id !== $v) { $this->id = $v; - $this->modifiedColumns[ImportExportTypeTableMap::ID] = true; + $this->modifiedColumns[ImportTableMap::ID] = true; } @@ -498,56 +481,35 @@ abstract class ImportExportType implements ActiveRecordInterface } // setId() /** - * Set the value of [url_action] column. - * - * @param string $v new value - * @return \Thelia\Model\ImportExportType The current object (for fluent API support) - */ - public function setUrlAction($v) - { - if ($v !== null) { - $v = (string) $v; - } - - if ($this->url_action !== $v) { - $this->url_action = $v; - $this->modifiedColumns[ImportExportTypeTableMap::URL_ACTION] = true; - } - - - return $this; - } // setUrlAction() - - /** - * Set the value of [import_export_category_id] column. + * Set the value of [import_category_id] column. * * @param int $v new value - * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + * @return \Thelia\Model\Import The current object (for fluent API support) */ - public function setImportExportCategoryId($v) + public function setImportCategoryId($v) { if ($v !== null) { $v = (int) $v; } - if ($this->import_export_category_id !== $v) { - $this->import_export_category_id = $v; - $this->modifiedColumns[ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID] = true; + if ($this->import_category_id !== $v) { + $this->import_category_id = $v; + $this->modifiedColumns[ImportTableMap::IMPORT_CATEGORY_ID] = true; } - if ($this->aImportExportCategory !== null && $this->aImportExportCategory->getId() !== $v) { - $this->aImportExportCategory = null; + if ($this->aImportCategory !== null && $this->aImportCategory->getId() !== $v) { + $this->aImportCategory = null; } return $this; - } // setImportExportCategoryId() + } // setImportCategoryId() /** * Set the value of [position] column. * * @param int $v new value - * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + * @return \Thelia\Model\Import The current object (for fluent API support) */ public function setPosition($v) { @@ -557,7 +519,7 @@ abstract class ImportExportType implements ActiveRecordInterface if ($this->position !== $v) { $this->position = $v; - $this->modifiedColumns[ImportExportTypeTableMap::POSITION] = true; + $this->modifiedColumns[ImportTableMap::POSITION] = true; } @@ -569,7 +531,7 @@ abstract class ImportExportType implements ActiveRecordInterface * * @param mixed $v string, integer (timestamp), or \DateTime value. * Empty strings are treated as NULL. - * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + * @return \Thelia\Model\Import The current object (for fluent API support) */ public function setCreatedAt($v) { @@ -577,7 +539,7 @@ abstract class ImportExportType implements ActiveRecordInterface if ($this->created_at !== null || $dt !== null) { if ($dt !== $this->created_at) { $this->created_at = $dt; - $this->modifiedColumns[ImportExportTypeTableMap::CREATED_AT] = true; + $this->modifiedColumns[ImportTableMap::CREATED_AT] = true; } } // if either are not null @@ -590,7 +552,7 @@ abstract class ImportExportType implements ActiveRecordInterface * * @param mixed $v string, integer (timestamp), or \DateTime value. * Empty strings are treated as NULL. - * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + * @return \Thelia\Model\Import The current object (for fluent API support) */ public function setUpdatedAt($v) { @@ -598,7 +560,7 @@ abstract class ImportExportType implements ActiveRecordInterface if ($this->updated_at !== null || $dt !== null) { if ($dt !== $this->updated_at) { $this->updated_at = $dt; - $this->modifiedColumns[ImportExportTypeTableMap::UPDATED_AT] = true; + $this->modifiedColumns[ImportTableMap::UPDATED_AT] = true; } } // if either are not null @@ -643,25 +605,22 @@ abstract class ImportExportType implements ActiveRecordInterface try { - $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ImportExportTypeTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ImportTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; $this->id = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ImportExportTypeTableMap::translateFieldName('UrlAction', TableMap::TYPE_PHPNAME, $indexType)]; - $this->url_action = (null !== $col) ? (string) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ImportTableMap::translateFieldName('ImportCategoryId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->import_category_id = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportExportTypeTableMap::translateFieldName('ImportExportCategoryId', TableMap::TYPE_PHPNAME, $indexType)]; - $this->import_export_category_id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportExportTypeTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; $this->position = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ImportExportTypeTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ImportExportTypeTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ImportTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -674,10 +633,10 @@ abstract class ImportExportType implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 6; // 6 = ImportExportTypeTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 5; // 5 = ImportTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { - throw new PropelException("Error populating \Thelia\Model\ImportExportType object", 0, $e); + throw new PropelException("Error populating \Thelia\Model\Import object", 0, $e); } } @@ -696,8 +655,8 @@ abstract class ImportExportType implements ActiveRecordInterface */ public function ensureConsistency() { - if ($this->aImportExportCategory !== null && $this->import_export_category_id !== $this->aImportExportCategory->getId()) { - $this->aImportExportCategory = null; + if ($this->aImportCategory !== null && $this->import_category_id !== $this->aImportCategory->getId()) { + $this->aImportCategory = null; } } // ensureConsistency @@ -722,13 +681,13 @@ abstract class ImportExportType implements ActiveRecordInterface } if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(ImportExportTypeTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getReadConnection(ImportTableMap::DATABASE_NAME); } // We don't need to alter the object instance pool; we're just modifying this instance // already in the pool. - $dataFetcher = ChildImportExportTypeQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $dataFetcher = ChildImportQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); $row = $dataFetcher->fetch(); $dataFetcher->close(); if (!$row) { @@ -738,8 +697,8 @@ abstract class ImportExportType implements ActiveRecordInterface if ($deep) { // also de-associate any related objects? - $this->aImportExportCategory = null; - $this->collImportExportTypeI18ns = null; + $this->aImportCategory = null; + $this->collImportI18ns = null; } // if (deep) } @@ -750,8 +709,8 @@ abstract class ImportExportType implements ActiveRecordInterface * @param ConnectionInterface $con * @return void * @throws PropelException - * @see ImportExportType::setDeleted() - * @see ImportExportType::isDeleted() + * @see Import::setDeleted() + * @see Import::isDeleted() */ public function delete(ConnectionInterface $con = null) { @@ -760,12 +719,12 @@ abstract class ImportExportType implements ActiveRecordInterface } if ($con === null) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportTableMap::DATABASE_NAME); } $con->beginTransaction(); try { - $deleteQuery = ChildImportExportTypeQuery::create() + $deleteQuery = ChildImportQuery::create() ->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { @@ -802,7 +761,7 @@ abstract class ImportExportType implements ActiveRecordInterface } if ($con === null) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportTableMap::DATABASE_NAME); } $con->beginTransaction(); @@ -812,16 +771,16 @@ abstract class ImportExportType implements ActiveRecordInterface if ($isInsert) { $ret = $ret && $this->preInsert($con); // timestampable behavior - if (!$this->isColumnModified(ImportExportTypeTableMap::CREATED_AT)) { + if (!$this->isColumnModified(ImportTableMap::CREATED_AT)) { $this->setCreatedAt(time()); } - if (!$this->isColumnModified(ImportExportTypeTableMap::UPDATED_AT)) { + if (!$this->isColumnModified(ImportTableMap::UPDATED_AT)) { $this->setUpdatedAt(time()); } } else { $ret = $ret && $this->preUpdate($con); // timestampable behavior - if ($this->isModified() && !$this->isColumnModified(ImportExportTypeTableMap::UPDATED_AT)) { + if ($this->isModified() && !$this->isColumnModified(ImportTableMap::UPDATED_AT)) { $this->setUpdatedAt(time()); } } @@ -833,7 +792,7 @@ abstract class ImportExportType implements ActiveRecordInterface $this->postUpdate($con); } $this->postSave($con); - ImportExportTypeTableMap::addInstanceToPool($this); + ImportTableMap::addInstanceToPool($this); } else { $affectedRows = 0; } @@ -868,11 +827,11 @@ abstract class ImportExportType implements ActiveRecordInterface // method. This object relates to these object(s) by a // foreign key reference. - if ($this->aImportExportCategory !== null) { - if ($this->aImportExportCategory->isModified() || $this->aImportExportCategory->isNew()) { - $affectedRows += $this->aImportExportCategory->save($con); + if ($this->aImportCategory !== null) { + if ($this->aImportCategory->isModified() || $this->aImportCategory->isNew()) { + $affectedRows += $this->aImportCategory->save($con); } - $this->setImportExportCategory($this->aImportExportCategory); + $this->setImportCategory($this->aImportCategory); } if ($this->isNew() || $this->isModified()) { @@ -886,17 +845,17 @@ abstract class ImportExportType implements ActiveRecordInterface $this->resetModified(); } - if ($this->importExportTypeI18nsScheduledForDeletion !== null) { - if (!$this->importExportTypeI18nsScheduledForDeletion->isEmpty()) { - \Thelia\Model\ImportExportTypeI18nQuery::create() - ->filterByPrimaryKeys($this->importExportTypeI18nsScheduledForDeletion->getPrimaryKeys(false)) + if ($this->importI18nsScheduledForDeletion !== null) { + if (!$this->importI18nsScheduledForDeletion->isEmpty()) { + \Thelia\Model\ImportI18nQuery::create() + ->filterByPrimaryKeys($this->importI18nsScheduledForDeletion->getPrimaryKeys(false)) ->delete($con); - $this->importExportTypeI18nsScheduledForDeletion = null; + $this->importI18nsScheduledForDeletion = null; } } - if ($this->collImportExportTypeI18ns !== null) { - foreach ($this->collImportExportTypeI18ns as $referrerFK) { + if ($this->collImportI18ns !== null) { + foreach ($this->collImportI18ns as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } @@ -923,33 +882,30 @@ abstract class ImportExportType implements ActiveRecordInterface $modifiedColumns = array(); $index = 0; - $this->modifiedColumns[ImportExportTypeTableMap::ID] = true; + $this->modifiedColumns[ImportTableMap::ID] = true; if (null !== $this->id) { - throw new PropelException('Cannot insert a value for auto-increment primary key (' . ImportExportTypeTableMap::ID . ')'); + throw new PropelException('Cannot insert a value for auto-increment primary key (' . ImportTableMap::ID . ')'); } // check the columns in natural order for more readable SQL queries - if ($this->isColumnModified(ImportExportTypeTableMap::ID)) { + if ($this->isColumnModified(ImportTableMap::ID)) { $modifiedColumns[':p' . $index++] = '`ID`'; } - if ($this->isColumnModified(ImportExportTypeTableMap::URL_ACTION)) { - $modifiedColumns[':p' . $index++] = '`URL_ACTION`'; + if ($this->isColumnModified(ImportTableMap::IMPORT_CATEGORY_ID)) { + $modifiedColumns[':p' . $index++] = '`IMPORT_CATEGORY_ID`'; } - if ($this->isColumnModified(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID)) { - $modifiedColumns[':p' . $index++] = '`IMPORT_EXPORT_CATEGORY_ID`'; - } - if ($this->isColumnModified(ImportExportTypeTableMap::POSITION)) { + if ($this->isColumnModified(ImportTableMap::POSITION)) { $modifiedColumns[':p' . $index++] = '`POSITION`'; } - if ($this->isColumnModified(ImportExportTypeTableMap::CREATED_AT)) { + if ($this->isColumnModified(ImportTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = '`CREATED_AT`'; } - if ($this->isColumnModified(ImportExportTypeTableMap::UPDATED_AT)) { + if ($this->isColumnModified(ImportTableMap::UPDATED_AT)) { $modifiedColumns[':p' . $index++] = '`UPDATED_AT`'; } $sql = sprintf( - 'INSERT INTO `import_export_type` (%s) VALUES (%s)', + 'INSERT INTO `import` (%s) VALUES (%s)', implode(', ', $modifiedColumns), implode(', ', array_keys($modifiedColumns)) ); @@ -961,11 +917,8 @@ abstract class ImportExportType implements ActiveRecordInterface case '`ID`': $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); break; - case '`URL_ACTION`': - $stmt->bindValue($identifier, $this->url_action, PDO::PARAM_STR); - break; - case '`IMPORT_EXPORT_CATEGORY_ID`': - $stmt->bindValue($identifier, $this->import_export_category_id, PDO::PARAM_INT); + case '`IMPORT_CATEGORY_ID`': + $stmt->bindValue($identifier, $this->import_category_id, PDO::PARAM_INT); break; case '`POSITION`': $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); @@ -1022,7 +975,7 @@ abstract class ImportExportType implements ActiveRecordInterface */ public function getByName($name, $type = TableMap::TYPE_PHPNAME) { - $pos = ImportExportTypeTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $pos = ImportTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); $field = $this->getByPosition($pos); return $field; @@ -1042,18 +995,15 @@ abstract class ImportExportType implements ActiveRecordInterface return $this->getId(); break; case 1: - return $this->getUrlAction(); + return $this->getImportCategoryId(); break; case 2: - return $this->getImportExportCategoryId(); - break; - case 3: return $this->getPosition(); break; - case 4: + case 3: return $this->getCreatedAt(); break; - case 5: + case 4: return $this->getUpdatedAt(); break; default: @@ -1079,18 +1029,17 @@ abstract class ImportExportType implements ActiveRecordInterface */ public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { - if (isset($alreadyDumpedObjects['ImportExportType'][$this->getPrimaryKey()])) { + if (isset($alreadyDumpedObjects['Import'][$this->getPrimaryKey()])) { return '*RECURSION*'; } - $alreadyDumpedObjects['ImportExportType'][$this->getPrimaryKey()] = true; - $keys = ImportExportTypeTableMap::getFieldNames($keyType); + $alreadyDumpedObjects['Import'][$this->getPrimaryKey()] = true; + $keys = ImportTableMap::getFieldNames($keyType); $result = array( $keys[0] => $this->getId(), - $keys[1] => $this->getUrlAction(), - $keys[2] => $this->getImportExportCategoryId(), - $keys[3] => $this->getPosition(), - $keys[4] => $this->getCreatedAt(), - $keys[5] => $this->getUpdatedAt(), + $keys[1] => $this->getImportCategoryId(), + $keys[2] => $this->getPosition(), + $keys[3] => $this->getCreatedAt(), + $keys[4] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { @@ -1098,11 +1047,11 @@ abstract class ImportExportType implements ActiveRecordInterface } if ($includeForeignObjects) { - if (null !== $this->aImportExportCategory) { - $result['ImportExportCategory'] = $this->aImportExportCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + if (null !== $this->aImportCategory) { + $result['ImportCategory'] = $this->aImportCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } - if (null !== $this->collImportExportTypeI18ns) { - $result['ImportExportTypeI18ns'] = $this->collImportExportTypeI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + if (null !== $this->collImportI18ns) { + $result['ImportI18ns'] = $this->collImportI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } } @@ -1122,7 +1071,7 @@ abstract class ImportExportType implements ActiveRecordInterface */ public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) { - $pos = ImportExportTypeTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $pos = ImportTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); return $this->setByPosition($pos, $value); } @@ -1142,18 +1091,15 @@ abstract class ImportExportType implements ActiveRecordInterface $this->setId($value); break; case 1: - $this->setUrlAction($value); + $this->setImportCategoryId($value); break; case 2: - $this->setImportExportCategoryId($value); - break; - case 3: $this->setPosition($value); break; - case 4: + case 3: $this->setCreatedAt($value); break; - case 5: + case 4: $this->setUpdatedAt($value); break; } // switch() @@ -1178,14 +1124,13 @@ abstract class ImportExportType implements ActiveRecordInterface */ public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) { - $keys = ImportExportTypeTableMap::getFieldNames($keyType); + $keys = ImportTableMap::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); - if (array_key_exists($keys[1], $arr)) $this->setUrlAction($arr[$keys[1]]); - if (array_key_exists($keys[2], $arr)) $this->setImportExportCategoryId($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setPosition($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]); - if (array_key_exists($keys[5], $arr)) $this->setUpdatedAt($arr[$keys[5]]); + if (array_key_exists($keys[1], $arr)) $this->setImportCategoryId($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setPosition($arr[$keys[2]]); + if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]); } /** @@ -1195,14 +1140,13 @@ abstract class ImportExportType implements ActiveRecordInterface */ public function buildCriteria() { - $criteria = new Criteria(ImportExportTypeTableMap::DATABASE_NAME); + $criteria = new Criteria(ImportTableMap::DATABASE_NAME); - if ($this->isColumnModified(ImportExportTypeTableMap::ID)) $criteria->add(ImportExportTypeTableMap::ID, $this->id); - if ($this->isColumnModified(ImportExportTypeTableMap::URL_ACTION)) $criteria->add(ImportExportTypeTableMap::URL_ACTION, $this->url_action); - if ($this->isColumnModified(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID)) $criteria->add(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $this->import_export_category_id); - if ($this->isColumnModified(ImportExportTypeTableMap::POSITION)) $criteria->add(ImportExportTypeTableMap::POSITION, $this->position); - if ($this->isColumnModified(ImportExportTypeTableMap::CREATED_AT)) $criteria->add(ImportExportTypeTableMap::CREATED_AT, $this->created_at); - if ($this->isColumnModified(ImportExportTypeTableMap::UPDATED_AT)) $criteria->add(ImportExportTypeTableMap::UPDATED_AT, $this->updated_at); + if ($this->isColumnModified(ImportTableMap::ID)) $criteria->add(ImportTableMap::ID, $this->id); + if ($this->isColumnModified(ImportTableMap::IMPORT_CATEGORY_ID)) $criteria->add(ImportTableMap::IMPORT_CATEGORY_ID, $this->import_category_id); + if ($this->isColumnModified(ImportTableMap::POSITION)) $criteria->add(ImportTableMap::POSITION, $this->position); + if ($this->isColumnModified(ImportTableMap::CREATED_AT)) $criteria->add(ImportTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(ImportTableMap::UPDATED_AT)) $criteria->add(ImportTableMap::UPDATED_AT, $this->updated_at); return $criteria; } @@ -1217,8 +1161,8 @@ abstract class ImportExportType implements ActiveRecordInterface */ public function buildPkeyCriteria() { - $criteria = new Criteria(ImportExportTypeTableMap::DATABASE_NAME); - $criteria->add(ImportExportTypeTableMap::ID, $this->id); + $criteria = new Criteria(ImportTableMap::DATABASE_NAME); + $criteria->add(ImportTableMap::ID, $this->id); return $criteria; } @@ -1259,15 +1203,14 @@ abstract class ImportExportType implements ActiveRecordInterface * If desired, this method can also make copies of all associated (fkey referrers) * objects. * - * @param object $copyObj An object of \Thelia\Model\ImportExportType (or compatible) type. + * @param object $copyObj An object of \Thelia\Model\Import (or compatible) type. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. * @throws PropelException */ public function copyInto($copyObj, $deepCopy = false, $makeNew = true) { - $copyObj->setUrlAction($this->getUrlAction()); - $copyObj->setImportExportCategoryId($this->getImportExportCategoryId()); + $copyObj->setImportCategoryId($this->getImportCategoryId()); $copyObj->setPosition($this->getPosition()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); @@ -1277,9 +1220,9 @@ abstract class ImportExportType implements ActiveRecordInterface // the getter/setter methods for fkey referrer objects. $copyObj->setNew(false); - foreach ($this->getImportExportTypeI18ns() as $relObj) { + foreach ($this->getImportI18ns() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves - $copyObj->addImportExportTypeI18n($relObj->copy($deepCopy)); + $copyObj->addImportI18n($relObj->copy($deepCopy)); } } @@ -1300,7 +1243,7 @@ abstract class ImportExportType implements ActiveRecordInterface * objects. * * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. - * @return \Thelia\Model\ImportExportType Clone of current object. + * @return \Thelia\Model\Import Clone of current object. * @throws PropelException */ public function copy($deepCopy = false) @@ -1314,26 +1257,26 @@ abstract class ImportExportType implements ActiveRecordInterface } /** - * Declares an association between this object and a ChildImportExportCategory object. + * Declares an association between this object and a ChildImportCategory object. * - * @param ChildImportExportCategory $v - * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + * @param ChildImportCategory $v + * @return \Thelia\Model\Import The current object (for fluent API support) * @throws PropelException */ - public function setImportExportCategory(ChildImportExportCategory $v = null) + public function setImportCategory(ChildImportCategory $v = null) { if ($v === null) { - $this->setImportExportCategoryId(NULL); + $this->setImportCategoryId(NULL); } else { - $this->setImportExportCategoryId($v->getId()); + $this->setImportCategoryId($v->getId()); } - $this->aImportExportCategory = $v; + $this->aImportCategory = $v; // Add binding for other direction of this n:n relationship. - // If this object has already been added to the ChildImportExportCategory object, it will not be re-added. + // If this object has already been added to the ChildImportCategory object, it will not be re-added. if ($v !== null) { - $v->addImportExportType($this); + $v->addImport($this); } @@ -1342,26 +1285,26 @@ abstract class ImportExportType implements ActiveRecordInterface /** - * Get the associated ChildImportExportCategory object + * Get the associated ChildImportCategory object * * @param ConnectionInterface $con Optional Connection object. - * @return ChildImportExportCategory The associated ChildImportExportCategory object. + * @return ChildImportCategory The associated ChildImportCategory object. * @throws PropelException */ - public function getImportExportCategory(ConnectionInterface $con = null) + public function getImportCategory(ConnectionInterface $con = null) { - if ($this->aImportExportCategory === null && ($this->import_export_category_id !== null)) { - $this->aImportExportCategory = ChildImportExportCategoryQuery::create()->findPk($this->import_export_category_id, $con); + if ($this->aImportCategory === null && ($this->import_category_id !== null)) { + $this->aImportCategory = ChildImportCategoryQuery::create()->findPk($this->import_category_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. - $this->aImportExportCategory->addImportExportTypes($this); + $this->aImportCategory->addImports($this); */ } - return $this->aImportExportCategory; + return $this->aImportCategory; } @@ -1375,37 +1318,37 @@ abstract class ImportExportType implements ActiveRecordInterface */ public function initRelation($relationName) { - if ('ImportExportTypeI18n' == $relationName) { - return $this->initImportExportTypeI18ns(); + if ('ImportI18n' == $relationName) { + return $this->initImportI18ns(); } } /** - * Clears out the collImportExportTypeI18ns collection + * Clears out the collImportI18ns collection * * This does not modify the database; however, it will remove any associated objects, causing * them to be refetched by subsequent calls to accessor method. * * @return void - * @see addImportExportTypeI18ns() + * @see addImportI18ns() */ - public function clearImportExportTypeI18ns() + public function clearImportI18ns() { - $this->collImportExportTypeI18ns = null; // important to set this to NULL since that means it is uninitialized + $this->collImportI18ns = null; // important to set this to NULL since that means it is uninitialized } /** - * Reset is the collImportExportTypeI18ns collection loaded partially. + * Reset is the collImportI18ns collection loaded partially. */ - public function resetPartialImportExportTypeI18ns($v = true) + public function resetPartialImportI18ns($v = true) { - $this->collImportExportTypeI18nsPartial = $v; + $this->collImportI18nsPartial = $v; } /** - * Initializes the collImportExportTypeI18ns collection. + * Initializes the collImportI18ns collection. * - * By default this just sets the collImportExportTypeI18ns collection to an empty array (like clearcollImportExportTypeI18ns()); + * By default this just sets the collImportI18ns collection to an empty array (like clearcollImportI18ns()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * @@ -1414,192 +1357,192 @@ abstract class ImportExportType implements ActiveRecordInterface * * @return void */ - public function initImportExportTypeI18ns($overrideExisting = true) + public function initImportI18ns($overrideExisting = true) { - if (null !== $this->collImportExportTypeI18ns && !$overrideExisting) { + if (null !== $this->collImportI18ns && !$overrideExisting) { return; } - $this->collImportExportTypeI18ns = new ObjectCollection(); - $this->collImportExportTypeI18ns->setModel('\Thelia\Model\ImportExportTypeI18n'); + $this->collImportI18ns = new ObjectCollection(); + $this->collImportI18ns->setModel('\Thelia\Model\ImportI18n'); } /** - * Gets an array of ChildImportExportTypeI18n objects which contain a foreign key that references this object. + * Gets an array of ChildImportI18n objects which contain a foreign key that references this object. * * If the $criteria is not null, it is used to always fetch the results from the database. * Otherwise the results are fetched from the database the first time, then cached. * Next time the same method is called without $criteria, the cached collection is returned. - * If this ChildImportExportType is new, it will return + * If this ChildImport is new, it will return * an empty collection or the current collection; the criteria is ignored on a new object. * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object - * @return Collection|ChildImportExportTypeI18n[] List of ChildImportExportTypeI18n objects + * @return Collection|ChildImportI18n[] List of ChildImportI18n objects * @throws PropelException */ - public function getImportExportTypeI18ns($criteria = null, ConnectionInterface $con = null) + public function getImportI18ns($criteria = null, ConnectionInterface $con = null) { - $partial = $this->collImportExportTypeI18nsPartial && !$this->isNew(); - if (null === $this->collImportExportTypeI18ns || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collImportExportTypeI18ns) { + $partial = $this->collImportI18nsPartial && !$this->isNew(); + if (null === $this->collImportI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collImportI18ns) { // return empty collection - $this->initImportExportTypeI18ns(); + $this->initImportI18ns(); } else { - $collImportExportTypeI18ns = ChildImportExportTypeI18nQuery::create(null, $criteria) - ->filterByImportExportType($this) + $collImportI18ns = ChildImportI18nQuery::create(null, $criteria) + ->filterByImport($this) ->find($con); if (null !== $criteria) { - if (false !== $this->collImportExportTypeI18nsPartial && count($collImportExportTypeI18ns)) { - $this->initImportExportTypeI18ns(false); + if (false !== $this->collImportI18nsPartial && count($collImportI18ns)) { + $this->initImportI18ns(false); - foreach ($collImportExportTypeI18ns as $obj) { - if (false == $this->collImportExportTypeI18ns->contains($obj)) { - $this->collImportExportTypeI18ns->append($obj); + foreach ($collImportI18ns as $obj) { + if (false == $this->collImportI18ns->contains($obj)) { + $this->collImportI18ns->append($obj); } } - $this->collImportExportTypeI18nsPartial = true; + $this->collImportI18nsPartial = true; } - reset($collImportExportTypeI18ns); + reset($collImportI18ns); - return $collImportExportTypeI18ns; + return $collImportI18ns; } - if ($partial && $this->collImportExportTypeI18ns) { - foreach ($this->collImportExportTypeI18ns as $obj) { + if ($partial && $this->collImportI18ns) { + foreach ($this->collImportI18ns as $obj) { if ($obj->isNew()) { - $collImportExportTypeI18ns[] = $obj; + $collImportI18ns[] = $obj; } } } - $this->collImportExportTypeI18ns = $collImportExportTypeI18ns; - $this->collImportExportTypeI18nsPartial = false; + $this->collImportI18ns = $collImportI18ns; + $this->collImportI18nsPartial = false; } } - return $this->collImportExportTypeI18ns; + return $this->collImportI18ns; } /** - * Sets a collection of ImportExportTypeI18n objects related by a one-to-many relationship + * Sets a collection of ImportI18n objects related by a one-to-many relationship * to the current object. * It will also schedule objects for deletion based on a diff between old objects (aka persisted) * and new objects from the given Propel collection. * - * @param Collection $importExportTypeI18ns A Propel collection. + * @param Collection $importI18ns A Propel collection. * @param ConnectionInterface $con Optional connection object - * @return ChildImportExportType The current object (for fluent API support) + * @return ChildImport The current object (for fluent API support) */ - public function setImportExportTypeI18ns(Collection $importExportTypeI18ns, ConnectionInterface $con = null) + public function setImportI18ns(Collection $importI18ns, ConnectionInterface $con = null) { - $importExportTypeI18nsToDelete = $this->getImportExportTypeI18ns(new Criteria(), $con)->diff($importExportTypeI18ns); + $importI18nsToDelete = $this->getImportI18ns(new Criteria(), $con)->diff($importI18ns); //since at least one column in the foreign key is at the same time a PK //we can not just set a PK to NULL in the lines below. We have to store //a backup of all values, so we are able to manipulate these items based on the onDelete value later. - $this->importExportTypeI18nsScheduledForDeletion = clone $importExportTypeI18nsToDelete; + $this->importI18nsScheduledForDeletion = clone $importI18nsToDelete; - foreach ($importExportTypeI18nsToDelete as $importExportTypeI18nRemoved) { - $importExportTypeI18nRemoved->setImportExportType(null); + foreach ($importI18nsToDelete as $importI18nRemoved) { + $importI18nRemoved->setImport(null); } - $this->collImportExportTypeI18ns = null; - foreach ($importExportTypeI18ns as $importExportTypeI18n) { - $this->addImportExportTypeI18n($importExportTypeI18n); + $this->collImportI18ns = null; + foreach ($importI18ns as $importI18n) { + $this->addImportI18n($importI18n); } - $this->collImportExportTypeI18ns = $importExportTypeI18ns; - $this->collImportExportTypeI18nsPartial = false; + $this->collImportI18ns = $importI18ns; + $this->collImportI18nsPartial = false; return $this; } /** - * Returns the number of related ImportExportTypeI18n objects. + * Returns the number of related ImportI18n objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con - * @return int Count of related ImportExportTypeI18n objects. + * @return int Count of related ImportI18n objects. * @throws PropelException */ - public function countImportExportTypeI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + public function countImportI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { - $partial = $this->collImportExportTypeI18nsPartial && !$this->isNew(); - if (null === $this->collImportExportTypeI18ns || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collImportExportTypeI18ns) { + $partial = $this->collImportI18nsPartial && !$this->isNew(); + if (null === $this->collImportI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collImportI18ns) { return 0; } if ($partial && !$criteria) { - return count($this->getImportExportTypeI18ns()); + return count($this->getImportI18ns()); } - $query = ChildImportExportTypeI18nQuery::create(null, $criteria); + $query = ChildImportI18nQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query - ->filterByImportExportType($this) + ->filterByImport($this) ->count($con); } - return count($this->collImportExportTypeI18ns); + return count($this->collImportI18ns); } /** - * Method called to associate a ChildImportExportTypeI18n object to this object - * through the ChildImportExportTypeI18n foreign key attribute. + * Method called to associate a ChildImportI18n object to this object + * through the ChildImportI18n foreign key attribute. * - * @param ChildImportExportTypeI18n $l ChildImportExportTypeI18n - * @return \Thelia\Model\ImportExportType The current object (for fluent API support) + * @param ChildImportI18n $l ChildImportI18n + * @return \Thelia\Model\Import The current object (for fluent API support) */ - public function addImportExportTypeI18n(ChildImportExportTypeI18n $l) + public function addImportI18n(ChildImportI18n $l) { if ($l && $locale = $l->getLocale()) { $this->setLocale($locale); $this->currentTranslations[$locale] = $l; } - if ($this->collImportExportTypeI18ns === null) { - $this->initImportExportTypeI18ns(); - $this->collImportExportTypeI18nsPartial = true; + if ($this->collImportI18ns === null) { + $this->initImportI18ns(); + $this->collImportI18nsPartial = true; } - if (!in_array($l, $this->collImportExportTypeI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated - $this->doAddImportExportTypeI18n($l); + if (!in_array($l, $this->collImportI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddImportI18n($l); } return $this; } /** - * @param ImportExportTypeI18n $importExportTypeI18n The importExportTypeI18n object to add. + * @param ImportI18n $importI18n The importI18n object to add. */ - protected function doAddImportExportTypeI18n($importExportTypeI18n) + protected function doAddImportI18n($importI18n) { - $this->collImportExportTypeI18ns[]= $importExportTypeI18n; - $importExportTypeI18n->setImportExportType($this); + $this->collImportI18ns[]= $importI18n; + $importI18n->setImport($this); } /** - * @param ImportExportTypeI18n $importExportTypeI18n The importExportTypeI18n object to remove. - * @return ChildImportExportType The current object (for fluent API support) + * @param ImportI18n $importI18n The importI18n object to remove. + * @return ChildImport The current object (for fluent API support) */ - public function removeImportExportTypeI18n($importExportTypeI18n) + public function removeImportI18n($importI18n) { - if ($this->getImportExportTypeI18ns()->contains($importExportTypeI18n)) { - $this->collImportExportTypeI18ns->remove($this->collImportExportTypeI18ns->search($importExportTypeI18n)); - if (null === $this->importExportTypeI18nsScheduledForDeletion) { - $this->importExportTypeI18nsScheduledForDeletion = clone $this->collImportExportTypeI18ns; - $this->importExportTypeI18nsScheduledForDeletion->clear(); + if ($this->getImportI18ns()->contains($importI18n)) { + $this->collImportI18ns->remove($this->collImportI18ns->search($importI18n)); + if (null === $this->importI18nsScheduledForDeletion) { + $this->importI18nsScheduledForDeletion = clone $this->collImportI18ns; + $this->importI18nsScheduledForDeletion->clear(); } - $this->importExportTypeI18nsScheduledForDeletion[]= clone $importExportTypeI18n; - $importExportTypeI18n->setImportExportType(null); + $this->importI18nsScheduledForDeletion[]= clone $importI18n; + $importI18n->setImport(null); } return $this; @@ -1611,8 +1554,7 @@ abstract class ImportExportType implements ActiveRecordInterface public function clear() { $this->id = null; - $this->url_action = null; - $this->import_export_category_id = null; + $this->import_category_id = null; $this->position = null; $this->created_at = null; $this->updated_at = null; @@ -1635,8 +1577,8 @@ abstract class ImportExportType implements ActiveRecordInterface public function clearAllReferences($deep = false) { if ($deep) { - if ($this->collImportExportTypeI18ns) { - foreach ($this->collImportExportTypeI18ns as $o) { + if ($this->collImportI18ns) { + foreach ($this->collImportI18ns as $o) { $o->clearAllReferences($deep); } } @@ -1646,8 +1588,8 @@ abstract class ImportExportType implements ActiveRecordInterface $this->currentLocale = 'en_US'; $this->currentTranslations = null; - $this->collImportExportTypeI18ns = null; - $this->aImportExportCategory = null; + $this->collImportI18ns = null; + $this->aImportCategory = null; } /** @@ -1657,7 +1599,7 @@ abstract class ImportExportType implements ActiveRecordInterface */ public function __toString() { - return (string) $this->exportTo(ImportExportTypeTableMap::DEFAULT_STRING_FORMAT); + return (string) $this->exportTo(ImportTableMap::DEFAULT_STRING_FORMAT); } // i18n behavior @@ -1667,7 +1609,7 @@ abstract class ImportExportType implements ActiveRecordInterface * * @param string $locale Locale to use for the translation, e.g. 'fr_FR' * - * @return ChildImportExportType The current object (for fluent API support) + * @return ChildImport The current object (for fluent API support) */ public function setLocale($locale = 'en_US') { @@ -1692,12 +1634,12 @@ abstract class ImportExportType implements ActiveRecordInterface * @param string $locale Locale to use for the translation, e.g. 'fr_FR' * @param ConnectionInterface $con an optional connection object * - * @return ChildImportExportTypeI18n */ + * @return ChildImportI18n */ public function getTranslation($locale = 'en_US', ConnectionInterface $con = null) { if (!isset($this->currentTranslations[$locale])) { - if (null !== $this->collImportExportTypeI18ns) { - foreach ($this->collImportExportTypeI18ns as $translation) { + if (null !== $this->collImportI18ns) { + foreach ($this->collImportI18ns as $translation) { if ($translation->getLocale() == $locale) { $this->currentTranslations[$locale] = $translation; @@ -1706,15 +1648,15 @@ abstract class ImportExportType implements ActiveRecordInterface } } if ($this->isNew()) { - $translation = new ChildImportExportTypeI18n(); + $translation = new ChildImportI18n(); $translation->setLocale($locale); } else { - $translation = ChildImportExportTypeI18nQuery::create() + $translation = ChildImportI18nQuery::create() ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) ->findOneOrCreate($con); $this->currentTranslations[$locale] = $translation; } - $this->addImportExportTypeI18n($translation); + $this->addImportI18n($translation); } return $this->currentTranslations[$locale]; @@ -1726,21 +1668,21 @@ abstract class ImportExportType implements ActiveRecordInterface * @param string $locale Locale to use for the translation, e.g. 'fr_FR' * @param ConnectionInterface $con an optional connection object * - * @return ChildImportExportType The current object (for fluent API support) + * @return ChildImport The current object (for fluent API support) */ public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null) { if (!$this->isNew()) { - ChildImportExportTypeI18nQuery::create() + ChildImportI18nQuery::create() ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) ->delete($con); } if (isset($this->currentTranslations[$locale])) { unset($this->currentTranslations[$locale]); } - foreach ($this->collImportExportTypeI18ns as $key => $translation) { + foreach ($this->collImportI18ns as $key => $translation) { if ($translation->getLocale() == $locale) { - unset($this->collImportExportTypeI18ns[$key]); + unset($this->collImportI18ns[$key]); break; } } @@ -1753,7 +1695,7 @@ abstract class ImportExportType implements ActiveRecordInterface * * @param ConnectionInterface $con an optional connection object * - * @return ChildImportExportTypeI18n */ + * @return ChildImportI18n */ public function getCurrentTranslation(ConnectionInterface $con = null) { return $this->getTranslation($this->getLocale(), $con); @@ -1775,7 +1717,7 @@ abstract class ImportExportType implements ActiveRecordInterface * Set the value of [title] column. * * @param string $v new value - * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + * @return \Thelia\Model\ImportI18n The current object (for fluent API support) */ public function setTitle($v) { $this->getCurrentTranslation()->setTitle($v); @@ -1799,7 +1741,7 @@ abstract class ImportExportType implements ActiveRecordInterface * Set the value of [description] column. * * @param string $v new value - * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + * @return \Thelia\Model\ImportI18n The current object (for fluent API support) */ public function setDescription($v) { $this->getCurrentTranslation()->setDescription($v); @@ -1812,11 +1754,11 @@ abstract class ImportExportType implements ActiveRecordInterface /** * Mark the current object so that the update date doesn't get updated during next save * - * @return ChildImportExportType The current object (for fluent API support) + * @return ChildImport The current object (for fluent API support) */ public function keepUpdateDateUnchanged() { - $this->modifiedColumns[ImportExportTypeTableMap::UPDATED_AT] = true; + $this->modifiedColumns[ImportTableMap::UPDATED_AT] = true; return $this; } diff --git a/core/lib/Thelia/Model/Base/ImportExportCategory.php b/core/lib/Thelia/Model/Base/ImportCategory.php similarity index 68% rename from core/lib/Thelia/Model/Base/ImportExportCategory.php rename to core/lib/Thelia/Model/Base/ImportCategory.php index ed0e5007c..83f3f2810 100644 --- a/core/lib/Thelia/Model/Base/ImportExportCategory.php +++ b/core/lib/Thelia/Model/Base/ImportCategory.php @@ -17,20 +17,20 @@ use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Parser\AbstractParser; use Propel\Runtime\Util\PropelDateTime; -use Thelia\Model\ImportExportCategory as ChildImportExportCategory; -use Thelia\Model\ImportExportCategoryI18n as ChildImportExportCategoryI18n; -use Thelia\Model\ImportExportCategoryI18nQuery as ChildImportExportCategoryI18nQuery; -use Thelia\Model\ImportExportCategoryQuery as ChildImportExportCategoryQuery; -use Thelia\Model\ImportExportType as ChildImportExportType; -use Thelia\Model\ImportExportTypeQuery as ChildImportExportTypeQuery; -use Thelia\Model\Map\ImportExportCategoryTableMap; +use Thelia\Model\Import as ChildImport; +use Thelia\Model\ImportCategory as ChildImportCategory; +use Thelia\Model\ImportCategoryI18n as ChildImportCategoryI18n; +use Thelia\Model\ImportCategoryI18nQuery as ChildImportCategoryI18nQuery; +use Thelia\Model\ImportCategoryQuery as ChildImportCategoryQuery; +use Thelia\Model\ImportQuery as ChildImportQuery; +use Thelia\Model\Map\ImportCategoryTableMap; -abstract class ImportExportCategory implements ActiveRecordInterface +abstract class ImportCategory implements ActiveRecordInterface { /** * TableMap class name */ - const TABLE_MAP = '\\Thelia\\Model\\Map\\ImportExportCategoryTableMap'; + const TABLE_MAP = '\\Thelia\\Model\\Map\\ImportCategoryTableMap'; /** @@ -84,16 +84,16 @@ abstract class ImportExportCategory implements ActiveRecordInterface protected $updated_at; /** - * @var ObjectCollection|ChildImportExportType[] Collection to store aggregation of ChildImportExportType objects. + * @var ObjectCollection|ChildImport[] Collection to store aggregation of ChildImport objects. */ - protected $collImportExportTypes; - protected $collImportExportTypesPartial; + protected $collImports; + protected $collImportsPartial; /** - * @var ObjectCollection|ChildImportExportCategoryI18n[] Collection to store aggregation of ChildImportExportCategoryI18n objects. + * @var ObjectCollection|ChildImportCategoryI18n[] Collection to store aggregation of ChildImportCategoryI18n objects. */ - protected $collImportExportCategoryI18ns; - protected $collImportExportCategoryI18nsPartial; + protected $collImportCategoryI18ns; + protected $collImportCategoryI18nsPartial; /** * Flag to prevent endless save loop, if this object is referenced @@ -113,7 +113,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface /** * Current translation objects - * @var array[ChildImportExportCategoryI18n] + * @var array[ChildImportCategoryI18n] */ protected $currentTranslations; @@ -121,16 +121,16 @@ abstract class ImportExportCategory implements ActiveRecordInterface * An array of objects scheduled for deletion. * @var ObjectCollection */ - protected $importExportTypesScheduledForDeletion = null; + protected $importsScheduledForDeletion = null; /** * An array of objects scheduled for deletion. * @var ObjectCollection */ - protected $importExportCategoryI18nsScheduledForDeletion = null; + protected $importCategoryI18nsScheduledForDeletion = null; /** - * Initializes internal state of Thelia\Model\Base\ImportExportCategory object. + * Initializes internal state of Thelia\Model\Base\ImportCategory object. */ public function __construct() { @@ -225,9 +225,9 @@ abstract class ImportExportCategory implements ActiveRecordInterface } /** - * Compares this with another ImportExportCategory instance. If - * obj is an instance of ImportExportCategory, delegates to - * equals(ImportExportCategory). Otherwise, returns false. + * Compares this with another ImportCategory instance. If + * obj is an instance of ImportCategory, delegates to + * equals(ImportCategory). Otherwise, returns false. * * @param mixed $obj The object to compare to. * @return boolean Whether equal to the object specified. @@ -310,7 +310,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface * @param string $name The virtual column name * @param mixed $value The value to give to the virtual column * - * @return ImportExportCategory The current object, for fluid interface + * @return ImportCategory The current object, for fluid interface */ public function setVirtualColumn($name, $value) { @@ -342,7 +342,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface * or a format name ('XML', 'YAML', 'JSON', 'CSV') * @param string $data The source data to import from * - * @return ImportExportCategory The current object, for fluid interface + * @return ImportCategory The current object, for fluid interface */ public function importFrom($parser, $data) { @@ -453,7 +453,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface * Set the value of [id] column. * * @param int $v new value - * @return \Thelia\Model\ImportExportCategory The current object (for fluent API support) + * @return \Thelia\Model\ImportCategory The current object (for fluent API support) */ public function setId($v) { @@ -463,7 +463,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface if ($this->id !== $v) { $this->id = $v; - $this->modifiedColumns[ImportExportCategoryTableMap::ID] = true; + $this->modifiedColumns[ImportCategoryTableMap::ID] = true; } @@ -474,7 +474,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface * Set the value of [position] column. * * @param int $v new value - * @return \Thelia\Model\ImportExportCategory The current object (for fluent API support) + * @return \Thelia\Model\ImportCategory The current object (for fluent API support) */ public function setPosition($v) { @@ -484,7 +484,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface if ($this->position !== $v) { $this->position = $v; - $this->modifiedColumns[ImportExportCategoryTableMap::POSITION] = true; + $this->modifiedColumns[ImportCategoryTableMap::POSITION] = true; } @@ -496,7 +496,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface * * @param mixed $v string, integer (timestamp), or \DateTime value. * Empty strings are treated as NULL. - * @return \Thelia\Model\ImportExportCategory The current object (for fluent API support) + * @return \Thelia\Model\ImportCategory The current object (for fluent API support) */ public function setCreatedAt($v) { @@ -504,7 +504,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface if ($this->created_at !== null || $dt !== null) { if ($dt !== $this->created_at) { $this->created_at = $dt; - $this->modifiedColumns[ImportExportCategoryTableMap::CREATED_AT] = true; + $this->modifiedColumns[ImportCategoryTableMap::CREATED_AT] = true; } } // if either are not null @@ -517,7 +517,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface * * @param mixed $v string, integer (timestamp), or \DateTime value. * Empty strings are treated as NULL. - * @return \Thelia\Model\ImportExportCategory The current object (for fluent API support) + * @return \Thelia\Model\ImportCategory The current object (for fluent API support) */ public function setUpdatedAt($v) { @@ -525,7 +525,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface if ($this->updated_at !== null || $dt !== null) { if ($dt !== $this->updated_at) { $this->updated_at = $dt; - $this->modifiedColumns[ImportExportCategoryTableMap::UPDATED_AT] = true; + $this->modifiedColumns[ImportCategoryTableMap::UPDATED_AT] = true; } } // if either are not null @@ -570,19 +570,19 @@ abstract class ImportExportCategory implements ActiveRecordInterface try { - $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ImportExportCategoryTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ImportCategoryTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; $this->id = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ImportExportCategoryTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ImportCategoryTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; $this->position = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportExportCategoryTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportCategoryTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportExportCategoryTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportCategoryTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -595,10 +595,10 @@ abstract class ImportExportCategory implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 4; // 4 = ImportExportCategoryTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 4; // 4 = ImportCategoryTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { - throw new PropelException("Error populating \Thelia\Model\ImportExportCategory object", 0, $e); + throw new PropelException("Error populating \Thelia\Model\ImportCategory object", 0, $e); } } @@ -640,13 +640,13 @@ abstract class ImportExportCategory implements ActiveRecordInterface } if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(ImportExportCategoryTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getReadConnection(ImportCategoryTableMap::DATABASE_NAME); } // We don't need to alter the object instance pool; we're just modifying this instance // already in the pool. - $dataFetcher = ChildImportExportCategoryQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $dataFetcher = ChildImportCategoryQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); $row = $dataFetcher->fetch(); $dataFetcher->close(); if (!$row) { @@ -656,9 +656,9 @@ abstract class ImportExportCategory implements ActiveRecordInterface if ($deep) { // also de-associate any related objects? - $this->collImportExportTypes = null; + $this->collImports = null; - $this->collImportExportCategoryI18ns = null; + $this->collImportCategoryI18ns = null; } // if (deep) } @@ -669,8 +669,8 @@ abstract class ImportExportCategory implements ActiveRecordInterface * @param ConnectionInterface $con * @return void * @throws PropelException - * @see ImportExportCategory::setDeleted() - * @see ImportExportCategory::isDeleted() + * @see ImportCategory::setDeleted() + * @see ImportCategory::isDeleted() */ public function delete(ConnectionInterface $con = null) { @@ -679,12 +679,12 @@ abstract class ImportExportCategory implements ActiveRecordInterface } if ($con === null) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryTableMap::DATABASE_NAME); } $con->beginTransaction(); try { - $deleteQuery = ChildImportExportCategoryQuery::create() + $deleteQuery = ChildImportCategoryQuery::create() ->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { @@ -721,7 +721,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface } if ($con === null) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryTableMap::DATABASE_NAME); } $con->beginTransaction(); @@ -731,16 +731,16 @@ abstract class ImportExportCategory implements ActiveRecordInterface if ($isInsert) { $ret = $ret && $this->preInsert($con); // timestampable behavior - if (!$this->isColumnModified(ImportExportCategoryTableMap::CREATED_AT)) { + if (!$this->isColumnModified(ImportCategoryTableMap::CREATED_AT)) { $this->setCreatedAt(time()); } - if (!$this->isColumnModified(ImportExportCategoryTableMap::UPDATED_AT)) { + if (!$this->isColumnModified(ImportCategoryTableMap::UPDATED_AT)) { $this->setUpdatedAt(time()); } } else { $ret = $ret && $this->preUpdate($con); // timestampable behavior - if ($this->isModified() && !$this->isColumnModified(ImportExportCategoryTableMap::UPDATED_AT)) { + if ($this->isModified() && !$this->isColumnModified(ImportCategoryTableMap::UPDATED_AT)) { $this->setUpdatedAt(time()); } } @@ -752,7 +752,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface $this->postUpdate($con); } $this->postSave($con); - ImportExportCategoryTableMap::addInstanceToPool($this); + ImportCategoryTableMap::addInstanceToPool($this); } else { $affectedRows = 0; } @@ -793,34 +793,34 @@ abstract class ImportExportCategory implements ActiveRecordInterface $this->resetModified(); } - if ($this->importExportTypesScheduledForDeletion !== null) { - if (!$this->importExportTypesScheduledForDeletion->isEmpty()) { - \Thelia\Model\ImportExportTypeQuery::create() - ->filterByPrimaryKeys($this->importExportTypesScheduledForDeletion->getPrimaryKeys(false)) + if ($this->importsScheduledForDeletion !== null) { + if (!$this->importsScheduledForDeletion->isEmpty()) { + \Thelia\Model\ImportQuery::create() + ->filterByPrimaryKeys($this->importsScheduledForDeletion->getPrimaryKeys(false)) ->delete($con); - $this->importExportTypesScheduledForDeletion = null; + $this->importsScheduledForDeletion = null; } } - if ($this->collImportExportTypes !== null) { - foreach ($this->collImportExportTypes as $referrerFK) { + if ($this->collImports !== null) { + foreach ($this->collImports as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } } } - if ($this->importExportCategoryI18nsScheduledForDeletion !== null) { - if (!$this->importExportCategoryI18nsScheduledForDeletion->isEmpty()) { - \Thelia\Model\ImportExportCategoryI18nQuery::create() - ->filterByPrimaryKeys($this->importExportCategoryI18nsScheduledForDeletion->getPrimaryKeys(false)) + if ($this->importCategoryI18nsScheduledForDeletion !== null) { + if (!$this->importCategoryI18nsScheduledForDeletion->isEmpty()) { + \Thelia\Model\ImportCategoryI18nQuery::create() + ->filterByPrimaryKeys($this->importCategoryI18nsScheduledForDeletion->getPrimaryKeys(false)) ->delete($con); - $this->importExportCategoryI18nsScheduledForDeletion = null; + $this->importCategoryI18nsScheduledForDeletion = null; } } - if ($this->collImportExportCategoryI18ns !== null) { - foreach ($this->collImportExportCategoryI18ns as $referrerFK) { + if ($this->collImportCategoryI18ns !== null) { + foreach ($this->collImportCategoryI18ns as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } @@ -847,27 +847,27 @@ abstract class ImportExportCategory implements ActiveRecordInterface $modifiedColumns = array(); $index = 0; - $this->modifiedColumns[ImportExportCategoryTableMap::ID] = true; + $this->modifiedColumns[ImportCategoryTableMap::ID] = true; if (null !== $this->id) { - throw new PropelException('Cannot insert a value for auto-increment primary key (' . ImportExportCategoryTableMap::ID . ')'); + throw new PropelException('Cannot insert a value for auto-increment primary key (' . ImportCategoryTableMap::ID . ')'); } // check the columns in natural order for more readable SQL queries - if ($this->isColumnModified(ImportExportCategoryTableMap::ID)) { + if ($this->isColumnModified(ImportCategoryTableMap::ID)) { $modifiedColumns[':p' . $index++] = '`ID`'; } - if ($this->isColumnModified(ImportExportCategoryTableMap::POSITION)) { + if ($this->isColumnModified(ImportCategoryTableMap::POSITION)) { $modifiedColumns[':p' . $index++] = '`POSITION`'; } - if ($this->isColumnModified(ImportExportCategoryTableMap::CREATED_AT)) { + if ($this->isColumnModified(ImportCategoryTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = '`CREATED_AT`'; } - if ($this->isColumnModified(ImportExportCategoryTableMap::UPDATED_AT)) { + if ($this->isColumnModified(ImportCategoryTableMap::UPDATED_AT)) { $modifiedColumns[':p' . $index++] = '`UPDATED_AT`'; } $sql = sprintf( - 'INSERT INTO `import_export_category` (%s) VALUES (%s)', + 'INSERT INTO `import_category` (%s) VALUES (%s)', implode(', ', $modifiedColumns), implode(', ', array_keys($modifiedColumns)) ); @@ -934,7 +934,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface */ public function getByName($name, $type = TableMap::TYPE_PHPNAME) { - $pos = ImportExportCategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $pos = ImportCategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); $field = $this->getByPosition($pos); return $field; @@ -985,11 +985,11 @@ abstract class ImportExportCategory implements ActiveRecordInterface */ public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { - if (isset($alreadyDumpedObjects['ImportExportCategory'][$this->getPrimaryKey()])) { + if (isset($alreadyDumpedObjects['ImportCategory'][$this->getPrimaryKey()])) { return '*RECURSION*'; } - $alreadyDumpedObjects['ImportExportCategory'][$this->getPrimaryKey()] = true; - $keys = ImportExportCategoryTableMap::getFieldNames($keyType); + $alreadyDumpedObjects['ImportCategory'][$this->getPrimaryKey()] = true; + $keys = ImportCategoryTableMap::getFieldNames($keyType); $result = array( $keys[0] => $this->getId(), $keys[1] => $this->getPosition(), @@ -1002,11 +1002,11 @@ abstract class ImportExportCategory implements ActiveRecordInterface } if ($includeForeignObjects) { - if (null !== $this->collImportExportTypes) { - $result['ImportExportTypes'] = $this->collImportExportTypes->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + if (null !== $this->collImports) { + $result['Imports'] = $this->collImports->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } - if (null !== $this->collImportExportCategoryI18ns) { - $result['ImportExportCategoryI18ns'] = $this->collImportExportCategoryI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + if (null !== $this->collImportCategoryI18ns) { + $result['ImportCategoryI18ns'] = $this->collImportCategoryI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); } } @@ -1026,7 +1026,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface */ public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) { - $pos = ImportExportCategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $pos = ImportCategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); return $this->setByPosition($pos, $value); } @@ -1076,7 +1076,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface */ public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) { - $keys = ImportExportCategoryTableMap::getFieldNames($keyType); + $keys = ImportCategoryTableMap::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setPosition($arr[$keys[1]]); @@ -1091,12 +1091,12 @@ abstract class ImportExportCategory implements ActiveRecordInterface */ public function buildCriteria() { - $criteria = new Criteria(ImportExportCategoryTableMap::DATABASE_NAME); + $criteria = new Criteria(ImportCategoryTableMap::DATABASE_NAME); - if ($this->isColumnModified(ImportExportCategoryTableMap::ID)) $criteria->add(ImportExportCategoryTableMap::ID, $this->id); - if ($this->isColumnModified(ImportExportCategoryTableMap::POSITION)) $criteria->add(ImportExportCategoryTableMap::POSITION, $this->position); - if ($this->isColumnModified(ImportExportCategoryTableMap::CREATED_AT)) $criteria->add(ImportExportCategoryTableMap::CREATED_AT, $this->created_at); - if ($this->isColumnModified(ImportExportCategoryTableMap::UPDATED_AT)) $criteria->add(ImportExportCategoryTableMap::UPDATED_AT, $this->updated_at); + if ($this->isColumnModified(ImportCategoryTableMap::ID)) $criteria->add(ImportCategoryTableMap::ID, $this->id); + if ($this->isColumnModified(ImportCategoryTableMap::POSITION)) $criteria->add(ImportCategoryTableMap::POSITION, $this->position); + if ($this->isColumnModified(ImportCategoryTableMap::CREATED_AT)) $criteria->add(ImportCategoryTableMap::CREATED_AT, $this->created_at); + if ($this->isColumnModified(ImportCategoryTableMap::UPDATED_AT)) $criteria->add(ImportCategoryTableMap::UPDATED_AT, $this->updated_at); return $criteria; } @@ -1111,8 +1111,8 @@ abstract class ImportExportCategory implements ActiveRecordInterface */ public function buildPkeyCriteria() { - $criteria = new Criteria(ImportExportCategoryTableMap::DATABASE_NAME); - $criteria->add(ImportExportCategoryTableMap::ID, $this->id); + $criteria = new Criteria(ImportCategoryTableMap::DATABASE_NAME); + $criteria->add(ImportCategoryTableMap::ID, $this->id); return $criteria; } @@ -1153,7 +1153,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface * If desired, this method can also make copies of all associated (fkey referrers) * objects. * - * @param object $copyObj An object of \Thelia\Model\ImportExportCategory (or compatible) type. + * @param object $copyObj An object of \Thelia\Model\ImportCategory (or compatible) type. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. * @throws PropelException @@ -1169,15 +1169,15 @@ abstract class ImportExportCategory implements ActiveRecordInterface // the getter/setter methods for fkey referrer objects. $copyObj->setNew(false); - foreach ($this->getImportExportTypes() as $relObj) { + foreach ($this->getImports() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves - $copyObj->addImportExportType($relObj->copy($deepCopy)); + $copyObj->addImport($relObj->copy($deepCopy)); } } - foreach ($this->getImportExportCategoryI18ns() as $relObj) { + foreach ($this->getImportCategoryI18ns() as $relObj) { if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves - $copyObj->addImportExportCategoryI18n($relObj->copy($deepCopy)); + $copyObj->addImportCategoryI18n($relObj->copy($deepCopy)); } } @@ -1198,7 +1198,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface * objects. * * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. - * @return \Thelia\Model\ImportExportCategory Clone of current object. + * @return \Thelia\Model\ImportCategory Clone of current object. * @throws PropelException */ public function copy($deepCopy = false) @@ -1222,40 +1222,40 @@ abstract class ImportExportCategory implements ActiveRecordInterface */ public function initRelation($relationName) { - if ('ImportExportType' == $relationName) { - return $this->initImportExportTypes(); + if ('Import' == $relationName) { + return $this->initImports(); } - if ('ImportExportCategoryI18n' == $relationName) { - return $this->initImportExportCategoryI18ns(); + if ('ImportCategoryI18n' == $relationName) { + return $this->initImportCategoryI18ns(); } } /** - * Clears out the collImportExportTypes collection + * Clears out the collImports collection * * This does not modify the database; however, it will remove any associated objects, causing * them to be refetched by subsequent calls to accessor method. * * @return void - * @see addImportExportTypes() + * @see addImports() */ - public function clearImportExportTypes() + public function clearImports() { - $this->collImportExportTypes = null; // important to set this to NULL since that means it is uninitialized + $this->collImports = null; // important to set this to NULL since that means it is uninitialized } /** - * Reset is the collImportExportTypes collection loaded partially. + * Reset is the collImports collection loaded partially. */ - public function resetPartialImportExportTypes($v = true) + public function resetPartialImports($v = true) { - $this->collImportExportTypesPartial = $v; + $this->collImportsPartial = $v; } /** - * Initializes the collImportExportTypes collection. + * Initializes the collImports collection. * - * By default this just sets the collImportExportTypes collection to an empty array (like clearcollImportExportTypes()); + * By default this just sets the collImports collection to an empty array (like clearcollImports()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * @@ -1264,216 +1264,216 @@ abstract class ImportExportCategory implements ActiveRecordInterface * * @return void */ - public function initImportExportTypes($overrideExisting = true) + public function initImports($overrideExisting = true) { - if (null !== $this->collImportExportTypes && !$overrideExisting) { + if (null !== $this->collImports && !$overrideExisting) { return; } - $this->collImportExportTypes = new ObjectCollection(); - $this->collImportExportTypes->setModel('\Thelia\Model\ImportExportType'); + $this->collImports = new ObjectCollection(); + $this->collImports->setModel('\Thelia\Model\Import'); } /** - * Gets an array of ChildImportExportType objects which contain a foreign key that references this object. + * Gets an array of ChildImport objects which contain a foreign key that references this object. * * If the $criteria is not null, it is used to always fetch the results from the database. * Otherwise the results are fetched from the database the first time, then cached. * Next time the same method is called without $criteria, the cached collection is returned. - * If this ChildImportExportCategory is new, it will return + * If this ChildImportCategory is new, it will return * an empty collection or the current collection; the criteria is ignored on a new object. * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object - * @return Collection|ChildImportExportType[] List of ChildImportExportType objects + * @return Collection|ChildImport[] List of ChildImport objects * @throws PropelException */ - public function getImportExportTypes($criteria = null, ConnectionInterface $con = null) + public function getImports($criteria = null, ConnectionInterface $con = null) { - $partial = $this->collImportExportTypesPartial && !$this->isNew(); - if (null === $this->collImportExportTypes || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collImportExportTypes) { + $partial = $this->collImportsPartial && !$this->isNew(); + if (null === $this->collImports || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collImports) { // return empty collection - $this->initImportExportTypes(); + $this->initImports(); } else { - $collImportExportTypes = ChildImportExportTypeQuery::create(null, $criteria) - ->filterByImportExportCategory($this) + $collImports = ChildImportQuery::create(null, $criteria) + ->filterByImportCategory($this) ->find($con); if (null !== $criteria) { - if (false !== $this->collImportExportTypesPartial && count($collImportExportTypes)) { - $this->initImportExportTypes(false); + if (false !== $this->collImportsPartial && count($collImports)) { + $this->initImports(false); - foreach ($collImportExportTypes as $obj) { - if (false == $this->collImportExportTypes->contains($obj)) { - $this->collImportExportTypes->append($obj); + foreach ($collImports as $obj) { + if (false == $this->collImports->contains($obj)) { + $this->collImports->append($obj); } } - $this->collImportExportTypesPartial = true; + $this->collImportsPartial = true; } - reset($collImportExportTypes); + reset($collImports); - return $collImportExportTypes; + return $collImports; } - if ($partial && $this->collImportExportTypes) { - foreach ($this->collImportExportTypes as $obj) { + if ($partial && $this->collImports) { + foreach ($this->collImports as $obj) { if ($obj->isNew()) { - $collImportExportTypes[] = $obj; + $collImports[] = $obj; } } } - $this->collImportExportTypes = $collImportExportTypes; - $this->collImportExportTypesPartial = false; + $this->collImports = $collImports; + $this->collImportsPartial = false; } } - return $this->collImportExportTypes; + return $this->collImports; } /** - * Sets a collection of ImportExportType objects related by a one-to-many relationship + * Sets a collection of Import objects related by a one-to-many relationship * to the current object. * It will also schedule objects for deletion based on a diff between old objects (aka persisted) * and new objects from the given Propel collection. * - * @param Collection $importExportTypes A Propel collection. + * @param Collection $imports A Propel collection. * @param ConnectionInterface $con Optional connection object - * @return ChildImportExportCategory The current object (for fluent API support) + * @return ChildImportCategory The current object (for fluent API support) */ - public function setImportExportTypes(Collection $importExportTypes, ConnectionInterface $con = null) + public function setImports(Collection $imports, ConnectionInterface $con = null) { - $importExportTypesToDelete = $this->getImportExportTypes(new Criteria(), $con)->diff($importExportTypes); + $importsToDelete = $this->getImports(new Criteria(), $con)->diff($imports); - $this->importExportTypesScheduledForDeletion = $importExportTypesToDelete; + $this->importsScheduledForDeletion = $importsToDelete; - foreach ($importExportTypesToDelete as $importExportTypeRemoved) { - $importExportTypeRemoved->setImportExportCategory(null); + foreach ($importsToDelete as $importRemoved) { + $importRemoved->setImportCategory(null); } - $this->collImportExportTypes = null; - foreach ($importExportTypes as $importExportType) { - $this->addImportExportType($importExportType); + $this->collImports = null; + foreach ($imports as $import) { + $this->addImport($import); } - $this->collImportExportTypes = $importExportTypes; - $this->collImportExportTypesPartial = false; + $this->collImports = $imports; + $this->collImportsPartial = false; return $this; } /** - * Returns the number of related ImportExportType objects. + * Returns the number of related Import objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con - * @return int Count of related ImportExportType objects. + * @return int Count of related Import objects. * @throws PropelException */ - public function countImportExportTypes(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + public function countImports(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { - $partial = $this->collImportExportTypesPartial && !$this->isNew(); - if (null === $this->collImportExportTypes || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collImportExportTypes) { + $partial = $this->collImportsPartial && !$this->isNew(); + if (null === $this->collImports || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collImports) { return 0; } if ($partial && !$criteria) { - return count($this->getImportExportTypes()); + return count($this->getImports()); } - $query = ChildImportExportTypeQuery::create(null, $criteria); + $query = ChildImportQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query - ->filterByImportExportCategory($this) + ->filterByImportCategory($this) ->count($con); } - return count($this->collImportExportTypes); + return count($this->collImports); } /** - * Method called to associate a ChildImportExportType object to this object - * through the ChildImportExportType foreign key attribute. + * Method called to associate a ChildImport object to this object + * through the ChildImport foreign key attribute. * - * @param ChildImportExportType $l ChildImportExportType - * @return \Thelia\Model\ImportExportCategory The current object (for fluent API support) + * @param ChildImport $l ChildImport + * @return \Thelia\Model\ImportCategory The current object (for fluent API support) */ - public function addImportExportType(ChildImportExportType $l) + public function addImport(ChildImport $l) { - if ($this->collImportExportTypes === null) { - $this->initImportExportTypes(); - $this->collImportExportTypesPartial = true; + if ($this->collImports === null) { + $this->initImports(); + $this->collImportsPartial = true; } - if (!in_array($l, $this->collImportExportTypes->getArrayCopy(), true)) { // only add it if the **same** object is not already associated - $this->doAddImportExportType($l); + if (!in_array($l, $this->collImports->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddImport($l); } return $this; } /** - * @param ImportExportType $importExportType The importExportType object to add. + * @param Import $import The import object to add. */ - protected function doAddImportExportType($importExportType) + protected function doAddImport($import) { - $this->collImportExportTypes[]= $importExportType; - $importExportType->setImportExportCategory($this); + $this->collImports[]= $import; + $import->setImportCategory($this); } /** - * @param ImportExportType $importExportType The importExportType object to remove. - * @return ChildImportExportCategory The current object (for fluent API support) + * @param Import $import The import object to remove. + * @return ChildImportCategory The current object (for fluent API support) */ - public function removeImportExportType($importExportType) + public function removeImport($import) { - if ($this->getImportExportTypes()->contains($importExportType)) { - $this->collImportExportTypes->remove($this->collImportExportTypes->search($importExportType)); - if (null === $this->importExportTypesScheduledForDeletion) { - $this->importExportTypesScheduledForDeletion = clone $this->collImportExportTypes; - $this->importExportTypesScheduledForDeletion->clear(); + if ($this->getImports()->contains($import)) { + $this->collImports->remove($this->collImports->search($import)); + if (null === $this->importsScheduledForDeletion) { + $this->importsScheduledForDeletion = clone $this->collImports; + $this->importsScheduledForDeletion->clear(); } - $this->importExportTypesScheduledForDeletion[]= clone $importExportType; - $importExportType->setImportExportCategory(null); + $this->importsScheduledForDeletion[]= clone $import; + $import->setImportCategory(null); } return $this; } /** - * Clears out the collImportExportCategoryI18ns collection + * Clears out the collImportCategoryI18ns collection * * This does not modify the database; however, it will remove any associated objects, causing * them to be refetched by subsequent calls to accessor method. * * @return void - * @see addImportExportCategoryI18ns() + * @see addImportCategoryI18ns() */ - public function clearImportExportCategoryI18ns() + public function clearImportCategoryI18ns() { - $this->collImportExportCategoryI18ns = null; // important to set this to NULL since that means it is uninitialized + $this->collImportCategoryI18ns = null; // important to set this to NULL since that means it is uninitialized } /** - * Reset is the collImportExportCategoryI18ns collection loaded partially. + * Reset is the collImportCategoryI18ns collection loaded partially. */ - public function resetPartialImportExportCategoryI18ns($v = true) + public function resetPartialImportCategoryI18ns($v = true) { - $this->collImportExportCategoryI18nsPartial = $v; + $this->collImportCategoryI18nsPartial = $v; } /** - * Initializes the collImportExportCategoryI18ns collection. + * Initializes the collImportCategoryI18ns collection. * - * By default this just sets the collImportExportCategoryI18ns collection to an empty array (like clearcollImportExportCategoryI18ns()); + * By default this just sets the collImportCategoryI18ns collection to an empty array (like clearcollImportCategoryI18ns()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * @@ -1482,192 +1482,192 @@ abstract class ImportExportCategory implements ActiveRecordInterface * * @return void */ - public function initImportExportCategoryI18ns($overrideExisting = true) + public function initImportCategoryI18ns($overrideExisting = true) { - if (null !== $this->collImportExportCategoryI18ns && !$overrideExisting) { + if (null !== $this->collImportCategoryI18ns && !$overrideExisting) { return; } - $this->collImportExportCategoryI18ns = new ObjectCollection(); - $this->collImportExportCategoryI18ns->setModel('\Thelia\Model\ImportExportCategoryI18n'); + $this->collImportCategoryI18ns = new ObjectCollection(); + $this->collImportCategoryI18ns->setModel('\Thelia\Model\ImportCategoryI18n'); } /** - * Gets an array of ChildImportExportCategoryI18n objects which contain a foreign key that references this object. + * Gets an array of ChildImportCategoryI18n objects which contain a foreign key that references this object. * * If the $criteria is not null, it is used to always fetch the results from the database. * Otherwise the results are fetched from the database the first time, then cached. * Next time the same method is called without $criteria, the cached collection is returned. - * If this ChildImportExportCategory is new, it will return + * If this ChildImportCategory is new, it will return * an empty collection or the current collection; the criteria is ignored on a new object. * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object - * @return Collection|ChildImportExportCategoryI18n[] List of ChildImportExportCategoryI18n objects + * @return Collection|ChildImportCategoryI18n[] List of ChildImportCategoryI18n objects * @throws PropelException */ - public function getImportExportCategoryI18ns($criteria = null, ConnectionInterface $con = null) + public function getImportCategoryI18ns($criteria = null, ConnectionInterface $con = null) { - $partial = $this->collImportExportCategoryI18nsPartial && !$this->isNew(); - if (null === $this->collImportExportCategoryI18ns || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collImportExportCategoryI18ns) { + $partial = $this->collImportCategoryI18nsPartial && !$this->isNew(); + if (null === $this->collImportCategoryI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collImportCategoryI18ns) { // return empty collection - $this->initImportExportCategoryI18ns(); + $this->initImportCategoryI18ns(); } else { - $collImportExportCategoryI18ns = ChildImportExportCategoryI18nQuery::create(null, $criteria) - ->filterByImportExportCategory($this) + $collImportCategoryI18ns = ChildImportCategoryI18nQuery::create(null, $criteria) + ->filterByImportCategory($this) ->find($con); if (null !== $criteria) { - if (false !== $this->collImportExportCategoryI18nsPartial && count($collImportExportCategoryI18ns)) { - $this->initImportExportCategoryI18ns(false); + if (false !== $this->collImportCategoryI18nsPartial && count($collImportCategoryI18ns)) { + $this->initImportCategoryI18ns(false); - foreach ($collImportExportCategoryI18ns as $obj) { - if (false == $this->collImportExportCategoryI18ns->contains($obj)) { - $this->collImportExportCategoryI18ns->append($obj); + foreach ($collImportCategoryI18ns as $obj) { + if (false == $this->collImportCategoryI18ns->contains($obj)) { + $this->collImportCategoryI18ns->append($obj); } } - $this->collImportExportCategoryI18nsPartial = true; + $this->collImportCategoryI18nsPartial = true; } - reset($collImportExportCategoryI18ns); + reset($collImportCategoryI18ns); - return $collImportExportCategoryI18ns; + return $collImportCategoryI18ns; } - if ($partial && $this->collImportExportCategoryI18ns) { - foreach ($this->collImportExportCategoryI18ns as $obj) { + if ($partial && $this->collImportCategoryI18ns) { + foreach ($this->collImportCategoryI18ns as $obj) { if ($obj->isNew()) { - $collImportExportCategoryI18ns[] = $obj; + $collImportCategoryI18ns[] = $obj; } } } - $this->collImportExportCategoryI18ns = $collImportExportCategoryI18ns; - $this->collImportExportCategoryI18nsPartial = false; + $this->collImportCategoryI18ns = $collImportCategoryI18ns; + $this->collImportCategoryI18nsPartial = false; } } - return $this->collImportExportCategoryI18ns; + return $this->collImportCategoryI18ns; } /** - * Sets a collection of ImportExportCategoryI18n objects related by a one-to-many relationship + * Sets a collection of ImportCategoryI18n objects related by a one-to-many relationship * to the current object. * It will also schedule objects for deletion based on a diff between old objects (aka persisted) * and new objects from the given Propel collection. * - * @param Collection $importExportCategoryI18ns A Propel collection. + * @param Collection $importCategoryI18ns A Propel collection. * @param ConnectionInterface $con Optional connection object - * @return ChildImportExportCategory The current object (for fluent API support) + * @return ChildImportCategory The current object (for fluent API support) */ - public function setImportExportCategoryI18ns(Collection $importExportCategoryI18ns, ConnectionInterface $con = null) + public function setImportCategoryI18ns(Collection $importCategoryI18ns, ConnectionInterface $con = null) { - $importExportCategoryI18nsToDelete = $this->getImportExportCategoryI18ns(new Criteria(), $con)->diff($importExportCategoryI18ns); + $importCategoryI18nsToDelete = $this->getImportCategoryI18ns(new Criteria(), $con)->diff($importCategoryI18ns); //since at least one column in the foreign key is at the same time a PK //we can not just set a PK to NULL in the lines below. We have to store //a backup of all values, so we are able to manipulate these items based on the onDelete value later. - $this->importExportCategoryI18nsScheduledForDeletion = clone $importExportCategoryI18nsToDelete; + $this->importCategoryI18nsScheduledForDeletion = clone $importCategoryI18nsToDelete; - foreach ($importExportCategoryI18nsToDelete as $importExportCategoryI18nRemoved) { - $importExportCategoryI18nRemoved->setImportExportCategory(null); + foreach ($importCategoryI18nsToDelete as $importCategoryI18nRemoved) { + $importCategoryI18nRemoved->setImportCategory(null); } - $this->collImportExportCategoryI18ns = null; - foreach ($importExportCategoryI18ns as $importExportCategoryI18n) { - $this->addImportExportCategoryI18n($importExportCategoryI18n); + $this->collImportCategoryI18ns = null; + foreach ($importCategoryI18ns as $importCategoryI18n) { + $this->addImportCategoryI18n($importCategoryI18n); } - $this->collImportExportCategoryI18ns = $importExportCategoryI18ns; - $this->collImportExportCategoryI18nsPartial = false; + $this->collImportCategoryI18ns = $importCategoryI18ns; + $this->collImportCategoryI18nsPartial = false; return $this; } /** - * Returns the number of related ImportExportCategoryI18n objects. + * Returns the number of related ImportCategoryI18n objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con - * @return int Count of related ImportExportCategoryI18n objects. + * @return int Count of related ImportCategoryI18n objects. * @throws PropelException */ - public function countImportExportCategoryI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + public function countImportCategoryI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { - $partial = $this->collImportExportCategoryI18nsPartial && !$this->isNew(); - if (null === $this->collImportExportCategoryI18ns || null !== $criteria || $partial) { - if ($this->isNew() && null === $this->collImportExportCategoryI18ns) { + $partial = $this->collImportCategoryI18nsPartial && !$this->isNew(); + if (null === $this->collImportCategoryI18ns || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collImportCategoryI18ns) { return 0; } if ($partial && !$criteria) { - return count($this->getImportExportCategoryI18ns()); + return count($this->getImportCategoryI18ns()); } - $query = ChildImportExportCategoryI18nQuery::create(null, $criteria); + $query = ChildImportCategoryI18nQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query - ->filterByImportExportCategory($this) + ->filterByImportCategory($this) ->count($con); } - return count($this->collImportExportCategoryI18ns); + return count($this->collImportCategoryI18ns); } /** - * Method called to associate a ChildImportExportCategoryI18n object to this object - * through the ChildImportExportCategoryI18n foreign key attribute. + * Method called to associate a ChildImportCategoryI18n object to this object + * through the ChildImportCategoryI18n foreign key attribute. * - * @param ChildImportExportCategoryI18n $l ChildImportExportCategoryI18n - * @return \Thelia\Model\ImportExportCategory The current object (for fluent API support) + * @param ChildImportCategoryI18n $l ChildImportCategoryI18n + * @return \Thelia\Model\ImportCategory The current object (for fluent API support) */ - public function addImportExportCategoryI18n(ChildImportExportCategoryI18n $l) + public function addImportCategoryI18n(ChildImportCategoryI18n $l) { if ($l && $locale = $l->getLocale()) { $this->setLocale($locale); $this->currentTranslations[$locale] = $l; } - if ($this->collImportExportCategoryI18ns === null) { - $this->initImportExportCategoryI18ns(); - $this->collImportExportCategoryI18nsPartial = true; + if ($this->collImportCategoryI18ns === null) { + $this->initImportCategoryI18ns(); + $this->collImportCategoryI18nsPartial = true; } - if (!in_array($l, $this->collImportExportCategoryI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated - $this->doAddImportExportCategoryI18n($l); + if (!in_array($l, $this->collImportCategoryI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated + $this->doAddImportCategoryI18n($l); } return $this; } /** - * @param ImportExportCategoryI18n $importExportCategoryI18n The importExportCategoryI18n object to add. + * @param ImportCategoryI18n $importCategoryI18n The importCategoryI18n object to add. */ - protected function doAddImportExportCategoryI18n($importExportCategoryI18n) + protected function doAddImportCategoryI18n($importCategoryI18n) { - $this->collImportExportCategoryI18ns[]= $importExportCategoryI18n; - $importExportCategoryI18n->setImportExportCategory($this); + $this->collImportCategoryI18ns[]= $importCategoryI18n; + $importCategoryI18n->setImportCategory($this); } /** - * @param ImportExportCategoryI18n $importExportCategoryI18n The importExportCategoryI18n object to remove. - * @return ChildImportExportCategory The current object (for fluent API support) + * @param ImportCategoryI18n $importCategoryI18n The importCategoryI18n object to remove. + * @return ChildImportCategory The current object (for fluent API support) */ - public function removeImportExportCategoryI18n($importExportCategoryI18n) + public function removeImportCategoryI18n($importCategoryI18n) { - if ($this->getImportExportCategoryI18ns()->contains($importExportCategoryI18n)) { - $this->collImportExportCategoryI18ns->remove($this->collImportExportCategoryI18ns->search($importExportCategoryI18n)); - if (null === $this->importExportCategoryI18nsScheduledForDeletion) { - $this->importExportCategoryI18nsScheduledForDeletion = clone $this->collImportExportCategoryI18ns; - $this->importExportCategoryI18nsScheduledForDeletion->clear(); + if ($this->getImportCategoryI18ns()->contains($importCategoryI18n)) { + $this->collImportCategoryI18ns->remove($this->collImportCategoryI18ns->search($importCategoryI18n)); + if (null === $this->importCategoryI18nsScheduledForDeletion) { + $this->importCategoryI18nsScheduledForDeletion = clone $this->collImportCategoryI18ns; + $this->importCategoryI18nsScheduledForDeletion->clear(); } - $this->importExportCategoryI18nsScheduledForDeletion[]= clone $importExportCategoryI18n; - $importExportCategoryI18n->setImportExportCategory(null); + $this->importCategoryI18nsScheduledForDeletion[]= clone $importCategoryI18n; + $importCategoryI18n->setImportCategory(null); } return $this; @@ -1701,13 +1701,13 @@ abstract class ImportExportCategory implements ActiveRecordInterface public function clearAllReferences($deep = false) { if ($deep) { - if ($this->collImportExportTypes) { - foreach ($this->collImportExportTypes as $o) { + if ($this->collImports) { + foreach ($this->collImports as $o) { $o->clearAllReferences($deep); } } - if ($this->collImportExportCategoryI18ns) { - foreach ($this->collImportExportCategoryI18ns as $o) { + if ($this->collImportCategoryI18ns) { + foreach ($this->collImportCategoryI18ns as $o) { $o->clearAllReferences($deep); } } @@ -1717,8 +1717,8 @@ abstract class ImportExportCategory implements ActiveRecordInterface $this->currentLocale = 'en_US'; $this->currentTranslations = null; - $this->collImportExportTypes = null; - $this->collImportExportCategoryI18ns = null; + $this->collImports = null; + $this->collImportCategoryI18ns = null; } /** @@ -1728,7 +1728,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface */ public function __toString() { - return (string) $this->exportTo(ImportExportCategoryTableMap::DEFAULT_STRING_FORMAT); + return (string) $this->exportTo(ImportCategoryTableMap::DEFAULT_STRING_FORMAT); } // i18n behavior @@ -1738,7 +1738,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface * * @param string $locale Locale to use for the translation, e.g. 'fr_FR' * - * @return ChildImportExportCategory The current object (for fluent API support) + * @return ChildImportCategory The current object (for fluent API support) */ public function setLocale($locale = 'en_US') { @@ -1763,12 +1763,12 @@ abstract class ImportExportCategory implements ActiveRecordInterface * @param string $locale Locale to use for the translation, e.g. 'fr_FR' * @param ConnectionInterface $con an optional connection object * - * @return ChildImportExportCategoryI18n */ + * @return ChildImportCategoryI18n */ public function getTranslation($locale = 'en_US', ConnectionInterface $con = null) { if (!isset($this->currentTranslations[$locale])) { - if (null !== $this->collImportExportCategoryI18ns) { - foreach ($this->collImportExportCategoryI18ns as $translation) { + if (null !== $this->collImportCategoryI18ns) { + foreach ($this->collImportCategoryI18ns as $translation) { if ($translation->getLocale() == $locale) { $this->currentTranslations[$locale] = $translation; @@ -1777,15 +1777,15 @@ abstract class ImportExportCategory implements ActiveRecordInterface } } if ($this->isNew()) { - $translation = new ChildImportExportCategoryI18n(); + $translation = new ChildImportCategoryI18n(); $translation->setLocale($locale); } else { - $translation = ChildImportExportCategoryI18nQuery::create() + $translation = ChildImportCategoryI18nQuery::create() ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) ->findOneOrCreate($con); $this->currentTranslations[$locale] = $translation; } - $this->addImportExportCategoryI18n($translation); + $this->addImportCategoryI18n($translation); } return $this->currentTranslations[$locale]; @@ -1797,21 +1797,21 @@ abstract class ImportExportCategory implements ActiveRecordInterface * @param string $locale Locale to use for the translation, e.g. 'fr_FR' * @param ConnectionInterface $con an optional connection object * - * @return ChildImportExportCategory The current object (for fluent API support) + * @return ChildImportCategory The current object (for fluent API support) */ public function removeTranslation($locale = 'en_US', ConnectionInterface $con = null) { if (!$this->isNew()) { - ChildImportExportCategoryI18nQuery::create() + ChildImportCategoryI18nQuery::create() ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale)) ->delete($con); } if (isset($this->currentTranslations[$locale])) { unset($this->currentTranslations[$locale]); } - foreach ($this->collImportExportCategoryI18ns as $key => $translation) { + foreach ($this->collImportCategoryI18ns as $key => $translation) { if ($translation->getLocale() == $locale) { - unset($this->collImportExportCategoryI18ns[$key]); + unset($this->collImportCategoryI18ns[$key]); break; } } @@ -1824,7 +1824,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface * * @param ConnectionInterface $con an optional connection object * - * @return ChildImportExportCategoryI18n */ + * @return ChildImportCategoryI18n */ public function getCurrentTranslation(ConnectionInterface $con = null) { return $this->getTranslation($this->getLocale(), $con); @@ -1846,7 +1846,7 @@ abstract class ImportExportCategory implements ActiveRecordInterface * Set the value of [title] column. * * @param string $v new value - * @return \Thelia\Model\ImportExportCategoryI18n The current object (for fluent API support) + * @return \Thelia\Model\ImportCategoryI18n The current object (for fluent API support) */ public function setTitle($v) { $this->getCurrentTranslation()->setTitle($v); @@ -1859,11 +1859,11 @@ abstract class ImportExportCategory implements ActiveRecordInterface /** * Mark the current object so that the update date doesn't get updated during next save * - * @return ChildImportExportCategory The current object (for fluent API support) + * @return ChildImportCategory The current object (for fluent API support) */ public function keepUpdateDateUnchanged() { - $this->modifiedColumns[ImportExportCategoryTableMap::UPDATED_AT] = true; + $this->modifiedColumns[ImportCategoryTableMap::UPDATED_AT] = true; return $this; } diff --git a/core/lib/Thelia/Model/Base/ImportExportCategoryI18n.php b/core/lib/Thelia/Model/Base/ImportCategoryI18n.php similarity index 84% rename from core/lib/Thelia/Model/Base/ImportExportCategoryI18n.php rename to core/lib/Thelia/Model/Base/ImportCategoryI18n.php index 53519dc56..6f6b5d6c4 100644 --- a/core/lib/Thelia/Model/Base/ImportExportCategoryI18n.php +++ b/core/lib/Thelia/Model/Base/ImportCategoryI18n.php @@ -14,17 +14,17 @@ use Propel\Runtime\Exception\BadMethodCallException; use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Parser\AbstractParser; -use Thelia\Model\ImportExportCategory as ChildImportExportCategory; -use Thelia\Model\ImportExportCategoryI18nQuery as ChildImportExportCategoryI18nQuery; -use Thelia\Model\ImportExportCategoryQuery as ChildImportExportCategoryQuery; -use Thelia\Model\Map\ImportExportCategoryI18nTableMap; +use Thelia\Model\ImportCategory as ChildImportCategory; +use Thelia\Model\ImportCategoryI18nQuery as ChildImportCategoryI18nQuery; +use Thelia\Model\ImportCategoryQuery as ChildImportCategoryQuery; +use Thelia\Model\Map\ImportCategoryI18nTableMap; -abstract class ImportExportCategoryI18n implements ActiveRecordInterface +abstract class ImportCategoryI18n implements ActiveRecordInterface { /** * TableMap class name */ - const TABLE_MAP = '\\Thelia\\Model\\Map\\ImportExportCategoryI18nTableMap'; + const TABLE_MAP = '\\Thelia\\Model\\Map\\ImportCategoryI18nTableMap'; /** @@ -73,9 +73,9 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface protected $title; /** - * @var ImportExportCategory + * @var ImportCategory */ - protected $aImportExportCategory; + protected $aImportCategory; /** * Flag to prevent endless save loop, if this object is referenced @@ -97,7 +97,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface } /** - * Initializes internal state of Thelia\Model\Base\ImportExportCategoryI18n object. + * Initializes internal state of Thelia\Model\Base\ImportCategoryI18n object. * @see applyDefaults() */ public function __construct() @@ -194,9 +194,9 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface } /** - * Compares this with another ImportExportCategoryI18n instance. If - * obj is an instance of ImportExportCategoryI18n, delegates to - * equals(ImportExportCategoryI18n). Otherwise, returns false. + * Compares this with another ImportCategoryI18n instance. If + * obj is an instance of ImportCategoryI18n, delegates to + * equals(ImportCategoryI18n). Otherwise, returns false. * * @param mixed $obj The object to compare to. * @return boolean Whether equal to the object specified. @@ -279,7 +279,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface * @param string $name The virtual column name * @param mixed $value The value to give to the virtual column * - * @return ImportExportCategoryI18n The current object, for fluid interface + * @return ImportCategoryI18n The current object, for fluid interface */ public function setVirtualColumn($name, $value) { @@ -311,7 +311,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface * or a format name ('XML', 'YAML', 'JSON', 'CSV') * @param string $data The source data to import from * - * @return ImportExportCategoryI18n The current object, for fluid interface + * @return ImportCategoryI18n The current object, for fluid interface */ public function importFrom($parser, $data) { @@ -393,7 +393,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface * Set the value of [id] column. * * @param int $v new value - * @return \Thelia\Model\ImportExportCategoryI18n The current object (for fluent API support) + * @return \Thelia\Model\ImportCategoryI18n The current object (for fluent API support) */ public function setId($v) { @@ -403,11 +403,11 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface if ($this->id !== $v) { $this->id = $v; - $this->modifiedColumns[ImportExportCategoryI18nTableMap::ID] = true; + $this->modifiedColumns[ImportCategoryI18nTableMap::ID] = true; } - if ($this->aImportExportCategory !== null && $this->aImportExportCategory->getId() !== $v) { - $this->aImportExportCategory = null; + if ($this->aImportCategory !== null && $this->aImportCategory->getId() !== $v) { + $this->aImportCategory = null; } @@ -418,7 +418,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface * Set the value of [locale] column. * * @param string $v new value - * @return \Thelia\Model\ImportExportCategoryI18n The current object (for fluent API support) + * @return \Thelia\Model\ImportCategoryI18n The current object (for fluent API support) */ public function setLocale($v) { @@ -428,7 +428,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface if ($this->locale !== $v) { $this->locale = $v; - $this->modifiedColumns[ImportExportCategoryI18nTableMap::LOCALE] = true; + $this->modifiedColumns[ImportCategoryI18nTableMap::LOCALE] = true; } @@ -439,7 +439,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface * Set the value of [title] column. * * @param string $v new value - * @return \Thelia\Model\ImportExportCategoryI18n The current object (for fluent API support) + * @return \Thelia\Model\ImportCategoryI18n The current object (for fluent API support) */ public function setTitle($v) { @@ -449,7 +449,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface if ($this->title !== $v) { $this->title = $v; - $this->modifiedColumns[ImportExportCategoryI18nTableMap::TITLE] = true; + $this->modifiedColumns[ImportCategoryI18nTableMap::TITLE] = true; } @@ -497,13 +497,13 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface try { - $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ImportExportCategoryI18nTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ImportCategoryI18nTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; $this->id = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ImportExportCategoryI18nTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ImportCategoryI18nTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; $this->locale = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportExportCategoryI18nTableMap::translateFieldName('Title', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportCategoryI18nTableMap::translateFieldName('Title', TableMap::TYPE_PHPNAME, $indexType)]; $this->title = (null !== $col) ? (string) $col : null; $this->resetModified(); @@ -513,10 +513,10 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 3; // 3 = ImportExportCategoryI18nTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 3; // 3 = ImportCategoryI18nTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { - throw new PropelException("Error populating \Thelia\Model\ImportExportCategoryI18n object", 0, $e); + throw new PropelException("Error populating \Thelia\Model\ImportCategoryI18n object", 0, $e); } } @@ -535,8 +535,8 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface */ public function ensureConsistency() { - if ($this->aImportExportCategory !== null && $this->id !== $this->aImportExportCategory->getId()) { - $this->aImportExportCategory = null; + if ($this->aImportCategory !== null && $this->id !== $this->aImportCategory->getId()) { + $this->aImportCategory = null; } } // ensureConsistency @@ -561,13 +561,13 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface } if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getReadConnection(ImportCategoryI18nTableMap::DATABASE_NAME); } // We don't need to alter the object instance pool; we're just modifying this instance // already in the pool. - $dataFetcher = ChildImportExportCategoryI18nQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $dataFetcher = ChildImportCategoryI18nQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); $row = $dataFetcher->fetch(); $dataFetcher->close(); if (!$row) { @@ -577,7 +577,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface if ($deep) { // also de-associate any related objects? - $this->aImportExportCategory = null; + $this->aImportCategory = null; } // if (deep) } @@ -587,8 +587,8 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface * @param ConnectionInterface $con * @return void * @throws PropelException - * @see ImportExportCategoryI18n::setDeleted() - * @see ImportExportCategoryI18n::isDeleted() + * @see ImportCategoryI18n::setDeleted() + * @see ImportCategoryI18n::isDeleted() */ public function delete(ConnectionInterface $con = null) { @@ -597,12 +597,12 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface } if ($con === null) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryI18nTableMap::DATABASE_NAME); } $con->beginTransaction(); try { - $deleteQuery = ChildImportExportCategoryI18nQuery::create() + $deleteQuery = ChildImportCategoryI18nQuery::create() ->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { @@ -639,7 +639,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface } if ($con === null) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryI18nTableMap::DATABASE_NAME); } $con->beginTransaction(); @@ -659,7 +659,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface $this->postUpdate($con); } $this->postSave($con); - ImportExportCategoryI18nTableMap::addInstanceToPool($this); + ImportCategoryI18nTableMap::addInstanceToPool($this); } else { $affectedRows = 0; } @@ -694,11 +694,11 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface // method. This object relates to these object(s) by a // foreign key reference. - if ($this->aImportExportCategory !== null) { - if ($this->aImportExportCategory->isModified() || $this->aImportExportCategory->isNew()) { - $affectedRows += $this->aImportExportCategory->save($con); + if ($this->aImportCategory !== null) { + if ($this->aImportCategory->isModified() || $this->aImportCategory->isNew()) { + $affectedRows += $this->aImportCategory->save($con); } - $this->setImportExportCategory($this->aImportExportCategory); + $this->setImportCategory($this->aImportCategory); } if ($this->isNew() || $this->isModified()) { @@ -734,18 +734,18 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface // check the columns in natural order for more readable SQL queries - if ($this->isColumnModified(ImportExportCategoryI18nTableMap::ID)) { + if ($this->isColumnModified(ImportCategoryI18nTableMap::ID)) { $modifiedColumns[':p' . $index++] = '`ID`'; } - if ($this->isColumnModified(ImportExportCategoryI18nTableMap::LOCALE)) { + if ($this->isColumnModified(ImportCategoryI18nTableMap::LOCALE)) { $modifiedColumns[':p' . $index++] = '`LOCALE`'; } - if ($this->isColumnModified(ImportExportCategoryI18nTableMap::TITLE)) { + if ($this->isColumnModified(ImportCategoryI18nTableMap::TITLE)) { $modifiedColumns[':p' . $index++] = '`TITLE`'; } $sql = sprintf( - 'INSERT INTO `import_export_category_i18n` (%s) VALUES (%s)', + 'INSERT INTO `import_category_i18n` (%s) VALUES (%s)', implode(', ', $modifiedColumns), implode(', ', array_keys($modifiedColumns)) ); @@ -802,7 +802,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface */ public function getByName($name, $type = TableMap::TYPE_PHPNAME) { - $pos = ImportExportCategoryI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $pos = ImportCategoryI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); $field = $this->getByPosition($pos); return $field; @@ -850,11 +850,11 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface */ public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { - if (isset($alreadyDumpedObjects['ImportExportCategoryI18n'][serialize($this->getPrimaryKey())])) { + if (isset($alreadyDumpedObjects['ImportCategoryI18n'][serialize($this->getPrimaryKey())])) { return '*RECURSION*'; } - $alreadyDumpedObjects['ImportExportCategoryI18n'][serialize($this->getPrimaryKey())] = true; - $keys = ImportExportCategoryI18nTableMap::getFieldNames($keyType); + $alreadyDumpedObjects['ImportCategoryI18n'][serialize($this->getPrimaryKey())] = true; + $keys = ImportCategoryI18nTableMap::getFieldNames($keyType); $result = array( $keys[0] => $this->getId(), $keys[1] => $this->getLocale(), @@ -866,8 +866,8 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface } if ($includeForeignObjects) { - if (null !== $this->aImportExportCategory) { - $result['ImportExportCategory'] = $this->aImportExportCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + if (null !== $this->aImportCategory) { + $result['ImportCategory'] = $this->aImportCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } } @@ -887,7 +887,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface */ public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) { - $pos = ImportExportCategoryI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $pos = ImportCategoryI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); return $this->setByPosition($pos, $value); } @@ -934,7 +934,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface */ public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) { - $keys = ImportExportCategoryI18nTableMap::getFieldNames($keyType); + $keys = ImportCategoryI18nTableMap::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setLocale($arr[$keys[1]]); @@ -948,11 +948,11 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface */ public function buildCriteria() { - $criteria = new Criteria(ImportExportCategoryI18nTableMap::DATABASE_NAME); + $criteria = new Criteria(ImportCategoryI18nTableMap::DATABASE_NAME); - if ($this->isColumnModified(ImportExportCategoryI18nTableMap::ID)) $criteria->add(ImportExportCategoryI18nTableMap::ID, $this->id); - if ($this->isColumnModified(ImportExportCategoryI18nTableMap::LOCALE)) $criteria->add(ImportExportCategoryI18nTableMap::LOCALE, $this->locale); - if ($this->isColumnModified(ImportExportCategoryI18nTableMap::TITLE)) $criteria->add(ImportExportCategoryI18nTableMap::TITLE, $this->title); + if ($this->isColumnModified(ImportCategoryI18nTableMap::ID)) $criteria->add(ImportCategoryI18nTableMap::ID, $this->id); + if ($this->isColumnModified(ImportCategoryI18nTableMap::LOCALE)) $criteria->add(ImportCategoryI18nTableMap::LOCALE, $this->locale); + if ($this->isColumnModified(ImportCategoryI18nTableMap::TITLE)) $criteria->add(ImportCategoryI18nTableMap::TITLE, $this->title); return $criteria; } @@ -967,9 +967,9 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface */ public function buildPkeyCriteria() { - $criteria = new Criteria(ImportExportCategoryI18nTableMap::DATABASE_NAME); - $criteria->add(ImportExportCategoryI18nTableMap::ID, $this->id); - $criteria->add(ImportExportCategoryI18nTableMap::LOCALE, $this->locale); + $criteria = new Criteria(ImportCategoryI18nTableMap::DATABASE_NAME); + $criteria->add(ImportCategoryI18nTableMap::ID, $this->id); + $criteria->add(ImportCategoryI18nTableMap::LOCALE, $this->locale); return $criteria; } @@ -1016,7 +1016,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface * If desired, this method can also make copies of all associated (fkey referrers) * objects. * - * @param object $copyObj An object of \Thelia\Model\ImportExportCategoryI18n (or compatible) type. + * @param object $copyObj An object of \Thelia\Model\ImportCategoryI18n (or compatible) type. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. * @throws PropelException @@ -1040,7 +1040,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface * objects. * * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. - * @return \Thelia\Model\ImportExportCategoryI18n Clone of current object. + * @return \Thelia\Model\ImportCategoryI18n Clone of current object. * @throws PropelException */ public function copy($deepCopy = false) @@ -1054,13 +1054,13 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface } /** - * Declares an association between this object and a ChildImportExportCategory object. + * Declares an association between this object and a ChildImportCategory object. * - * @param ChildImportExportCategory $v - * @return \Thelia\Model\ImportExportCategoryI18n The current object (for fluent API support) + * @param ChildImportCategory $v + * @return \Thelia\Model\ImportCategoryI18n The current object (for fluent API support) * @throws PropelException */ - public function setImportExportCategory(ChildImportExportCategory $v = null) + public function setImportCategory(ChildImportCategory $v = null) { if ($v === null) { $this->setId(NULL); @@ -1068,12 +1068,12 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface $this->setId($v->getId()); } - $this->aImportExportCategory = $v; + $this->aImportCategory = $v; // Add binding for other direction of this n:n relationship. - // If this object has already been added to the ChildImportExportCategory object, it will not be re-added. + // If this object has already been added to the ChildImportCategory object, it will not be re-added. if ($v !== null) { - $v->addImportExportCategoryI18n($this); + $v->addImportCategoryI18n($this); } @@ -1082,26 +1082,26 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface /** - * Get the associated ChildImportExportCategory object + * Get the associated ChildImportCategory object * * @param ConnectionInterface $con Optional Connection object. - * @return ChildImportExportCategory The associated ChildImportExportCategory object. + * @return ChildImportCategory The associated ChildImportCategory object. * @throws PropelException */ - public function getImportExportCategory(ConnectionInterface $con = null) + public function getImportCategory(ConnectionInterface $con = null) { - if ($this->aImportExportCategory === null && ($this->id !== null)) { - $this->aImportExportCategory = ChildImportExportCategoryQuery::create()->findPk($this->id, $con); + if ($this->aImportCategory === null && ($this->id !== null)) { + $this->aImportCategory = ChildImportCategoryQuery::create()->findPk($this->id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. - $this->aImportExportCategory->addImportExportCategoryI18ns($this); + $this->aImportCategory->addImportCategoryI18ns($this); */ } - return $this->aImportExportCategory; + return $this->aImportCategory; } /** @@ -1134,7 +1134,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface if ($deep) { } // if ($deep) - $this->aImportExportCategory = null; + $this->aImportCategory = null; } /** @@ -1144,7 +1144,7 @@ abstract class ImportExportCategoryI18n implements ActiveRecordInterface */ public function __toString() { - return (string) $this->exportTo(ImportExportCategoryI18nTableMap::DEFAULT_STRING_FORMAT); + return (string) $this->exportTo(ImportCategoryI18nTableMap::DEFAULT_STRING_FORMAT); } /** diff --git a/core/lib/Thelia/Model/Base/ImportExportCategoryI18nQuery.php b/core/lib/Thelia/Model/Base/ImportCategoryI18nQuery.php similarity index 60% rename from core/lib/Thelia/Model/Base/ImportExportCategoryI18nQuery.php rename to core/lib/Thelia/Model/Base/ImportCategoryI18nQuery.php index 05ee2eb89..648858914 100644 --- a/core/lib/Thelia/Model/Base/ImportExportCategoryI18nQuery.php +++ b/core/lib/Thelia/Model/Base/ImportCategoryI18nQuery.php @@ -12,72 +12,72 @@ use Propel\Runtime\Collection\Collection; use Propel\Runtime\Collection\ObjectCollection; use Propel\Runtime\Connection\ConnectionInterface; use Propel\Runtime\Exception\PropelException; -use Thelia\Model\ImportExportCategoryI18n as ChildImportExportCategoryI18n; -use Thelia\Model\ImportExportCategoryI18nQuery as ChildImportExportCategoryI18nQuery; -use Thelia\Model\Map\ImportExportCategoryI18nTableMap; +use Thelia\Model\ImportCategoryI18n as ChildImportCategoryI18n; +use Thelia\Model\ImportCategoryI18nQuery as ChildImportCategoryI18nQuery; +use Thelia\Model\Map\ImportCategoryI18nTableMap; /** - * Base class that represents a query for the 'import_export_category_i18n' table. + * Base class that represents a query for the 'import_category_i18n' table. * * * - * @method ChildImportExportCategoryI18nQuery orderById($order = Criteria::ASC) Order by the id column - * @method ChildImportExportCategoryI18nQuery orderByLocale($order = Criteria::ASC) Order by the locale column - * @method ChildImportExportCategoryI18nQuery orderByTitle($order = Criteria::ASC) Order by the title column + * @method ChildImportCategoryI18nQuery orderById($order = Criteria::ASC) Order by the id column + * @method ChildImportCategoryI18nQuery orderByLocale($order = Criteria::ASC) Order by the locale column + * @method ChildImportCategoryI18nQuery orderByTitle($order = Criteria::ASC) Order by the title column * - * @method ChildImportExportCategoryI18nQuery groupById() Group by the id column - * @method ChildImportExportCategoryI18nQuery groupByLocale() Group by the locale column - * @method ChildImportExportCategoryI18nQuery groupByTitle() Group by the title column + * @method ChildImportCategoryI18nQuery groupById() Group by the id column + * @method ChildImportCategoryI18nQuery groupByLocale() Group by the locale column + * @method ChildImportCategoryI18nQuery groupByTitle() Group by the title column * - * @method ChildImportExportCategoryI18nQuery leftJoin($relation) Adds a LEFT JOIN clause to the query - * @method ChildImportExportCategoryI18nQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query - * @method ChildImportExportCategoryI18nQuery innerJoin($relation) Adds a INNER JOIN clause to the query + * @method ChildImportCategoryI18nQuery leftJoin($relation) Adds a LEFT JOIN clause to the query + * @method ChildImportCategoryI18nQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query + * @method ChildImportCategoryI18nQuery innerJoin($relation) Adds a INNER JOIN clause to the query * - * @method ChildImportExportCategoryI18nQuery leftJoinImportExportCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportExportCategory relation - * @method ChildImportExportCategoryI18nQuery rightJoinImportExportCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportExportCategory relation - * @method ChildImportExportCategoryI18nQuery innerJoinImportExportCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportExportCategory relation + * @method ChildImportCategoryI18nQuery leftJoinImportCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportCategory relation + * @method ChildImportCategoryI18nQuery rightJoinImportCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportCategory relation + * @method ChildImportCategoryI18nQuery innerJoinImportCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportCategory relation * - * @method ChildImportExportCategoryI18n findOne(ConnectionInterface $con = null) Return the first ChildImportExportCategoryI18n matching the query - * @method ChildImportExportCategoryI18n findOneOrCreate(ConnectionInterface $con = null) Return the first ChildImportExportCategoryI18n matching the query, or a new ChildImportExportCategoryI18n object populated from the query conditions when no match is found + * @method ChildImportCategoryI18n findOne(ConnectionInterface $con = null) Return the first ChildImportCategoryI18n matching the query + * @method ChildImportCategoryI18n findOneOrCreate(ConnectionInterface $con = null) Return the first ChildImportCategoryI18n matching the query, or a new ChildImportCategoryI18n object populated from the query conditions when no match is found * - * @method ChildImportExportCategoryI18n findOneById(int $id) Return the first ChildImportExportCategoryI18n filtered by the id column - * @method ChildImportExportCategoryI18n findOneByLocale(string $locale) Return the first ChildImportExportCategoryI18n filtered by the locale column - * @method ChildImportExportCategoryI18n findOneByTitle(string $title) Return the first ChildImportExportCategoryI18n filtered by the title column + * @method ChildImportCategoryI18n findOneById(int $id) Return the first ChildImportCategoryI18n filtered by the id column + * @method ChildImportCategoryI18n findOneByLocale(string $locale) Return the first ChildImportCategoryI18n filtered by the locale column + * @method ChildImportCategoryI18n findOneByTitle(string $title) Return the first ChildImportCategoryI18n filtered by the title column * - * @method array findById(int $id) Return ChildImportExportCategoryI18n objects filtered by the id column - * @method array findByLocale(string $locale) Return ChildImportExportCategoryI18n objects filtered by the locale column - * @method array findByTitle(string $title) Return ChildImportExportCategoryI18n objects filtered by the title column + * @method array findById(int $id) Return ChildImportCategoryI18n objects filtered by the id column + * @method array findByLocale(string $locale) Return ChildImportCategoryI18n objects filtered by the locale column + * @method array findByTitle(string $title) Return ChildImportCategoryI18n objects filtered by the title column * */ -abstract class ImportExportCategoryI18nQuery extends ModelCriteria +abstract class ImportCategoryI18nQuery extends ModelCriteria { /** - * Initializes internal state of \Thelia\Model\Base\ImportExportCategoryI18nQuery object. + * Initializes internal state of \Thelia\Model\Base\ImportCategoryI18nQuery object. * * @param string $dbName The database name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ - public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ImportExportCategoryI18n', $modelAlias = null) + public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ImportCategoryI18n', $modelAlias = null) { parent::__construct($dbName, $modelName, $modelAlias); } /** - * Returns a new ChildImportExportCategoryI18nQuery object. + * Returns a new ChildImportCategoryI18nQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * - * @return ChildImportExportCategoryI18nQuery + * @return ChildImportCategoryI18nQuery */ public static function create($modelAlias = null, $criteria = null) { - if ($criteria instanceof \Thelia\Model\ImportExportCategoryI18nQuery) { + if ($criteria instanceof \Thelia\Model\ImportCategoryI18nQuery) { return $criteria; } - $query = new \Thelia\Model\ImportExportCategoryI18nQuery(); + $query = new \Thelia\Model\ImportCategoryI18nQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } @@ -100,19 +100,19 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria * @param array[$id, $locale] $key Primary key to use for the query * @param ConnectionInterface $con an optional connection object * - * @return ChildImportExportCategoryI18n|array|mixed the result, formatted by the current formatter + * @return ChildImportCategoryI18n|array|mixed the result, formatted by the current formatter */ public function findPk($key, $con = null) { if ($key === null) { return null; } - if ((null !== ($obj = ImportExportCategoryI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { + if ((null !== ($obj = ImportCategoryI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { // the object is already in the instance pool return $obj; } if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getReadConnection(ImportCategoryI18nTableMap::DATABASE_NAME); } $this->basePreSelect($con); if ($this->formatter || $this->modelAlias || $this->with || $this->select @@ -131,11 +131,11 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria * @param mixed $key Primary key to use for the query * @param ConnectionInterface $con A connection object * - * @return ChildImportExportCategoryI18n A model object, or null if the key is not found + * @return ChildImportCategoryI18n A model object, or null if the key is not found */ protected function findPkSimple($key, $con) { - $sql = 'SELECT `ID`, `LOCALE`, `TITLE` FROM `import_export_category_i18n` WHERE `ID` = :p0 AND `LOCALE` = :p1'; + $sql = 'SELECT `ID`, `LOCALE`, `TITLE` FROM `import_category_i18n` WHERE `ID` = :p0 AND `LOCALE` = :p1'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); @@ -147,9 +147,9 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria } $obj = null; if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { - $obj = new ChildImportExportCategoryI18n(); + $obj = new ChildImportCategoryI18n(); $obj->hydrate($row); - ImportExportCategoryI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); + ImportCategoryI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); } $stmt->closeCursor(); @@ -162,7 +162,7 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria * @param mixed $key Primary key to use for the query * @param ConnectionInterface $con A connection object * - * @return ChildImportExportCategoryI18n|array|mixed the result, formatted by the current formatter + * @return ChildImportCategoryI18n|array|mixed the result, formatted by the current formatter */ protected function findPkComplex($key, $con) { @@ -204,12 +204,12 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria * * @param mixed $key Primary key to use for the query * - * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + * @return ChildImportCategoryI18nQuery The current query, for fluid interface */ public function filterByPrimaryKey($key) { - $this->addUsingAlias(ImportExportCategoryI18nTableMap::ID, $key[0], Criteria::EQUAL); - $this->addUsingAlias(ImportExportCategoryI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + $this->addUsingAlias(ImportCategoryI18nTableMap::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(ImportCategoryI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); return $this; } @@ -219,7 +219,7 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria * * @param array $keys The list of primary key to use for the query * - * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + * @return ChildImportCategoryI18nQuery The current query, for fluid interface */ public function filterByPrimaryKeys($keys) { @@ -227,8 +227,8 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria return $this->add(null, '1<>1', Criteria::CUSTOM); } foreach ($keys as $key) { - $cton0 = $this->getNewCriterion(ImportExportCategoryI18nTableMap::ID, $key[0], Criteria::EQUAL); - $cton1 = $this->getNewCriterion(ImportExportCategoryI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + $cton0 = $this->getNewCriterion(ImportCategoryI18nTableMap::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(ImportCategoryI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); $cton0->addAnd($cton1); $this->addOr($cton0); } @@ -246,7 +246,7 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria * $query->filterById(array('min' => 12)); // WHERE id > 12 * * - * @see filterByImportExportCategory() + * @see filterByImportCategory() * * @param mixed $id The value to use as filter. * Use scalar values for equality. @@ -254,18 +254,18 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + * @return ChildImportCategoryI18nQuery The current query, for fluid interface */ public function filterById($id = null, $comparison = null) { if (is_array($id)) { $useMinMax = false; if (isset($id['min'])) { - $this->addUsingAlias(ImportExportCategoryI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $this->addUsingAlias(ImportCategoryI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($id['max'])) { - $this->addUsingAlias(ImportExportCategoryI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $this->addUsingAlias(ImportCategoryI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -276,7 +276,7 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportCategoryI18nTableMap::ID, $id, $comparison); + return $this->addUsingAlias(ImportCategoryI18nTableMap::ID, $id, $comparison); } /** @@ -292,7 +292,7 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria * Accepts wildcards (* and % trigger a LIKE) * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + * @return ChildImportCategoryI18nQuery The current query, for fluid interface */ public function filterByLocale($locale = null, $comparison = null) { @@ -305,7 +305,7 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportCategoryI18nTableMap::LOCALE, $locale, $comparison); + return $this->addUsingAlias(ImportCategoryI18nTableMap::LOCALE, $locale, $comparison); } /** @@ -321,7 +321,7 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria * Accepts wildcards (* and % trigger a LIKE) * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + * @return ChildImportCategoryI18nQuery The current query, for fluid interface */ public function filterByTitle($title = null, $comparison = null) { @@ -334,46 +334,46 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportCategoryI18nTableMap::TITLE, $title, $comparison); + return $this->addUsingAlias(ImportCategoryI18nTableMap::TITLE, $title, $comparison); } /** - * Filter the query by a related \Thelia\Model\ImportExportCategory object + * Filter the query by a related \Thelia\Model\ImportCategory object * - * @param \Thelia\Model\ImportExportCategory|ObjectCollection $importExportCategory The related object(s) to use as filter + * @param \Thelia\Model\ImportCategory|ObjectCollection $importCategory The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + * @return ChildImportCategoryI18nQuery The current query, for fluid interface */ - public function filterByImportExportCategory($importExportCategory, $comparison = null) + public function filterByImportCategory($importCategory, $comparison = null) { - if ($importExportCategory instanceof \Thelia\Model\ImportExportCategory) { + if ($importCategory instanceof \Thelia\Model\ImportCategory) { return $this - ->addUsingAlias(ImportExportCategoryI18nTableMap::ID, $importExportCategory->getId(), $comparison); - } elseif ($importExportCategory instanceof ObjectCollection) { + ->addUsingAlias(ImportCategoryI18nTableMap::ID, $importCategory->getId(), $comparison); + } elseif ($importCategory instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this - ->addUsingAlias(ImportExportCategoryI18nTableMap::ID, $importExportCategory->toKeyValue('PrimaryKey', 'Id'), $comparison); + ->addUsingAlias(ImportCategoryI18nTableMap::ID, $importCategory->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { - throw new PropelException('filterByImportExportCategory() only accepts arguments of type \Thelia\Model\ImportExportCategory or Collection'); + throw new PropelException('filterByImportCategory() only accepts arguments of type \Thelia\Model\ImportCategory or Collection'); } } /** - * Adds a JOIN clause to the query using the ImportExportCategory relation + * Adds a JOIN clause to the query using the ImportCategory relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + * @return ChildImportCategoryI18nQuery The current query, for fluid interface */ - public function joinImportExportCategory($relationAlias = null, $joinType = 'LEFT JOIN') + public function joinImportCategory($relationAlias = null, $joinType = 'LEFT JOIN') { $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('ImportExportCategory'); + $relationMap = $tableMap->getRelation('ImportCategory'); // create a ModelJoin object for this join $join = new ModelJoin(); @@ -388,14 +388,14 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { - $this->addJoinObject($join, 'ImportExportCategory'); + $this->addJoinObject($join, 'ImportCategory'); } return $this; } /** - * Use the ImportExportCategory relation ImportExportCategory object + * Use the ImportCategory relation ImportCategory object * * @see useQuery() * @@ -403,27 +403,27 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria * to be used as main alias in the secondary query * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return \Thelia\Model\ImportExportCategoryQuery A secondary query class using the current class as primary query + * @return \Thelia\Model\ImportCategoryQuery A secondary query class using the current class as primary query */ - public function useImportExportCategoryQuery($relationAlias = null, $joinType = 'LEFT JOIN') + public function useImportCategoryQuery($relationAlias = null, $joinType = 'LEFT JOIN') { return $this - ->joinImportExportCategory($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'ImportExportCategory', '\Thelia\Model\ImportExportCategoryQuery'); + ->joinImportCategory($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ImportCategory', '\Thelia\Model\ImportCategoryQuery'); } /** * Exclude object from result * - * @param ChildImportExportCategoryI18n $importExportCategoryI18n Object to remove from the list of results + * @param ChildImportCategoryI18n $importCategoryI18n Object to remove from the list of results * - * @return ChildImportExportCategoryI18nQuery The current query, for fluid interface + * @return ChildImportCategoryI18nQuery The current query, for fluid interface */ - public function prune($importExportCategoryI18n = null) + public function prune($importCategoryI18n = null) { - if ($importExportCategoryI18n) { - $this->addCond('pruneCond0', $this->getAliasedColName(ImportExportCategoryI18nTableMap::ID), $importExportCategoryI18n->getId(), Criteria::NOT_EQUAL); - $this->addCond('pruneCond1', $this->getAliasedColName(ImportExportCategoryI18nTableMap::LOCALE), $importExportCategoryI18n->getLocale(), Criteria::NOT_EQUAL); + if ($importCategoryI18n) { + $this->addCond('pruneCond0', $this->getAliasedColName(ImportCategoryI18nTableMap::ID), $importCategoryI18n->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(ImportCategoryI18nTableMap::LOCALE), $importCategoryI18n->getLocale(), Criteria::NOT_EQUAL); $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); } @@ -431,7 +431,7 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria } /** - * Deletes all rows from the import_export_category_i18n table. + * Deletes all rows from the import_category_i18n table. * * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). @@ -439,7 +439,7 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria public function doDeleteAll(ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryI18nTableMap::DATABASE_NAME); } $affectedRows = 0; // initialize var to track total num of affected rows try { @@ -450,8 +450,8 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria // Because this db requires some delete cascade/set null emulation, we have to // clear the cached instance *after* the emulation has happened (since // instances get re-added by the select statement contained therein). - ImportExportCategoryI18nTableMap::clearInstancePool(); - ImportExportCategoryI18nTableMap::clearRelatedInstancePool(); + ImportCategoryI18nTableMap::clearInstancePool(); + ImportCategoryI18nTableMap::clearRelatedInstancePool(); $con->commit(); } catch (PropelException $e) { @@ -463,9 +463,9 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria } /** - * Performs a DELETE on the database, given a ChildImportExportCategoryI18n or Criteria object OR a primary key value. + * Performs a DELETE on the database, given a ChildImportCategoryI18n or Criteria object OR a primary key value. * - * @param mixed $values Criteria or ChildImportExportCategoryI18n object or primary key or array of primary keys + * @param mixed $values Criteria or ChildImportCategoryI18n object or primary key or array of primary keys * which is used to create the DELETE statement * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows @@ -476,13 +476,13 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria public function delete(ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryI18nTableMap::DATABASE_NAME); } $criteria = $this; // Set the correct dbName - $criteria->setDbName(ImportExportCategoryI18nTableMap::DATABASE_NAME); + $criteria->setDbName(ImportCategoryI18nTableMap::DATABASE_NAME); $affectedRows = 0; // initialize var to track total num of affected rows @@ -492,10 +492,10 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria $con->beginTransaction(); - ImportExportCategoryI18nTableMap::removeInstanceFromPool($criteria); + ImportCategoryI18nTableMap::removeInstanceFromPool($criteria); $affectedRows += ModelCriteria::delete($con); - ImportExportCategoryI18nTableMap::clearRelatedInstancePool(); + ImportCategoryI18nTableMap::clearRelatedInstancePool(); $con->commit(); return $affectedRows; @@ -505,4 +505,4 @@ abstract class ImportExportCategoryI18nQuery extends ModelCriteria } } -} // ImportExportCategoryI18nQuery +} // ImportCategoryI18nQuery diff --git a/core/lib/Thelia/Model/Base/ImportExportCategoryQuery.php b/core/lib/Thelia/Model/Base/ImportCategoryQuery.php similarity index 59% rename from core/lib/Thelia/Model/Base/ImportExportCategoryQuery.php rename to core/lib/Thelia/Model/Base/ImportCategoryQuery.php index 535ad75ac..9c00639ad 100644 --- a/core/lib/Thelia/Model/Base/ImportExportCategoryQuery.php +++ b/core/lib/Thelia/Model/Base/ImportCategoryQuery.php @@ -12,81 +12,81 @@ use Propel\Runtime\Collection\Collection; use Propel\Runtime\Collection\ObjectCollection; use Propel\Runtime\Connection\ConnectionInterface; use Propel\Runtime\Exception\PropelException; -use Thelia\Model\ImportExportCategory as ChildImportExportCategory; -use Thelia\Model\ImportExportCategoryI18nQuery as ChildImportExportCategoryI18nQuery; -use Thelia\Model\ImportExportCategoryQuery as ChildImportExportCategoryQuery; -use Thelia\Model\Map\ImportExportCategoryTableMap; +use Thelia\Model\ImportCategory as ChildImportCategory; +use Thelia\Model\ImportCategoryI18nQuery as ChildImportCategoryI18nQuery; +use Thelia\Model\ImportCategoryQuery as ChildImportCategoryQuery; +use Thelia\Model\Map\ImportCategoryTableMap; /** - * Base class that represents a query for the 'import_export_category' table. + * Base class that represents a query for the 'import_category' table. * * * - * @method ChildImportExportCategoryQuery orderById($order = Criteria::ASC) Order by the id column - * @method ChildImportExportCategoryQuery orderByPosition($order = Criteria::ASC) Order by the position column - * @method ChildImportExportCategoryQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column - * @method ChildImportExportCategoryQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column + * @method ChildImportCategoryQuery orderById($order = Criteria::ASC) Order by the id column + * @method ChildImportCategoryQuery orderByPosition($order = Criteria::ASC) Order by the position column + * @method ChildImportCategoryQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column + * @method ChildImportCategoryQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * - * @method ChildImportExportCategoryQuery groupById() Group by the id column - * @method ChildImportExportCategoryQuery groupByPosition() Group by the position column - * @method ChildImportExportCategoryQuery groupByCreatedAt() Group by the created_at column - * @method ChildImportExportCategoryQuery groupByUpdatedAt() Group by the updated_at column + * @method ChildImportCategoryQuery groupById() Group by the id column + * @method ChildImportCategoryQuery groupByPosition() Group by the position column + * @method ChildImportCategoryQuery groupByCreatedAt() Group by the created_at column + * @method ChildImportCategoryQuery groupByUpdatedAt() Group by the updated_at column * - * @method ChildImportExportCategoryQuery leftJoin($relation) Adds a LEFT JOIN clause to the query - * @method ChildImportExportCategoryQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query - * @method ChildImportExportCategoryQuery innerJoin($relation) Adds a INNER JOIN clause to the query + * @method ChildImportCategoryQuery leftJoin($relation) Adds a LEFT JOIN clause to the query + * @method ChildImportCategoryQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query + * @method ChildImportCategoryQuery innerJoin($relation) Adds a INNER JOIN clause to the query * - * @method ChildImportExportCategoryQuery leftJoinImportExportType($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportExportType relation - * @method ChildImportExportCategoryQuery rightJoinImportExportType($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportExportType relation - * @method ChildImportExportCategoryQuery innerJoinImportExportType($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportExportType relation + * @method ChildImportCategoryQuery leftJoinImport($relationAlias = null) Adds a LEFT JOIN clause to the query using the Import relation + * @method ChildImportCategoryQuery rightJoinImport($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Import relation + * @method ChildImportCategoryQuery innerJoinImport($relationAlias = null) Adds a INNER JOIN clause to the query using the Import relation * - * @method ChildImportExportCategoryQuery leftJoinImportExportCategoryI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportExportCategoryI18n relation - * @method ChildImportExportCategoryQuery rightJoinImportExportCategoryI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportExportCategoryI18n relation - * @method ChildImportExportCategoryQuery innerJoinImportExportCategoryI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportExportCategoryI18n relation + * @method ChildImportCategoryQuery leftJoinImportCategoryI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportCategoryI18n relation + * @method ChildImportCategoryQuery rightJoinImportCategoryI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportCategoryI18n relation + * @method ChildImportCategoryQuery innerJoinImportCategoryI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportCategoryI18n relation * - * @method ChildImportExportCategory findOne(ConnectionInterface $con = null) Return the first ChildImportExportCategory matching the query - * @method ChildImportExportCategory findOneOrCreate(ConnectionInterface $con = null) Return the first ChildImportExportCategory matching the query, or a new ChildImportExportCategory object populated from the query conditions when no match is found + * @method ChildImportCategory findOne(ConnectionInterface $con = null) Return the first ChildImportCategory matching the query + * @method ChildImportCategory findOneOrCreate(ConnectionInterface $con = null) Return the first ChildImportCategory matching the query, or a new ChildImportCategory object populated from the query conditions when no match is found * - * @method ChildImportExportCategory findOneById(int $id) Return the first ChildImportExportCategory filtered by the id column - * @method ChildImportExportCategory findOneByPosition(int $position) Return the first ChildImportExportCategory filtered by the position column - * @method ChildImportExportCategory findOneByCreatedAt(string $created_at) Return the first ChildImportExportCategory filtered by the created_at column - * @method ChildImportExportCategory findOneByUpdatedAt(string $updated_at) Return the first ChildImportExportCategory filtered by the updated_at column + * @method ChildImportCategory findOneById(int $id) Return the first ChildImportCategory filtered by the id column + * @method ChildImportCategory findOneByPosition(int $position) Return the first ChildImportCategory filtered by the position column + * @method ChildImportCategory findOneByCreatedAt(string $created_at) Return the first ChildImportCategory filtered by the created_at column + * @method ChildImportCategory findOneByUpdatedAt(string $updated_at) Return the first ChildImportCategory filtered by the updated_at column * - * @method array findById(int $id) Return ChildImportExportCategory objects filtered by the id column - * @method array findByPosition(int $position) Return ChildImportExportCategory objects filtered by the position column - * @method array findByCreatedAt(string $created_at) Return ChildImportExportCategory objects filtered by the created_at column - * @method array findByUpdatedAt(string $updated_at) Return ChildImportExportCategory objects filtered by the updated_at column + * @method array findById(int $id) Return ChildImportCategory objects filtered by the id column + * @method array findByPosition(int $position) Return ChildImportCategory objects filtered by the position column + * @method array findByCreatedAt(string $created_at) Return ChildImportCategory objects filtered by the created_at column + * @method array findByUpdatedAt(string $updated_at) Return ChildImportCategory objects filtered by the updated_at column * */ -abstract class ImportExportCategoryQuery extends ModelCriteria +abstract class ImportCategoryQuery extends ModelCriteria { /** - * Initializes internal state of \Thelia\Model\Base\ImportExportCategoryQuery object. + * Initializes internal state of \Thelia\Model\Base\ImportCategoryQuery object. * * @param string $dbName The database name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ - public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ImportExportCategory', $modelAlias = null) + public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ImportCategory', $modelAlias = null) { parent::__construct($dbName, $modelName, $modelAlias); } /** - * Returns a new ChildImportExportCategoryQuery object. + * Returns a new ChildImportCategoryQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * - * @return ChildImportExportCategoryQuery + * @return ChildImportCategoryQuery */ public static function create($modelAlias = null, $criteria = null) { - if ($criteria instanceof \Thelia\Model\ImportExportCategoryQuery) { + if ($criteria instanceof \Thelia\Model\ImportCategoryQuery) { return $criteria; } - $query = new \Thelia\Model\ImportExportCategoryQuery(); + $query = new \Thelia\Model\ImportCategoryQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } @@ -109,19 +109,19 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * @param mixed $key Primary key to use for the query * @param ConnectionInterface $con an optional connection object * - * @return ChildImportExportCategory|array|mixed the result, formatted by the current formatter + * @return ChildImportCategory|array|mixed the result, formatted by the current formatter */ public function findPk($key, $con = null) { if ($key === null) { return null; } - if ((null !== ($obj = ImportExportCategoryTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + if ((null !== ($obj = ImportCategoryTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { // the object is already in the instance pool return $obj; } if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(ImportExportCategoryTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getReadConnection(ImportCategoryTableMap::DATABASE_NAME); } $this->basePreSelect($con); if ($this->formatter || $this->modelAlias || $this->with || $this->select @@ -140,11 +140,11 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * @param mixed $key Primary key to use for the query * @param ConnectionInterface $con A connection object * - * @return ChildImportExportCategory A model object, or null if the key is not found + * @return ChildImportCategory A model object, or null if the key is not found */ protected function findPkSimple($key, $con) { - $sql = 'SELECT `ID`, `POSITION`, `CREATED_AT`, `UPDATED_AT` FROM `import_export_category` WHERE `ID` = :p0'; + $sql = 'SELECT `ID`, `POSITION`, `CREATED_AT`, `UPDATED_AT` FROM `import_category` WHERE `ID` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -155,9 +155,9 @@ abstract class ImportExportCategoryQuery extends ModelCriteria } $obj = null; if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { - $obj = new ChildImportExportCategory(); + $obj = new ChildImportCategory(); $obj->hydrate($row); - ImportExportCategoryTableMap::addInstanceToPool($obj, (string) $key); + ImportCategoryTableMap::addInstanceToPool($obj, (string) $key); } $stmt->closeCursor(); @@ -170,7 +170,7 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * @param mixed $key Primary key to use for the query * @param ConnectionInterface $con A connection object * - * @return ChildImportExportCategory|array|mixed the result, formatted by the current formatter + * @return ChildImportCategory|array|mixed the result, formatted by the current formatter */ protected function findPkComplex($key, $con) { @@ -212,12 +212,12 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * * @param mixed $key Primary key to use for the query * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function filterByPrimaryKey($key) { - return $this->addUsingAlias(ImportExportCategoryTableMap::ID, $key, Criteria::EQUAL); + return $this->addUsingAlias(ImportCategoryTableMap::ID, $key, Criteria::EQUAL); } /** @@ -225,12 +225,12 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * * @param array $keys The list of primary key to use for the query * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function filterByPrimaryKeys($keys) { - return $this->addUsingAlias(ImportExportCategoryTableMap::ID, $keys, Criteria::IN); + return $this->addUsingAlias(ImportCategoryTableMap::ID, $keys, Criteria::IN); } /** @@ -249,18 +249,18 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function filterById($id = null, $comparison = null) { if (is_array($id)) { $useMinMax = false; if (isset($id['min'])) { - $this->addUsingAlias(ImportExportCategoryTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $this->addUsingAlias(ImportCategoryTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($id['max'])) { - $this->addUsingAlias(ImportExportCategoryTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $this->addUsingAlias(ImportCategoryTableMap::ID, $id['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -271,7 +271,7 @@ abstract class ImportExportCategoryQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportCategoryTableMap::ID, $id, $comparison); + return $this->addUsingAlias(ImportCategoryTableMap::ID, $id, $comparison); } /** @@ -290,18 +290,18 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function filterByPosition($position = null, $comparison = null) { if (is_array($position)) { $useMinMax = false; if (isset($position['min'])) { - $this->addUsingAlias(ImportExportCategoryTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL); + $this->addUsingAlias(ImportCategoryTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($position['max'])) { - $this->addUsingAlias(ImportExportCategoryTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL); + $this->addUsingAlias(ImportCategoryTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -312,7 +312,7 @@ abstract class ImportExportCategoryQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportCategoryTableMap::POSITION, $position, $comparison); + return $this->addUsingAlias(ImportCategoryTableMap::POSITION, $position, $comparison); } /** @@ -333,18 +333,18 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function filterByCreatedAt($createdAt = null, $comparison = null) { if (is_array($createdAt)) { $useMinMax = false; if (isset($createdAt['min'])) { - $this->addUsingAlias(ImportExportCategoryTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $this->addUsingAlias(ImportCategoryTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($createdAt['max'])) { - $this->addUsingAlias(ImportExportCategoryTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $this->addUsingAlias(ImportCategoryTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -355,7 +355,7 @@ abstract class ImportExportCategoryQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportCategoryTableMap::CREATED_AT, $createdAt, $comparison); + return $this->addUsingAlias(ImportCategoryTableMap::CREATED_AT, $createdAt, $comparison); } /** @@ -376,18 +376,18 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function filterByUpdatedAt($updatedAt = null, $comparison = null) { if (is_array($updatedAt)) { $useMinMax = false; if (isset($updatedAt['min'])) { - $this->addUsingAlias(ImportExportCategoryTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $this->addUsingAlias(ImportCategoryTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($updatedAt['max'])) { - $this->addUsingAlias(ImportExportCategoryTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $this->addUsingAlias(ImportCategoryTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -398,44 +398,44 @@ abstract class ImportExportCategoryQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportCategoryTableMap::UPDATED_AT, $updatedAt, $comparison); + return $this->addUsingAlias(ImportCategoryTableMap::UPDATED_AT, $updatedAt, $comparison); } /** - * Filter the query by a related \Thelia\Model\ImportExportType object + * Filter the query by a related \Thelia\Model\Import object * - * @param \Thelia\Model\ImportExportType|ObjectCollection $importExportType the related object to use as filter + * @param \Thelia\Model\Import|ObjectCollection $import the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ - public function filterByImportExportType($importExportType, $comparison = null) + public function filterByImport($import, $comparison = null) { - if ($importExportType instanceof \Thelia\Model\ImportExportType) { + if ($import instanceof \Thelia\Model\Import) { return $this - ->addUsingAlias(ImportExportCategoryTableMap::ID, $importExportType->getImportExportCategoryId(), $comparison); - } elseif ($importExportType instanceof ObjectCollection) { + ->addUsingAlias(ImportCategoryTableMap::ID, $import->getImportCategoryId(), $comparison); + } elseif ($import instanceof ObjectCollection) { return $this - ->useImportExportTypeQuery() - ->filterByPrimaryKeys($importExportType->getPrimaryKeys()) + ->useImportQuery() + ->filterByPrimaryKeys($import->getPrimaryKeys()) ->endUse(); } else { - throw new PropelException('filterByImportExportType() only accepts arguments of type \Thelia\Model\ImportExportType or Collection'); + throw new PropelException('filterByImport() only accepts arguments of type \Thelia\Model\Import or Collection'); } } /** - * Adds a JOIN clause to the query using the ImportExportType relation + * Adds a JOIN clause to the query using the Import relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ - public function joinImportExportType($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function joinImport($relationAlias = null, $joinType = Criteria::INNER_JOIN) { $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('ImportExportType'); + $relationMap = $tableMap->getRelation('Import'); // create a ModelJoin object for this join $join = new ModelJoin(); @@ -450,14 +450,14 @@ abstract class ImportExportCategoryQuery extends ModelCriteria $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { - $this->addJoinObject($join, 'ImportExportType'); + $this->addJoinObject($join, 'Import'); } return $this; } /** - * Use the ImportExportType relation ImportExportType object + * Use the Import relation Import object * * @see useQuery() * @@ -465,50 +465,50 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * to be used as main alias in the secondary query * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return \Thelia\Model\ImportExportTypeQuery A secondary query class using the current class as primary query + * @return \Thelia\Model\ImportQuery A secondary query class using the current class as primary query */ - public function useImportExportTypeQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function useImportQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) { return $this - ->joinImportExportType($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'ImportExportType', '\Thelia\Model\ImportExportTypeQuery'); + ->joinImport($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Import', '\Thelia\Model\ImportQuery'); } /** - * Filter the query by a related \Thelia\Model\ImportExportCategoryI18n object + * Filter the query by a related \Thelia\Model\ImportCategoryI18n object * - * @param \Thelia\Model\ImportExportCategoryI18n|ObjectCollection $importExportCategoryI18n the related object to use as filter + * @param \Thelia\Model\ImportCategoryI18n|ObjectCollection $importCategoryI18n the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ - public function filterByImportExportCategoryI18n($importExportCategoryI18n, $comparison = null) + public function filterByImportCategoryI18n($importCategoryI18n, $comparison = null) { - if ($importExportCategoryI18n instanceof \Thelia\Model\ImportExportCategoryI18n) { + if ($importCategoryI18n instanceof \Thelia\Model\ImportCategoryI18n) { return $this - ->addUsingAlias(ImportExportCategoryTableMap::ID, $importExportCategoryI18n->getId(), $comparison); - } elseif ($importExportCategoryI18n instanceof ObjectCollection) { + ->addUsingAlias(ImportCategoryTableMap::ID, $importCategoryI18n->getId(), $comparison); + } elseif ($importCategoryI18n instanceof ObjectCollection) { return $this - ->useImportExportCategoryI18nQuery() - ->filterByPrimaryKeys($importExportCategoryI18n->getPrimaryKeys()) + ->useImportCategoryI18nQuery() + ->filterByPrimaryKeys($importCategoryI18n->getPrimaryKeys()) ->endUse(); } else { - throw new PropelException('filterByImportExportCategoryI18n() only accepts arguments of type \Thelia\Model\ImportExportCategoryI18n or Collection'); + throw new PropelException('filterByImportCategoryI18n() only accepts arguments of type \Thelia\Model\ImportCategoryI18n or Collection'); } } /** - * Adds a JOIN clause to the query using the ImportExportCategoryI18n relation + * Adds a JOIN clause to the query using the ImportCategoryI18n relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ - public function joinImportExportCategoryI18n($relationAlias = null, $joinType = 'LEFT JOIN') + public function joinImportCategoryI18n($relationAlias = null, $joinType = 'LEFT JOIN') { $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('ImportExportCategoryI18n'); + $relationMap = $tableMap->getRelation('ImportCategoryI18n'); // create a ModelJoin object for this join $join = new ModelJoin(); @@ -523,14 +523,14 @@ abstract class ImportExportCategoryQuery extends ModelCriteria $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { - $this->addJoinObject($join, 'ImportExportCategoryI18n'); + $this->addJoinObject($join, 'ImportCategoryI18n'); } return $this; } /** - * Use the ImportExportCategoryI18n relation ImportExportCategoryI18n object + * Use the ImportCategoryI18n relation ImportCategoryI18n object * * @see useQuery() * @@ -538,33 +538,33 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * to be used as main alias in the secondary query * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return \Thelia\Model\ImportExportCategoryI18nQuery A secondary query class using the current class as primary query + * @return \Thelia\Model\ImportCategoryI18nQuery A secondary query class using the current class as primary query */ - public function useImportExportCategoryI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') + public function useImportCategoryI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') { return $this - ->joinImportExportCategoryI18n($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'ImportExportCategoryI18n', '\Thelia\Model\ImportExportCategoryI18nQuery'); + ->joinImportCategoryI18n($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ImportCategoryI18n', '\Thelia\Model\ImportCategoryI18nQuery'); } /** * Exclude object from result * - * @param ChildImportExportCategory $importExportCategory Object to remove from the list of results + * @param ChildImportCategory $importCategory Object to remove from the list of results * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ - public function prune($importExportCategory = null) + public function prune($importCategory = null) { - if ($importExportCategory) { - $this->addUsingAlias(ImportExportCategoryTableMap::ID, $importExportCategory->getId(), Criteria::NOT_EQUAL); + if ($importCategory) { + $this->addUsingAlias(ImportCategoryTableMap::ID, $importCategory->getId(), Criteria::NOT_EQUAL); } return $this; } /** - * Deletes all rows from the import_export_category table. + * Deletes all rows from the import_category table. * * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). @@ -572,7 +572,7 @@ abstract class ImportExportCategoryQuery extends ModelCriteria public function doDeleteAll(ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryTableMap::DATABASE_NAME); } $affectedRows = 0; // initialize var to track total num of affected rows try { @@ -583,8 +583,8 @@ abstract class ImportExportCategoryQuery extends ModelCriteria // Because this db requires some delete cascade/set null emulation, we have to // clear the cached instance *after* the emulation has happened (since // instances get re-added by the select statement contained therein). - ImportExportCategoryTableMap::clearInstancePool(); - ImportExportCategoryTableMap::clearRelatedInstancePool(); + ImportCategoryTableMap::clearInstancePool(); + ImportCategoryTableMap::clearRelatedInstancePool(); $con->commit(); } catch (PropelException $e) { @@ -596,9 +596,9 @@ abstract class ImportExportCategoryQuery extends ModelCriteria } /** - * Performs a DELETE on the database, given a ChildImportExportCategory or Criteria object OR a primary key value. + * Performs a DELETE on the database, given a ChildImportCategory or Criteria object OR a primary key value. * - * @param mixed $values Criteria or ChildImportExportCategory object or primary key or array of primary keys + * @param mixed $values Criteria or ChildImportCategory object or primary key or array of primary keys * which is used to create the DELETE statement * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows @@ -609,13 +609,13 @@ abstract class ImportExportCategoryQuery extends ModelCriteria public function delete(ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryTableMap::DATABASE_NAME); } $criteria = $this; // Set the correct dbName - $criteria->setDbName(ImportExportCategoryTableMap::DATABASE_NAME); + $criteria->setDbName(ImportCategoryTableMap::DATABASE_NAME); $affectedRows = 0; // initialize var to track total num of affected rows @@ -625,10 +625,10 @@ abstract class ImportExportCategoryQuery extends ModelCriteria $con->beginTransaction(); - ImportExportCategoryTableMap::removeInstanceFromPool($criteria); + ImportCategoryTableMap::removeInstanceFromPool($criteria); $affectedRows += ModelCriteria::delete($con); - ImportExportCategoryTableMap::clearRelatedInstancePool(); + ImportCategoryTableMap::clearRelatedInstancePool(); $con->commit(); return $affectedRows; @@ -647,14 +647,14 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function joinI18n($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) { - $relationName = $relationAlias ? $relationAlias : 'ImportExportCategoryI18n'; + $relationName = $relationAlias ? $relationAlias : 'ImportCategoryI18n'; return $this - ->joinImportExportCategoryI18n($relationAlias, $joinType) + ->joinImportCategoryI18n($relationAlias, $joinType) ->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale); } @@ -665,14 +665,14 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function joinWithI18n($locale = 'en_US', $joinType = Criteria::LEFT_JOIN) { $this ->joinI18n($locale, null, $joinType) - ->with('ImportExportCategoryI18n'); - $this->with['ImportExportCategoryI18n']->setIsWithOneToMany(false); + ->with('ImportCategoryI18n'); + $this->with['ImportCategoryI18n']->setIsWithOneToMany(false); return $this; } @@ -686,13 +686,13 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. * - * @return ChildImportExportCategoryI18nQuery A secondary query class using the current class as primary query + * @return ChildImportCategoryI18nQuery A secondary query class using the current class as primary query */ public function useI18nQuery($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) { return $this ->joinI18n($locale, $relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'ImportExportCategoryI18n', '\Thelia\Model\ImportExportCategoryI18nQuery'); + ->useQuery($relationAlias ? $relationAlias : 'ImportCategoryI18n', '\Thelia\Model\ImportCategoryI18nQuery'); } // timestampable behavior @@ -702,11 +702,11 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * * @param int $nbDays Maximum age of the latest update in days * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function recentlyUpdated($nbDays = 7) { - return $this->addUsingAlias(ImportExportCategoryTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + return $this->addUsingAlias(ImportCategoryTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); } /** @@ -714,51 +714,51 @@ abstract class ImportExportCategoryQuery extends ModelCriteria * * @param int $nbDays Maximum age of in days * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function recentlyCreated($nbDays = 7) { - return $this->addUsingAlias(ImportExportCategoryTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + return $this->addUsingAlias(ImportCategoryTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); } /** * Order by update date desc * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function lastUpdatedFirst() { - return $this->addDescendingOrderByColumn(ImportExportCategoryTableMap::UPDATED_AT); + return $this->addDescendingOrderByColumn(ImportCategoryTableMap::UPDATED_AT); } /** * Order by update date asc * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function firstUpdatedFirst() { - return $this->addAscendingOrderByColumn(ImportExportCategoryTableMap::UPDATED_AT); + return $this->addAscendingOrderByColumn(ImportCategoryTableMap::UPDATED_AT); } /** * Order by create date desc * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function lastCreatedFirst() { - return $this->addDescendingOrderByColumn(ImportExportCategoryTableMap::CREATED_AT); + return $this->addDescendingOrderByColumn(ImportCategoryTableMap::CREATED_AT); } /** * Order by create date asc * - * @return ChildImportExportCategoryQuery The current query, for fluid interface + * @return ChildImportCategoryQuery The current query, for fluid interface */ public function firstCreatedFirst() { - return $this->addAscendingOrderByColumn(ImportExportCategoryTableMap::CREATED_AT); + return $this->addAscendingOrderByColumn(ImportCategoryTableMap::CREATED_AT); } -} // ImportExportCategoryQuery +} // ImportCategoryQuery diff --git a/core/lib/Thelia/Model/Base/ImportExportTypeI18n.php b/core/lib/Thelia/Model/Base/ImportI18n.php similarity index 84% rename from core/lib/Thelia/Model/Base/ImportExportTypeI18n.php rename to core/lib/Thelia/Model/Base/ImportI18n.php index 0aca83a7f..9387e2419 100644 --- a/core/lib/Thelia/Model/Base/ImportExportTypeI18n.php +++ b/core/lib/Thelia/Model/Base/ImportI18n.php @@ -14,17 +14,17 @@ use Propel\Runtime\Exception\BadMethodCallException; use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Parser\AbstractParser; -use Thelia\Model\ImportExportType as ChildImportExportType; -use Thelia\Model\ImportExportTypeI18nQuery as ChildImportExportTypeI18nQuery; -use Thelia\Model\ImportExportTypeQuery as ChildImportExportTypeQuery; -use Thelia\Model\Map\ImportExportTypeI18nTableMap; +use Thelia\Model\Import as ChildImport; +use Thelia\Model\ImportI18nQuery as ChildImportI18nQuery; +use Thelia\Model\ImportQuery as ChildImportQuery; +use Thelia\Model\Map\ImportI18nTableMap; -abstract class ImportExportTypeI18n implements ActiveRecordInterface +abstract class ImportI18n implements ActiveRecordInterface { /** * TableMap class name */ - const TABLE_MAP = '\\Thelia\\Model\\Map\\ImportExportTypeI18nTableMap'; + const TABLE_MAP = '\\Thelia\\Model\\Map\\ImportI18nTableMap'; /** @@ -79,9 +79,9 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface protected $description; /** - * @var ImportExportType + * @var Import */ - protected $aImportExportType; + protected $aImport; /** * Flag to prevent endless save loop, if this object is referenced @@ -103,7 +103,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface } /** - * Initializes internal state of Thelia\Model\Base\ImportExportTypeI18n object. + * Initializes internal state of Thelia\Model\Base\ImportI18n object. * @see applyDefaults() */ public function __construct() @@ -200,9 +200,9 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface } /** - * Compares this with another ImportExportTypeI18n instance. If - * obj is an instance of ImportExportTypeI18n, delegates to - * equals(ImportExportTypeI18n). Otherwise, returns false. + * Compares this with another ImportI18n instance. If + * obj is an instance of ImportI18n, delegates to + * equals(ImportI18n). Otherwise, returns false. * * @param mixed $obj The object to compare to. * @return boolean Whether equal to the object specified. @@ -285,7 +285,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface * @param string $name The virtual column name * @param mixed $value The value to give to the virtual column * - * @return ImportExportTypeI18n The current object, for fluid interface + * @return ImportI18n The current object, for fluid interface */ public function setVirtualColumn($name, $value) { @@ -317,7 +317,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface * or a format name ('XML', 'YAML', 'JSON', 'CSV') * @param string $data The source data to import from * - * @return ImportExportTypeI18n The current object, for fluid interface + * @return ImportI18n The current object, for fluid interface */ public function importFrom($parser, $data) { @@ -410,7 +410,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface * Set the value of [id] column. * * @param int $v new value - * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + * @return \Thelia\Model\ImportI18n The current object (for fluent API support) */ public function setId($v) { @@ -420,11 +420,11 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface if ($this->id !== $v) { $this->id = $v; - $this->modifiedColumns[ImportExportTypeI18nTableMap::ID] = true; + $this->modifiedColumns[ImportI18nTableMap::ID] = true; } - if ($this->aImportExportType !== null && $this->aImportExportType->getId() !== $v) { - $this->aImportExportType = null; + if ($this->aImport !== null && $this->aImport->getId() !== $v) { + $this->aImport = null; } @@ -435,7 +435,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface * Set the value of [locale] column. * * @param string $v new value - * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + * @return \Thelia\Model\ImportI18n The current object (for fluent API support) */ public function setLocale($v) { @@ -445,7 +445,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface if ($this->locale !== $v) { $this->locale = $v; - $this->modifiedColumns[ImportExportTypeI18nTableMap::LOCALE] = true; + $this->modifiedColumns[ImportI18nTableMap::LOCALE] = true; } @@ -456,7 +456,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface * Set the value of [title] column. * * @param string $v new value - * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + * @return \Thelia\Model\ImportI18n The current object (for fluent API support) */ public function setTitle($v) { @@ -466,7 +466,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface if ($this->title !== $v) { $this->title = $v; - $this->modifiedColumns[ImportExportTypeI18nTableMap::TITLE] = true; + $this->modifiedColumns[ImportI18nTableMap::TITLE] = true; } @@ -477,7 +477,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface * Set the value of [description] column. * * @param string $v new value - * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + * @return \Thelia\Model\ImportI18n The current object (for fluent API support) */ public function setDescription($v) { @@ -487,7 +487,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface if ($this->description !== $v) { $this->description = $v; - $this->modifiedColumns[ImportExportTypeI18nTableMap::DESCRIPTION] = true; + $this->modifiedColumns[ImportI18nTableMap::DESCRIPTION] = true; } @@ -535,16 +535,16 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface try { - $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ImportExportTypeI18nTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : ImportI18nTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; $this->id = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ImportExportTypeI18nTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : ImportI18nTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; $this->locale = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportExportTypeI18nTableMap::translateFieldName('Title', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportI18nTableMap::translateFieldName('Title', TableMap::TYPE_PHPNAME, $indexType)]; $this->title = (null !== $col) ? (string) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportExportTypeI18nTableMap::translateFieldName('Description', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportI18nTableMap::translateFieldName('Description', TableMap::TYPE_PHPNAME, $indexType)]; $this->description = (null !== $col) ? (string) $col : null; $this->resetModified(); @@ -554,10 +554,10 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 4; // 4 = ImportExportTypeI18nTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 4; // 4 = ImportI18nTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { - throw new PropelException("Error populating \Thelia\Model\ImportExportTypeI18n object", 0, $e); + throw new PropelException("Error populating \Thelia\Model\ImportI18n object", 0, $e); } } @@ -576,8 +576,8 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface */ public function ensureConsistency() { - if ($this->aImportExportType !== null && $this->id !== $this->aImportExportType->getId()) { - $this->aImportExportType = null; + if ($this->aImport !== null && $this->id !== $this->aImport->getId()) { + $this->aImport = null; } } // ensureConsistency @@ -602,13 +602,13 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface } if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getReadConnection(ImportI18nTableMap::DATABASE_NAME); } // We don't need to alter the object instance pool; we're just modifying this instance // already in the pool. - $dataFetcher = ChildImportExportTypeI18nQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $dataFetcher = ChildImportI18nQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); $row = $dataFetcher->fetch(); $dataFetcher->close(); if (!$row) { @@ -618,7 +618,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface if ($deep) { // also de-associate any related objects? - $this->aImportExportType = null; + $this->aImport = null; } // if (deep) } @@ -628,8 +628,8 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface * @param ConnectionInterface $con * @return void * @throws PropelException - * @see ImportExportTypeI18n::setDeleted() - * @see ImportExportTypeI18n::isDeleted() + * @see ImportI18n::setDeleted() + * @see ImportI18n::isDeleted() */ public function delete(ConnectionInterface $con = null) { @@ -638,12 +638,12 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface } if ($con === null) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportI18nTableMap::DATABASE_NAME); } $con->beginTransaction(); try { - $deleteQuery = ChildImportExportTypeI18nQuery::create() + $deleteQuery = ChildImportI18nQuery::create() ->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { @@ -680,7 +680,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface } if ($con === null) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportI18nTableMap::DATABASE_NAME); } $con->beginTransaction(); @@ -700,7 +700,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface $this->postUpdate($con); } $this->postSave($con); - ImportExportTypeI18nTableMap::addInstanceToPool($this); + ImportI18nTableMap::addInstanceToPool($this); } else { $affectedRows = 0; } @@ -735,11 +735,11 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface // method. This object relates to these object(s) by a // foreign key reference. - if ($this->aImportExportType !== null) { - if ($this->aImportExportType->isModified() || $this->aImportExportType->isNew()) { - $affectedRows += $this->aImportExportType->save($con); + if ($this->aImport !== null) { + if ($this->aImport->isModified() || $this->aImport->isNew()) { + $affectedRows += $this->aImport->save($con); } - $this->setImportExportType($this->aImportExportType); + $this->setImport($this->aImport); } if ($this->isNew() || $this->isModified()) { @@ -775,21 +775,21 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface // check the columns in natural order for more readable SQL queries - if ($this->isColumnModified(ImportExportTypeI18nTableMap::ID)) { + if ($this->isColumnModified(ImportI18nTableMap::ID)) { $modifiedColumns[':p' . $index++] = '`ID`'; } - if ($this->isColumnModified(ImportExportTypeI18nTableMap::LOCALE)) { + if ($this->isColumnModified(ImportI18nTableMap::LOCALE)) { $modifiedColumns[':p' . $index++] = '`LOCALE`'; } - if ($this->isColumnModified(ImportExportTypeI18nTableMap::TITLE)) { + if ($this->isColumnModified(ImportI18nTableMap::TITLE)) { $modifiedColumns[':p' . $index++] = '`TITLE`'; } - if ($this->isColumnModified(ImportExportTypeI18nTableMap::DESCRIPTION)) { + if ($this->isColumnModified(ImportI18nTableMap::DESCRIPTION)) { $modifiedColumns[':p' . $index++] = '`DESCRIPTION`'; } $sql = sprintf( - 'INSERT INTO `import_export_type_i18n` (%s) VALUES (%s)', + 'INSERT INTO `import_i18n` (%s) VALUES (%s)', implode(', ', $modifiedColumns), implode(', ', array_keys($modifiedColumns)) ); @@ -849,7 +849,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface */ public function getByName($name, $type = TableMap::TYPE_PHPNAME) { - $pos = ImportExportTypeI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $pos = ImportI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); $field = $this->getByPosition($pos); return $field; @@ -900,11 +900,11 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface */ public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { - if (isset($alreadyDumpedObjects['ImportExportTypeI18n'][serialize($this->getPrimaryKey())])) { + if (isset($alreadyDumpedObjects['ImportI18n'][serialize($this->getPrimaryKey())])) { return '*RECURSION*'; } - $alreadyDumpedObjects['ImportExportTypeI18n'][serialize($this->getPrimaryKey())] = true; - $keys = ImportExportTypeI18nTableMap::getFieldNames($keyType); + $alreadyDumpedObjects['ImportI18n'][serialize($this->getPrimaryKey())] = true; + $keys = ImportI18nTableMap::getFieldNames($keyType); $result = array( $keys[0] => $this->getId(), $keys[1] => $this->getLocale(), @@ -917,8 +917,8 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface } if ($includeForeignObjects) { - if (null !== $this->aImportExportType) { - $result['ImportExportType'] = $this->aImportExportType->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + if (null !== $this->aImport) { + $result['Import'] = $this->aImport->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } } @@ -938,7 +938,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface */ public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) { - $pos = ImportExportTypeI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $pos = ImportI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); return $this->setByPosition($pos, $value); } @@ -988,7 +988,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface */ public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) { - $keys = ImportExportTypeI18nTableMap::getFieldNames($keyType); + $keys = ImportI18nTableMap::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setLocale($arr[$keys[1]]); @@ -1003,12 +1003,12 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface */ public function buildCriteria() { - $criteria = new Criteria(ImportExportTypeI18nTableMap::DATABASE_NAME); + $criteria = new Criteria(ImportI18nTableMap::DATABASE_NAME); - if ($this->isColumnModified(ImportExportTypeI18nTableMap::ID)) $criteria->add(ImportExportTypeI18nTableMap::ID, $this->id); - if ($this->isColumnModified(ImportExportTypeI18nTableMap::LOCALE)) $criteria->add(ImportExportTypeI18nTableMap::LOCALE, $this->locale); - if ($this->isColumnModified(ImportExportTypeI18nTableMap::TITLE)) $criteria->add(ImportExportTypeI18nTableMap::TITLE, $this->title); - if ($this->isColumnModified(ImportExportTypeI18nTableMap::DESCRIPTION)) $criteria->add(ImportExportTypeI18nTableMap::DESCRIPTION, $this->description); + if ($this->isColumnModified(ImportI18nTableMap::ID)) $criteria->add(ImportI18nTableMap::ID, $this->id); + if ($this->isColumnModified(ImportI18nTableMap::LOCALE)) $criteria->add(ImportI18nTableMap::LOCALE, $this->locale); + if ($this->isColumnModified(ImportI18nTableMap::TITLE)) $criteria->add(ImportI18nTableMap::TITLE, $this->title); + if ($this->isColumnModified(ImportI18nTableMap::DESCRIPTION)) $criteria->add(ImportI18nTableMap::DESCRIPTION, $this->description); return $criteria; } @@ -1023,9 +1023,9 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface */ public function buildPkeyCriteria() { - $criteria = new Criteria(ImportExportTypeI18nTableMap::DATABASE_NAME); - $criteria->add(ImportExportTypeI18nTableMap::ID, $this->id); - $criteria->add(ImportExportTypeI18nTableMap::LOCALE, $this->locale); + $criteria = new Criteria(ImportI18nTableMap::DATABASE_NAME); + $criteria->add(ImportI18nTableMap::ID, $this->id); + $criteria->add(ImportI18nTableMap::LOCALE, $this->locale); return $criteria; } @@ -1072,7 +1072,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface * If desired, this method can also make copies of all associated (fkey referrers) * objects. * - * @param object $copyObj An object of \Thelia\Model\ImportExportTypeI18n (or compatible) type. + * @param object $copyObj An object of \Thelia\Model\ImportI18n (or compatible) type. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. * @throws PropelException @@ -1097,7 +1097,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface * objects. * * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. - * @return \Thelia\Model\ImportExportTypeI18n Clone of current object. + * @return \Thelia\Model\ImportI18n Clone of current object. * @throws PropelException */ public function copy($deepCopy = false) @@ -1111,13 +1111,13 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface } /** - * Declares an association between this object and a ChildImportExportType object. + * Declares an association between this object and a ChildImport object. * - * @param ChildImportExportType $v - * @return \Thelia\Model\ImportExportTypeI18n The current object (for fluent API support) + * @param ChildImport $v + * @return \Thelia\Model\ImportI18n The current object (for fluent API support) * @throws PropelException */ - public function setImportExportType(ChildImportExportType $v = null) + public function setImport(ChildImport $v = null) { if ($v === null) { $this->setId(NULL); @@ -1125,12 +1125,12 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface $this->setId($v->getId()); } - $this->aImportExportType = $v; + $this->aImport = $v; // Add binding for other direction of this n:n relationship. - // If this object has already been added to the ChildImportExportType object, it will not be re-added. + // If this object has already been added to the ChildImport object, it will not be re-added. if ($v !== null) { - $v->addImportExportTypeI18n($this); + $v->addImportI18n($this); } @@ -1139,26 +1139,26 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface /** - * Get the associated ChildImportExportType object + * Get the associated ChildImport object * * @param ConnectionInterface $con Optional Connection object. - * @return ChildImportExportType The associated ChildImportExportType object. + * @return ChildImport The associated ChildImport object. * @throws PropelException */ - public function getImportExportType(ConnectionInterface $con = null) + public function getImport(ConnectionInterface $con = null) { - if ($this->aImportExportType === null && ($this->id !== null)) { - $this->aImportExportType = ChildImportExportTypeQuery::create()->findPk($this->id, $con); + if ($this->aImport === null && ($this->id !== null)) { + $this->aImport = ChildImportQuery::create()->findPk($this->id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. - $this->aImportExportType->addImportExportTypeI18ns($this); + $this->aImport->addImportI18ns($this); */ } - return $this->aImportExportType; + return $this->aImport; } /** @@ -1192,7 +1192,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface if ($deep) { } // if ($deep) - $this->aImportExportType = null; + $this->aImport = null; } /** @@ -1202,7 +1202,7 @@ abstract class ImportExportTypeI18n implements ActiveRecordInterface */ public function __toString() { - return (string) $this->exportTo(ImportExportTypeI18nTableMap::DEFAULT_STRING_FORMAT); + return (string) $this->exportTo(ImportI18nTableMap::DEFAULT_STRING_FORMAT); } /** diff --git a/core/lib/Thelia/Model/Base/ImportExportTypeI18nQuery.php b/core/lib/Thelia/Model/Base/ImportI18nQuery.php similarity index 61% rename from core/lib/Thelia/Model/Base/ImportExportTypeI18nQuery.php rename to core/lib/Thelia/Model/Base/ImportI18nQuery.php index 2d5176307..630823b9e 100644 --- a/core/lib/Thelia/Model/Base/ImportExportTypeI18nQuery.php +++ b/core/lib/Thelia/Model/Base/ImportI18nQuery.php @@ -12,76 +12,76 @@ use Propel\Runtime\Collection\Collection; use Propel\Runtime\Collection\ObjectCollection; use Propel\Runtime\Connection\ConnectionInterface; use Propel\Runtime\Exception\PropelException; -use Thelia\Model\ImportExportTypeI18n as ChildImportExportTypeI18n; -use Thelia\Model\ImportExportTypeI18nQuery as ChildImportExportTypeI18nQuery; -use Thelia\Model\Map\ImportExportTypeI18nTableMap; +use Thelia\Model\ImportI18n as ChildImportI18n; +use Thelia\Model\ImportI18nQuery as ChildImportI18nQuery; +use Thelia\Model\Map\ImportI18nTableMap; /** - * Base class that represents a query for the 'import_export_type_i18n' table. + * Base class that represents a query for the 'import_i18n' table. * * * - * @method ChildImportExportTypeI18nQuery orderById($order = Criteria::ASC) Order by the id column - * @method ChildImportExportTypeI18nQuery orderByLocale($order = Criteria::ASC) Order by the locale column - * @method ChildImportExportTypeI18nQuery orderByTitle($order = Criteria::ASC) Order by the title column - * @method ChildImportExportTypeI18nQuery orderByDescription($order = Criteria::ASC) Order by the description column + * @method ChildImportI18nQuery orderById($order = Criteria::ASC) Order by the id column + * @method ChildImportI18nQuery orderByLocale($order = Criteria::ASC) Order by the locale column + * @method ChildImportI18nQuery orderByTitle($order = Criteria::ASC) Order by the title column + * @method ChildImportI18nQuery orderByDescription($order = Criteria::ASC) Order by the description column * - * @method ChildImportExportTypeI18nQuery groupById() Group by the id column - * @method ChildImportExportTypeI18nQuery groupByLocale() Group by the locale column - * @method ChildImportExportTypeI18nQuery groupByTitle() Group by the title column - * @method ChildImportExportTypeI18nQuery groupByDescription() Group by the description column + * @method ChildImportI18nQuery groupById() Group by the id column + * @method ChildImportI18nQuery groupByLocale() Group by the locale column + * @method ChildImportI18nQuery groupByTitle() Group by the title column + * @method ChildImportI18nQuery groupByDescription() Group by the description column * - * @method ChildImportExportTypeI18nQuery leftJoin($relation) Adds a LEFT JOIN clause to the query - * @method ChildImportExportTypeI18nQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query - * @method ChildImportExportTypeI18nQuery innerJoin($relation) Adds a INNER JOIN clause to the query + * @method ChildImportI18nQuery leftJoin($relation) Adds a LEFT JOIN clause to the query + * @method ChildImportI18nQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query + * @method ChildImportI18nQuery innerJoin($relation) Adds a INNER JOIN clause to the query * - * @method ChildImportExportTypeI18nQuery leftJoinImportExportType($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportExportType relation - * @method ChildImportExportTypeI18nQuery rightJoinImportExportType($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportExportType relation - * @method ChildImportExportTypeI18nQuery innerJoinImportExportType($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportExportType relation + * @method ChildImportI18nQuery leftJoinImport($relationAlias = null) Adds a LEFT JOIN clause to the query using the Import relation + * @method ChildImportI18nQuery rightJoinImport($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Import relation + * @method ChildImportI18nQuery innerJoinImport($relationAlias = null) Adds a INNER JOIN clause to the query using the Import relation * - * @method ChildImportExportTypeI18n findOne(ConnectionInterface $con = null) Return the first ChildImportExportTypeI18n matching the query - * @method ChildImportExportTypeI18n findOneOrCreate(ConnectionInterface $con = null) Return the first ChildImportExportTypeI18n matching the query, or a new ChildImportExportTypeI18n object populated from the query conditions when no match is found + * @method ChildImportI18n findOne(ConnectionInterface $con = null) Return the first ChildImportI18n matching the query + * @method ChildImportI18n findOneOrCreate(ConnectionInterface $con = null) Return the first ChildImportI18n matching the query, or a new ChildImportI18n object populated from the query conditions when no match is found * - * @method ChildImportExportTypeI18n findOneById(int $id) Return the first ChildImportExportTypeI18n filtered by the id column - * @method ChildImportExportTypeI18n findOneByLocale(string $locale) Return the first ChildImportExportTypeI18n filtered by the locale column - * @method ChildImportExportTypeI18n findOneByTitle(string $title) Return the first ChildImportExportTypeI18n filtered by the title column - * @method ChildImportExportTypeI18n findOneByDescription(string $description) Return the first ChildImportExportTypeI18n filtered by the description column + * @method ChildImportI18n findOneById(int $id) Return the first ChildImportI18n filtered by the id column + * @method ChildImportI18n findOneByLocale(string $locale) Return the first ChildImportI18n filtered by the locale column + * @method ChildImportI18n findOneByTitle(string $title) Return the first ChildImportI18n filtered by the title column + * @method ChildImportI18n findOneByDescription(string $description) Return the first ChildImportI18n filtered by the description column * - * @method array findById(int $id) Return ChildImportExportTypeI18n objects filtered by the id column - * @method array findByLocale(string $locale) Return ChildImportExportTypeI18n objects filtered by the locale column - * @method array findByTitle(string $title) Return ChildImportExportTypeI18n objects filtered by the title column - * @method array findByDescription(string $description) Return ChildImportExportTypeI18n objects filtered by the description column + * @method array findById(int $id) Return ChildImportI18n objects filtered by the id column + * @method array findByLocale(string $locale) Return ChildImportI18n objects filtered by the locale column + * @method array findByTitle(string $title) Return ChildImportI18n objects filtered by the title column + * @method array findByDescription(string $description) Return ChildImportI18n objects filtered by the description column * */ -abstract class ImportExportTypeI18nQuery extends ModelCriteria +abstract class ImportI18nQuery extends ModelCriteria { /** - * Initializes internal state of \Thelia\Model\Base\ImportExportTypeI18nQuery object. + * Initializes internal state of \Thelia\Model\Base\ImportI18nQuery object. * * @param string $dbName The database name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ - public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ImportExportTypeI18n', $modelAlias = null) + public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ImportI18n', $modelAlias = null) { parent::__construct($dbName, $modelName, $modelAlias); } /** - * Returns a new ChildImportExportTypeI18nQuery object. + * Returns a new ChildImportI18nQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * - * @return ChildImportExportTypeI18nQuery + * @return ChildImportI18nQuery */ public static function create($modelAlias = null, $criteria = null) { - if ($criteria instanceof \Thelia\Model\ImportExportTypeI18nQuery) { + if ($criteria instanceof \Thelia\Model\ImportI18nQuery) { return $criteria; } - $query = new \Thelia\Model\ImportExportTypeI18nQuery(); + $query = new \Thelia\Model\ImportI18nQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } @@ -104,19 +104,19 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria * @param array[$id, $locale] $key Primary key to use for the query * @param ConnectionInterface $con an optional connection object * - * @return ChildImportExportTypeI18n|array|mixed the result, formatted by the current formatter + * @return ChildImportI18n|array|mixed the result, formatted by the current formatter */ public function findPk($key, $con = null) { if ($key === null) { return null; } - if ((null !== ($obj = ImportExportTypeI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { + if ((null !== ($obj = ImportI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { // the object is already in the instance pool return $obj; } if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getReadConnection(ImportI18nTableMap::DATABASE_NAME); } $this->basePreSelect($con); if ($this->formatter || $this->modelAlias || $this->with || $this->select @@ -135,11 +135,11 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria * @param mixed $key Primary key to use for the query * @param ConnectionInterface $con A connection object * - * @return ChildImportExportTypeI18n A model object, or null if the key is not found + * @return ChildImportI18n A model object, or null if the key is not found */ protected function findPkSimple($key, $con) { - $sql = 'SELECT `ID`, `LOCALE`, `TITLE`, `DESCRIPTION` FROM `import_export_type_i18n` WHERE `ID` = :p0 AND `LOCALE` = :p1'; + $sql = 'SELECT `ID`, `LOCALE`, `TITLE`, `DESCRIPTION` FROM `import_i18n` WHERE `ID` = :p0 AND `LOCALE` = :p1'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); @@ -151,9 +151,9 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria } $obj = null; if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { - $obj = new ChildImportExportTypeI18n(); + $obj = new ChildImportI18n(); $obj->hydrate($row); - ImportExportTypeI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); + ImportI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1]))); } $stmt->closeCursor(); @@ -166,7 +166,7 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria * @param mixed $key Primary key to use for the query * @param ConnectionInterface $con A connection object * - * @return ChildImportExportTypeI18n|array|mixed the result, formatted by the current formatter + * @return ChildImportI18n|array|mixed the result, formatted by the current formatter */ protected function findPkComplex($key, $con) { @@ -208,12 +208,12 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria * * @param mixed $key Primary key to use for the query * - * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + * @return ChildImportI18nQuery The current query, for fluid interface */ public function filterByPrimaryKey($key) { - $this->addUsingAlias(ImportExportTypeI18nTableMap::ID, $key[0], Criteria::EQUAL); - $this->addUsingAlias(ImportExportTypeI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + $this->addUsingAlias(ImportI18nTableMap::ID, $key[0], Criteria::EQUAL); + $this->addUsingAlias(ImportI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); return $this; } @@ -223,7 +223,7 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria * * @param array $keys The list of primary key to use for the query * - * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + * @return ChildImportI18nQuery The current query, for fluid interface */ public function filterByPrimaryKeys($keys) { @@ -231,8 +231,8 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria return $this->add(null, '1<>1', Criteria::CUSTOM); } foreach ($keys as $key) { - $cton0 = $this->getNewCriterion(ImportExportTypeI18nTableMap::ID, $key[0], Criteria::EQUAL); - $cton1 = $this->getNewCriterion(ImportExportTypeI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); + $cton0 = $this->getNewCriterion(ImportI18nTableMap::ID, $key[0], Criteria::EQUAL); + $cton1 = $this->getNewCriterion(ImportI18nTableMap::LOCALE, $key[1], Criteria::EQUAL); $cton0->addAnd($cton1); $this->addOr($cton0); } @@ -250,7 +250,7 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria * $query->filterById(array('min' => 12)); // WHERE id > 12 * * - * @see filterByImportExportType() + * @see filterByImport() * * @param mixed $id The value to use as filter. * Use scalar values for equality. @@ -258,18 +258,18 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + * @return ChildImportI18nQuery The current query, for fluid interface */ public function filterById($id = null, $comparison = null) { if (is_array($id)) { $useMinMax = false; if (isset($id['min'])) { - $this->addUsingAlias(ImportExportTypeI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $this->addUsingAlias(ImportI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($id['max'])) { - $this->addUsingAlias(ImportExportTypeI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $this->addUsingAlias(ImportI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -280,7 +280,7 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportTypeI18nTableMap::ID, $id, $comparison); + return $this->addUsingAlias(ImportI18nTableMap::ID, $id, $comparison); } /** @@ -296,7 +296,7 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria * Accepts wildcards (* and % trigger a LIKE) * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + * @return ChildImportI18nQuery The current query, for fluid interface */ public function filterByLocale($locale = null, $comparison = null) { @@ -309,7 +309,7 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportTypeI18nTableMap::LOCALE, $locale, $comparison); + return $this->addUsingAlias(ImportI18nTableMap::LOCALE, $locale, $comparison); } /** @@ -325,7 +325,7 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria * Accepts wildcards (* and % trigger a LIKE) * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + * @return ChildImportI18nQuery The current query, for fluid interface */ public function filterByTitle($title = null, $comparison = null) { @@ -338,7 +338,7 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportTypeI18nTableMap::TITLE, $title, $comparison); + return $this->addUsingAlias(ImportI18nTableMap::TITLE, $title, $comparison); } /** @@ -354,7 +354,7 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria * Accepts wildcards (* and % trigger a LIKE) * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + * @return ChildImportI18nQuery The current query, for fluid interface */ public function filterByDescription($description = null, $comparison = null) { @@ -367,46 +367,46 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportTypeI18nTableMap::DESCRIPTION, $description, $comparison); + return $this->addUsingAlias(ImportI18nTableMap::DESCRIPTION, $description, $comparison); } /** - * Filter the query by a related \Thelia\Model\ImportExportType object + * Filter the query by a related \Thelia\Model\Import object * - * @param \Thelia\Model\ImportExportType|ObjectCollection $importExportType The related object(s) to use as filter + * @param \Thelia\Model\Import|ObjectCollection $import The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + * @return ChildImportI18nQuery The current query, for fluid interface */ - public function filterByImportExportType($importExportType, $comparison = null) + public function filterByImport($import, $comparison = null) { - if ($importExportType instanceof \Thelia\Model\ImportExportType) { + if ($import instanceof \Thelia\Model\Import) { return $this - ->addUsingAlias(ImportExportTypeI18nTableMap::ID, $importExportType->getId(), $comparison); - } elseif ($importExportType instanceof ObjectCollection) { + ->addUsingAlias(ImportI18nTableMap::ID, $import->getId(), $comparison); + } elseif ($import instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this - ->addUsingAlias(ImportExportTypeI18nTableMap::ID, $importExportType->toKeyValue('PrimaryKey', 'Id'), $comparison); + ->addUsingAlias(ImportI18nTableMap::ID, $import->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { - throw new PropelException('filterByImportExportType() only accepts arguments of type \Thelia\Model\ImportExportType or Collection'); + throw new PropelException('filterByImport() only accepts arguments of type \Thelia\Model\Import or Collection'); } } /** - * Adds a JOIN clause to the query using the ImportExportType relation + * Adds a JOIN clause to the query using the Import relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + * @return ChildImportI18nQuery The current query, for fluid interface */ - public function joinImportExportType($relationAlias = null, $joinType = 'LEFT JOIN') + public function joinImport($relationAlias = null, $joinType = 'LEFT JOIN') { $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('ImportExportType'); + $relationMap = $tableMap->getRelation('Import'); // create a ModelJoin object for this join $join = new ModelJoin(); @@ -421,14 +421,14 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { - $this->addJoinObject($join, 'ImportExportType'); + $this->addJoinObject($join, 'Import'); } return $this; } /** - * Use the ImportExportType relation ImportExportType object + * Use the Import relation Import object * * @see useQuery() * @@ -436,27 +436,27 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria * to be used as main alias in the secondary query * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return \Thelia\Model\ImportExportTypeQuery A secondary query class using the current class as primary query + * @return \Thelia\Model\ImportQuery A secondary query class using the current class as primary query */ - public function useImportExportTypeQuery($relationAlias = null, $joinType = 'LEFT JOIN') + public function useImportQuery($relationAlias = null, $joinType = 'LEFT JOIN') { return $this - ->joinImportExportType($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'ImportExportType', '\Thelia\Model\ImportExportTypeQuery'); + ->joinImport($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Import', '\Thelia\Model\ImportQuery'); } /** * Exclude object from result * - * @param ChildImportExportTypeI18n $importExportTypeI18n Object to remove from the list of results + * @param ChildImportI18n $importI18n Object to remove from the list of results * - * @return ChildImportExportTypeI18nQuery The current query, for fluid interface + * @return ChildImportI18nQuery The current query, for fluid interface */ - public function prune($importExportTypeI18n = null) + public function prune($importI18n = null) { - if ($importExportTypeI18n) { - $this->addCond('pruneCond0', $this->getAliasedColName(ImportExportTypeI18nTableMap::ID), $importExportTypeI18n->getId(), Criteria::NOT_EQUAL); - $this->addCond('pruneCond1', $this->getAliasedColName(ImportExportTypeI18nTableMap::LOCALE), $importExportTypeI18n->getLocale(), Criteria::NOT_EQUAL); + if ($importI18n) { + $this->addCond('pruneCond0', $this->getAliasedColName(ImportI18nTableMap::ID), $importI18n->getId(), Criteria::NOT_EQUAL); + $this->addCond('pruneCond1', $this->getAliasedColName(ImportI18nTableMap::LOCALE), $importI18n->getLocale(), Criteria::NOT_EQUAL); $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); } @@ -464,7 +464,7 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria } /** - * Deletes all rows from the import_export_type_i18n table. + * Deletes all rows from the import_i18n table. * * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). @@ -472,7 +472,7 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria public function doDeleteAll(ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportI18nTableMap::DATABASE_NAME); } $affectedRows = 0; // initialize var to track total num of affected rows try { @@ -483,8 +483,8 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria // Because this db requires some delete cascade/set null emulation, we have to // clear the cached instance *after* the emulation has happened (since // instances get re-added by the select statement contained therein). - ImportExportTypeI18nTableMap::clearInstancePool(); - ImportExportTypeI18nTableMap::clearRelatedInstancePool(); + ImportI18nTableMap::clearInstancePool(); + ImportI18nTableMap::clearRelatedInstancePool(); $con->commit(); } catch (PropelException $e) { @@ -496,9 +496,9 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria } /** - * Performs a DELETE on the database, given a ChildImportExportTypeI18n or Criteria object OR a primary key value. + * Performs a DELETE on the database, given a ChildImportI18n or Criteria object OR a primary key value. * - * @param mixed $values Criteria or ChildImportExportTypeI18n object or primary key or array of primary keys + * @param mixed $values Criteria or ChildImportI18n object or primary key or array of primary keys * which is used to create the DELETE statement * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows @@ -509,13 +509,13 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria public function delete(ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportI18nTableMap::DATABASE_NAME); } $criteria = $this; // Set the correct dbName - $criteria->setDbName(ImportExportTypeI18nTableMap::DATABASE_NAME); + $criteria->setDbName(ImportI18nTableMap::DATABASE_NAME); $affectedRows = 0; // initialize var to track total num of affected rows @@ -525,10 +525,10 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria $con->beginTransaction(); - ImportExportTypeI18nTableMap::removeInstanceFromPool($criteria); + ImportI18nTableMap::removeInstanceFromPool($criteria); $affectedRows += ModelCriteria::delete($con); - ImportExportTypeI18nTableMap::clearRelatedInstancePool(); + ImportI18nTableMap::clearRelatedInstancePool(); $con->commit(); return $affectedRows; @@ -538,4 +538,4 @@ abstract class ImportExportTypeI18nQuery extends ModelCriteria } } -} // ImportExportTypeI18nQuery +} // ImportI18nQuery diff --git a/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php b/core/lib/Thelia/Model/Base/ImportQuery.php similarity index 54% rename from core/lib/Thelia/Model/Base/ImportExportTypeQuery.php rename to core/lib/Thelia/Model/Base/ImportQuery.php index 953591923..7fa735844 100644 --- a/core/lib/Thelia/Model/Base/ImportExportTypeQuery.php +++ b/core/lib/Thelia/Model/Base/ImportQuery.php @@ -12,89 +12,85 @@ use Propel\Runtime\Collection\Collection; use Propel\Runtime\Collection\ObjectCollection; use Propel\Runtime\Connection\ConnectionInterface; use Propel\Runtime\Exception\PropelException; -use Thelia\Model\ImportExportType as ChildImportExportType; -use Thelia\Model\ImportExportTypeI18nQuery as ChildImportExportTypeI18nQuery; -use Thelia\Model\ImportExportTypeQuery as ChildImportExportTypeQuery; -use Thelia\Model\Map\ImportExportTypeTableMap; +use Thelia\Model\Import as ChildImport; +use Thelia\Model\ImportI18nQuery as ChildImportI18nQuery; +use Thelia\Model\ImportQuery as ChildImportQuery; +use Thelia\Model\Map\ImportTableMap; /** - * Base class that represents a query for the 'import_export_type' table. + * Base class that represents a query for the 'import' table. * * * - * @method ChildImportExportTypeQuery orderById($order = Criteria::ASC) Order by the id column - * @method ChildImportExportTypeQuery orderByUrlAction($order = Criteria::ASC) Order by the url_action column - * @method ChildImportExportTypeQuery orderByImportExportCategoryId($order = Criteria::ASC) Order by the import_export_category_id column - * @method ChildImportExportTypeQuery orderByPosition($order = Criteria::ASC) Order by the position column - * @method ChildImportExportTypeQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column - * @method ChildImportExportTypeQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column + * @method ChildImportQuery orderById($order = Criteria::ASC) Order by the id column + * @method ChildImportQuery orderByImportCategoryId($order = Criteria::ASC) Order by the import_category_id column + * @method ChildImportQuery orderByPosition($order = Criteria::ASC) Order by the position column + * @method ChildImportQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column + * @method ChildImportQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * - * @method ChildImportExportTypeQuery groupById() Group by the id column - * @method ChildImportExportTypeQuery groupByUrlAction() Group by the url_action column - * @method ChildImportExportTypeQuery groupByImportExportCategoryId() Group by the import_export_category_id column - * @method ChildImportExportTypeQuery groupByPosition() Group by the position column - * @method ChildImportExportTypeQuery groupByCreatedAt() Group by the created_at column - * @method ChildImportExportTypeQuery groupByUpdatedAt() Group by the updated_at column + * @method ChildImportQuery groupById() Group by the id column + * @method ChildImportQuery groupByImportCategoryId() Group by the import_category_id column + * @method ChildImportQuery groupByPosition() Group by the position column + * @method ChildImportQuery groupByCreatedAt() Group by the created_at column + * @method ChildImportQuery groupByUpdatedAt() Group by the updated_at column * - * @method ChildImportExportTypeQuery leftJoin($relation) Adds a LEFT JOIN clause to the query - * @method ChildImportExportTypeQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query - * @method ChildImportExportTypeQuery innerJoin($relation) Adds a INNER JOIN clause to the query + * @method ChildImportQuery leftJoin($relation) Adds a LEFT JOIN clause to the query + * @method ChildImportQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query + * @method ChildImportQuery innerJoin($relation) Adds a INNER JOIN clause to the query * - * @method ChildImportExportTypeQuery leftJoinImportExportCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportExportCategory relation - * @method ChildImportExportTypeQuery rightJoinImportExportCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportExportCategory relation - * @method ChildImportExportTypeQuery innerJoinImportExportCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportExportCategory relation + * @method ChildImportQuery leftJoinImportCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportCategory relation + * @method ChildImportQuery rightJoinImportCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportCategory relation + * @method ChildImportQuery innerJoinImportCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportCategory relation * - * @method ChildImportExportTypeQuery leftJoinImportExportTypeI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportExportTypeI18n relation - * @method ChildImportExportTypeQuery rightJoinImportExportTypeI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportExportTypeI18n relation - * @method ChildImportExportTypeQuery innerJoinImportExportTypeI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportExportTypeI18n relation + * @method ChildImportQuery leftJoinImportI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportI18n relation + * @method ChildImportQuery rightJoinImportI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportI18n relation + * @method ChildImportQuery innerJoinImportI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportI18n relation * - * @method ChildImportExportType findOne(ConnectionInterface $con = null) Return the first ChildImportExportType matching the query - * @method ChildImportExportType findOneOrCreate(ConnectionInterface $con = null) Return the first ChildImportExportType matching the query, or a new ChildImportExportType object populated from the query conditions when no match is found + * @method ChildImport findOne(ConnectionInterface $con = null) Return the first ChildImport matching the query + * @method ChildImport findOneOrCreate(ConnectionInterface $con = null) Return the first ChildImport matching the query, or a new ChildImport object populated from the query conditions when no match is found * - * @method ChildImportExportType findOneById(int $id) Return the first ChildImportExportType filtered by the id column - * @method ChildImportExportType findOneByUrlAction(string $url_action) Return the first ChildImportExportType filtered by the url_action column - * @method ChildImportExportType findOneByImportExportCategoryId(int $import_export_category_id) Return the first ChildImportExportType filtered by the import_export_category_id column - * @method ChildImportExportType findOneByPosition(int $position) Return the first ChildImportExportType filtered by the position column - * @method ChildImportExportType findOneByCreatedAt(string $created_at) Return the first ChildImportExportType filtered by the created_at column - * @method ChildImportExportType findOneByUpdatedAt(string $updated_at) Return the first ChildImportExportType filtered by the updated_at column + * @method ChildImport findOneById(int $id) Return the first ChildImport filtered by the id column + * @method ChildImport findOneByImportCategoryId(int $import_category_id) Return the first ChildImport filtered by the import_category_id column + * @method ChildImport findOneByPosition(int $position) Return the first ChildImport filtered by the position column + * @method ChildImport findOneByCreatedAt(string $created_at) Return the first ChildImport filtered by the created_at column + * @method ChildImport findOneByUpdatedAt(string $updated_at) Return the first ChildImport filtered by the updated_at column * - * @method array findById(int $id) Return ChildImportExportType objects filtered by the id column - * @method array findByUrlAction(string $url_action) Return ChildImportExportType objects filtered by the url_action column - * @method array findByImportExportCategoryId(int $import_export_category_id) Return ChildImportExportType objects filtered by the import_export_category_id column - * @method array findByPosition(int $position) Return ChildImportExportType objects filtered by the position column - * @method array findByCreatedAt(string $created_at) Return ChildImportExportType objects filtered by the created_at column - * @method array findByUpdatedAt(string $updated_at) Return ChildImportExportType objects filtered by the updated_at column + * @method array findById(int $id) Return ChildImport objects filtered by the id column + * @method array findByImportCategoryId(int $import_category_id) Return ChildImport objects filtered by the import_category_id column + * @method array findByPosition(int $position) Return ChildImport objects filtered by the position column + * @method array findByCreatedAt(string $created_at) Return ChildImport objects filtered by the created_at column + * @method array findByUpdatedAt(string $updated_at) Return ChildImport objects filtered by the updated_at column * */ -abstract class ImportExportTypeQuery extends ModelCriteria +abstract class ImportQuery extends ModelCriteria { /** - * Initializes internal state of \Thelia\Model\Base\ImportExportTypeQuery object. + * Initializes internal state of \Thelia\Model\Base\ImportQuery object. * * @param string $dbName The database name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ - public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ImportExportType', $modelAlias = null) + public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\Import', $modelAlias = null) { parent::__construct($dbName, $modelName, $modelAlias); } /** - * Returns a new ChildImportExportTypeQuery object. + * Returns a new ChildImportQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * - * @return ChildImportExportTypeQuery + * @return ChildImportQuery */ public static function create($modelAlias = null, $criteria = null) { - if ($criteria instanceof \Thelia\Model\ImportExportTypeQuery) { + if ($criteria instanceof \Thelia\Model\ImportQuery) { return $criteria; } - $query = new \Thelia\Model\ImportExportTypeQuery(); + $query = new \Thelia\Model\ImportQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } @@ -117,19 +113,19 @@ abstract class ImportExportTypeQuery extends ModelCriteria * @param mixed $key Primary key to use for the query * @param ConnectionInterface $con an optional connection object * - * @return ChildImportExportType|array|mixed the result, formatted by the current formatter + * @return ChildImport|array|mixed the result, formatted by the current formatter */ public function findPk($key, $con = null) { if ($key === null) { return null; } - if ((null !== ($obj = ImportExportTypeTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { + if ((null !== ($obj = ImportTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { // the object is already in the instance pool return $obj; } if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(ImportExportTypeTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getReadConnection(ImportTableMap::DATABASE_NAME); } $this->basePreSelect($con); if ($this->formatter || $this->modelAlias || $this->with || $this->select @@ -148,11 +144,11 @@ abstract class ImportExportTypeQuery extends ModelCriteria * @param mixed $key Primary key to use for the query * @param ConnectionInterface $con A connection object * - * @return ChildImportExportType A model object, or null if the key is not found + * @return ChildImport A model object, or null if the key is not found */ protected function findPkSimple($key, $con) { - $sql = 'SELECT `ID`, `URL_ACTION`, `IMPORT_EXPORT_CATEGORY_ID`, `POSITION`, `CREATED_AT`, `UPDATED_AT` FROM `import_export_type` WHERE `ID` = :p0'; + $sql = 'SELECT `ID`, `IMPORT_CATEGORY_ID`, `POSITION`, `CREATED_AT`, `UPDATED_AT` FROM `import` WHERE `ID` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -163,9 +159,9 @@ abstract class ImportExportTypeQuery extends ModelCriteria } $obj = null; if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { - $obj = new ChildImportExportType(); + $obj = new ChildImport(); $obj->hydrate($row); - ImportExportTypeTableMap::addInstanceToPool($obj, (string) $key); + ImportTableMap::addInstanceToPool($obj, (string) $key); } $stmt->closeCursor(); @@ -178,7 +174,7 @@ abstract class ImportExportTypeQuery extends ModelCriteria * @param mixed $key Primary key to use for the query * @param ConnectionInterface $con A connection object * - * @return ChildImportExportType|array|mixed the result, formatted by the current formatter + * @return ChildImport|array|mixed the result, formatted by the current formatter */ protected function findPkComplex($key, $con) { @@ -220,12 +216,12 @@ abstract class ImportExportTypeQuery extends ModelCriteria * * @param mixed $key Primary key to use for the query * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function filterByPrimaryKey($key) { - return $this->addUsingAlias(ImportExportTypeTableMap::ID, $key, Criteria::EQUAL); + return $this->addUsingAlias(ImportTableMap::ID, $key, Criteria::EQUAL); } /** @@ -233,12 +229,12 @@ abstract class ImportExportTypeQuery extends ModelCriteria * * @param array $keys The list of primary key to use for the query * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function filterByPrimaryKeys($keys) { - return $this->addUsingAlias(ImportExportTypeTableMap::ID, $keys, Criteria::IN); + return $this->addUsingAlias(ImportTableMap::ID, $keys, Criteria::IN); } /** @@ -257,18 +253,18 @@ abstract class ImportExportTypeQuery extends ModelCriteria * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function filterById($id = null, $comparison = null) { if (is_array($id)) { $useMinMax = false; if (isset($id['min'])) { - $this->addUsingAlias(ImportExportTypeTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); + $this->addUsingAlias(ImportTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($id['max'])) { - $this->addUsingAlias(ImportExportTypeTableMap::ID, $id['max'], Criteria::LESS_EQUAL); + $this->addUsingAlias(ImportTableMap::ID, $id['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -279,68 +275,39 @@ abstract class ImportExportTypeQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportTypeTableMap::ID, $id, $comparison); + return $this->addUsingAlias(ImportTableMap::ID, $id, $comparison); } /** - * Filter the query on the url_action column + * Filter the query on the import_category_id column * * Example usage: * - * $query->filterByUrlAction('fooValue'); // WHERE url_action = 'fooValue' - * $query->filterByUrlAction('%fooValue%'); // WHERE url_action LIKE '%fooValue%' + * $query->filterByImportCategoryId(1234); // WHERE import_category_id = 1234 + * $query->filterByImportCategoryId(array(12, 34)); // WHERE import_category_id IN (12, 34) + * $query->filterByImportCategoryId(array('min' => 12)); // WHERE import_category_id > 12 * * - * @param string $urlAction The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * @see filterByImportCategory() * - * @return ChildImportExportTypeQuery The current query, for fluid interface - */ - public function filterByUrlAction($urlAction = null, $comparison = null) - { - if (null === $comparison) { - if (is_array($urlAction)) { - $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $urlAction)) { - $urlAction = str_replace('*', '%', $urlAction); - $comparison = Criteria::LIKE; - } - } - - return $this->addUsingAlias(ImportExportTypeTableMap::URL_ACTION, $urlAction, $comparison); - } - - /** - * Filter the query on the import_export_category_id column - * - * Example usage: - * - * $query->filterByImportExportCategoryId(1234); // WHERE import_export_category_id = 1234 - * $query->filterByImportExportCategoryId(array(12, 34)); // WHERE import_export_category_id IN (12, 34) - * $query->filterByImportExportCategoryId(array('min' => 12)); // WHERE import_export_category_id > 12 - * - * - * @see filterByImportExportCategory() - * - * @param mixed $importExportCategoryId The value to use as filter. + * @param mixed $importCategoryId The value to use as filter. * Use scalar values for equality. * Use array values for in_array() equivalent. * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ - public function filterByImportExportCategoryId($importExportCategoryId = null, $comparison = null) + public function filterByImportCategoryId($importCategoryId = null, $comparison = null) { - if (is_array($importExportCategoryId)) { + if (is_array($importCategoryId)) { $useMinMax = false; - if (isset($importExportCategoryId['min'])) { - $this->addUsingAlias(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $importExportCategoryId['min'], Criteria::GREATER_EQUAL); + if (isset($importCategoryId['min'])) { + $this->addUsingAlias(ImportTableMap::IMPORT_CATEGORY_ID, $importCategoryId['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } - if (isset($importExportCategoryId['max'])) { - $this->addUsingAlias(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $importExportCategoryId['max'], Criteria::LESS_EQUAL); + if (isset($importCategoryId['max'])) { + $this->addUsingAlias(ImportTableMap::IMPORT_CATEGORY_ID, $importCategoryId['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -351,7 +318,7 @@ abstract class ImportExportTypeQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $importExportCategoryId, $comparison); + return $this->addUsingAlias(ImportTableMap::IMPORT_CATEGORY_ID, $importCategoryId, $comparison); } /** @@ -370,18 +337,18 @@ abstract class ImportExportTypeQuery extends ModelCriteria * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function filterByPosition($position = null, $comparison = null) { if (is_array($position)) { $useMinMax = false; if (isset($position['min'])) { - $this->addUsingAlias(ImportExportTypeTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL); + $this->addUsingAlias(ImportTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($position['max'])) { - $this->addUsingAlias(ImportExportTypeTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL); + $this->addUsingAlias(ImportTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -392,7 +359,7 @@ abstract class ImportExportTypeQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportTypeTableMap::POSITION, $position, $comparison); + return $this->addUsingAlias(ImportTableMap::POSITION, $position, $comparison); } /** @@ -413,18 +380,18 @@ abstract class ImportExportTypeQuery extends ModelCriteria * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function filterByCreatedAt($createdAt = null, $comparison = null) { if (is_array($createdAt)) { $useMinMax = false; if (isset($createdAt['min'])) { - $this->addUsingAlias(ImportExportTypeTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); + $this->addUsingAlias(ImportTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($createdAt['max'])) { - $this->addUsingAlias(ImportExportTypeTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); + $this->addUsingAlias(ImportTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -435,7 +402,7 @@ abstract class ImportExportTypeQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportTypeTableMap::CREATED_AT, $createdAt, $comparison); + return $this->addUsingAlias(ImportTableMap::CREATED_AT, $createdAt, $comparison); } /** @@ -456,18 +423,18 @@ abstract class ImportExportTypeQuery extends ModelCriteria * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function filterByUpdatedAt($updatedAt = null, $comparison = null) { if (is_array($updatedAt)) { $useMinMax = false; if (isset($updatedAt['min'])) { - $this->addUsingAlias(ImportExportTypeTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); + $this->addUsingAlias(ImportTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); $useMinMax = true; } if (isset($updatedAt['max'])) { - $this->addUsingAlias(ImportExportTypeTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); + $this->addUsingAlias(ImportTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); $useMinMax = true; } if ($useMinMax) { @@ -478,46 +445,46 @@ abstract class ImportExportTypeQuery extends ModelCriteria } } - return $this->addUsingAlias(ImportExportTypeTableMap::UPDATED_AT, $updatedAt, $comparison); + return $this->addUsingAlias(ImportTableMap::UPDATED_AT, $updatedAt, $comparison); } /** - * Filter the query by a related \Thelia\Model\ImportExportCategory object + * Filter the query by a related \Thelia\Model\ImportCategory object * - * @param \Thelia\Model\ImportExportCategory|ObjectCollection $importExportCategory The related object(s) to use as filter + * @param \Thelia\Model\ImportCategory|ObjectCollection $importCategory The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ - public function filterByImportExportCategory($importExportCategory, $comparison = null) + public function filterByImportCategory($importCategory, $comparison = null) { - if ($importExportCategory instanceof \Thelia\Model\ImportExportCategory) { + if ($importCategory instanceof \Thelia\Model\ImportCategory) { return $this - ->addUsingAlias(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $importExportCategory->getId(), $comparison); - } elseif ($importExportCategory instanceof ObjectCollection) { + ->addUsingAlias(ImportTableMap::IMPORT_CATEGORY_ID, $importCategory->getId(), $comparison); + } elseif ($importCategory instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this - ->addUsingAlias(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, $importExportCategory->toKeyValue('PrimaryKey', 'Id'), $comparison); + ->addUsingAlias(ImportTableMap::IMPORT_CATEGORY_ID, $importCategory->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { - throw new PropelException('filterByImportExportCategory() only accepts arguments of type \Thelia\Model\ImportExportCategory or Collection'); + throw new PropelException('filterByImportCategory() only accepts arguments of type \Thelia\Model\ImportCategory or Collection'); } } /** - * Adds a JOIN clause to the query using the ImportExportCategory relation + * Adds a JOIN clause to the query using the ImportCategory relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ - public function joinImportExportCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function joinImportCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN) { $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('ImportExportCategory'); + $relationMap = $tableMap->getRelation('ImportCategory'); // create a ModelJoin object for this join $join = new ModelJoin(); @@ -532,14 +499,14 @@ abstract class ImportExportTypeQuery extends ModelCriteria $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { - $this->addJoinObject($join, 'ImportExportCategory'); + $this->addJoinObject($join, 'ImportCategory'); } return $this; } /** - * Use the ImportExportCategory relation ImportExportCategory object + * Use the ImportCategory relation ImportCategory object * * @see useQuery() * @@ -547,50 +514,50 @@ abstract class ImportExportTypeQuery extends ModelCriteria * to be used as main alias in the secondary query * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return \Thelia\Model\ImportExportCategoryQuery A secondary query class using the current class as primary query + * @return \Thelia\Model\ImportCategoryQuery A secondary query class using the current class as primary query */ - public function useImportExportCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + public function useImportCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) { return $this - ->joinImportExportCategory($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'ImportExportCategory', '\Thelia\Model\ImportExportCategoryQuery'); + ->joinImportCategory($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ImportCategory', '\Thelia\Model\ImportCategoryQuery'); } /** - * Filter the query by a related \Thelia\Model\ImportExportTypeI18n object + * Filter the query by a related \Thelia\Model\ImportI18n object * - * @param \Thelia\Model\ImportExportTypeI18n|ObjectCollection $importExportTypeI18n the related object to use as filter + * @param \Thelia\Model\ImportI18n|ObjectCollection $importI18n the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ - public function filterByImportExportTypeI18n($importExportTypeI18n, $comparison = null) + public function filterByImportI18n($importI18n, $comparison = null) { - if ($importExportTypeI18n instanceof \Thelia\Model\ImportExportTypeI18n) { + if ($importI18n instanceof \Thelia\Model\ImportI18n) { return $this - ->addUsingAlias(ImportExportTypeTableMap::ID, $importExportTypeI18n->getId(), $comparison); - } elseif ($importExportTypeI18n instanceof ObjectCollection) { + ->addUsingAlias(ImportTableMap::ID, $importI18n->getId(), $comparison); + } elseif ($importI18n instanceof ObjectCollection) { return $this - ->useImportExportTypeI18nQuery() - ->filterByPrimaryKeys($importExportTypeI18n->getPrimaryKeys()) + ->useImportI18nQuery() + ->filterByPrimaryKeys($importI18n->getPrimaryKeys()) ->endUse(); } else { - throw new PropelException('filterByImportExportTypeI18n() only accepts arguments of type \Thelia\Model\ImportExportTypeI18n or Collection'); + throw new PropelException('filterByImportI18n() only accepts arguments of type \Thelia\Model\ImportI18n or Collection'); } } /** - * Adds a JOIN clause to the query using the ImportExportTypeI18n relation + * Adds a JOIN clause to the query using the ImportI18n relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ - public function joinImportExportTypeI18n($relationAlias = null, $joinType = 'LEFT JOIN') + public function joinImportI18n($relationAlias = null, $joinType = 'LEFT JOIN') { $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('ImportExportTypeI18n'); + $relationMap = $tableMap->getRelation('ImportI18n'); // create a ModelJoin object for this join $join = new ModelJoin(); @@ -605,14 +572,14 @@ abstract class ImportExportTypeQuery extends ModelCriteria $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { - $this->addJoinObject($join, 'ImportExportTypeI18n'); + $this->addJoinObject($join, 'ImportI18n'); } return $this; } /** - * Use the ImportExportTypeI18n relation ImportExportTypeI18n object + * Use the ImportI18n relation ImportI18n object * * @see useQuery() * @@ -620,33 +587,33 @@ abstract class ImportExportTypeQuery extends ModelCriteria * to be used as main alias in the secondary query * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return \Thelia\Model\ImportExportTypeI18nQuery A secondary query class using the current class as primary query + * @return \Thelia\Model\ImportI18nQuery A secondary query class using the current class as primary query */ - public function useImportExportTypeI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') + public function useImportI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') { return $this - ->joinImportExportTypeI18n($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'ImportExportTypeI18n', '\Thelia\Model\ImportExportTypeI18nQuery'); + ->joinImportI18n($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'ImportI18n', '\Thelia\Model\ImportI18nQuery'); } /** * Exclude object from result * - * @param ChildImportExportType $importExportType Object to remove from the list of results + * @param ChildImport $import Object to remove from the list of results * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ - public function prune($importExportType = null) + public function prune($import = null) { - if ($importExportType) { - $this->addUsingAlias(ImportExportTypeTableMap::ID, $importExportType->getId(), Criteria::NOT_EQUAL); + if ($import) { + $this->addUsingAlias(ImportTableMap::ID, $import->getId(), Criteria::NOT_EQUAL); } return $this; } /** - * Deletes all rows from the import_export_type table. + * Deletes all rows from the import table. * * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). @@ -654,7 +621,7 @@ abstract class ImportExportTypeQuery extends ModelCriteria public function doDeleteAll(ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportTableMap::DATABASE_NAME); } $affectedRows = 0; // initialize var to track total num of affected rows try { @@ -665,8 +632,8 @@ abstract class ImportExportTypeQuery extends ModelCriteria // Because this db requires some delete cascade/set null emulation, we have to // clear the cached instance *after* the emulation has happened (since // instances get re-added by the select statement contained therein). - ImportExportTypeTableMap::clearInstancePool(); - ImportExportTypeTableMap::clearRelatedInstancePool(); + ImportTableMap::clearInstancePool(); + ImportTableMap::clearRelatedInstancePool(); $con->commit(); } catch (PropelException $e) { @@ -678,9 +645,9 @@ abstract class ImportExportTypeQuery extends ModelCriteria } /** - * Performs a DELETE on the database, given a ChildImportExportType or Criteria object OR a primary key value. + * Performs a DELETE on the database, given a ChildImport or Criteria object OR a primary key value. * - * @param mixed $values Criteria or ChildImportExportType object or primary key or array of primary keys + * @param mixed $values Criteria or ChildImport object or primary key or array of primary keys * which is used to create the DELETE statement * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows @@ -691,13 +658,13 @@ abstract class ImportExportTypeQuery extends ModelCriteria public function delete(ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportTableMap::DATABASE_NAME); } $criteria = $this; // Set the correct dbName - $criteria->setDbName(ImportExportTypeTableMap::DATABASE_NAME); + $criteria->setDbName(ImportTableMap::DATABASE_NAME); $affectedRows = 0; // initialize var to track total num of affected rows @@ -707,10 +674,10 @@ abstract class ImportExportTypeQuery extends ModelCriteria $con->beginTransaction(); - ImportExportTypeTableMap::removeInstanceFromPool($criteria); + ImportTableMap::removeInstanceFromPool($criteria); $affectedRows += ModelCriteria::delete($con); - ImportExportTypeTableMap::clearRelatedInstancePool(); + ImportTableMap::clearRelatedInstancePool(); $con->commit(); return $affectedRows; @@ -729,14 +696,14 @@ abstract class ImportExportTypeQuery extends ModelCriteria * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function joinI18n($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) { - $relationName = $relationAlias ? $relationAlias : 'ImportExportTypeI18n'; + $relationName = $relationAlias ? $relationAlias : 'ImportI18n'; return $this - ->joinImportExportTypeI18n($relationAlias, $joinType) + ->joinImportI18n($relationAlias, $joinType) ->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale); } @@ -747,14 +714,14 @@ abstract class ImportExportTypeQuery extends ModelCriteria * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function joinWithI18n($locale = 'en_US', $joinType = Criteria::LEFT_JOIN) { $this ->joinI18n($locale, null, $joinType) - ->with('ImportExportTypeI18n'); - $this->with['ImportExportTypeI18n']->setIsWithOneToMany(false); + ->with('ImportI18n'); + $this->with['ImportI18n']->setIsWithOneToMany(false); return $this; } @@ -768,13 +735,13 @@ abstract class ImportExportTypeQuery extends ModelCriteria * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. * - * @return ChildImportExportTypeI18nQuery A secondary query class using the current class as primary query + * @return ChildImportI18nQuery A secondary query class using the current class as primary query */ public function useI18nQuery($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) { return $this ->joinI18n($locale, $relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'ImportExportTypeI18n', '\Thelia\Model\ImportExportTypeI18nQuery'); + ->useQuery($relationAlias ? $relationAlias : 'ImportI18n', '\Thelia\Model\ImportI18nQuery'); } // timestampable behavior @@ -784,11 +751,11 @@ abstract class ImportExportTypeQuery extends ModelCriteria * * @param int $nbDays Maximum age of the latest update in days * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function recentlyUpdated($nbDays = 7) { - return $this->addUsingAlias(ImportExportTypeTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + return $this->addUsingAlias(ImportTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); } /** @@ -796,51 +763,51 @@ abstract class ImportExportTypeQuery extends ModelCriteria * * @param int $nbDays Maximum age of in days * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function recentlyCreated($nbDays = 7) { - return $this->addUsingAlias(ImportExportTypeTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); + return $this->addUsingAlias(ImportTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); } /** * Order by update date desc * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function lastUpdatedFirst() { - return $this->addDescendingOrderByColumn(ImportExportTypeTableMap::UPDATED_AT); + return $this->addDescendingOrderByColumn(ImportTableMap::UPDATED_AT); } /** * Order by update date asc * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function firstUpdatedFirst() { - return $this->addAscendingOrderByColumn(ImportExportTypeTableMap::UPDATED_AT); + return $this->addAscendingOrderByColumn(ImportTableMap::UPDATED_AT); } /** * Order by create date desc * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function lastCreatedFirst() { - return $this->addDescendingOrderByColumn(ImportExportTypeTableMap::CREATED_AT); + return $this->addDescendingOrderByColumn(ImportTableMap::CREATED_AT); } /** * Order by create date asc * - * @return ChildImportExportTypeQuery The current query, for fluid interface + * @return ChildImportQuery The current query, for fluid interface */ public function firstCreatedFirst() { - return $this->addAscendingOrderByColumn(ImportExportTypeTableMap::CREATED_AT); + return $this->addAscendingOrderByColumn(ImportTableMap::CREATED_AT); } -} // ImportExportTypeQuery +} // ImportQuery diff --git a/core/lib/Thelia/Model/Export.php b/core/lib/Thelia/Model/Export.php new file mode 100644 index 000000000..1f1d5e100 --- /dev/null +++ b/core/lib/Thelia/Model/Export.php @@ -0,0 +1,10 @@ + array('Id', 'Locale', 'Title', ), + self::TYPE_STUDLYPHPNAME => array('id', 'locale', 'title', ), + self::TYPE_COLNAME => array(ExportCategoryI18nTableMap::ID, ExportCategoryI18nTableMap::LOCALE, ExportCategoryI18nTableMap::TITLE, ), + self::TYPE_RAW_COLNAME => array('ID', 'LOCALE', 'TITLE', ), + self::TYPE_FIELDNAME => array('id', 'locale', 'title', ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Locale' => 1, 'Title' => 2, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'locale' => 1, 'title' => 2, ), + self::TYPE_COLNAME => array(ExportCategoryI18nTableMap::ID => 0, ExportCategoryI18nTableMap::LOCALE => 1, ExportCategoryI18nTableMap::TITLE => 2, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'LOCALE' => 1, 'TITLE' => 2, ), + self::TYPE_FIELDNAME => array('id' => 0, 'locale' => 1, 'title' => 2, ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('export_category_i18n'); + $this->setPhpName('ExportCategoryI18n'); + $this->setClassName('\\Thelia\\Model\\ExportCategoryI18n'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'export_category', 'ID', true, null, null); + $this->addPrimaryKey('LOCALE', 'Locale', 'VARCHAR', true, 5, 'en_US'); + $this->addColumn('TITLE', 'Title', 'VARCHAR', true, 255, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('ExportCategory', '\\Thelia\\Model\\ExportCategory', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', null); + } // buildRelations() + + /** + * Adds an object to the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases you may need to explicitly add objects + * to the cache in order to ensure that the same objects are always returned by find*() + * and findPk*() calls. + * + * @param \Thelia\Model\ExportCategoryI18n $obj A \Thelia\Model\ExportCategoryI18n object. + * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). + */ + public static function addInstanceToPool($obj, $key = null) + { + if (Propel::isInstancePoolingEnabled()) { + if (null === $key) { + $key = serialize(array((string) $obj->getId(), (string) $obj->getLocale())); + } // if key === null + self::$instances[$key] = $obj; + } + } + + /** + * Removes an object from the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases -- especially when you override doDelete + * methods in your stub classes -- you may need to explicitly remove objects + * from the cache in order to prevent returning objects that no longer exist. + * + * @param mixed $value A \Thelia\Model\ExportCategoryI18n object or a primary key value. + */ + public static function removeInstanceFromPool($value) + { + if (Propel::isInstancePoolingEnabled() && null !== $value) { + if (is_object($value) && $value instanceof \Thelia\Model\ExportCategoryI18n) { + $key = serialize(array((string) $value->getId(), (string) $value->getLocale())); + + } elseif (is_array($value) && count($value) === 2) { + // assume we've been passed a primary key"; + $key = serialize(array((string) $value[0], (string) $value[1])); + } elseif ($value instanceof Criteria) { + self::$instances = []; + + return; + } else { + $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Thelia\Model\ExportCategoryI18n object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); + throw $e; + } + + unset(self::$instances[$key]); + } + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)])); + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return $pks; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? ExportCategoryI18nTableMap::CLASS_DEFAULT : ExportCategoryI18nTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (ExportCategoryI18n object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = ExportCategoryI18nTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ExportCategoryI18nTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + ExportCategoryI18nTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = ExportCategoryI18nTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + ExportCategoryI18nTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = ExportCategoryI18nTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ExportCategoryI18nTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + ExportCategoryI18nTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(ExportCategoryI18nTableMap::ID); + $criteria->addSelectColumn(ExportCategoryI18nTableMap::LOCALE); + $criteria->addSelectColumn(ExportCategoryI18nTableMap::TITLE); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.LOCALE'); + $criteria->addSelectColumn($alias . '.TITLE'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(ExportCategoryI18nTableMap::DATABASE_NAME)->getTable(ExportCategoryI18nTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ExportCategoryI18nTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ExportCategoryI18nTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ExportCategoryI18nTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a ExportCategoryI18n or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ExportCategoryI18n object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryI18nTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\ExportCategoryI18n) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(ExportCategoryI18nTableMap::DATABASE_NAME); + // primary key is composite; we therefore, expect + // the primary key passed to be an array of pkey values + if (count($values) == count($values, COUNT_RECURSIVE)) { + // array is not multi-dimensional + $values = array($values); + } + foreach ($values as $value) { + $criterion = $criteria->getNewCriterion(ExportCategoryI18nTableMap::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(ExportCategoryI18nTableMap::LOCALE, $value[1])); + $criteria->addOr($criterion); + } + } + + $query = ExportCategoryI18nQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { ExportCategoryI18nTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { ExportCategoryI18nTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the export_category_i18n table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return ExportCategoryI18nQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a ExportCategoryI18n or Criteria object. + * + * @param mixed $criteria Criteria or ExportCategoryI18n object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryI18nTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from ExportCategoryI18n object + } + + + // Set the correct dbName + $query = ExportCategoryI18nQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // ExportCategoryI18nTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +ExportCategoryI18nTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/ExportCategoryTableMap.php b/core/lib/Thelia/Model/Map/ExportCategoryTableMap.php new file mode 100644 index 000000000..1d5f32451 --- /dev/null +++ b/core/lib/Thelia/Model/Map/ExportCategoryTableMap.php @@ -0,0 +1,461 @@ + array('Id', 'Position', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'position', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(ExportCategoryTableMap::ID, ExportCategoryTableMap::POSITION, ExportCategoryTableMap::CREATED_AT, ExportCategoryTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'position', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Position' => 1, 'CreatedAt' => 2, 'UpdatedAt' => 3, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'position' => 1, 'createdAt' => 2, 'updatedAt' => 3, ), + self::TYPE_COLNAME => array(ExportCategoryTableMap::ID => 0, ExportCategoryTableMap::POSITION => 1, ExportCategoryTableMap::CREATED_AT => 2, ExportCategoryTableMap::UPDATED_AT => 3, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'POSITION' => 1, 'CREATED_AT' => 2, 'UPDATED_AT' => 3, ), + self::TYPE_FIELDNAME => array('id' => 0, 'position' => 1, 'created_at' => 2, 'updated_at' => 3, ), + self::TYPE_NUM => array(0, 1, 2, 3, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('export_category'); + $this->setPhpName('ExportCategory'); + $this->setClassName('\\Thelia\\Model\\ExportCategory'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addColumn('POSITION', 'Position', 'INTEGER', true, null, null); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Export', '\\Thelia\\Model\\Export', RelationMap::ONE_TO_MANY, array('id' => 'export_category_id', ), 'CASCADE', 'RESTRICT', 'Exports'); + $this->addRelation('ExportCategoryI18n', '\\Thelia\\Model\\ExportCategoryI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ExportCategoryI18ns'); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'i18n' => array('i18n_table' => '%TABLE%_i18n', 'i18n_phpname' => '%PHPNAME%I18n', 'i18n_columns' => 'title', 'locale_column' => 'locale', 'locale_length' => '5', 'default_locale' => '', 'locale_alias' => '', ), + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + ); + } // getBehaviors() + /** + * Method to invalidate the instance pool of all tables related to export_category * by a foreign key with ON DELETE CASCADE + */ + public static function clearRelatedInstancePool() + { + // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, + // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. + ExportTableMap::clearInstancePool(); + ExportCategoryI18nTableMap::clearInstancePool(); + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? ExportCategoryTableMap::CLASS_DEFAULT : ExportCategoryTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (ExportCategory object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = ExportCategoryTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ExportCategoryTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + ExportCategoryTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = ExportCategoryTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + ExportCategoryTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = ExportCategoryTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ExportCategoryTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + ExportCategoryTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(ExportCategoryTableMap::ID); + $criteria->addSelectColumn(ExportCategoryTableMap::POSITION); + $criteria->addSelectColumn(ExportCategoryTableMap::CREATED_AT); + $criteria->addSelectColumn(ExportCategoryTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.POSITION'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(ExportCategoryTableMap::DATABASE_NAME)->getTable(ExportCategoryTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ExportCategoryTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ExportCategoryTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ExportCategoryTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a ExportCategory or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ExportCategory object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\ExportCategory) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(ExportCategoryTableMap::DATABASE_NAME); + $criteria->add(ExportCategoryTableMap::ID, (array) $values, Criteria::IN); + } + + $query = ExportCategoryQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { ExportCategoryTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { ExportCategoryTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the export_category table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return ExportCategoryQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a ExportCategory or Criteria object. + * + * @param mixed $criteria Criteria or ExportCategory object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from ExportCategory object + } + + if ($criteria->containsKey(ExportCategoryTableMap::ID) && $criteria->keyContainsValue(ExportCategoryTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.ExportCategoryTableMap::ID.')'); + } + + + // Set the correct dbName + $query = ExportCategoryQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // ExportCategoryTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +ExportCategoryTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/ExportI18nTableMap.php b/core/lib/Thelia/Model/Map/ExportI18nTableMap.php new file mode 100644 index 000000000..228a4e288 --- /dev/null +++ b/core/lib/Thelia/Model/Map/ExportI18nTableMap.php @@ -0,0 +1,482 @@ + array('Id', 'Locale', 'Title', 'Description', ), + self::TYPE_STUDLYPHPNAME => array('id', 'locale', 'title', 'description', ), + self::TYPE_COLNAME => array(ExportI18nTableMap::ID, ExportI18nTableMap::LOCALE, ExportI18nTableMap::TITLE, ExportI18nTableMap::DESCRIPTION, ), + self::TYPE_RAW_COLNAME => array('ID', 'LOCALE', 'TITLE', 'DESCRIPTION', ), + self::TYPE_FIELDNAME => array('id', 'locale', 'title', 'description', ), + self::TYPE_NUM => array(0, 1, 2, 3, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Locale' => 1, 'Title' => 2, 'Description' => 3, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'locale' => 1, 'title' => 2, 'description' => 3, ), + self::TYPE_COLNAME => array(ExportI18nTableMap::ID => 0, ExportI18nTableMap::LOCALE => 1, ExportI18nTableMap::TITLE => 2, ExportI18nTableMap::DESCRIPTION => 3, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'LOCALE' => 1, 'TITLE' => 2, 'DESCRIPTION' => 3, ), + self::TYPE_FIELDNAME => array('id' => 0, 'locale' => 1, 'title' => 2, 'description' => 3, ), + self::TYPE_NUM => array(0, 1, 2, 3, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('export_i18n'); + $this->setPhpName('ExportI18n'); + $this->setClassName('\\Thelia\\Model\\ExportI18n'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(false); + // columns + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'export', 'ID', true, null, null); + $this->addPrimaryKey('LOCALE', 'Locale', 'VARCHAR', true, 5, 'en_US'); + $this->addColumn('TITLE', 'Title', 'VARCHAR', true, 255, null); + $this->addColumn('DESCRIPTION', 'Description', 'CLOB', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Export', '\\Thelia\\Model\\Export', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', null); + } // buildRelations() + + /** + * Adds an object to the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases you may need to explicitly add objects + * to the cache in order to ensure that the same objects are always returned by find*() + * and findPk*() calls. + * + * @param \Thelia\Model\ExportI18n $obj A \Thelia\Model\ExportI18n object. + * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). + */ + public static function addInstanceToPool($obj, $key = null) + { + if (Propel::isInstancePoolingEnabled()) { + if (null === $key) { + $key = serialize(array((string) $obj->getId(), (string) $obj->getLocale())); + } // if key === null + self::$instances[$key] = $obj; + } + } + + /** + * Removes an object from the instance pool. + * + * Propel keeps cached copies of objects in an instance pool when they are retrieved + * from the database. In some cases -- especially when you override doDelete + * methods in your stub classes -- you may need to explicitly remove objects + * from the cache in order to prevent returning objects that no longer exist. + * + * @param mixed $value A \Thelia\Model\ExportI18n object or a primary key value. + */ + public static function removeInstanceFromPool($value) + { + if (Propel::isInstancePoolingEnabled() && null !== $value) { + if (is_object($value) && $value instanceof \Thelia\Model\ExportI18n) { + $key = serialize(array((string) $value->getId(), (string) $value->getLocale())); + + } elseif (is_array($value) && count($value) === 2) { + // assume we've been passed a primary key"; + $key = serialize(array((string) $value[0], (string) $value[1])); + } elseif ($value instanceof Criteria) { + self::$instances = []; + + return; + } else { + $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Thelia\Model\ExportI18n object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); + throw $e; + } + + unset(self::$instances[$key]); + } + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null && $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return serialize(array((string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], (string) $row[TableMap::TYPE_NUM == $indexType ? 1 + $offset : static::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)])); + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return $pks; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? ExportI18nTableMap::CLASS_DEFAULT : ExportI18nTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (ExportI18n object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = ExportI18nTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ExportI18nTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + ExportI18nTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = ExportI18nTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + ExportI18nTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = ExportI18nTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ExportI18nTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + ExportI18nTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(ExportI18nTableMap::ID); + $criteria->addSelectColumn(ExportI18nTableMap::LOCALE); + $criteria->addSelectColumn(ExportI18nTableMap::TITLE); + $criteria->addSelectColumn(ExportI18nTableMap::DESCRIPTION); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.LOCALE'); + $criteria->addSelectColumn($alias . '.TITLE'); + $criteria->addSelectColumn($alias . '.DESCRIPTION'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(ExportI18nTableMap::DATABASE_NAME)->getTable(ExportI18nTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ExportI18nTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ExportI18nTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ExportI18nTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a ExportI18n or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or ExportI18n object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportI18nTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\ExportI18n) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(ExportI18nTableMap::DATABASE_NAME); + // primary key is composite; we therefore, expect + // the primary key passed to be an array of pkey values + if (count($values) == count($values, COUNT_RECURSIVE)) { + // array is not multi-dimensional + $values = array($values); + } + foreach ($values as $value) { + $criterion = $criteria->getNewCriterion(ExportI18nTableMap::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(ExportI18nTableMap::LOCALE, $value[1])); + $criteria->addOr($criterion); + } + } + + $query = ExportI18nQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { ExportI18nTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { ExportI18nTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the export_i18n table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return ExportI18nQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a ExportI18n or Criteria object. + * + * @param mixed $criteria Criteria or ExportI18n object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportI18nTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from ExportI18n object + } + + + // Set the correct dbName + $query = ExportI18nQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // ExportI18nTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +ExportI18nTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/ExportTableMap.php b/core/lib/Thelia/Model/Map/ExportTableMap.php new file mode 100644 index 000000000..f9ead6b5b --- /dev/null +++ b/core/lib/Thelia/Model/Map/ExportTableMap.php @@ -0,0 +1,468 @@ + array('Id', 'ExportCategoryId', 'Position', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'exportCategoryId', 'position', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(ExportTableMap::ID, ExportTableMap::EXPORT_CATEGORY_ID, ExportTableMap::POSITION, ExportTableMap::CREATED_AT, ExportTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'EXPORT_CATEGORY_ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'export_category_id', 'position', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'ExportCategoryId' => 1, 'Position' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'exportCategoryId' => 1, 'position' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), + self::TYPE_COLNAME => array(ExportTableMap::ID => 0, ExportTableMap::EXPORT_CATEGORY_ID => 1, ExportTableMap::POSITION => 2, ExportTableMap::CREATED_AT => 3, ExportTableMap::UPDATED_AT => 4, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'EXPORT_CATEGORY_ID' => 1, 'POSITION' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), + self::TYPE_FIELDNAME => array('id' => 0, 'export_category_id' => 1, 'position' => 2, 'created_at' => 3, 'updated_at' => 4, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('export'); + $this->setPhpName('Export'); + $this->setClassName('\\Thelia\\Model\\Export'); + $this->setPackage('Thelia.Model'); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addForeignKey('EXPORT_CATEGORY_ID', 'ExportCategoryId', 'INTEGER', 'export_category', 'ID', true, null, null); + $this->addColumn('POSITION', 'Position', 'INTEGER', true, null, null); + $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); + $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('ExportCategory', '\\Thelia\\Model\\ExportCategory', RelationMap::MANY_TO_ONE, array('export_category_id' => 'id', ), 'CASCADE', 'RESTRICT'); + $this->addRelation('ExportI18n', '\\Thelia\\Model\\ExportI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ExportI18ns'); + } // buildRelations() + + /** + * + * Gets the list of behaviors registered for this table + * + * @return array Associative array (name => parameters) of behaviors + */ + public function getBehaviors() + { + return array( + 'i18n' => array('i18n_table' => '%TABLE%_i18n', 'i18n_phpname' => '%PHPNAME%I18n', 'i18n_columns' => 'title, description', 'locale_column' => 'locale', 'locale_length' => '5', 'default_locale' => '', 'locale_alias' => '', ), + 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), + ); + } // getBehaviors() + /** + * Method to invalidate the instance pool of all tables related to export * by a foreign key with ON DELETE CASCADE + */ + public static function clearRelatedInstancePool() + { + // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, + // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. + ExportI18nTableMap::clearInstancePool(); + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? ExportTableMap::CLASS_DEFAULT : ExportTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (Export object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = ExportTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ExportTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + ExportTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = ExportTableMap::OM_CLASS; + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + ExportTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = ExportTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ExportTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + ExportTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(ExportTableMap::ID); + $criteria->addSelectColumn(ExportTableMap::EXPORT_CATEGORY_ID); + $criteria->addSelectColumn(ExportTableMap::POSITION); + $criteria->addSelectColumn(ExportTableMap::CREATED_AT); + $criteria->addSelectColumn(ExportTableMap::UPDATED_AT); + } else { + $criteria->addSelectColumn($alias . '.ID'); + $criteria->addSelectColumn($alias . '.EXPORT_CATEGORY_ID'); + $criteria->addSelectColumn($alias . '.POSITION'); + $criteria->addSelectColumn($alias . '.CREATED_AT'); + $criteria->addSelectColumn($alias . '.UPDATED_AT'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(ExportTableMap::DATABASE_NAME)->getTable(ExportTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ExportTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ExportTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ExportTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a Export or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or Export object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Thelia\Model\Export) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(ExportTableMap::DATABASE_NAME); + $criteria->add(ExportTableMap::ID, (array) $values, Criteria::IN); + } + + $query = ExportQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { ExportTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { ExportTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the export table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return ExportQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a Export or Criteria object. + * + * @param mixed $criteria Criteria or Export object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(ExportTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from Export object + } + + if ($criteria->containsKey(ExportTableMap::ID) && $criteria->keyContainsValue(ExportTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.ExportTableMap::ID.')'); + } + + + // Set the correct dbName + $query = ExportQuery::create()->mergeWith($criteria); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->beginTransaction(); + $pk = $query->doInsert($con); + $con->commit(); + } catch (PropelException $e) { + $con->rollBack(); + throw $e; + } + + return $pk; + } + +} // ExportTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +ExportTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/ImportExportCategoryI18nTableMap.php b/core/lib/Thelia/Model/Map/ImportCategoryI18nTableMap.php similarity index 76% rename from core/lib/Thelia/Model/Map/ImportExportCategoryI18nTableMap.php rename to core/lib/Thelia/Model/Map/ImportCategoryI18nTableMap.php index daf000bf1..c4e254f43 100644 --- a/core/lib/Thelia/Model/Map/ImportExportCategoryI18nTableMap.php +++ b/core/lib/Thelia/Model/Map/ImportCategoryI18nTableMap.php @@ -11,12 +11,12 @@ use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\RelationMap; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Map\TableMapTrait; -use Thelia\Model\ImportExportCategoryI18n; -use Thelia\Model\ImportExportCategoryI18nQuery; +use Thelia\Model\ImportCategoryI18n; +use Thelia\Model\ImportCategoryI18nQuery; /** - * This class defines the structure of the 'import_export_category_i18n' table. + * This class defines the structure of the 'import_category_i18n' table. * * * @@ -26,14 +26,14 @@ use Thelia\Model\ImportExportCategoryI18nQuery; * (i.e. if it's a text column type). * */ -class ImportExportCategoryI18nTableMap extends TableMap +class ImportCategoryI18nTableMap extends TableMap { use InstancePoolTrait; use TableMapTrait; /** * The (dot-path) name of this class */ - const CLASS_NAME = 'Thelia.Model.Map.ImportExportCategoryI18nTableMap'; + const CLASS_NAME = 'Thelia.Model.Map.ImportCategoryI18nTableMap'; /** * The default database name for this class @@ -43,17 +43,17 @@ class ImportExportCategoryI18nTableMap extends TableMap /** * The table name for this class */ - const TABLE_NAME = 'import_export_category_i18n'; + const TABLE_NAME = 'import_category_i18n'; /** * The related Propel class for this table */ - const OM_CLASS = '\\Thelia\\Model\\ImportExportCategoryI18n'; + const OM_CLASS = '\\Thelia\\Model\\ImportCategoryI18n'; /** * A class that can be returned by this tableMap */ - const CLASS_DEFAULT = 'Thelia.Model.ImportExportCategoryI18n'; + const CLASS_DEFAULT = 'Thelia.Model.ImportCategoryI18n'; /** * The total number of columns @@ -73,17 +73,17 @@ class ImportExportCategoryI18nTableMap extends TableMap /** * the column name for the ID field */ - const ID = 'import_export_category_i18n.ID'; + const ID = 'import_category_i18n.ID'; /** * the column name for the LOCALE field */ - const LOCALE = 'import_export_category_i18n.LOCALE'; + const LOCALE = 'import_category_i18n.LOCALE'; /** * the column name for the TITLE field */ - const TITLE = 'import_export_category_i18n.TITLE'; + const TITLE = 'import_category_i18n.TITLE'; /** * The default string format for model objects of the related table @@ -99,7 +99,7 @@ class ImportExportCategoryI18nTableMap extends TableMap protected static $fieldNames = array ( self::TYPE_PHPNAME => array('Id', 'Locale', 'Title', ), self::TYPE_STUDLYPHPNAME => array('id', 'locale', 'title', ), - self::TYPE_COLNAME => array(ImportExportCategoryI18nTableMap::ID, ImportExportCategoryI18nTableMap::LOCALE, ImportExportCategoryI18nTableMap::TITLE, ), + self::TYPE_COLNAME => array(ImportCategoryI18nTableMap::ID, ImportCategoryI18nTableMap::LOCALE, ImportCategoryI18nTableMap::TITLE, ), self::TYPE_RAW_COLNAME => array('ID', 'LOCALE', 'TITLE', ), self::TYPE_FIELDNAME => array('id', 'locale', 'title', ), self::TYPE_NUM => array(0, 1, 2, ) @@ -114,7 +114,7 @@ class ImportExportCategoryI18nTableMap extends TableMap protected static $fieldKeys = array ( self::TYPE_PHPNAME => array('Id' => 0, 'Locale' => 1, 'Title' => 2, ), self::TYPE_STUDLYPHPNAME => array('id' => 0, 'locale' => 1, 'title' => 2, ), - self::TYPE_COLNAME => array(ImportExportCategoryI18nTableMap::ID => 0, ImportExportCategoryI18nTableMap::LOCALE => 1, ImportExportCategoryI18nTableMap::TITLE => 2, ), + self::TYPE_COLNAME => array(ImportCategoryI18nTableMap::ID => 0, ImportCategoryI18nTableMap::LOCALE => 1, ImportCategoryI18nTableMap::TITLE => 2, ), self::TYPE_RAW_COLNAME => array('ID' => 0, 'LOCALE' => 1, 'TITLE' => 2, ), self::TYPE_FIELDNAME => array('id' => 0, 'locale' => 1, 'title' => 2, ), self::TYPE_NUM => array(0, 1, 2, ) @@ -130,13 +130,13 @@ class ImportExportCategoryI18nTableMap extends TableMap public function initialize() { // attributes - $this->setName('import_export_category_i18n'); - $this->setPhpName('ImportExportCategoryI18n'); - $this->setClassName('\\Thelia\\Model\\ImportExportCategoryI18n'); + $this->setName('import_category_i18n'); + $this->setPhpName('ImportCategoryI18n'); + $this->setClassName('\\Thelia\\Model\\ImportCategoryI18n'); $this->setPackage('Thelia.Model'); $this->setUseIdGenerator(false); // columns - $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'import_export_category', 'ID', true, null, null); + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'import_category', 'ID', true, null, null); $this->addPrimaryKey('LOCALE', 'Locale', 'VARCHAR', true, 5, 'en_US'); $this->addColumn('TITLE', 'Title', 'VARCHAR', true, 255, null); } // initialize() @@ -146,7 +146,7 @@ class ImportExportCategoryI18nTableMap extends TableMap */ public function buildRelations() { - $this->addRelation('ImportExportCategory', '\\Thelia\\Model\\ImportExportCategory', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', null); + $this->addRelation('ImportCategory', '\\Thelia\\Model\\ImportCategory', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', null); } // buildRelations() /** @@ -157,7 +157,7 @@ class ImportExportCategoryI18nTableMap extends TableMap * to the cache in order to ensure that the same objects are always returned by find*() * and findPk*() calls. * - * @param \Thelia\Model\ImportExportCategoryI18n $obj A \Thelia\Model\ImportExportCategoryI18n object. + * @param \Thelia\Model\ImportCategoryI18n $obj A \Thelia\Model\ImportCategoryI18n object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool($obj, $key = null) @@ -178,12 +178,12 @@ class ImportExportCategoryI18nTableMap extends TableMap * methods in your stub classes -- you may need to explicitly remove objects * from the cache in order to prevent returning objects that no longer exist. * - * @param mixed $value A \Thelia\Model\ImportExportCategoryI18n object or a primary key value. + * @param mixed $value A \Thelia\Model\ImportCategoryI18n object or a primary key value. */ public static function removeInstanceFromPool($value) { if (Propel::isInstancePoolingEnabled() && null !== $value) { - if (is_object($value) && $value instanceof \Thelia\Model\ImportExportCategoryI18n) { + if (is_object($value) && $value instanceof \Thelia\Model\ImportCategoryI18n) { $key = serialize(array((string) $value->getId(), (string) $value->getLocale())); } elseif (is_array($value) && count($value) === 2) { @@ -194,7 +194,7 @@ class ImportExportCategoryI18nTableMap extends TableMap return; } else { - $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Thelia\Model\ImportExportCategoryI18n object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); + $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Thelia\Model\ImportCategoryI18n object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); throw $e; } @@ -254,7 +254,7 @@ class ImportExportCategoryI18nTableMap extends TableMap */ public static function getOMClass($withPrefix = true) { - return $withPrefix ? ImportExportCategoryI18nTableMap::CLASS_DEFAULT : ImportExportCategoryI18nTableMap::OM_CLASS; + return $withPrefix ? ImportCategoryI18nTableMap::CLASS_DEFAULT : ImportCategoryI18nTableMap::OM_CLASS; } /** @@ -268,21 +268,21 @@ class ImportExportCategoryI18nTableMap extends TableMap * * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. - * @return array (ImportExportCategoryI18n object, last column rank) + * @return array (ImportCategoryI18n object, last column rank) */ public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) { - $key = ImportExportCategoryI18nTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); - if (null !== ($obj = ImportExportCategoryI18nTableMap::getInstanceFromPool($key))) { + $key = ImportCategoryI18nTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ImportCategoryI18nTableMap::getInstanceFromPool($key))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj->hydrate($row, $offset, true); // rehydrate - $col = $offset + ImportExportCategoryI18nTableMap::NUM_HYDRATE_COLUMNS; + $col = $offset + ImportCategoryI18nTableMap::NUM_HYDRATE_COLUMNS; } else { - $cls = ImportExportCategoryI18nTableMap::OM_CLASS; + $cls = ImportCategoryI18nTableMap::OM_CLASS; $obj = new $cls(); $col = $obj->hydrate($row, $offset, false, $indexType); - ImportExportCategoryI18nTableMap::addInstanceToPool($obj, $key); + ImportCategoryI18nTableMap::addInstanceToPool($obj, $key); } return array($obj, $col); @@ -305,8 +305,8 @@ class ImportExportCategoryI18nTableMap extends TableMap $cls = static::getOMClass(false); // populate the object(s) while ($row = $dataFetcher->fetch()) { - $key = ImportExportCategoryI18nTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); - if (null !== ($obj = ImportExportCategoryI18nTableMap::getInstanceFromPool($key))) { + $key = ImportCategoryI18nTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ImportCategoryI18nTableMap::getInstanceFromPool($key))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj->hydrate($row, 0, true); // rehydrate @@ -315,7 +315,7 @@ class ImportExportCategoryI18nTableMap extends TableMap $obj = new $cls(); $obj->hydrate($row); $results[] = $obj; - ImportExportCategoryI18nTableMap::addInstanceToPool($obj, $key); + ImportCategoryI18nTableMap::addInstanceToPool($obj, $key); } // if key exists } @@ -336,9 +336,9 @@ class ImportExportCategoryI18nTableMap extends TableMap public static function addSelectColumns(Criteria $criteria, $alias = null) { if (null === $alias) { - $criteria->addSelectColumn(ImportExportCategoryI18nTableMap::ID); - $criteria->addSelectColumn(ImportExportCategoryI18nTableMap::LOCALE); - $criteria->addSelectColumn(ImportExportCategoryI18nTableMap::TITLE); + $criteria->addSelectColumn(ImportCategoryI18nTableMap::ID); + $criteria->addSelectColumn(ImportCategoryI18nTableMap::LOCALE); + $criteria->addSelectColumn(ImportCategoryI18nTableMap::TITLE); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.LOCALE'); @@ -355,7 +355,7 @@ class ImportExportCategoryI18nTableMap extends TableMap */ public static function getTableMap() { - return Propel::getServiceContainer()->getDatabaseMap(ImportExportCategoryI18nTableMap::DATABASE_NAME)->getTable(ImportExportCategoryI18nTableMap::TABLE_NAME); + return Propel::getServiceContainer()->getDatabaseMap(ImportCategoryI18nTableMap::DATABASE_NAME)->getTable(ImportCategoryI18nTableMap::TABLE_NAME); } /** @@ -363,16 +363,16 @@ class ImportExportCategoryI18nTableMap extends TableMap */ public static function buildTableMap() { - $dbMap = Propel::getServiceContainer()->getDatabaseMap(ImportExportCategoryI18nTableMap::DATABASE_NAME); - if (!$dbMap->hasTable(ImportExportCategoryI18nTableMap::TABLE_NAME)) { - $dbMap->addTableObject(new ImportExportCategoryI18nTableMap()); + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ImportCategoryI18nTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ImportCategoryI18nTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ImportCategoryI18nTableMap()); } } /** - * Performs a DELETE on the database, given a ImportExportCategoryI18n or Criteria object OR a primary key value. + * Performs a DELETE on the database, given a ImportCategoryI18n or Criteria object OR a primary key value. * - * @param mixed $values Criteria or ImportExportCategoryI18n object or primary key or array of primary keys + * @param mixed $values Criteria or ImportCategoryI18n object or primary key or array of primary keys * which is used to create the DELETE statement * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows @@ -383,17 +383,17 @@ class ImportExportCategoryI18nTableMap extends TableMap public static function doDelete($values, ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryI18nTableMap::DATABASE_NAME); } if ($values instanceof Criteria) { // rename for clarity $criteria = $values; - } elseif ($values instanceof \Thelia\Model\ImportExportCategoryI18n) { // it's a model object + } elseif ($values instanceof \Thelia\Model\ImportCategoryI18n) { // it's a model object // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it's a primary key, or an array of pks - $criteria = new Criteria(ImportExportCategoryI18nTableMap::DATABASE_NAME); + $criteria = new Criteria(ImportCategoryI18nTableMap::DATABASE_NAME); // primary key is composite; we therefore, expect // the primary key passed to be an array of pkey values if (count($values) == count($values, COUNT_RECURSIVE)) { @@ -401,17 +401,17 @@ class ImportExportCategoryI18nTableMap extends TableMap $values = array($values); } foreach ($values as $value) { - $criterion = $criteria->getNewCriterion(ImportExportCategoryI18nTableMap::ID, $value[0]); - $criterion->addAnd($criteria->getNewCriterion(ImportExportCategoryI18nTableMap::LOCALE, $value[1])); + $criterion = $criteria->getNewCriterion(ImportCategoryI18nTableMap::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(ImportCategoryI18nTableMap::LOCALE, $value[1])); $criteria->addOr($criterion); } } - $query = ImportExportCategoryI18nQuery::create()->mergeWith($criteria); + $query = ImportCategoryI18nQuery::create()->mergeWith($criteria); - if ($values instanceof Criteria) { ImportExportCategoryI18nTableMap::clearInstancePool(); + if ($values instanceof Criteria) { ImportCategoryI18nTableMap::clearInstancePool(); } elseif (!is_object($values)) { // it's a primary key, or an array of pks - foreach ((array) $values as $singleval) { ImportExportCategoryI18nTableMap::removeInstanceFromPool($singleval); + foreach ((array) $values as $singleval) { ImportCategoryI18nTableMap::removeInstanceFromPool($singleval); } } @@ -419,20 +419,20 @@ class ImportExportCategoryI18nTableMap extends TableMap } /** - * Deletes all rows from the import_export_category_i18n table. + * Deletes all rows from the import_category_i18n table. * * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). */ public static function doDeleteAll(ConnectionInterface $con = null) { - return ImportExportCategoryI18nQuery::create()->doDeleteAll($con); + return ImportCategoryI18nQuery::create()->doDeleteAll($con); } /** - * Performs an INSERT on the database, given a ImportExportCategoryI18n or Criteria object. + * Performs an INSERT on the database, given a ImportCategoryI18n or Criteria object. * - * @param mixed $criteria Criteria or ImportExportCategoryI18n object containing data that is used to create the INSERT statement. + * @param mixed $criteria Criteria or ImportCategoryI18n object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be @@ -441,18 +441,18 @@ class ImportExportCategoryI18nTableMap extends TableMap public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryI18nTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { - $criteria = $criteria->buildCriteria(); // build Criteria from ImportExportCategoryI18n object + $criteria = $criteria->buildCriteria(); // build Criteria from ImportCategoryI18n object } // Set the correct dbName - $query = ImportExportCategoryI18nQuery::create()->mergeWith($criteria); + $query = ImportCategoryI18nQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info @@ -468,7 +468,7 @@ class ImportExportCategoryI18nTableMap extends TableMap return $pk; } -} // ImportExportCategoryI18nTableMap +} // ImportCategoryI18nTableMap // This is the static code needed to register the TableMap for this table with the main Propel class. // -ImportExportCategoryI18nTableMap::buildTableMap(); +ImportCategoryI18nTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/ImportExportCategoryTableMap.php b/core/lib/Thelia/Model/Map/ImportCategoryTableMap.php similarity index 74% rename from core/lib/Thelia/Model/Map/ImportExportCategoryTableMap.php rename to core/lib/Thelia/Model/Map/ImportCategoryTableMap.php index 96a0d768c..e75ddf2ba 100644 --- a/core/lib/Thelia/Model/Map/ImportExportCategoryTableMap.php +++ b/core/lib/Thelia/Model/Map/ImportCategoryTableMap.php @@ -11,12 +11,12 @@ use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\RelationMap; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Map\TableMapTrait; -use Thelia\Model\ImportExportCategory; -use Thelia\Model\ImportExportCategoryQuery; +use Thelia\Model\ImportCategory; +use Thelia\Model\ImportCategoryQuery; /** - * This class defines the structure of the 'import_export_category' table. + * This class defines the structure of the 'import_category' table. * * * @@ -26,14 +26,14 @@ use Thelia\Model\ImportExportCategoryQuery; * (i.e. if it's a text column type). * */ -class ImportExportCategoryTableMap extends TableMap +class ImportCategoryTableMap extends TableMap { use InstancePoolTrait; use TableMapTrait; /** * The (dot-path) name of this class */ - const CLASS_NAME = 'Thelia.Model.Map.ImportExportCategoryTableMap'; + const CLASS_NAME = 'Thelia.Model.Map.ImportCategoryTableMap'; /** * The default database name for this class @@ -43,17 +43,17 @@ class ImportExportCategoryTableMap extends TableMap /** * The table name for this class */ - const TABLE_NAME = 'import_export_category'; + const TABLE_NAME = 'import_category'; /** * The related Propel class for this table */ - const OM_CLASS = '\\Thelia\\Model\\ImportExportCategory'; + const OM_CLASS = '\\Thelia\\Model\\ImportCategory'; /** * A class that can be returned by this tableMap */ - const CLASS_DEFAULT = 'Thelia.Model.ImportExportCategory'; + const CLASS_DEFAULT = 'Thelia.Model.ImportCategory'; /** * The total number of columns @@ -73,22 +73,22 @@ class ImportExportCategoryTableMap extends TableMap /** * the column name for the ID field */ - const ID = 'import_export_category.ID'; + const ID = 'import_category.ID'; /** * the column name for the POSITION field */ - const POSITION = 'import_export_category.POSITION'; + const POSITION = 'import_category.POSITION'; /** * the column name for the CREATED_AT field */ - const CREATED_AT = 'import_export_category.CREATED_AT'; + const CREATED_AT = 'import_category.CREATED_AT'; /** * the column name for the UPDATED_AT field */ - const UPDATED_AT = 'import_export_category.UPDATED_AT'; + const UPDATED_AT = 'import_category.UPDATED_AT'; /** * The default string format for model objects of the related table @@ -113,7 +113,7 @@ class ImportExportCategoryTableMap extends TableMap protected static $fieldNames = array ( self::TYPE_PHPNAME => array('Id', 'Position', 'CreatedAt', 'UpdatedAt', ), self::TYPE_STUDLYPHPNAME => array('id', 'position', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(ImportExportCategoryTableMap::ID, ImportExportCategoryTableMap::POSITION, ImportExportCategoryTableMap::CREATED_AT, ImportExportCategoryTableMap::UPDATED_AT, ), + self::TYPE_COLNAME => array(ImportCategoryTableMap::ID, ImportCategoryTableMap::POSITION, ImportCategoryTableMap::CREATED_AT, ImportCategoryTableMap::UPDATED_AT, ), self::TYPE_RAW_COLNAME => array('ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), self::TYPE_FIELDNAME => array('id', 'position', 'created_at', 'updated_at', ), self::TYPE_NUM => array(0, 1, 2, 3, ) @@ -128,7 +128,7 @@ class ImportExportCategoryTableMap extends TableMap protected static $fieldKeys = array ( self::TYPE_PHPNAME => array('Id' => 0, 'Position' => 1, 'CreatedAt' => 2, 'UpdatedAt' => 3, ), self::TYPE_STUDLYPHPNAME => array('id' => 0, 'position' => 1, 'createdAt' => 2, 'updatedAt' => 3, ), - self::TYPE_COLNAME => array(ImportExportCategoryTableMap::ID => 0, ImportExportCategoryTableMap::POSITION => 1, ImportExportCategoryTableMap::CREATED_AT => 2, ImportExportCategoryTableMap::UPDATED_AT => 3, ), + self::TYPE_COLNAME => array(ImportCategoryTableMap::ID => 0, ImportCategoryTableMap::POSITION => 1, ImportCategoryTableMap::CREATED_AT => 2, ImportCategoryTableMap::UPDATED_AT => 3, ), self::TYPE_RAW_COLNAME => array('ID' => 0, 'POSITION' => 1, 'CREATED_AT' => 2, 'UPDATED_AT' => 3, ), self::TYPE_FIELDNAME => array('id' => 0, 'position' => 1, 'created_at' => 2, 'updated_at' => 3, ), self::TYPE_NUM => array(0, 1, 2, 3, ) @@ -144,9 +144,9 @@ class ImportExportCategoryTableMap extends TableMap public function initialize() { // attributes - $this->setName('import_export_category'); - $this->setPhpName('ImportExportCategory'); - $this->setClassName('\\Thelia\\Model\\ImportExportCategory'); + $this->setName('import_category'); + $this->setPhpName('ImportCategory'); + $this->setClassName('\\Thelia\\Model\\ImportCategory'); $this->setPackage('Thelia.Model'); $this->setUseIdGenerator(true); // columns @@ -161,8 +161,8 @@ class ImportExportCategoryTableMap extends TableMap */ public function buildRelations() { - $this->addRelation('ImportExportType', '\\Thelia\\Model\\ImportExportType', RelationMap::ONE_TO_MANY, array('id' => 'import_export_category_id', ), 'CASCADE', 'RESTRICT', 'ImportExportTypes'); - $this->addRelation('ImportExportCategoryI18n', '\\Thelia\\Model\\ImportExportCategoryI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ImportExportCategoryI18ns'); + $this->addRelation('Import', '\\Thelia\\Model\\Import', RelationMap::ONE_TO_MANY, array('id' => 'import_category_id', ), 'CASCADE', 'RESTRICT', 'Imports'); + $this->addRelation('ImportCategoryI18n', '\\Thelia\\Model\\ImportCategoryI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ImportCategoryI18ns'); } // buildRelations() /** @@ -179,14 +179,14 @@ class ImportExportCategoryTableMap extends TableMap ); } // getBehaviors() /** - * Method to invalidate the instance pool of all tables related to import_export_category * by a foreign key with ON DELETE CASCADE + * Method to invalidate the instance pool of all tables related to import_category * by a foreign key with ON DELETE CASCADE */ public static function clearRelatedInstancePool() { // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. - ImportExportTypeTableMap::clearInstancePool(); - ImportExportCategoryI18nTableMap::clearInstancePool(); + ImportTableMap::clearInstancePool(); + ImportCategoryI18nTableMap::clearInstancePool(); } /** @@ -245,7 +245,7 @@ class ImportExportCategoryTableMap extends TableMap */ public static function getOMClass($withPrefix = true) { - return $withPrefix ? ImportExportCategoryTableMap::CLASS_DEFAULT : ImportExportCategoryTableMap::OM_CLASS; + return $withPrefix ? ImportCategoryTableMap::CLASS_DEFAULT : ImportCategoryTableMap::OM_CLASS; } /** @@ -259,21 +259,21 @@ class ImportExportCategoryTableMap extends TableMap * * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. - * @return array (ImportExportCategory object, last column rank) + * @return array (ImportCategory object, last column rank) */ public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) { - $key = ImportExportCategoryTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); - if (null !== ($obj = ImportExportCategoryTableMap::getInstanceFromPool($key))) { + $key = ImportCategoryTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ImportCategoryTableMap::getInstanceFromPool($key))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj->hydrate($row, $offset, true); // rehydrate - $col = $offset + ImportExportCategoryTableMap::NUM_HYDRATE_COLUMNS; + $col = $offset + ImportCategoryTableMap::NUM_HYDRATE_COLUMNS; } else { - $cls = ImportExportCategoryTableMap::OM_CLASS; + $cls = ImportCategoryTableMap::OM_CLASS; $obj = new $cls(); $col = $obj->hydrate($row, $offset, false, $indexType); - ImportExportCategoryTableMap::addInstanceToPool($obj, $key); + ImportCategoryTableMap::addInstanceToPool($obj, $key); } return array($obj, $col); @@ -296,8 +296,8 @@ class ImportExportCategoryTableMap extends TableMap $cls = static::getOMClass(false); // populate the object(s) while ($row = $dataFetcher->fetch()) { - $key = ImportExportCategoryTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); - if (null !== ($obj = ImportExportCategoryTableMap::getInstanceFromPool($key))) { + $key = ImportCategoryTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ImportCategoryTableMap::getInstanceFromPool($key))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj->hydrate($row, 0, true); // rehydrate @@ -306,7 +306,7 @@ class ImportExportCategoryTableMap extends TableMap $obj = new $cls(); $obj->hydrate($row); $results[] = $obj; - ImportExportCategoryTableMap::addInstanceToPool($obj, $key); + ImportCategoryTableMap::addInstanceToPool($obj, $key); } // if key exists } @@ -327,10 +327,10 @@ class ImportExportCategoryTableMap extends TableMap public static function addSelectColumns(Criteria $criteria, $alias = null) { if (null === $alias) { - $criteria->addSelectColumn(ImportExportCategoryTableMap::ID); - $criteria->addSelectColumn(ImportExportCategoryTableMap::POSITION); - $criteria->addSelectColumn(ImportExportCategoryTableMap::CREATED_AT); - $criteria->addSelectColumn(ImportExportCategoryTableMap::UPDATED_AT); + $criteria->addSelectColumn(ImportCategoryTableMap::ID); + $criteria->addSelectColumn(ImportCategoryTableMap::POSITION); + $criteria->addSelectColumn(ImportCategoryTableMap::CREATED_AT); + $criteria->addSelectColumn(ImportCategoryTableMap::UPDATED_AT); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.POSITION'); @@ -348,7 +348,7 @@ class ImportExportCategoryTableMap extends TableMap */ public static function getTableMap() { - return Propel::getServiceContainer()->getDatabaseMap(ImportExportCategoryTableMap::DATABASE_NAME)->getTable(ImportExportCategoryTableMap::TABLE_NAME); + return Propel::getServiceContainer()->getDatabaseMap(ImportCategoryTableMap::DATABASE_NAME)->getTable(ImportCategoryTableMap::TABLE_NAME); } /** @@ -356,16 +356,16 @@ class ImportExportCategoryTableMap extends TableMap */ public static function buildTableMap() { - $dbMap = Propel::getServiceContainer()->getDatabaseMap(ImportExportCategoryTableMap::DATABASE_NAME); - if (!$dbMap->hasTable(ImportExportCategoryTableMap::TABLE_NAME)) { - $dbMap->addTableObject(new ImportExportCategoryTableMap()); + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ImportCategoryTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ImportCategoryTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ImportCategoryTableMap()); } } /** - * Performs a DELETE on the database, given a ImportExportCategory or Criteria object OR a primary key value. + * Performs a DELETE on the database, given a ImportCategory or Criteria object OR a primary key value. * - * @param mixed $values Criteria or ImportExportCategory object or primary key or array of primary keys + * @param mixed $values Criteria or ImportCategory object or primary key or array of primary keys * which is used to create the DELETE statement * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows @@ -376,25 +376,25 @@ class ImportExportCategoryTableMap extends TableMap public static function doDelete($values, ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryTableMap::DATABASE_NAME); } if ($values instanceof Criteria) { // rename for clarity $criteria = $values; - } elseif ($values instanceof \Thelia\Model\ImportExportCategory) { // it's a model object + } elseif ($values instanceof \Thelia\Model\ImportCategory) { // it's a model object // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it's a primary key, or an array of pks - $criteria = new Criteria(ImportExportCategoryTableMap::DATABASE_NAME); - $criteria->add(ImportExportCategoryTableMap::ID, (array) $values, Criteria::IN); + $criteria = new Criteria(ImportCategoryTableMap::DATABASE_NAME); + $criteria->add(ImportCategoryTableMap::ID, (array) $values, Criteria::IN); } - $query = ImportExportCategoryQuery::create()->mergeWith($criteria); + $query = ImportCategoryQuery::create()->mergeWith($criteria); - if ($values instanceof Criteria) { ImportExportCategoryTableMap::clearInstancePool(); + if ($values instanceof Criteria) { ImportCategoryTableMap::clearInstancePool(); } elseif (!is_object($values)) { // it's a primary key, or an array of pks - foreach ((array) $values as $singleval) { ImportExportCategoryTableMap::removeInstanceFromPool($singleval); + foreach ((array) $values as $singleval) { ImportCategoryTableMap::removeInstanceFromPool($singleval); } } @@ -402,20 +402,20 @@ class ImportExportCategoryTableMap extends TableMap } /** - * Deletes all rows from the import_export_category table. + * Deletes all rows from the import_category table. * * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). */ public static function doDeleteAll(ConnectionInterface $con = null) { - return ImportExportCategoryQuery::create()->doDeleteAll($con); + return ImportCategoryQuery::create()->doDeleteAll($con); } /** - * Performs an INSERT on the database, given a ImportExportCategory or Criteria object. + * Performs an INSERT on the database, given a ImportCategory or Criteria object. * - * @param mixed $criteria Criteria or ImportExportCategory object containing data that is used to create the INSERT statement. + * @param mixed $criteria Criteria or ImportCategory object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be @@ -424,22 +424,22 @@ class ImportExportCategoryTableMap extends TableMap public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportCategoryTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { - $criteria = $criteria->buildCriteria(); // build Criteria from ImportExportCategory object + $criteria = $criteria->buildCriteria(); // build Criteria from ImportCategory object } - if ($criteria->containsKey(ImportExportCategoryTableMap::ID) && $criteria->keyContainsValue(ImportExportCategoryTableMap::ID) ) { - throw new PropelException('Cannot insert a value for auto-increment primary key ('.ImportExportCategoryTableMap::ID.')'); + if ($criteria->containsKey(ImportCategoryTableMap::ID) && $criteria->keyContainsValue(ImportCategoryTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.ImportCategoryTableMap::ID.')'); } // Set the correct dbName - $query = ImportExportCategoryQuery::create()->mergeWith($criteria); + $query = ImportCategoryQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info @@ -455,7 +455,7 @@ class ImportExportCategoryTableMap extends TableMap return $pk; } -} // ImportExportCategoryTableMap +} // ImportCategoryTableMap // This is the static code needed to register the TableMap for this table with the main Propel class. // -ImportExportCategoryTableMap::buildTableMap(); +ImportCategoryTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/ImportExportTypeI18nTableMap.php b/core/lib/Thelia/Model/Map/ImportI18nTableMap.php similarity index 77% rename from core/lib/Thelia/Model/Map/ImportExportTypeI18nTableMap.php rename to core/lib/Thelia/Model/Map/ImportI18nTableMap.php index 291ccf906..98279a3c8 100644 --- a/core/lib/Thelia/Model/Map/ImportExportTypeI18nTableMap.php +++ b/core/lib/Thelia/Model/Map/ImportI18nTableMap.php @@ -11,12 +11,12 @@ use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\RelationMap; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Map\TableMapTrait; -use Thelia\Model\ImportExportTypeI18n; -use Thelia\Model\ImportExportTypeI18nQuery; +use Thelia\Model\ImportI18n; +use Thelia\Model\ImportI18nQuery; /** - * This class defines the structure of the 'import_export_type_i18n' table. + * This class defines the structure of the 'import_i18n' table. * * * @@ -26,14 +26,14 @@ use Thelia\Model\ImportExportTypeI18nQuery; * (i.e. if it's a text column type). * */ -class ImportExportTypeI18nTableMap extends TableMap +class ImportI18nTableMap extends TableMap { use InstancePoolTrait; use TableMapTrait; /** * The (dot-path) name of this class */ - const CLASS_NAME = 'Thelia.Model.Map.ImportExportTypeI18nTableMap'; + const CLASS_NAME = 'Thelia.Model.Map.ImportI18nTableMap'; /** * The default database name for this class @@ -43,17 +43,17 @@ class ImportExportTypeI18nTableMap extends TableMap /** * The table name for this class */ - const TABLE_NAME = 'import_export_type_i18n'; + const TABLE_NAME = 'import_i18n'; /** * The related Propel class for this table */ - const OM_CLASS = '\\Thelia\\Model\\ImportExportTypeI18n'; + const OM_CLASS = '\\Thelia\\Model\\ImportI18n'; /** * A class that can be returned by this tableMap */ - const CLASS_DEFAULT = 'Thelia.Model.ImportExportTypeI18n'; + const CLASS_DEFAULT = 'Thelia.Model.ImportI18n'; /** * The total number of columns @@ -73,22 +73,22 @@ class ImportExportTypeI18nTableMap extends TableMap /** * the column name for the ID field */ - const ID = 'import_export_type_i18n.ID'; + const ID = 'import_i18n.ID'; /** * the column name for the LOCALE field */ - const LOCALE = 'import_export_type_i18n.LOCALE'; + const LOCALE = 'import_i18n.LOCALE'; /** * the column name for the TITLE field */ - const TITLE = 'import_export_type_i18n.TITLE'; + const TITLE = 'import_i18n.TITLE'; /** * the column name for the DESCRIPTION field */ - const DESCRIPTION = 'import_export_type_i18n.DESCRIPTION'; + const DESCRIPTION = 'import_i18n.DESCRIPTION'; /** * The default string format for model objects of the related table @@ -104,7 +104,7 @@ class ImportExportTypeI18nTableMap extends TableMap protected static $fieldNames = array ( self::TYPE_PHPNAME => array('Id', 'Locale', 'Title', 'Description', ), self::TYPE_STUDLYPHPNAME => array('id', 'locale', 'title', 'description', ), - self::TYPE_COLNAME => array(ImportExportTypeI18nTableMap::ID, ImportExportTypeI18nTableMap::LOCALE, ImportExportTypeI18nTableMap::TITLE, ImportExportTypeI18nTableMap::DESCRIPTION, ), + self::TYPE_COLNAME => array(ImportI18nTableMap::ID, ImportI18nTableMap::LOCALE, ImportI18nTableMap::TITLE, ImportI18nTableMap::DESCRIPTION, ), self::TYPE_RAW_COLNAME => array('ID', 'LOCALE', 'TITLE', 'DESCRIPTION', ), self::TYPE_FIELDNAME => array('id', 'locale', 'title', 'description', ), self::TYPE_NUM => array(0, 1, 2, 3, ) @@ -119,7 +119,7 @@ class ImportExportTypeI18nTableMap extends TableMap protected static $fieldKeys = array ( self::TYPE_PHPNAME => array('Id' => 0, 'Locale' => 1, 'Title' => 2, 'Description' => 3, ), self::TYPE_STUDLYPHPNAME => array('id' => 0, 'locale' => 1, 'title' => 2, 'description' => 3, ), - self::TYPE_COLNAME => array(ImportExportTypeI18nTableMap::ID => 0, ImportExportTypeI18nTableMap::LOCALE => 1, ImportExportTypeI18nTableMap::TITLE => 2, ImportExportTypeI18nTableMap::DESCRIPTION => 3, ), + self::TYPE_COLNAME => array(ImportI18nTableMap::ID => 0, ImportI18nTableMap::LOCALE => 1, ImportI18nTableMap::TITLE => 2, ImportI18nTableMap::DESCRIPTION => 3, ), self::TYPE_RAW_COLNAME => array('ID' => 0, 'LOCALE' => 1, 'TITLE' => 2, 'DESCRIPTION' => 3, ), self::TYPE_FIELDNAME => array('id' => 0, 'locale' => 1, 'title' => 2, 'description' => 3, ), self::TYPE_NUM => array(0, 1, 2, 3, ) @@ -135,13 +135,13 @@ class ImportExportTypeI18nTableMap extends TableMap public function initialize() { // attributes - $this->setName('import_export_type_i18n'); - $this->setPhpName('ImportExportTypeI18n'); - $this->setClassName('\\Thelia\\Model\\ImportExportTypeI18n'); + $this->setName('import_i18n'); + $this->setPhpName('ImportI18n'); + $this->setClassName('\\Thelia\\Model\\ImportI18n'); $this->setPackage('Thelia.Model'); $this->setUseIdGenerator(false); // columns - $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'import_export_type', 'ID', true, null, null); + $this->addForeignPrimaryKey('ID', 'Id', 'INTEGER' , 'import', 'ID', true, null, null); $this->addPrimaryKey('LOCALE', 'Locale', 'VARCHAR', true, 5, 'en_US'); $this->addColumn('TITLE', 'Title', 'VARCHAR', true, 255, null); $this->addColumn('DESCRIPTION', 'Description', 'CLOB', false, null, null); @@ -152,7 +152,7 @@ class ImportExportTypeI18nTableMap extends TableMap */ public function buildRelations() { - $this->addRelation('ImportExportType', '\\Thelia\\Model\\ImportExportType', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', null); + $this->addRelation('Import', '\\Thelia\\Model\\Import', RelationMap::MANY_TO_ONE, array('id' => 'id', ), 'CASCADE', null); } // buildRelations() /** @@ -163,7 +163,7 @@ class ImportExportTypeI18nTableMap extends TableMap * to the cache in order to ensure that the same objects are always returned by find*() * and findPk*() calls. * - * @param \Thelia\Model\ImportExportTypeI18n $obj A \Thelia\Model\ImportExportTypeI18n object. + * @param \Thelia\Model\ImportI18n $obj A \Thelia\Model\ImportI18n object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool($obj, $key = null) @@ -184,12 +184,12 @@ class ImportExportTypeI18nTableMap extends TableMap * methods in your stub classes -- you may need to explicitly remove objects * from the cache in order to prevent returning objects that no longer exist. * - * @param mixed $value A \Thelia\Model\ImportExportTypeI18n object or a primary key value. + * @param mixed $value A \Thelia\Model\ImportI18n object or a primary key value. */ public static function removeInstanceFromPool($value) { if (Propel::isInstancePoolingEnabled() && null !== $value) { - if (is_object($value) && $value instanceof \Thelia\Model\ImportExportTypeI18n) { + if (is_object($value) && $value instanceof \Thelia\Model\ImportI18n) { $key = serialize(array((string) $value->getId(), (string) $value->getLocale())); } elseif (is_array($value) && count($value) === 2) { @@ -200,7 +200,7 @@ class ImportExportTypeI18nTableMap extends TableMap return; } else { - $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Thelia\Model\ImportExportTypeI18n object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); + $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \Thelia\Model\ImportI18n object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true))); throw $e; } @@ -260,7 +260,7 @@ class ImportExportTypeI18nTableMap extends TableMap */ public static function getOMClass($withPrefix = true) { - return $withPrefix ? ImportExportTypeI18nTableMap::CLASS_DEFAULT : ImportExportTypeI18nTableMap::OM_CLASS; + return $withPrefix ? ImportI18nTableMap::CLASS_DEFAULT : ImportI18nTableMap::OM_CLASS; } /** @@ -274,21 +274,21 @@ class ImportExportTypeI18nTableMap extends TableMap * * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. - * @return array (ImportExportTypeI18n object, last column rank) + * @return array (ImportI18n object, last column rank) */ public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) { - $key = ImportExportTypeI18nTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); - if (null !== ($obj = ImportExportTypeI18nTableMap::getInstanceFromPool($key))) { + $key = ImportI18nTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ImportI18nTableMap::getInstanceFromPool($key))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj->hydrate($row, $offset, true); // rehydrate - $col = $offset + ImportExportTypeI18nTableMap::NUM_HYDRATE_COLUMNS; + $col = $offset + ImportI18nTableMap::NUM_HYDRATE_COLUMNS; } else { - $cls = ImportExportTypeI18nTableMap::OM_CLASS; + $cls = ImportI18nTableMap::OM_CLASS; $obj = new $cls(); $col = $obj->hydrate($row, $offset, false, $indexType); - ImportExportTypeI18nTableMap::addInstanceToPool($obj, $key); + ImportI18nTableMap::addInstanceToPool($obj, $key); } return array($obj, $col); @@ -311,8 +311,8 @@ class ImportExportTypeI18nTableMap extends TableMap $cls = static::getOMClass(false); // populate the object(s) while ($row = $dataFetcher->fetch()) { - $key = ImportExportTypeI18nTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); - if (null !== ($obj = ImportExportTypeI18nTableMap::getInstanceFromPool($key))) { + $key = ImportI18nTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ImportI18nTableMap::getInstanceFromPool($key))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj->hydrate($row, 0, true); // rehydrate @@ -321,7 +321,7 @@ class ImportExportTypeI18nTableMap extends TableMap $obj = new $cls(); $obj->hydrate($row); $results[] = $obj; - ImportExportTypeI18nTableMap::addInstanceToPool($obj, $key); + ImportI18nTableMap::addInstanceToPool($obj, $key); } // if key exists } @@ -342,10 +342,10 @@ class ImportExportTypeI18nTableMap extends TableMap public static function addSelectColumns(Criteria $criteria, $alias = null) { if (null === $alias) { - $criteria->addSelectColumn(ImportExportTypeI18nTableMap::ID); - $criteria->addSelectColumn(ImportExportTypeI18nTableMap::LOCALE); - $criteria->addSelectColumn(ImportExportTypeI18nTableMap::TITLE); - $criteria->addSelectColumn(ImportExportTypeI18nTableMap::DESCRIPTION); + $criteria->addSelectColumn(ImportI18nTableMap::ID); + $criteria->addSelectColumn(ImportI18nTableMap::LOCALE); + $criteria->addSelectColumn(ImportI18nTableMap::TITLE); + $criteria->addSelectColumn(ImportI18nTableMap::DESCRIPTION); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.LOCALE'); @@ -363,7 +363,7 @@ class ImportExportTypeI18nTableMap extends TableMap */ public static function getTableMap() { - return Propel::getServiceContainer()->getDatabaseMap(ImportExportTypeI18nTableMap::DATABASE_NAME)->getTable(ImportExportTypeI18nTableMap::TABLE_NAME); + return Propel::getServiceContainer()->getDatabaseMap(ImportI18nTableMap::DATABASE_NAME)->getTable(ImportI18nTableMap::TABLE_NAME); } /** @@ -371,16 +371,16 @@ class ImportExportTypeI18nTableMap extends TableMap */ public static function buildTableMap() { - $dbMap = Propel::getServiceContainer()->getDatabaseMap(ImportExportTypeI18nTableMap::DATABASE_NAME); - if (!$dbMap->hasTable(ImportExportTypeI18nTableMap::TABLE_NAME)) { - $dbMap->addTableObject(new ImportExportTypeI18nTableMap()); + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ImportI18nTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ImportI18nTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ImportI18nTableMap()); } } /** - * Performs a DELETE on the database, given a ImportExportTypeI18n or Criteria object OR a primary key value. + * Performs a DELETE on the database, given a ImportI18n or Criteria object OR a primary key value. * - * @param mixed $values Criteria or ImportExportTypeI18n object or primary key or array of primary keys + * @param mixed $values Criteria or ImportI18n object or primary key or array of primary keys * which is used to create the DELETE statement * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows @@ -391,17 +391,17 @@ class ImportExportTypeI18nTableMap extends TableMap public static function doDelete($values, ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportI18nTableMap::DATABASE_NAME); } if ($values instanceof Criteria) { // rename for clarity $criteria = $values; - } elseif ($values instanceof \Thelia\Model\ImportExportTypeI18n) { // it's a model object + } elseif ($values instanceof \Thelia\Model\ImportI18n) { // it's a model object // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it's a primary key, or an array of pks - $criteria = new Criteria(ImportExportTypeI18nTableMap::DATABASE_NAME); + $criteria = new Criteria(ImportI18nTableMap::DATABASE_NAME); // primary key is composite; we therefore, expect // the primary key passed to be an array of pkey values if (count($values) == count($values, COUNT_RECURSIVE)) { @@ -409,17 +409,17 @@ class ImportExportTypeI18nTableMap extends TableMap $values = array($values); } foreach ($values as $value) { - $criterion = $criteria->getNewCriterion(ImportExportTypeI18nTableMap::ID, $value[0]); - $criterion->addAnd($criteria->getNewCriterion(ImportExportTypeI18nTableMap::LOCALE, $value[1])); + $criterion = $criteria->getNewCriterion(ImportI18nTableMap::ID, $value[0]); + $criterion->addAnd($criteria->getNewCriterion(ImportI18nTableMap::LOCALE, $value[1])); $criteria->addOr($criterion); } } - $query = ImportExportTypeI18nQuery::create()->mergeWith($criteria); + $query = ImportI18nQuery::create()->mergeWith($criteria); - if ($values instanceof Criteria) { ImportExportTypeI18nTableMap::clearInstancePool(); + if ($values instanceof Criteria) { ImportI18nTableMap::clearInstancePool(); } elseif (!is_object($values)) { // it's a primary key, or an array of pks - foreach ((array) $values as $singleval) { ImportExportTypeI18nTableMap::removeInstanceFromPool($singleval); + foreach ((array) $values as $singleval) { ImportI18nTableMap::removeInstanceFromPool($singleval); } } @@ -427,20 +427,20 @@ class ImportExportTypeI18nTableMap extends TableMap } /** - * Deletes all rows from the import_export_type_i18n table. + * Deletes all rows from the import_i18n table. * * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). */ public static function doDeleteAll(ConnectionInterface $con = null) { - return ImportExportTypeI18nQuery::create()->doDeleteAll($con); + return ImportI18nQuery::create()->doDeleteAll($con); } /** - * Performs an INSERT on the database, given a ImportExportTypeI18n or Criteria object. + * Performs an INSERT on the database, given a ImportI18n or Criteria object. * - * @param mixed $criteria Criteria or ImportExportTypeI18n object containing data that is used to create the INSERT statement. + * @param mixed $criteria Criteria or ImportI18n object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be @@ -449,18 +449,18 @@ class ImportExportTypeI18nTableMap extends TableMap public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeI18nTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportI18nTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { - $criteria = $criteria->buildCriteria(); // build Criteria from ImportExportTypeI18n object + $criteria = $criteria->buildCriteria(); // build Criteria from ImportI18n object } // Set the correct dbName - $query = ImportExportTypeI18nQuery::create()->mergeWith($criteria); + $query = ImportI18nQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info @@ -476,7 +476,7 @@ class ImportExportTypeI18nTableMap extends TableMap return $pk; } -} // ImportExportTypeI18nTableMap +} // ImportI18nTableMap // This is the static code needed to register the TableMap for this table with the main Propel class. // -ImportExportTypeI18nTableMap::buildTableMap(); +ImportI18nTableMap::buildTableMap(); diff --git a/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php b/core/lib/Thelia/Model/Map/ImportTableMap.php similarity index 65% rename from core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php rename to core/lib/Thelia/Model/Map/ImportTableMap.php index 5533343fd..873b4d196 100644 --- a/core/lib/Thelia/Model/Map/ImportExportTypeTableMap.php +++ b/core/lib/Thelia/Model/Map/ImportTableMap.php @@ -11,12 +11,12 @@ use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Map\RelationMap; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Map\TableMapTrait; -use Thelia\Model\ImportExportType; -use Thelia\Model\ImportExportTypeQuery; +use Thelia\Model\Import; +use Thelia\Model\ImportQuery; /** - * This class defines the structure of the 'import_export_type' table. + * This class defines the structure of the 'import' table. * * * @@ -26,14 +26,14 @@ use Thelia\Model\ImportExportTypeQuery; * (i.e. if it's a text column type). * */ -class ImportExportTypeTableMap extends TableMap +class ImportTableMap extends TableMap { use InstancePoolTrait; use TableMapTrait; /** * The (dot-path) name of this class */ - const CLASS_NAME = 'Thelia.Model.Map.ImportExportTypeTableMap'; + const CLASS_NAME = 'Thelia.Model.Map.ImportTableMap'; /** * The default database name for this class @@ -43,22 +43,22 @@ class ImportExportTypeTableMap extends TableMap /** * The table name for this class */ - const TABLE_NAME = 'import_export_type'; + const TABLE_NAME = 'import'; /** * The related Propel class for this table */ - const OM_CLASS = '\\Thelia\\Model\\ImportExportType'; + const OM_CLASS = '\\Thelia\\Model\\Import'; /** * A class that can be returned by this tableMap */ - const CLASS_DEFAULT = 'Thelia.Model.ImportExportType'; + const CLASS_DEFAULT = 'Thelia.Model.Import'; /** * The total number of columns */ - const NUM_COLUMNS = 6; + const NUM_COLUMNS = 5; /** * The number of lazy-loaded columns @@ -68,37 +68,32 @@ class ImportExportTypeTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 6; + const NUM_HYDRATE_COLUMNS = 5; /** * the column name for the ID field */ - const ID = 'import_export_type.ID'; + const ID = 'import.ID'; /** - * the column name for the URL_ACTION field + * the column name for the IMPORT_CATEGORY_ID field */ - const URL_ACTION = 'import_export_type.URL_ACTION'; - - /** - * the column name for the IMPORT_EXPORT_CATEGORY_ID field - */ - const IMPORT_EXPORT_CATEGORY_ID = 'import_export_type.IMPORT_EXPORT_CATEGORY_ID'; + const IMPORT_CATEGORY_ID = 'import.IMPORT_CATEGORY_ID'; /** * the column name for the POSITION field */ - const POSITION = 'import_export_type.POSITION'; + const POSITION = 'import.POSITION'; /** * the column name for the CREATED_AT field */ - const CREATED_AT = 'import_export_type.CREATED_AT'; + const CREATED_AT = 'import.CREATED_AT'; /** * the column name for the UPDATED_AT field */ - const UPDATED_AT = 'import_export_type.UPDATED_AT'; + const UPDATED_AT = 'import.UPDATED_AT'; /** * The default string format for model objects of the related table @@ -121,12 +116,12 @@ class ImportExportTypeTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'UrlAction', 'ImportExportCategoryId', 'Position', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'urlAction', 'importExportCategoryId', 'position', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(ImportExportTypeTableMap::ID, ImportExportTypeTableMap::URL_ACTION, ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID, ImportExportTypeTableMap::POSITION, ImportExportTypeTableMap::CREATED_AT, ImportExportTypeTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'URL_ACTION', 'IMPORT_EXPORT_CATEGORY_ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'url_action', 'import_export_category_id', 'position', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) + self::TYPE_PHPNAME => array('Id', 'ImportCategoryId', 'Position', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'importCategoryId', 'position', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(ImportTableMap::ID, ImportTableMap::IMPORT_CATEGORY_ID, ImportTableMap::POSITION, ImportTableMap::CREATED_AT, ImportTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'IMPORT_CATEGORY_ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'import_category_id', 'position', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, ) ); /** @@ -136,12 +131,12 @@ class ImportExportTypeTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'UrlAction' => 1, 'ImportExportCategoryId' => 2, 'Position' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'urlAction' => 1, 'importExportCategoryId' => 2, 'position' => 3, 'createdAt' => 4, 'updatedAt' => 5, ), - self::TYPE_COLNAME => array(ImportExportTypeTableMap::ID => 0, ImportExportTypeTableMap::URL_ACTION => 1, ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID => 2, ImportExportTypeTableMap::POSITION => 3, ImportExportTypeTableMap::CREATED_AT => 4, ImportExportTypeTableMap::UPDATED_AT => 5, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'URL_ACTION' => 1, 'IMPORT_EXPORT_CATEGORY_ID' => 2, 'POSITION' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ), - self::TYPE_FIELDNAME => array('id' => 0, 'url_action' => 1, 'import_export_category_id' => 2, 'position' => 3, 'created_at' => 4, 'updated_at' => 5, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) + self::TYPE_PHPNAME => array('Id' => 0, 'ImportCategoryId' => 1, 'Position' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'importCategoryId' => 1, 'position' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), + self::TYPE_COLNAME => array(ImportTableMap::ID => 0, ImportTableMap::IMPORT_CATEGORY_ID => 1, ImportTableMap::POSITION => 2, ImportTableMap::CREATED_AT => 3, ImportTableMap::UPDATED_AT => 4, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'IMPORT_CATEGORY_ID' => 1, 'POSITION' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), + self::TYPE_FIELDNAME => array('id' => 0, 'import_category_id' => 1, 'position' => 2, 'created_at' => 3, 'updated_at' => 4, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, ) ); /** @@ -154,15 +149,14 @@ class ImportExportTypeTableMap extends TableMap public function initialize() { // attributes - $this->setName('import_export_type'); - $this->setPhpName('ImportExportType'); - $this->setClassName('\\Thelia\\Model\\ImportExportType'); + $this->setName('import'); + $this->setPhpName('Import'); + $this->setClassName('\\Thelia\\Model\\Import'); $this->setPackage('Thelia.Model'); $this->setUseIdGenerator(true); // columns $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); - $this->addColumn('URL_ACTION', 'UrlAction', 'VARCHAR', true, 255, null); - $this->addForeignKey('IMPORT_EXPORT_CATEGORY_ID', 'ImportExportCategoryId', 'INTEGER', 'import_export_category', 'ID', true, null, null); + $this->addForeignKey('IMPORT_CATEGORY_ID', 'ImportCategoryId', 'INTEGER', 'import_category', 'ID', true, null, null); $this->addColumn('POSITION', 'Position', 'INTEGER', true, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); @@ -173,8 +167,8 @@ class ImportExportTypeTableMap extends TableMap */ public function buildRelations() { - $this->addRelation('ImportExportCategory', '\\Thelia\\Model\\ImportExportCategory', RelationMap::MANY_TO_ONE, array('import_export_category_id' => 'id', ), 'CASCADE', 'RESTRICT'); - $this->addRelation('ImportExportTypeI18n', '\\Thelia\\Model\\ImportExportTypeI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ImportExportTypeI18ns'); + $this->addRelation('ImportCategory', '\\Thelia\\Model\\ImportCategory', RelationMap::MANY_TO_ONE, array('import_category_id' => 'id', ), 'CASCADE', 'RESTRICT'); + $this->addRelation('ImportI18n', '\\Thelia\\Model\\ImportI18n', RelationMap::ONE_TO_MANY, array('id' => 'id', ), 'CASCADE', null, 'ImportI18ns'); } // buildRelations() /** @@ -191,13 +185,13 @@ class ImportExportTypeTableMap extends TableMap ); } // getBehaviors() /** - * Method to invalidate the instance pool of all tables related to import_export_type * by a foreign key with ON DELETE CASCADE + * Method to invalidate the instance pool of all tables related to import * by a foreign key with ON DELETE CASCADE */ public static function clearRelatedInstancePool() { // Invalidate objects in ".$this->getClassNameFromBuilder($joinedTableTableMapBuilder)." instance pool, // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. - ImportExportTypeI18nTableMap::clearInstancePool(); + ImportI18nTableMap::clearInstancePool(); } /** @@ -256,7 +250,7 @@ class ImportExportTypeTableMap extends TableMap */ public static function getOMClass($withPrefix = true) { - return $withPrefix ? ImportExportTypeTableMap::CLASS_DEFAULT : ImportExportTypeTableMap::OM_CLASS; + return $withPrefix ? ImportTableMap::CLASS_DEFAULT : ImportTableMap::OM_CLASS; } /** @@ -270,21 +264,21 @@ class ImportExportTypeTableMap extends TableMap * * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. - * @return array (ImportExportType object, last column rank) + * @return array (Import object, last column rank) */ public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) { - $key = ImportExportTypeTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); - if (null !== ($obj = ImportExportTypeTableMap::getInstanceFromPool($key))) { + $key = ImportTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = ImportTableMap::getInstanceFromPool($key))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj->hydrate($row, $offset, true); // rehydrate - $col = $offset + ImportExportTypeTableMap::NUM_HYDRATE_COLUMNS; + $col = $offset + ImportTableMap::NUM_HYDRATE_COLUMNS; } else { - $cls = ImportExportTypeTableMap::OM_CLASS; + $cls = ImportTableMap::OM_CLASS; $obj = new $cls(); $col = $obj->hydrate($row, $offset, false, $indexType); - ImportExportTypeTableMap::addInstanceToPool($obj, $key); + ImportTableMap::addInstanceToPool($obj, $key); } return array($obj, $col); @@ -307,8 +301,8 @@ class ImportExportTypeTableMap extends TableMap $cls = static::getOMClass(false); // populate the object(s) while ($row = $dataFetcher->fetch()) { - $key = ImportExportTypeTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); - if (null !== ($obj = ImportExportTypeTableMap::getInstanceFromPool($key))) { + $key = ImportTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = ImportTableMap::getInstanceFromPool($key))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj->hydrate($row, 0, true); // rehydrate @@ -317,7 +311,7 @@ class ImportExportTypeTableMap extends TableMap $obj = new $cls(); $obj->hydrate($row); $results[] = $obj; - ImportExportTypeTableMap::addInstanceToPool($obj, $key); + ImportTableMap::addInstanceToPool($obj, $key); } // if key exists } @@ -338,16 +332,14 @@ class ImportExportTypeTableMap extends TableMap public static function addSelectColumns(Criteria $criteria, $alias = null) { if (null === $alias) { - $criteria->addSelectColumn(ImportExportTypeTableMap::ID); - $criteria->addSelectColumn(ImportExportTypeTableMap::URL_ACTION); - $criteria->addSelectColumn(ImportExportTypeTableMap::IMPORT_EXPORT_CATEGORY_ID); - $criteria->addSelectColumn(ImportExportTypeTableMap::POSITION); - $criteria->addSelectColumn(ImportExportTypeTableMap::CREATED_AT); - $criteria->addSelectColumn(ImportExportTypeTableMap::UPDATED_AT); + $criteria->addSelectColumn(ImportTableMap::ID); + $criteria->addSelectColumn(ImportTableMap::IMPORT_CATEGORY_ID); + $criteria->addSelectColumn(ImportTableMap::POSITION); + $criteria->addSelectColumn(ImportTableMap::CREATED_AT); + $criteria->addSelectColumn(ImportTableMap::UPDATED_AT); } else { $criteria->addSelectColumn($alias . '.ID'); - $criteria->addSelectColumn($alias . '.URL_ACTION'); - $criteria->addSelectColumn($alias . '.IMPORT_EXPORT_CATEGORY_ID'); + $criteria->addSelectColumn($alias . '.IMPORT_CATEGORY_ID'); $criteria->addSelectColumn($alias . '.POSITION'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); @@ -363,7 +355,7 @@ class ImportExportTypeTableMap extends TableMap */ public static function getTableMap() { - return Propel::getServiceContainer()->getDatabaseMap(ImportExportTypeTableMap::DATABASE_NAME)->getTable(ImportExportTypeTableMap::TABLE_NAME); + return Propel::getServiceContainer()->getDatabaseMap(ImportTableMap::DATABASE_NAME)->getTable(ImportTableMap::TABLE_NAME); } /** @@ -371,16 +363,16 @@ class ImportExportTypeTableMap extends TableMap */ public static function buildTableMap() { - $dbMap = Propel::getServiceContainer()->getDatabaseMap(ImportExportTypeTableMap::DATABASE_NAME); - if (!$dbMap->hasTable(ImportExportTypeTableMap::TABLE_NAME)) { - $dbMap->addTableObject(new ImportExportTypeTableMap()); + $dbMap = Propel::getServiceContainer()->getDatabaseMap(ImportTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(ImportTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new ImportTableMap()); } } /** - * Performs a DELETE on the database, given a ImportExportType or Criteria object OR a primary key value. + * Performs a DELETE on the database, given a Import or Criteria object OR a primary key value. * - * @param mixed $values Criteria or ImportExportType object or primary key or array of primary keys + * @param mixed $values Criteria or Import object or primary key or array of primary keys * which is used to create the DELETE statement * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows @@ -391,25 +383,25 @@ class ImportExportTypeTableMap extends TableMap public static function doDelete($values, ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportTableMap::DATABASE_NAME); } if ($values instanceof Criteria) { // rename for clarity $criteria = $values; - } elseif ($values instanceof \Thelia\Model\ImportExportType) { // it's a model object + } elseif ($values instanceof \Thelia\Model\Import) { // it's a model object // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it's a primary key, or an array of pks - $criteria = new Criteria(ImportExportTypeTableMap::DATABASE_NAME); - $criteria->add(ImportExportTypeTableMap::ID, (array) $values, Criteria::IN); + $criteria = new Criteria(ImportTableMap::DATABASE_NAME); + $criteria->add(ImportTableMap::ID, (array) $values, Criteria::IN); } - $query = ImportExportTypeQuery::create()->mergeWith($criteria); + $query = ImportQuery::create()->mergeWith($criteria); - if ($values instanceof Criteria) { ImportExportTypeTableMap::clearInstancePool(); + if ($values instanceof Criteria) { ImportTableMap::clearInstancePool(); } elseif (!is_object($values)) { // it's a primary key, or an array of pks - foreach ((array) $values as $singleval) { ImportExportTypeTableMap::removeInstanceFromPool($singleval); + foreach ((array) $values as $singleval) { ImportTableMap::removeInstanceFromPool($singleval); } } @@ -417,20 +409,20 @@ class ImportExportTypeTableMap extends TableMap } /** - * Deletes all rows from the import_export_type table. + * Deletes all rows from the import table. * * @param ConnectionInterface $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). */ public static function doDeleteAll(ConnectionInterface $con = null) { - return ImportExportTypeQuery::create()->doDeleteAll($con); + return ImportQuery::create()->doDeleteAll($con); } /** - * Performs an INSERT on the database, given a ImportExportType or Criteria object. + * Performs an INSERT on the database, given a Import or Criteria object. * - * @param mixed $criteria Criteria or ImportExportType object containing data that is used to create the INSERT statement. + * @param mixed $criteria Criteria or Import object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be @@ -439,22 +431,22 @@ class ImportExportTypeTableMap extends TableMap public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(ImportExportTypeTableMap::DATABASE_NAME); + $con = Propel::getServiceContainer()->getWriteConnection(ImportTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { - $criteria = $criteria->buildCriteria(); // build Criteria from ImportExportType object + $criteria = $criteria->buildCriteria(); // build Criteria from Import object } - if ($criteria->containsKey(ImportExportTypeTableMap::ID) && $criteria->keyContainsValue(ImportExportTypeTableMap::ID) ) { - throw new PropelException('Cannot insert a value for auto-increment primary key ('.ImportExportTypeTableMap::ID.')'); + if ($criteria->containsKey(ImportTableMap::ID) && $criteria->keyContainsValue(ImportTableMap::ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.ImportTableMap::ID.')'); } // Set the correct dbName - $query = ImportExportTypeQuery::create()->mergeWith($criteria); + $query = ImportQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info @@ -470,7 +462,7 @@ class ImportExportTypeTableMap extends TableMap return $pk; } -} // ImportExportTypeTableMap +} // ImportTableMap // This is the static code needed to register the TableMap for this table with the main Propel class. // -ImportExportTypeTableMap::buildTableMap(); +ImportTableMap::buildTableMap(); diff --git a/local/config/schema.xml b/local/config/schema.xml index 0738419ee..a62929ec3 100644 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1512,7 +1512,7 @@ - +
@@ -1521,18 +1521,43 @@
- +
+ + + + + + + +
+ - - + - - + + - - + + + + + + + +
+ + + + + + + + + + + diff --git a/setup/thelia.sql b/setup/thelia.sql index d5d300552..c5fa24f45 100644 --- a/setup/thelia.sql +++ b/setup/thelia.sql @@ -1874,12 +1874,12 @@ CREATE TABLE `form_firewall` ) ENGINE=InnoDB; -- --------------------------------------------------------------------- --- import_export_category +-- import_category -- --------------------------------------------------------------------- -DROP TABLE IF EXISTS `import_export_category`; +DROP TABLE IF EXISTS `import_category`; -CREATE TABLE `import_export_category` +CREATE TABLE `import_category` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `position` INTEGER NOT NULL, @@ -1889,24 +1889,60 @@ CREATE TABLE `import_export_category` ) ENGINE=InnoDB; -- --------------------------------------------------------------------- --- import_export_type +-- export_category -- --------------------------------------------------------------------- -DROP TABLE IF EXISTS `import_export_type`; +DROP TABLE IF EXISTS `export_category`; -CREATE TABLE `import_export_type` +CREATE TABLE `export_category` ( `id` INTEGER NOT NULL AUTO_INCREMENT, - `url_action` VARCHAR(255) NOT NULL, - `import_export_category_id` INTEGER NOT NULL, + `position` INTEGER NOT NULL, + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`) +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- import +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `import`; + +CREATE TABLE `import` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `import_category_id` INTEGER NOT NULL, `position` INTEGER NOT NULL, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), - INDEX `idx_import_export_type_import_export_category_id` (`import_export_category_id`), - CONSTRAINT `fk_import_export_type_import_export_category_id` - FOREIGN KEY (`import_export_category_id`) - REFERENCES `import_export_category` (`id`) + INDEX `idx_import_import_category_id` (`import_category_id`), + CONSTRAINT `fk_import_import_category_id` + FOREIGN KEY (`import_category_id`) + REFERENCES `import_category` (`id`) + ON UPDATE RESTRICT + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- export +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `export`; + +CREATE TABLE `export` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `export_category_id` INTEGER NOT NULL, + `position` INTEGER NOT NULL, + `created_at` DATETIME, + `updated_at` DATETIME, + PRIMARY KEY (`id`), + INDEX `idx_export_export_category_id` (`export_category_id`), + CONSTRAINT `fk_export_export_category_id` + FOREIGN KEY (`export_category_id`) + REFERENCES `export_category` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE ) ENGINE=InnoDB; @@ -2607,39 +2643,76 @@ CREATE TABLE `brand_image_i18n` ) ENGINE=InnoDB; -- --------------------------------------------------------------------- --- import_export_category_i18n +-- import_category_i18n -- --------------------------------------------------------------------- -DROP TABLE IF EXISTS `import_export_category_i18n`; +DROP TABLE IF EXISTS `import_category_i18n`; -CREATE TABLE `import_export_category_i18n` +CREATE TABLE `import_category_i18n` ( `id` INTEGER NOT NULL, `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, `title` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`,`locale`), - CONSTRAINT `import_export_category_i18n_FK_1` + CONSTRAINT `import_category_i18n_FK_1` FOREIGN KEY (`id`) - REFERENCES `import_export_category` (`id`) + REFERENCES `import_category` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB; -- --------------------------------------------------------------------- --- import_export_type_i18n +-- export_category_i18n -- --------------------------------------------------------------------- -DROP TABLE IF EXISTS `import_export_type_i18n`; +DROP TABLE IF EXISTS `export_category_i18n`; -CREATE TABLE `import_export_type_i18n` +CREATE TABLE `export_category_i18n` +( + `id` INTEGER NOT NULL, + `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, + `title` VARCHAR(255) NOT NULL, + PRIMARY KEY (`id`,`locale`), + CONSTRAINT `export_category_i18n_FK_1` + FOREIGN KEY (`id`) + REFERENCES `export_category` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- import_i18n +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `import_i18n`; + +CREATE TABLE `import_i18n` ( `id` INTEGER NOT NULL, `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, `title` VARCHAR(255) NOT NULL, `description` LONGTEXT, PRIMARY KEY (`id`,`locale`), - CONSTRAINT `import_export_type_i18n_FK_1` + CONSTRAINT `import_i18n_FK_1` FOREIGN KEY (`id`) - REFERENCES `import_export_type` (`id`) + REFERENCES `import` (`id`) + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- export_i18n +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `export_i18n`; + +CREATE TABLE `export_i18n` +( + `id` INTEGER NOT NULL, + `locale` VARCHAR(5) DEFAULT 'en_US' NOT NULL, + `title` VARCHAR(255) NOT NULL, + `description` LONGTEXT, + PRIMARY KEY (`id`,`locale`), + CONSTRAINT `export_i18n_FK_1` + FOREIGN KEY (`id`) + REFERENCES `export` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB; diff --git a/templates/backOffice/default/export.html b/templates/backOffice/default/export.html index 6cafbd178..e1a1b0b87 100644 --- a/templates/backOffice/default/export.html +++ b/templates/backOffice/default/export.html @@ -27,7 +27,7 @@ {module_include location='tools_top'} - {loop name="import-export-category" type="import-export-category"} + {loop name="export-category" type="export-category"} {if $LOOP_COUNT % 3}
{/if} @@ -51,9 +51,11 @@
- - - + {loop name="export-categ-list" type="export" category=$ID} + + + + {/loop}
n
{$TITLE}
From 7727c14440bf29a2f8af82671832ca454771b745 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 10 Jul 2014 11:19:49 +0200 Subject: [PATCH 051/158] =?UTF-8?q?Refactor=20services=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Config/Resources/con?= =?UTF-8?q?fig.xml=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/T?= =?UTF-8?q?helia/Model/Country.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Model/Currency.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Tools/URL.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/config.xml | 66 +++------------------ core/lib/Thelia/Tools/URL.php | 8 --- 2 files changed, 7 insertions(+), 67 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 0013941be..9b9d7df13 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -108,10 +108,6 @@ %kernel.debug%
-<<<<<<< HEAD -======= - ->>>>>>> Readd services %file_model.classes% @@ -141,11 +137,6 @@ -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> Readd services @@ -154,69 +145,27 @@ - - - - - - - - - - - - - - - - - - - - -<<<<<<< HEAD - -<<<<<<< HEAD -<<<<<<< HEAD - ->>>>>>> Add archive builder manager and formatter manager services - - - - - %kernel.environment% - - - - + - - + + - - + + - - + + - -======= - ->>>>>>> Fix services -======= - ->>>>>>> Readd services -======= @@ -226,6 +175,5 @@ ->>>>>>> Begin import export management diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 8ef2b4b31..ab52472e6 100644 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -315,15 +315,7 @@ class URL $clean; } -<<<<<<< HEAD -<<<<<<< HEAD public static function checkUrl($url, array $protocols = ["http", "https"]) -======= - public function checkUrl($url, array $protocols = ["http", "https"]) ->>>>>>> Define archive builders and formatters -======= - public static function checkUrl($url, array $protocols = ["http", "https"]) ->>>>>>> Fix FileDownloader test { $pattern = sprintf(UrlValidator::PATTERN, implode('|', $protocols)); From fa7b02c9c9e4d1516a36fc932969a3220e6f42c2 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 10 Jul 2014 13:32:48 +0200 Subject: [PATCH 052/158] =?UTF-8?q?Export=20positions=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Config/Resources/rou?= =?UTF-8?q?ting/admin.xml=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20cor?= =?UTF-8?q?e/lib/Thelia/Controller/Admin/ExportController.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Controller/Ad?= =?UTF-8?q?min/ImportExportController.php=20=09modifi=C3=A9:=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20core/lib/Thelia/Core/Template/Loop/ImportExportT?= =?UTF-8?q?ype.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/T?= =?UTF-8?q?helia/Model/Export.php=20=09nouveau=20fichier:=20templates/back?= =?UTF-8?q?Office/default/export-page.html=20=09modifi=C3=A9:=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20templates/backOffice/default/export.html=20=09no?= =?UTF-8?q?uveau=20fichier:=20templates/backOffice/default/import-page.htm?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Thelia/Config/Resources/routing/admin.xml | 40 +++++++++-- .../Controller/Admin/ExportController.php | 67 ++++++++++++++++++- .../Admin/ImportExportController.php | 11 +++ .../Core/Template/Loop/ImportExportType.php | 15 +++-- core/lib/Thelia/Model/Export.php | 63 +++++++++++++++++ templates/backOffice/default/export-page.html | 0 templates/backOffice/default/export.html | 33 +++++++-- templates/backOffice/default/import-page.html | 0 8 files changed, 212 insertions(+), 17 deletions(-) create mode 100644 templates/backOffice/default/export-page.html create mode 100644 templates/backOffice/default/import-page.html diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 31823709f..52d4d6ca3 100644 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -1160,16 +1160,44 @@ - - Thelia\Controller\Admin\ImportExportController::export - \d+ + + Thelia\Controller\Admin\ExportController::indexAction - - Thelia\Controller\Admin\ImportExportController::import - \d+ + + Thelia\Controller\Admin\ExportController::changePosition + up|down + \d+ + + Thelia\Controller\Admin\ExportController::updatePosition + \d+ + \d+ + + + + Thelia\Controller\Admin\ImportExportController::export + \d+ + + + + Thelia\Controller\Admin\ImportExportController::exportView + \d+ + + + + Thelia\Controller\Admin\ImportExportController::import + \d+ + + + + Thelia\Controller\Admin\ImportExportController::importView + \d+ + + + + diff --git a/core/lib/Thelia/Controller/Admin/ExportController.php b/core/lib/Thelia/Controller/Admin/ExportController.php index 90c79dc23..69832b9e8 100644 --- a/core/lib/Thelia/Controller/Admin/ExportController.php +++ b/core/lib/Thelia/Controller/Admin/ExportController.php @@ -14,6 +14,9 @@ namespace Thelia\Controller\Admin; use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\Resource\AdminResources; +use Thelia\Core\Template\Loop\ImportExportType; +use Thelia\Core\Translation\Translator; +use Thelia\Model\ExportQuery; /** * Class ExportController @@ -22,18 +25,78 @@ use Thelia\Core\Security\Resource\AdminResources; */ class ExportController extends BaseAdminController { - public function indexAction() { if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::VIEW])) { return $response; } + $export_order = $this->getRequest()->query->get("export_order"); + + if (!in_array($export_order, ImportExportType::getAllowedOrders())) { + $export_order = ImportExportType::DEFAULT_ORDER; + } + + $this->getParserContext() + ->set("export_order", $export_order) + ; + return $this->render('export'); } - public function export($exportType) + public function changePosition($action, $id) { + if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::UPDATE])) { + return $response; + } + $export = $this->getExport($id); + + if ($action === "up") { + $export->upPosition(); + } elseif ($action === "down") { + $export->downPosition(); + } + + $this->getParserContext() + ->set("export_order", "manual") + ; + + return $this->render('export'); + } + + public function updatePosition($id, $value) + { + if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::UPDATE])) { + return $response; + } + + $export = $this->getExport($id); + + $export->updatePosition($value); + + $this->getParserContext() + ->set("export_order", "manual") + ; + + return $this->render('export'); + } + + + protected function getExport($id) + { + $export = ExportQuery::create()->findPk($id); + + if (null === $export) { + throw new \ErrorException( + Translator::getInstance()->trans( + "There is no id \"%id\" in the exports", + [ + "%id" => $id + ] + ) + ); + } + return $export; } } diff --git a/core/lib/Thelia/Controller/Admin/ImportExportController.php b/core/lib/Thelia/Controller/Admin/ImportExportController.php index 4e35fa0bf..4226ef0e4 100644 --- a/core/lib/Thelia/Controller/Admin/ImportExportController.php +++ b/core/lib/Thelia/Controller/Admin/ImportExportController.php @@ -11,6 +11,7 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\HttpFoundation\Response; /** * Class ImportExportController @@ -28,4 +29,14 @@ class ImportExportController extends BaseAdminController { } + + public function importView() + { + return $this->render("import-page"); + } + + public function exportView() + { + return $this->render("export-page"); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/ImportExportType.php b/core/lib/Thelia/Core/Template/Loop/ImportExportType.php index ae02e6854..13ecf422d 100644 --- a/core/lib/Thelia/Core/Template/Loop/ImportExportType.php +++ b/core/lib/Thelia/Core/Template/Loop/ImportExportType.php @@ -29,6 +29,8 @@ use Thelia\Type\TypeCollection; */ abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInterface { + const DEFAULT_ORDER = "manual"; + protected $timestampable = true; /** @@ -49,9 +51,9 @@ abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInte ->set("ID", $type->getId()) ->set("TITLE", $type->getTitle()) ->set("DESCRIPTION", $type->getDescription()) - ->set("URL", $type->isImport() ? $url : null) + ->set("URL", $url) ->set("POSITION", $type->getPosition()) - ->set("CATEGORY_ID", $type->getImportExportCategoryId()) + ->set("CATEGORY_ID", $type->getByName($this->getCategoryName())) ; $loopResult->addRow($loopResultRow); @@ -137,13 +139,18 @@ abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInte new Argument( "order", new TypeCollection( - new EnumListType(["id", "id_reverse", "alpha", "alpha_reverse", "manual", "manual_reverse"]) + new EnumListType(static::getAllowedOrders()) ), - "manual" + static::DEFAULT_ORDER ) ); } + public static function getAllowedOrders() + { + return ["id", "id_reverse", "alpha", "alpha_reverse", "manual", "manual_reverse"]; + } + abstract protected function getBaseUrl(); abstract protected function getQueryModel(); diff --git a/core/lib/Thelia/Model/Export.php b/core/lib/Thelia/Model/Export.php index 1f1d5e100..1abef0932 100644 --- a/core/lib/Thelia/Model/Export.php +++ b/core/lib/Thelia/Model/Export.php @@ -2,9 +2,72 @@ namespace Thelia\Model; +use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Model\Base\Export as BaseExport; +use Thelia\Model\Map\ExportTableMap; class Export extends BaseExport { + public function upPosition() + { + if (($position = $this->getPosition()) > 1) { + $previous = ExportQuery::create() + ->filterByPosition($position - 1) + ->findOneByExportCategoryId($this->getExportCategoryId()); + + if (null !== $previous) { + $previous->setPosition($position)->save(); + } + + $this->setPosition($position - 1)->save(); + } + + return $this; + } + + public function downPosition() + { + $max = ExportQuery::create() + ->orderByPosition(Criteria::DESC) + ->select(ExportTableMap::POSITION) + ->findOne() + ; + + $count = $this->getExportCategory()->countExports(); + + if ($count > $max) { + $max = $count; + } + + $position = $this->getPosition(); + + if ($position < $max) { + + $next = ExportQuery::create() + ->filterByPosition($position + 1) + ->findOneByExportCategoryId($this->getExportCategoryId()); + + if (null !== $next) { + $next->setPosition($position)->save(); + } + + $this->setPosition($position + 1)->save(); + } + + return $this; + } + + public function updatePosition($position) + { + $reverse = ExportQuery::create() + ->findOneByPosition($position) + ; + + if (null !== $reverse) { + $reverse->setPosition($this->getPosition())->save(); + } + + $this->setPosition($position)->save(); + } } diff --git a/templates/backOffice/default/export-page.html b/templates/backOffice/default/export-page.html new file mode 100644 index 000000000..e69de29bb diff --git a/templates/backOffice/default/export.html b/templates/backOffice/default/export.html index e1a1b0b87..889e74449 100644 --- a/templates/backOffice/default/export.html +++ b/templates/backOffice/default/export.html @@ -42,18 +42,41 @@ - - {intl l="Name"} + + + {intl l="ID"} + + + + + {intl l="Name"} + - {intl l="Position"} + + {intl l="Position"} + - {loop name="export-categ-list" type="export" category=$ID} + {loop name="export-categ-list" type="export" order=$export_order category=$ID} - {$TITLE} + + {$ID} + + + {$TITLE} + + + + + + {$POSITION} + + + + {/loop} diff --git a/templates/backOffice/default/import-page.html b/templates/backOffice/default/import-page.html new file mode 100644 index 000000000..e69de29bb From 45bb5a7bfb7fe507db414902996d2e1066ef417d Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 10 Jul 2014 14:04:26 +0200 Subject: [PATCH 053/158] =?UTF-8?q?Revert=20files=20=09modifi=C3=A9:=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Ab?= =?UTF-8?q?stractArchiveBuilder.php=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder?= =?UTF-8?q?/Exception/TarArchiveException.php=20=09supprim=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveB?= =?UTF-8?q?uilder/Exception/ZipArchiveException.php~HEAD=20=09modifi=C3=A9?= =?UTF-8?q?:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Arc?= =?UTF-8?q?hive/ArchiveBuilder/TarArchiveBuilder.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive?= =?UTF-8?q?/ArchiveBuilder/TarBz2ArchiveBuilder.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive?= =?UTF-8?q?/ArchiveBuilder/TarGzArchiveBuilder.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive?= =?UTF-8?q?/ArchiveBuilder/ZipArchiveBuilder.php=20=09modifi=C3=A9:=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Archive/Ar?= =?UTF-8?q?chiveBuilderInterface.php=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder?= =?UTF-8?q?Manager.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/l?= =?UTF-8?q?ib/Thelia/Core/FileFormat/FormatInterface.php=20=09modifi=C3=A9?= =?UTF-8?q?:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/For?= =?UTF-8?q?matting/AbstractFormatter.php=20=09nouveau=20fichier:=20core/li?= =?UTF-8?q?b/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php?= =?UTF-8?q?=20=09nouveau=20fichier:=20core/lib/Thelia/Core/FileFormat/Form?= =?UTF-8?q?atting/Formatter/XMLFormatter.php=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatting/Fo?= =?UTF-8?q?rmatterData.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20co?= =?UTF-8?q?re/lib/Thelia/Tests/Action/FolderTest.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFormat/Archiv?= =?UTF-8?q?e/ArchiveBuilder/TarArchiveBuilderTest.php=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFormat/Arc?= =?UTF-8?q?hive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/FileFor?= =?UTF-8?q?mat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php=20=09mod?= =?UTF-8?q?ifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/File?= =?UTF-8?q?Format/Archive/ArchiveBuilder/TestResources/bad=5Fformatted.tar?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/T?= =?UTF-8?q?ests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.ph?= =?UTF-8?q?p=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/?= =?UTF-8?q?Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php=20=09nou?= =?UTF-8?q?veau=20fichier:=20core/lib/Thelia/Tests/FileFormat/Formatting/F?= =?UTF-8?q?ormatter/XMLFormatterTest.php=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Tests/FileFormat/Formatting/Formatt?= =?UTF-8?q?erDataTest.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20cor?= =?UTF-8?q?e/lib/Thelia/Tests/Tools/FakeFileDownloader.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/Tools/F?= =?UTF-8?q?ileDownloaderTest.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Tools/FileDownload/FileDownloader.php=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tool?= =?UTF-8?q?s/FileDownload/FileDownloaderAwareTrait.php=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tools/FileDownload/F?= =?UTF-8?q?ileDownloaderInterface.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Archive/AbstractArchiveBuilder.php | 79 -- .../Exception/TarArchiveException.php | 8 - .../Exception/ZipArchiveException.php~HEAD | 23 - .../ArchiveBuilder/TarArchiveBuilder.php | 400 ---------- .../ArchiveBuilder/TarBz2ArchiveBuilder.php | 8 - .../ArchiveBuilder/TarGzArchiveBuilder.php | 8 - .../ArchiveBuilder/ZipArchiveBuilder.php | 695 ------------------ .../Archive/ArchiveBuilderInterface.php | 139 ---- .../Archive/ArchiveBuilderManager.php | 116 --- .../Core/FileFormat/FormatInterface.php | 8 - .../Formatting/AbstractFormatter.php | 7 - .../Formatting/Formatter/JsonFormatter.php | 90 +++ .../Formatting/Formatter/XMLFormatter.php | 144 ++++ .../FileFormat/Formatting/FormatterData.php | 21 - .../ArchiveBuilder/TarArchiveBuilderTest.php | 239 ------ .../TarBz2ArchiveBuilderTest.php | 8 - .../TarGzArchiveBuilderTest.php | 15 - .../TestResources/bad_formatted.tar | 2 - .../ArchiveBuilder/ZipArchiveBuilderTest.php | 313 -------- .../Archive/ArchiveBuilderManagerTest.php | 8 - .../Formatting/Formatter/XMLFormatterTest.php | 178 +++++ .../Formatting/FormatterDataTest.php | 3 - .../Thelia/Tests/Tools/FakeFileDownloader.php | 21 - .../Thelia/Tests/Tools/FileDownloaderTest.php | 16 - .../Tools/FileDownload/FileDownloader.php | 33 - .../FileDownload/FileDownloaderAwareTrait.php | 16 - .../FileDownload/FileDownloaderInterface.php | 25 - 27 files changed, 412 insertions(+), 2211 deletions(-) delete mode 100644 core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php~HEAD create mode 100644 core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php create mode 100644 core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php create mode 100644 core/lib/Thelia/Tests/FileFormat/Formatting/Formatter/XMLFormatterTest.php diff --git a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php index 18b06931c..e873d74ef 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php @@ -12,18 +12,10 @@ 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; /** @@ -34,25 +26,12 @@ use Thelia\Tools\FileDownload\FileDownloaderAwareTrait; abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilderInterface { use FileDownloaderAwareTrait; -<<<<<<< HEAD -<<<<<<< HEAD const TEMP_DIRECTORY_NAME = "archive_builder"; /** @var string */ protected $cacheFile; -======= - - const TEMP_DIRECTORY_NAME = "archive_builder"; - -<<<<<<< HEAD ->>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources -======= - /** @var string */ - protected $cacheFile; - ->>>>>>> Finish implementing and testing zip /** @var \Thelia\Core\Translation\Translator */ protected $translator; @@ -62,18 +41,9 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder /** @var string */ protected $cacheDir; -<<<<<<< HEAD -<<<<<<< HEAD /** @var string */ protected $environment; -======= ->>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources -======= - /** @var string */ - protected $environment; - ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests public function __construct() { $this->translator = Translator::getInstance(); @@ -96,15 +66,7 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder ); } -<<<<<<< HEAD -<<<<<<< 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 -======= - $archiveBuilderCacheDir = $this->cacheDir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; ->>>>>>> Finish implementing and testing zip if (!is_dir($archiveBuilderCacheDir) && !mkdir($archiveBuilderCacheDir, 0755)) { throw new \ErrorException( @@ -120,10 +82,6 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder return $archiveBuilderCacheDir; } -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Finish implementing and testing zip /** * @param $pathToFile * @param $destination @@ -215,11 +173,6 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder return $this; } -<<<<<<< HEAD -======= ->>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources -======= ->>>>>>> Finish implementing and testing zip public function getCacheDir() { @@ -241,29 +194,14 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder { return $this->translator; } -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Finish implementing and testing zip public function getCacheFile() { return $this->cacheFile; } -<<<<<<< HEAD -<<<<<<< HEAD /** * @param string $environment -======= - - /** -<<<<<<< HEAD - * @param string $environment ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests -======= - * @param string $environment ->>>>>>> Fix cs * @return $this * * Sets the execution environment of the Kernel, @@ -273,21 +211,4 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder { $this->environment = $environment; } -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Define archive builders and formatters -======= -} ->>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources -======= -} ->>>>>>> Finish implementing and testing zip -======= -} ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php index 977860947..3e2d583d6 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php @@ -20,12 +20,4 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception; class TarArchiveException extends \Exception { -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Finish implementing and testing zip -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php~HEAD b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php~HEAD deleted file mode 100644 index f69375dec..000000000 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php~HEAD +++ /dev/null @@ -1,23 +0,0 @@ - - */ -class ZipArchiveException extends \ErrorException -{ - -} diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php index d9c150b85..35f9a5d55 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php @@ -13,23 +13,10 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder; use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException; -<<<<<<< HEAD -<<<<<<< HEAD use Thelia\Core\HttpFoundation\Response; use Thelia\Core\Thelia; use Thelia\Core\Translation\Translator; use Thelia\Exception\FileNotReadableException; -======= -use Thelia\Core\FileFormat\Archive\ArchiveBuilderInterface; -use Thelia\Core\Thelia; -use Thelia\Core\Translation\Translator; ->>>>>>> Finish implementing and testing zip -======= -use Thelia\Core\HttpFoundation\Response; -use Thelia\Core\Thelia; -use Thelia\Core\Translation\Translator; -use Thelia\Exception\FileNotReadableException; ->>>>>>> Finish Tar archive builder use Thelia\Log\Tlog; use Thelia\Tools\FileDownload\FileDownloaderInterface; @@ -60,39 +47,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \Thelia\Log\Tlog */ protected $logger; -<<<<<<< HEAD -<<<<<<< HEAD -======= - function __construct($compressionType = null) - { - $this->translator = Translator::getInstance(); - $this->logger = Tlog::getNewInstance(); - - $supportedCompression = [ - "gz", - "bz2", - null - ]; - - if (!in_array($compressionType, $supportedCompression)) { - throw new TarArchiveException( - $this->translator->trans( - "The compression %type is not supported" - ) - ); - } - - $this->compression = $compressionType; - } - -<<<<<<< HEAD - /** ->>>>>>> Finish implementing and testing zip -======= - ->>>>>>> Finish Tar archive builder -======= ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests public function __destruct() { if ($this->tar instanceof \PharData) { @@ -100,8 +54,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder unlink($this->cacheFile); } } -<<<<<<< HEAD -<<<<<<< HEAD } /** @@ -109,21 +61,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * @param string $directoryInArchive This is the directory where it will be stored in the archive * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name * @param bool $isOnline -<<<<<<< HEAD -======= - }*/ -======= - } ->>>>>>> Finish Tar archive builder - - /** - * @param string $filePath It is the path to access the file. - * @param string $directoryInArchive This is the directory where it will be stored in the archive - * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name - * @param bool $isOnline ->>>>>>> Finish implementing and testing zip -======= ->>>>>>> Fix cs * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -143,15 +80,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * Download the file if it is online * If it's local check if the file exists and if it is redable */ -<<<<<<< HEAD -<<<<<<< HEAD $fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp"; -======= - $fileDownloadCache = $this->cacheDir . DS . "download.tmp"; ->>>>>>> Finish implementing and testing zip -======= - $fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp"; ->>>>>>> Complete zip tests $this->copyFile($filePath, $fileDownloadCache, $isOnline); /** @@ -167,35 +96,18 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $this->tar->addFile($filePath, $name); -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Finish Tar archive builder /** * And clear the download temp file */ unlink($fileDownloadCache); -<<<<<<< HEAD -======= ->>>>>>> Finish implementing and testing zip -======= ->>>>>>> Finish Tar archive builder return $this; } /** * @param $content * @param $name -<<<<<<< HEAD -<<<<<<< HEAD * @param string $directoryInArchive -======= - * @param string $directoryInArchive ->>>>>>> Finish implementing and testing zip -======= - * @param string $directoryInArchive ->>>>>>> Fix cs * @return mixed * @throws \ErrorException * @@ -220,15 +132,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } try { $this->tar->addFromString($name, $content); -<<<<<<< HEAD -<<<<<<< HEAD } catch (\Exception $e) { -======= - } catch(\Exception $e) { ->>>>>>> Finish implementing and testing zip -======= - } catch (\Exception $e) { ->>>>>>> Fix cs throw new \ErrorException( $this->translator->trans( "Error while writing the file into the archive, error message: %errmes", @@ -240,13 +144,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } } -<<<<<<< HEAD -<<<<<<< HEAD -======= - ->>>>>>> Finish implementing and testing zip -======= ->>>>>>> Fix cs /** * @param $directoryPath * @return $this @@ -262,15 +159,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder try { $this->tar->addEmptyDir($directoryInArchive); -<<<<<<< HEAD -<<<<<<< HEAD } catch (\Exception $e) { -======= - } catch(\Exception $e) { ->>>>>>> Finish implementing and testing zip -======= - } catch (\Exception $e) { ->>>>>>> Fix cs throw new \ErrorException( $this->translator->trans( "The directory %dir has not been created in the archive", @@ -286,15 +175,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $pathToFile -======= - * @param string $pathToFile ->>>>>>> Finish implementing and testing zip -======= - * @param string $pathToFile ->>>>>>> Fix cs * @return null|string * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -304,11 +185,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getFileContent($pathToFile) { -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Fix FileDownloader test $pathToFile = $this->formatFilePath($pathToFile); if (!$this->hasFile($pathToFile)) { @@ -317,19 +193,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \PharFileInfo $fileInfo*/ $fileInfo = $this->tar[$pathToFile]; -<<<<<<< HEAD /** @var \SplFileObject $file */ $file = $fileInfo->openFile(); $content = ""; -======= - - /** @var \SplFileObject $file */ - $file = $fileInfo->openFile(); - $content = ""; - ->>>>>>> Fix FileDownloader test while (false !== ($char = $file->fgetc())) { $content .= $char; } @@ -337,18 +205,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder return $content; } -<<<<<<< HEAD -======= - -======= - ->>>>>>> Complete zip tests - } - - ->>>>>>> Finish implementing and testing zip -======= ->>>>>>> Fix cs /** * @param $pathInArchive * @return $this @@ -380,8 +236,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * * This method return an instance of a Response with the archive as content. */ -<<<<<<< HEAD -<<<<<<< HEAD public function buildArchiveResponse($filename) { $this->tar->setMetadata("Generated by Thelia v" . Thelia::THELIA_VERSION); @@ -418,54 +272,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * @param string $environment * @param bool $isOnline * @param FileDownloaderInterface $fileDownloader -======= - public function buildArchiveResponse() -======= - public function buildArchiveResponse($filename) ->>>>>>> Add filename in build archive response - { - $this->tar->setMetadata("Generated by Thelia v" . Thelia::THELIA_VERSION); - - if (!is_file($this->cacheFile)) { - $this->throwFileNotFound($this->cacheFile); - } - - if (!is_readable($this->cacheFile)) { - throw new FileNotReadableException( - $this->translator->trans( - "The file %file is not readable", - [ - "%file" => $this->cacheFile - ] - ) - ); - } - - $content = file_get_contents($this->cacheFile); - - return new Response( - $content, - 200, - [ - "Content-Type" => $this->getMimeType(), - "Content-Disposition" => $filename . "." . $this->getExtension(), - ] - ); - } - - /** -<<<<<<< HEAD - * @param string $pathToArchive - * @param string $environment - * @param bool $isOnline - * @param FileDownloaderInterface $fileDownloader ->>>>>>> Finish implementing and testing zip -======= - * @param string $pathToArchive - * @param string $environment - * @param bool $isOnline - * @param FileDownloaderInterface $fileDownloader ->>>>>>> Fix cs * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException @@ -473,8 +279,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * * Loads an archive */ -<<<<<<< HEAD -<<<<<<< HEAD public function loadArchive($pathToArchive, $isOnline = false) { $tar = clone $this; @@ -482,57 +286,13 @@ class TarArchiveBuilder extends AbstractArchiveBuilder $tar ->setCacheFile($tar->generateCacheFile($this->environment)) ->copyFile($pathToArchive, $tar->getCacheFile(), $isOnline); -======= - public static function loadArchive( - $pathToArchive, - $environment, - $isOnline = false, - FileDownloaderInterface $fileDownloader = null - ) { - /** @var TarArchiveBuilder $instance */ - $instance = new static(); - - if ($fileDownloader !== null) { - $instance->setFileDownloader($fileDownloader); - } - -<<<<<<< HEAD - $instance->setCacheFile($instance->getCacheFile()) - ->copyFile($pathToArchive, $isOnline); ->>>>>>> Finish implementing and testing zip -======= - $instance->setCacheFile($instance->generateCacheFile($environment)) - ->copyFile($pathToArchive, $instance->getCacheFile(), $isOnline); ->>>>>>> Fix FileDownloader test -======= - public function loadArchive($pathToArchive, $isOnline = false) - { - $tar = clone $this; - - $tar - ->setCacheFile($tar->generateCacheFile($this->environment)) - ->copyFile($pathToArchive, $tar->getCacheFile(), $isOnline); ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests /** * This throws TarArchiveBuilderException if * the archive is not valid. */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Fix cs return $tar->setEnvironment($tar->environment); -======= - $instance->setEnvironment($environment); - - return $instance; ->>>>>>> Finish implementing and testing zip -======= - return $tar->setEnvironment($tar->environment); ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests } /** @@ -552,43 +312,19 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \PharFileInfo $fileInfo */ $fileInfo = $this->tar[$pathToFile]; -<<<<<<< HEAD -<<<<<<< HEAD if ($fileInfo->isFile()) { -======= - if($fileInfo->isFile()) { ->>>>>>> Finish implementing and testing zip -======= - if ($fileInfo->isFile()) { ->>>>>>> Fix cs $isFile = true; } /** * Catch the exception to avoid its displaying. */ -<<<<<<< HEAD -<<<<<<< HEAD } catch (\BadMethodCallException $e) {} -======= - } catch(\BadMethodCallException $e) {} ->>>>>>> Finish implementing and testing zip -======= - } catch (\BadMethodCallException $e) {} ->>>>>>> Fix cs return $isFile; } /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $directory -======= - * @param string $directory ->>>>>>> Finish implementing and testing zip -======= - * @param string $directory ->>>>>>> Fix cs * @return bool * * Check if the archive has a directory @@ -602,43 +338,19 @@ class TarArchiveBuilder extends AbstractArchiveBuilder /** @var \PharFileInfo $fileInfo */ $fileInfo = $this->tar[$pathToDir]; -<<<<<<< HEAD -<<<<<<< HEAD if ($fileInfo->isDir()) { -======= - if($fileInfo->isDir()) { ->>>>>>> Finish implementing and testing zip -======= - if ($fileInfo->isDir()) { ->>>>>>> Fix cs $isDir = true; } /** * Catch the exception to avoid its displaying. */ -<<<<<<< HEAD -<<<<<<< HEAD } catch (\BadMethodCallException $e) {} -======= - } catch(\BadMethodCallException $e) {} ->>>>>>> Finish implementing and testing zip -======= - } catch (\BadMethodCallException $e) {} ->>>>>>> Fix cs return $isDir; } /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $environment -======= - * @param string $environment ->>>>>>> Finish implementing and testing zip -======= - * @param string $environment ->>>>>>> Fix cs * @return $this * * Sets the execution environment of the Kernel, @@ -646,10 +358,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function setEnvironment($environment) { -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests if (empty($environment)) { throw new \ErrorException( $this->translator->trans( @@ -658,11 +366,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder ); } -<<<<<<< HEAD -======= ->>>>>>> Finish implementing and testing zip -======= ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests if ($this->cacheFile === null) { $cacheFile = $this->generateCacheFile($environment); @@ -678,45 +381,14 @@ class TarArchiveBuilder extends AbstractArchiveBuilder try { $this->tar = new \PharData($cacheFile, null, null, static::PHAR_FORMAT); -<<<<<<< HEAD -<<<<<<< HEAD $this->compressionEntryPoint(); } catch (\BadMethodCallException $e) { -<<<<<<< HEAD -======= - switch ($this->compression) { - case "gz": - $this->tar = $this->tar->compress(\Phar::GZ); - $cacheFile .= ".gz"; - break; - case "bz2": - $this->tar = $this->tar->compress(\Phar::BZ2); - $cacheFile .= ".bz2"; - break; - } -======= - $this->compressionEntryPoint(); - ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests - - } catch(\BadMethodCallException $e) { ->>>>>>> Finish implementing and testing zip -======= ->>>>>>> Fix cs /** * This should not happen */ $errorMessage = "You have badly called the method setEnvironment twice for %file"; -<<<<<<< HEAD -<<<<<<< HEAD } catch (\UnexpectedValueException $e) { -======= - } catch(\UnexpectedValueException $e) { ->>>>>>> Finish implementing and testing zip -======= - } catch (\UnexpectedValueException $e) { ->>>>>>> Fix cs $errorMessage = "The file %file is corrupted"; } @@ -732,28 +404,13 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } $this->cacheFile = $cacheFile; -<<<<<<< HEAD -<<<<<<< HEAD $this->environment = $environment; -======= ->>>>>>> Finish implementing and testing zip -======= - $this->environment = $environment; ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests return $this; } /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $initialString -======= - * @param string $initialString ->>>>>>> Finish implementing and testing zip -======= - * @param string $initialString ->>>>>>> Fix cs * @return string * * Gives a valid file path for \ZipArchive @@ -774,15 +431,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder } /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $initialString -======= - * @param string $initialString ->>>>>>> Finish implementing and testing zip -======= - * @param string $initialString ->>>>>>> Fix cs * @return string * * Gives a valid directory path for \ZipArchive @@ -804,21 +453,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getName() { -<<<<<<< HEAD -<<<<<<< HEAD return "tar"; -======= - $name = "tar"; - - if ($this->compression !== null) { - $name .= "." . $this->compression; - } - - return $name; ->>>>>>> Finish implementing and testing zip -======= - return "tar"; ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests } /** @@ -832,15 +467,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getExtension() { -<<<<<<< HEAD -<<<<<<< HEAD return "tar"; -======= - return $this->getName(); ->>>>>>> Finish implementing and testing zip -======= - return "tar"; ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests } /** @@ -853,10 +480,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder */ public function getMimeType() { -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests return "application/x-tar"; } @@ -866,7 +489,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder * This method must be overwritten if you want to do some * stuff to compress you archive */ -<<<<<<< HEAD } public function getCompression() @@ -874,25 +496,3 @@ class TarArchiveBuilder extends AbstractArchiveBuilder return $this->compression; } } -======= - return $this->compression === null ? - "application/x-tar" : - "application/x-gtar" - ; - } - -} ->>>>>>> Finish implementing and testing zip -======= - } - - public function getCompression() - { - return $this->compression; - } -<<<<<<< HEAD -} ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php index 1b198bd8c..774d082df 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php @@ -44,12 +44,4 @@ class TarBz2ArchiveBuilder extends TarArchiveBuilder return $this; } -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php index 5ae97afff..4722417fa 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php @@ -49,12 +49,4 @@ class TarGzArchiveBuilder extends TarArchiveBuilder return $this; } -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php index ea2a6a811..220cd24e4 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php @@ -12,24 +12,10 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder; -<<<<<<< HEAD -<<<<<<< HEAD use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException; use Thelia\Core\HttpFoundation\Response; use Thelia\Core\Thelia; use Thelia\Exception\FileNotReadableException; -======= -======= -use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException; ->>>>>>> Finish implementing and testing zip -use Thelia\Core\HttpFoundation\Response; -use Thelia\Core\Thelia; -use Thelia\Exception\FileNotReadableException; -<<<<<<< HEAD -use Thelia\Log\Tlog; ->>>>>>> Define archive builders and formatters -======= ->>>>>>> Finish implementing and testing zip use Thelia\Tools\FileDownload\FileDownloaderInterface; /** @@ -45,118 +31,42 @@ 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 */ protected $zip; -<<<<<<< HEAD -<<<<<<< HEAD public function __construct() { parent::__construct(); $this->zip = new \ZipArchive(); -======= - /** - * @var string This is the absolute path to the zip file in cache - */ - protected $zipCacheFile; - - /** - * @var string This is the path of the cache - */ - protected $cacheDir; - -======= ->>>>>>> Finish implementing and testing zip - public function __construct() - { - 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 } /** * On the destruction of the class, * remove the temporary file. */ -<<<<<<< HEAD -<<<<<<< HEAD public function __destruct() -======= - function __destruct() ->>>>>>> Define archive builders and formatters -======= - public function __destruct() ->>>>>>> Fix cs { if ($this->zip instanceof \ZipArchive) { @$this->zip->close(); -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD if (file_exists($this->cacheFile)) { unlink($this->cacheFile); -======= - 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 -======= - if (file_exists($this->cacheFile)) { - unlink($this->cacheFile); ->>>>>>> Finish implementing and testing zip } } } /** -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Fix cs * @param string $filePath It is the path to access the file. * @param string $directoryInArchive This is the directory where it will be stored in the archive * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name * @param bool $isOnline -<<<<<<< HEAD * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException * @throws \ErrorException -======= - * @param string $filePath It is the path to access the file. - * @param string $directoryInArchive This is the directory where it will be stored in the archive - * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name - * @param bool $isOnline -======= ->>>>>>> Fix cs - * @return $this - * @throws \Thelia\Exception\FileNotFoundException - * @throws \Thelia\Exception\FileNotReadableException -<<<<<<< HEAD ->>>>>>> Define archive builders and formatters -======= - * @throws \ErrorException ->>>>>>> Finish implementing and testing zip * * This methods adds a file in the archive. * If the file is local, $isOnline must be false, @@ -164,8 +74,6 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function addFile($filePath, $directoryInArchive = null, $name = null, $isOnline = false) { -<<<<<<< HEAD -<<<<<<< HEAD $directoryInArchive = $this->formatDirectoryPath($directoryInArchive); /** @@ -173,7 +81,6 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ if (!empty($directoryInArchive)) { -<<<<<<< HEAD $this->addDirectory($directoryInArchive); } @@ -259,242 +166,6 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } - /** - * @param $directoryPath - * @return $this - * @throws \ErrorException - * - * This method creates an empty directory - */ - public function addDirectory($directoryPath) - { - $directoryInArchive = $this->formatDirectoryPath($directoryPath); - - if (!empty($directoryInArchive)) { -======= -======= - $directoryInArchive = $this->formatDirectoryPath($directoryInArchive); - ->>>>>>> Finish implementing and testing zip - /** - * Add empty directory if it doesn't exist - */ - - if(!empty($directoryInArchive)) { -======= ->>>>>>> Fix cs - $this->addDirectory($directoryInArchive); - } - -<<<<<<< HEAD ->>>>>>> Define archive builders and formatters - if (!$this->zip->addEmptyDir($directoryInArchive)) { - throw new \ErrorException( - $this->translator->trans( - "The directory %dir has not been created in the archive", - [ - "%dir" => $directoryInArchive - ] - ) - ); - } -======= - if (empty($name) || !is_scalar($name)) { - $name = basename($filePath); ->>>>>>> Finish implementing and testing zip - } - -<<<<<<< HEAD -<<<<<<< HEAD - return $this; - } - - /** - * @param string $pathToFile - * @return null|string - * @throws \Thelia\Exception\FileNotFoundException - * @throws \Thelia\Exception\FileNotReadableException - * @throws \ErrorException - * - * This method returns a file content - */ - public function getFileContent($pathToFile) - { - $pathToFile = $this->formatFilePath($pathToFile); - - if (!$this->hasFile($pathToFile)) { - $this->throwFileNotFound($pathToFile); - } - - $stream = $this->zip->getStream($pathToFile); - $content = ""; - - while (!feof($stream)) { - $content .= fread($stream, 2); - } - - fclose($stream); - - return $content; - } - - - /** - * @param string $initialString - * @return string - * - * Gives a valid file path for \ZipArchive - */ - public function getFilePath($initialString) - { - /** - * Remove the / at the beginning and the end. - */ - $initialString = trim($initialString, "/"); - - /** - * Remove the double, triple, ... slashes - */ - $initialString = preg_replace("#\/{2,}#", "/", $initialString); - - if (preg_match("#\/?[^\/]+\/[^\/]+\/?#", $initialString)) { - $initialString = "/" . $initialString; - } - - return $initialString; - } - - /** - * @param string $initialString - * @return string - * - * Gives a valid directory path for \ZipArchive - */ - public function getDirectoryPath($initialString) - { - $initialString = $this->getFilePath($initialString); - - if ($initialString[0] !== "/") { - $initialString = "/" . $initialString; - } - - return $initialString . "/"; -======= -======= - /** - * Download the file if it is online - * If it's local check if the file exists and if it is redable - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources - if ($isOnline) { - $fileDownloadCache = $this->cacheDir . DS . "download"; - - $this->getFileDownloader() - ->download($filePath, $fileDownloadCache) - ; - - $filePath = $fileDownloadCache; - } else { - if (!file_exists($filePath)) { - $this->throwFileNotFound($filePath); - } else if (!is_readable($filePath)) { - throw new FileNotReadableException( - $this->translator - ->trans( - "The file %file is not readable", - [ - "%file" => $filePath, - ] - ) - ); - } - } - - if (empty($name)) { - $name = basename($filePath); - } -======= - $fileDownloadCache = $this->cacheDir . DS . "download.tmp"; -======= - $fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp"; ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests - $this->copyFile($filePath, $fileDownloadCache, $isOnline); ->>>>>>> Finish implementing and testing zip - - /** - * Then write the file in the archive and commit the changes - */ - $destination = $directoryInArchive . $name; - - if (!$this->zip->addFile($fileDownloadCache, $destination)) { - $translatedErrorMessage = $this->translator->trans( - "An error occurred while adding this file to the archive: %file", - [ - "%file" => $fileDownloadCache - ] - ); - - $this->logger->error($translatedErrorMessage); - - // if error delete the cache file - unlink($fileDownloadCache); - - throw new \ErrorException($translatedErrorMessage); - } - - $this->commit(); - - // Delete the temp file - unlink($fileDownloadCache); - - return $this; ->>>>>>> Define archive builders and formatters - } - - /** - * @param $content - * @param $name - * @param string $directoryInArchive - * @return mixed - * @throws \ErrorException - * - * This method creates a file in the archive with its content - */ - public function addFileFromString($content, $name, $directoryInArchive = "/") - { - $directoryInArchive = $this->formatDirectoryPath($directoryInArchive); - - if (!empty($directoryInArchive) && $directoryInArchive !== "/") { - $this->addDirectory($directoryInArchive); - } - - if (empty($name) || !is_scalar($name)) { - throw new \ErrorException( - $this->translator->trans( - "The filename is not correct" - ) - ); - } - - $filePath = $this->getFilePath($directoryInArchive . DS . $name); - - if (!$this->zip->addFromString($filePath, $content)) { - throw new \ErrorException( - $this->translator->trans( - "Unable to write the file %file into the archive", - [ - "%file" => $filePath, - ] - ) - ); - } - - $this->commit(); - } - - /** * @param $directoryPath * @return $this @@ -604,15 +275,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function deleteFile($pathInArchive) { -<<<<<<< HEAD -<<<<<<< HEAD $pathInArchive = $this->formatFilePath($pathInArchive); -======= - $pathInArchive = $this->getFilePath($pathInArchive); ->>>>>>> Define archive builders and formatters -======= - $pathInArchive = $this->formatFilePath($pathInArchive); ->>>>>>> Finish implementing and testing zip if (!$this->hasFile($pathInArchive)) { $this->throwFileNotFound($pathInArchive); @@ -639,84 +302,28 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder * * This method return an instance of a Response with the archive as content. */ -<<<<<<< HEAD -<<<<<<< HEAD public function buildArchiveResponse($filename) -======= - public function buildArchiveResponse() ->>>>>>> Define archive builders and formatters -======= - public function buildArchiveResponse($filename) ->>>>>>> Add filename in build archive response { $this->zip->comment = "Generated by Thelia v" . Thelia::THELIA_VERSION; $this->commit(); -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD if (!file_exists($this->cacheFile)) { $this->throwFileNotFound($this->cacheFile); } if (!is_readable($this->cacheFile)) { -======= - if (!file_exists($this->zip_cache_file)) { - $this->throwFileNotFound($this->zip_cache_file); - } - - 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 -======= - if (!file_exists($this->cacheFile)) { - $this->throwFileNotFound($this->cacheFile); - } - - if (!is_readable($this->cacheFile)) { ->>>>>>> Finish implementing and testing zip throw new FileNotReadableException( $this->translator->trans( "The cache file %file is not readable", [ -<<<<<<< HEAD -<<<<<<< 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 -======= - "%file" => $this->cacheFile ->>>>>>> Finish implementing and testing zip ] ) ); } -<<<<<<< HEAD -<<<<<<< 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 -======= - $content = file_get_contents($this->cacheFile); ->>>>>>> Finish implementing and testing zip $this->zip->close(); @@ -724,59 +331,28 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder $content, 200, [ -<<<<<<< HEAD -<<<<<<< HEAD "Content-Type" => $this->getMimeType(), "Content-Disposition" => $filename . "." . $this->getExtension(), -======= - "Content-Type" => $this->getMimeType() ->>>>>>> Define archive builders and formatters -======= - "Content-Type" => $this->getMimeType(), - "Content-Disposition" => $filename . "." . $this->getExtension(), ->>>>>>> Add filename in build archive response ] ); } /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $pathToArchive * @param bool $isOnline * @param FileDownloaderInterface $fileDownloader * @return ZipArchiveBuilder -======= - * @param string $pathToArchive - * @param bool $isOnline - * @param FileDownloaderInterface $fileDownloader -<<<<<<< HEAD - * @return $this ->>>>>>> Define archive builders and formatters -======= -======= - * @param string $pathToArchive - * @param bool $isOnline - * @param FileDownloaderInterface $fileDownloader ->>>>>>> Fix cs - * @return ZipArchiveBuilder ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException * * Loads an archive */ -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests public function loadArchive($pathToArchive, $isOnline = false) { $back = $this->zip; $this->zip = new \ZipArchive(); $zip = clone $this; $this->zip = $back; -<<<<<<< HEAD $zip->setEnvironment($this->environment); @@ -793,46 +369,6 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } return $zip; -======= - public static function loadArchive( - $pathToArchive, - $environment, - $isOnline = false, - FileDownloaderInterface $fileDownloader = null - ) { - /** @var ZipArchiveBuilder $instance */ - $instance = new static(); - - $instance->setEnvironment($environment); - $zip = $instance->getRawZipArchive(); - $zip->close(); - - if ($fileDownloader !== null) { - $instance->setFileDownloader($fileDownloader); - } -======= ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests - - $zip->setEnvironment($this->environment); - - $zip->copyFile( - $pathToArchive, - $zip->getCacheFile(), - $isOnline - ); - - if (true !== $return = $zip->getRawZipArchive()->open($zip->getCacheFile())) { - throw new ZipArchiveException( - $zip->getZipErrorMessage($return) - ); - } - -<<<<<<< HEAD - return $instance; ->>>>>>> Define archive builders and formatters -======= - return $zip; ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests } /** @@ -844,57 +380,25 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder public function hasFile($pathToFile) { return $this->zip -<<<<<<< HEAD -<<<<<<< HEAD ->locateName($this->formatFilePath($pathToFile)) !== false -======= - ->locateName($this->getFilePath($pathToFile)) !== false ->>>>>>> Define archive builders and formatters -======= - ->locateName($this->formatFilePath($pathToFile)) !== false ->>>>>>> Finish implementing and testing zip ; } /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $directory -======= - * @param string $directory ->>>>>>> Define archive builders and formatters -======= - * @param string $directory ->>>>>>> Fix cs * @return bool * * Checks if the link $directory exists and if it's not a file. */ public function hasDirectory($directory) { -<<<<<<< HEAD -<<<<<<< HEAD $link = $this->zip->locateName($this->formatDirectoryPath($directory)); -======= - $link = $this->zip->locateName($this->getDirectoryPath($directory)); ->>>>>>> Define archive builders and formatters -======= - $link = $this->zip->locateName($this->formatDirectoryPath($directory)); ->>>>>>> Finish implementing and testing zip return $link !== false; } /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $environment -======= - * @param string $environment ->>>>>>> Define archive builders and formatters -======= - * @param string $environment ->>>>>>> Fix cs * @return $this * * Sets the execution environment of the Kernel, @@ -902,58 +406,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder */ public function setEnvironment($environment) { -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD parent::setEnvironment($environment); $cacheFile = $this->generateCacheFile($environment); -======= - $theliaCacheDir = THELIA_CACHE_DIR . $environment . DS; - - if (!is_writable($theliaCacheDir)) { - throw new \ErrorException( - $this->translator->trans( - "The cache directory \"%env\" is not writable", - [ - "%env" => $environment - ] - ) - ); - } - - $archiveBuilderCacheDir = $this->cache_dir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; - - if (!is_dir($archiveBuilderCacheDir) && !mkdir($archiveBuilderCacheDir, 0755)) { - throw new \ErrorException( - $this->translator->trans( - "Error while creating the directory \"%directory\"", - [ - "%directory" => static::TEMP_DIRECTORY_NAME - ] - ) - ); - } - - $cacheFileName = md5 (uniqid()); - - $cacheFile = $archiveBuilderCacheDir . DS . $cacheFileName; - $cacheFile .= "." . $this->getExtension(); ->>>>>>> Define archive builders and formatters -======= -======= - parent::setEnvironment($environment); ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests - -<<<<<<< HEAD - $cacheFileName = md5 (uniqid()); - - $cacheFile = $this->getArchiveBuilderCacheDirectory($environment) . DS; - $cacheFile .= $cacheFileName . "." . $this->getExtension(); ->>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources -======= - $cacheFile = $this->generateCacheFile($environment); ->>>>>>> Finish implementing and testing zip if (file_exists($cacheFile)) { unlink($cacheFile); @@ -964,42 +419,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder \ZipArchive::CREATE ); -<<<<<<< HEAD -<<<<<<< HEAD if ($opening !== true) { throw new \ErrorException( $this->translator->trans( "An unknown error append" -======= - if($opening !== true) { -======= - if ($opening !== true) { ->>>>>>> Fix cs - 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 -<<<<<<< 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 -======= - $this->cacheFile = $cacheFile; ->>>>>>> Finish implementing and testing zip return $this; } @@ -1071,15 +499,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder public function commit() { $this->zip->close(); -<<<<<<< HEAD -<<<<<<< HEAD $result = $this->zip->open($this->getCacheFile()); -======= - $result = $this->zip->open($this->getZipCacheFile()); ->>>>>>> Define archive builders and formatters -======= - $result = $this->zip->open($this->getCacheFile()); ->>>>>>> Finish implementing and testing zip if ($result !== true) { throw new \ErrorException( @@ -1093,28 +513,12 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $initialString -======= - * @param string $initialString ->>>>>>> Define archive builders and formatters -======= - * @param string $initialString ->>>>>>> Fix cs * @return string * * Gives a valid file path for \ZipArchive */ -<<<<<<< HEAD -<<<<<<< HEAD public function formatFilePath($initialString) -======= - public function getFilePath($initialString) ->>>>>>> Define archive builders and formatters -======= - public function formatFilePath($initialString) ->>>>>>> Finish implementing and testing zip { /** * Remove the / at the beginning and the end. @@ -1129,78 +533,27 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) { $initialString = "/" . $initialString; } -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Define archive builders and formatters -======= - ->>>>>>> Fix cs return $initialString; } /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $initialString -======= - * @param string $initialString ->>>>>>> Define archive builders and formatters -======= - * @param string $initialString ->>>>>>> Fix cs * @return string * * Gives a valid directory path for \ZipArchive */ -<<<<<<< HEAD -<<<<<<< HEAD public function formatDirectoryPath($initialString) { $initialString = $this->formatFilePath($initialString); if ($initialString !== "" && $initialString[0] !== "/") { -======= - public function getDirectoryPath($initialString) -======= - public function formatDirectoryPath($initialString) ->>>>>>> Finish implementing and testing zip - { - $initialString = $this->formatFilePath($initialString); - -<<<<<<< HEAD - if ($initialString[0] !== "/") { ->>>>>>> Define archive builders and formatters -======= - if ($initialString !== "" && $initialString[0] !== "/") { ->>>>>>> Finish implementing and testing zip $initialString = "/" . $initialString; } return $initialString . "/"; } -<<<<<<< HEAD -<<<<<<< HEAD -======= - public function throwFileNotFound($file) - { - - throw new FileNotFoundException( - $this->getTranslator() - ->trans( - "The file %file is missing or is not readable", - [ - "%file" => $file, - ] - ) - ); - } - ->>>>>>> Define archive builders and formatters -======= ->>>>>>> Finish implementing and testing zip /** * @return string * @@ -1242,58 +595,10 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder } /** -<<<<<<< HEAD -<<<<<<< HEAD -======= - * @return Tlog - */ - public function getLogger() - { - return $this->logger; - } - - /** - * @return Translator - */ - public function getTranslator() - { - return $this->translator; - } - - /** ->>>>>>> Define archive builders and formatters -======= ->>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources * @return \ZipArchive */ public function getRawZipArchive() { return $this->zip; } -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD } -======= - - public function getZipCacheFile() - { - 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 -======= -} ->>>>>>> Finish implementing and testing zip -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php index 626b7ae87..0ff882ae5 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php @@ -17,47 +17,19 @@ namespace Thelia\Core\FileFormat\Archive; * @package Thelia\Core\FileFormat\Archive * @author Benjamin Perche * -<<<<<<< HEAD -<<<<<<< HEAD * This interface defines the methods that an archive builder must have. -======= - * This interface defines the methods that an archive creator must have. ->>>>>>> Define archive builders and formatters -======= - * This interface defines the methods that an archive builder must have. ->>>>>>> Complete zip tests */ interface ArchiveBuilderInterface { /** -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Fix cs * @param string $filePath It is the path to access the file. * @param string $directoryInArchive This is the directory where it will be stored in the archive * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name * @param bool $isOnline -<<<<<<< HEAD * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException * @throws \ErrorException -======= - * @param string $filePath It is the path to access the file. - * @param string $directoryInArchive This is the directory where it will be stored in the archive - * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name - * @param bool $isOnline -======= ->>>>>>> Fix cs - * @return $this - * @throws \Thelia\Exception\FileNotFoundException - * @throws \Thelia\Exception\FileNotReadableException -<<<<<<< HEAD ->>>>>>> Define archive builders and formatters -======= - * @throws \ErrorException ->>>>>>> Finish implementing and testing zip * * This methods adds a file in the archive. * If the file is local, $isOnline must be false, @@ -66,20 +38,9 @@ interface ArchiveBuilderInterface public function addFile($filePath, $directoryInArchive = "/", $name = null, $isOnline = false); /** -<<<<<<< HEAD -<<<<<<< HEAD * @param $content * @param $name * @param string $directoryInArchive -======= - * @param $content - * @param $name -<<<<<<< HEAD - * @param string $directoryInArchive ->>>>>>> Finish implementing and testing zip -======= - * @param string $directoryInArchive ->>>>>>> Fix cs * @return mixed * @throws \ErrorException * @@ -88,15 +49,7 @@ interface ArchiveBuilderInterface public function addFileFromString($content, $name, $directoryInArchive = "/"); /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $pathToFile -======= - * @param string $pathToFile ->>>>>>> Finish implementing and testing zip -======= - * @param string $pathToFile ->>>>>>> Fix cs * @return null|string * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotReadableException @@ -106,32 +59,16 @@ interface ArchiveBuilderInterface */ public function getFileContent($pathToFile); /** -<<<<<<< HEAD * @param $pathInArchive * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException -======= - * @param $pathInArchive - * @return $this - * @throws \Thelia\Exception\FileNotFoundException ->>>>>>> Define archive builders and formatters -======= - * @param $pathInArchive - * @return $this - * @throws \Thelia\Exception\FileNotFoundException - * @throws \ErrorException ->>>>>>> Finish implementing and testing zip * * This method deletes a file in the archive */ public function deleteFile($pathInArchive); /** -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Finish implementing and testing zip * @param $directoryPath * @return $this * @throws \ErrorException @@ -139,73 +76,25 @@ interface ArchiveBuilderInterface * This method creates an empty directory */ public function addDirectory($directoryPath); -<<<<<<< HEAD -<<<<<<< HEAD /** * @params string $filename -======= ->>>>>>> Define archive builders and formatters -======= - /** ->>>>>>> Finish implementing and testing zip -======= - - /** - * @params string $filename ->>>>>>> Add filename in build archive response * @return \Thelia\Core\HttpFoundation\Response * * This method return an instance of a Response with the archive as content. */ -<<<<<<< HEAD -<<<<<<< HEAD public function buildArchiveResponse($filename); /** * @param string $pathToArchive * @param bool $isOnline -======= - public function buildArchiveResponse(); -======= - public function buildArchiveResponse($filename); ->>>>>>> Add filename in build archive response - - /** -<<<<<<< HEAD - * @param string $pathToArchive - * @param bool $isOnline -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> Define archive builders and formatters -======= - * @param FileDownloaderInterface $fileDownloader ->>>>>>> Finish implementing and testing zip -======= ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests -======= - * @param string $pathToArchive - * @param bool $isOnline ->>>>>>> Fix cs * @return $this * @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\HttpUrlException * * Loads an archive */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD public function loadArchive($pathToArchive, $isOnline = false); -======= - public static function loadArchive($pathToArchive, $environment, $isOnline = false); ->>>>>>> Define archive builders and formatters -======= - public static function loadArchive($pathToArchive, $environment, $isOnline = false, FileDownloaderInterface $fileDownloader = null); ->>>>>>> Finish implementing and testing zip -======= - public function loadArchive($pathToArchive, $isOnline = false); ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests /** * @param $pathToFile @@ -216,39 +105,11 @@ interface ArchiveBuilderInterface public function hasFile($pathToFile); /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $directory -======= - * @param string $directory ->>>>>>> Define archive builders and formatters -======= - * @param string $directory ->>>>>>> Fix cs * @return bool * * Check if the archive has a directory */ public function hasDirectory($directory); -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD } -======= - /** - * @param string $environment - * @return $this - * - * Sets the execution environment of the Kernel, - * used to know which cache is used. - */ - public function setEnvironment($environment); -} ->>>>>>> Define archive builders and formatters -======= -} ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php index 0b9e111c5..938445822 100644 --- a/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php +++ b/core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php @@ -20,19 +20,8 @@ use Thelia\Core\Translation\Translator; */ class ArchiveBuilderManager { -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Add getNames methods to managers /** @var array */ protected $archiveBuilders = array(); -======= - protected $archiveCreators = array(); ->>>>>>> Define archive builders and formatters -======= - protected $archiveBuilders = array(); ->>>>>>> Fix cs and add get method in managers protected $environment; @@ -41,9 +30,6 @@ class ArchiveBuilderManager $this->environment = $environment; } /** -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD * @param AbstractArchiveBuilder $archiveBuilder * @return $this */ @@ -53,31 +39,6 @@ class ArchiveBuilderManager $archiveBuilder->setEnvironment($this->environment); $this->archiveBuilders[$archiveBuilder->getName()] = $archiveBuilder; -======= - * @param AbstractArchiveBuilder $archiveCreator -======= - * @param AbstractArchiveBuilder $archiveCreator ->>>>>>> Fix cs -======= - * @param AbstractArchiveBuilder $archiveBuilder ->>>>>>> Add getNames methods to managers - * @return $this - */ - public function add(AbstractArchiveBuilder $archiveBuilder) - { - if (null !== $archiveBuilder) { - $archiveBuilder->setEnvironment($this->environment); - -<<<<<<< HEAD -<<<<<<< HEAD - $this->archiveCreators[$archiveCreator->getName()] = $archiveCreator; ->>>>>>> Define archive builders and formatters -======= - $this->archiveBuilders[$archiveCreator->getName()] = $archiveCreator; ->>>>>>> Fix cs and add get method in managers -======= - $this->archiveBuilders[$archiveBuilder->getName()] = $archiveBuilder; ->>>>>>> Add getNames methods to managers } return $this; @@ -90,41 +51,16 @@ class ArchiveBuilderManager */ public function delete($name) { -<<<<<<< HEAD -<<<<<<< HEAD if (!array_key_exists($name, $this->archiveBuilders)) { $this->throwOutOfBounds($name); } unset($this->archiveBuilders[$name]); -======= - if (!array_key_exists($name, $this->archiveCreators)) { - throw new \OutOfBoundsException( - Translator::getInstance()->trans( - "The archive creator %name doesn't exist", - [ - "%name" => $name - ] - ) - ); - } - - unset($this->archiveCreators[$name]); ->>>>>>> Define archive builders and formatters -======= - if (!array_key_exists($name, $this->archiveBuilders)) { - $this->throwOutOfBounds($name); - } - - unset($this->archiveBuilders[$name]); ->>>>>>> Fix cs and add get method in managers return $this; } /** -<<<<<<< HEAD -<<<<<<< HEAD * @return array */ public function getAll() @@ -168,55 +104,3 @@ class ArchiveBuilderManager ); } } -======= - * @return array[AbstractArchiveBuilder] -======= - * @return array ->>>>>>> Add getNames methods to managers - */ - public function getAll() - { - return $this->archiveBuilders; - } - - /** - * @return array - */ - public function getNames() - { - $names = []; - - /** @var AbstractArchiveBuilder $builder */ - foreach($this->archiveBuilders as $builder) { - $names[] = $builder->getName(); - } - - return $names; - } - - public function get($name) - { - if (!array_key_exists($name, $this->archiveBuilders)) { - $this->throwOutOfBounds($name); - } - - return $this->archiveBuilders[$name]; - } - - protected function throwOutOfBounds($name) - { - throw new \OutOfBoundsException( - Translator::getInstance()->trans( - "The archive creator %name doesn't exist", - [ - "%name" => $name - ] - ) - ); - } -<<<<<<< HEAD -} ->>>>>>> Define archive builders and formatters -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/FormatInterface.php b/core/lib/Thelia/Core/FileFormat/FormatInterface.php index 290bdabc5..4b327271d 100644 --- a/core/lib/Thelia/Core/FileFormat/FormatInterface.php +++ b/core/lib/Thelia/Core/FileFormat/FormatInterface.php @@ -55,12 +55,4 @@ interface FormatInterface * return "application/json"; */ public function getMimeType(); -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Define archive builders and formatters -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php index 8a015f9bb..33bbd63bf 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php @@ -12,11 +12,8 @@ namespace Thelia\Core\FileFormat\Formatting; use Thelia\Core\FileFormat\FormatInterface; -<<<<<<< HEAD -======= use Thelia\Core\Translation\Translator; use Thelia\Log\Tlog; ->>>>>>> Remove conflicts /** * Class AbstractFormatter @@ -25,9 +22,6 @@ use Thelia\Log\Tlog; */ abstract class AbstractFormatter implements FormatInterface, FormatterInterface { -<<<<<<< HEAD - -======= /** @var \Thelia\Core\Translation\Translator */ protected $translator; @@ -55,5 +49,4 @@ abstract class AbstractFormatter implements FormatInterface, FormatterInterface { return $this->aliases; } ->>>>>>> Remove conflicts } diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php new file mode 100644 index 000000000..06f182a00 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php @@ -0,0 +1,90 @@ + + */ +class JsonFormatter extends AbstractFormatter +{ + /** + * @return string + * + * This method must return a string, the name of the format. + * + * example: + * return "XML"; + */ + public function getName() + { + return "Json"; + } + + /** + * @return string + * + * This method must return a string, the extension of the file format, without the ".". + * The string should be lowercase. + * + * example: + * return "xml"; + */ + public function getExtension() + { + return "json"; + } + + /** + * @return string + * + * This method must return a string, the mime type of the file format. + * + * example: + * return "application/json"; + */ + public function getMimeType() + { + return "application/json"; + } + + /** + * @param FormatterData $data + * @return mixed + * + * This method must use a FormatterData object and output + * a formatted value. + */ + public function encode(FormatterData $data) + { + return json_encode($data->getData()); + } + + /** + * @param $rawData + * @return FormatterData + * + * This must takes raw data as argument and outputs + * a FormatterData object. + */ + public function decode($rawData) + { + return (new FormatterData($this->getAliases()))->setData( + json_decode($rawData, true) + ); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php new file mode 100644 index 000000000..3ab3f7de4 --- /dev/null +++ b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php @@ -0,0 +1,144 @@ + + */ +class XMLFormatter extends AbstractFormatter +{ + public $root = "data"; + public $nodeName = "node"; + + /** + * @return string + * + * This method must return a string, the name of the format. + * + * example: + * return "XML"; + */ + public function getName() + { + return "XML"; + } + + /** + * @return string + * + * This method must return a string, the extension of the file format, without the ".". + * The string should be lowercase. + * + * example: + * return "xml"; + */ + public function getExtension() + { + return "xml"; + } + + /** + * @return string + * + * This method must return a string, the mime type of the file format. + * + * example: + * return "application/json"; + */ + public function getMimeType() + { + return "application/xml"; + } + + /** + * @param FormatterData $data + * @return mixed + * + * This method must use a FormatterData object and output + * a formatted value. + */ + public function encode(FormatterData $data) + { + $arrayData = $data->getData(); + + $domDocument = new \DOMDocument("1.0"); + $container = $domDocument->appendChild(new \DOMElement($this->root)); + + foreach ($arrayData as $key=>$entry) { + if (is_array($entry)) { + $node = $container->appendChild(new \DOMElement($this->nodeName)); + $this->recursiveBuild($entry, $node); + } else { + $container->appendChild(new \DOMElement($key, $entry)); + } + } + + $domDocument->preserveWhiteSpace = false; + $domDocument->formatOutput = true; + + return $domDocument->saveXML(); + } + + protected function recursiveBuild(array $data, \DOMNode $node) + { + foreach ($data as $key=>$entry) { + if (is_array($entry)) { + $newNode = $node->appendChild(new \DOMElement($key)); + $this->recursiveBuild($entry, $newNode); + } else { + $node->appendChild(new \DOMElement($key, $entry)); + } + } + } + + /** + * @param $rawData + * @return FormatterData + * + * This must takes raw data as argument and outputs + * a FormatterData object. + */ + public function decode($rawData) + { + try { + $xml = new \SimpleXMLElement($rawData); + } catch (\Exception $e) { + $errorMessage = $this->translator->trans( + "You tried to load a bad formatted XML" + ); + + $this->logger->error( + $errorMessage .": ". $e->getMessage() + ); + + throw new BadFormattedStringException( + $errorMessage + ); + } + + $array = json_decode(json_encode($xml),true); + + if (isset($array[$this->nodeName])) { + $array += $array[$this->nodeName]; + unset($array[$this->nodeName]); + } + + $data = new FormatterData($this->getAliases()); + return $data->setData($array); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php index 285dd1de4..707b7e374 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php @@ -14,14 +14,6 @@ namespace Thelia\Core\FileFormat\Formatting; use Propel\Runtime\ActiveQuery\ModelCriteria; use Propel\Runtime\Map\TableMap; use Thelia\Core\Translation\Translator; -<<<<<<< HEAD -<<<<<<< HEAD - -======= -use Thelia\Model\Map\ProductTableMap; ->>>>>>> Remove conflicts -======= ->>>>>>> Restore /** * Class FormatterData * @package Thelia\Core\FileFormat\Formatting @@ -30,11 +22,7 @@ use Thelia\Model\Map\ProductTableMap; class FormatterData { /** @var array */ -<<<<<<< HEAD - protected $data; -======= protected $data = array(); ->>>>>>> Remove conflicts /** @var null|array */ protected $aliases; @@ -81,10 +69,7 @@ class FormatterData * @return $this * * Sets raw data with aliases -<<<<<<< HEAD -======= * may bug with some formatter ->>>>>>> Remove conflicts */ public function setData(array $data) { @@ -171,8 +156,6 @@ class FormatterData return $formattedData; } -<<<<<<< HEAD -======= /** * @param array $row * @return $this @@ -234,17 +217,13 @@ class FormatterData return $this->applyAliases($data, array_flip($aliases)); } ->>>>>>> Remove conflicts public function getData() { return $this->data; } -<<<<<<< HEAD -======= public function getDataReverseAliases() { return $this->reverseAliases($this->data, $this->aliases); } ->>>>>>> Remove conflicts } diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php index 03490d45a..e34acdf76 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php @@ -33,26 +33,11 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase Tlog::getNewInstance(); $this->tar = new TarArchiveBuilder(); -<<<<<<< HEAD -<<<<<<< HEAD $this->tar->setEnvironment("dev"); -======= ->>>>>>> Finish implementing and testing zip -======= - $this->tar->setEnvironment("dev"); ->>>>>>> Fix FileDownloader test } public function testAddFileAndDirectory() { -<<<<<<< HEAD -<<<<<<< HEAD -======= - $this->tar->setEnvironment("dev"); - ->>>>>>> Finish implementing and testing zip -======= ->>>>>>> Fix FileDownloader test /** * File */ @@ -97,20 +82,10 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->tar->hasDirectory("bar")); } -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Complete zip tests public function testAddValidFileFromString() { -<<<<<<< HEAD -<<<<<<< HEAD $this->tar->addFileFromString( -<<<<<<< HEAD -======= - $this->tar->addFileFromString( ->>>>>>> Fix FileDownloader test "foo", "bar" ); @@ -122,7 +97,6 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase "foo", $this->tar->getFileContent("bar") ); -<<<<<<< HEAD $this->tar->addFileFromString( "foo", "bar", "baz" @@ -315,216 +289,3 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase ); } } -======= -} ->>>>>>> Finish implementing and testing zip -======= -======= ->>>>>>> Fix FileDownloader test -======= ->>>>>>> Fix FileDownloader test - - $this->tar->addFileFromString( - "foo", "bar", "baz" - ); - - $this->assertTrue( - $this->tar->hasFile("baz/bar") - ); - - $this->assertEquals( - "foo", - $this->tar->getFileContent("baz/bar") - ); - } - - /** - * @expectedException \ErrorException - */ - public function testAddNotValidFileFromString() - { - $this->tar->addFileFromString( - "foo", $this - ); - } - - /** - * @expectedException \ErrorException - */ - public function testAddNotValidFileValueFromString() - { - $this->tar->addFileFromString( - $this, "foo" - ); - } - - public function testDeleteFile() - { - $this->tar->addFileFromString( - "foo", "bar" - ); - - $this->assertTrue( - $this->tar->hasFile("bar") - ); - - $this->tar->deleteFile("bar"); - - $this->assertFalse( - $this->tar->hasFile("bar") - ); - } -<<<<<<< HEAD -} ->>>>>>> Complete zip tests -======= - - public function testLoadValidArchive() - { - $tar = $this->tar->loadArchive( - __DIR__ . DS . "TestResources/well_formatted.tar" - ); - - $this->assertInstanceOf( - get_class($this->tar), - $tar - ); - - $this->assertTrue( - $tar->hasFile("LICENSE.txt") - ); - } - - /** - * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException - */ - public function testLoadInvalidArchive() - { - $tar = $this->tar->loadArchive( - __DIR__ . DS . "TestResources/bad_formatted.tar" - ); - } - - public function testFormatDirectoryPath() - { - $this->assertEquals( - "foo/", - $this->tar->formatDirectoryPath("foo") - ); - - $this->assertEquals( - "foo/", - $this->tar->formatDirectoryPath("/foo") - ); - - $this->assertEquals( - "foo/", - $this->tar->formatDirectoryPath("foo/") - ); - - $this->assertEquals( - "foo/", - $this->tar->formatDirectoryPath("/foo/") - ); - - $this->assertEquals( - "foo/bar/", - $this->tar->formatDirectoryPath("foo/bar") - ); - - $this->assertEquals( - "foo/bar/", - $this->tar->formatDirectoryPath("/foo/bar") - ); - - $this->assertEquals( - "foo/bar/", - $this->tar->formatDirectoryPath("/foo//bar/") - ); - - $this->assertEquals( - "foo/bar/", - $this->tar->formatDirectoryPath("/foo/bar/") - ); - - $this->assertEquals( - "foo/bar/baz/", - $this->tar->formatDirectoryPath("foo/bar/baz") - ); - - $this->assertEquals( - "foo/bar/baz/", - $this->tar->formatDirectoryPath("//foo/bar///baz/") - ); - } - - public function testFormatFilePath() - { - $this->assertEquals( - "foo", - $this->tar->formatFilePath("foo") - ); - - $this->assertEquals( - "foo", - $this->tar->formatFilePath("/foo") - ); - - $this->assertEquals( - "foo", - $this->tar->formatFilePath("foo/") - ); - - $this->assertEquals( - "foo", - $this->tar->formatFilePath("/foo/") - ); - - $this->assertEquals( - "foo/bar", - $this->tar->formatFilePath("foo/bar") - ); - - $this->assertEquals( - "foo/bar", - $this->tar->formatFilePath("/foo/bar") - ); - - $this->assertEquals( - "foo/bar", - $this->tar->formatFilePath("/foo//bar/") - ); - - $this->assertEquals( - "foo/bar", - $this->tar->formatFilePath("/foo/bar/") - ); - - $this->assertEquals( - "foo/bar/baz", - $this->tar->formatFilePath("foo/bar/baz") - ); - - $this->assertEquals( - "foo/bar/baz", - $this->tar->formatFilePath("//foo/bar///baz/") - ); - } -<<<<<<< HEAD -} ->>>>>>> Finish Tar archive builder -======= - - public function testCompression() - { - $this->assertEquals( - null, - $this->tar->getCompression() - ); - } -<<<<<<< HEAD -} ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php index 47bd9e82d..a65892424 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php @@ -35,12 +35,4 @@ class TarBz2ArchiveBuilderTest extends TarArchiveBuilderTest $this->tar->getCompression() ); } -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php index 324d5f2dc..5b1aded6e 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php @@ -12,13 +12,6 @@ namespace Thelia\Tests\FileFormat\Archive\ArchiveBuilder; use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarGzArchiveBuilder; -<<<<<<< HEAD -<<<<<<< HEAD -======= -use Thelia\Core\HttpFoundation\Response; ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests -======= ->>>>>>> Fix cs /** * Class TarGzArchiveBuilderTest @@ -42,12 +35,4 @@ class TarGzArchiveBuilderTest extends TarArchiveBuilderTest $this->tar->getCompression() ); } -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.tar b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.tar index 3bd1f0e29..e69de29bb 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.tar +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TestResources/bad_formatted.tar @@ -1,2 +0,0 @@ -foo -bar diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php index f0c6b2385..450af71b2 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php @@ -40,325 +40,126 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase $this->zip = new ZipArchiveBuilder(); -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->setEnvironment("dev"); $this->loadedZip = $this->zip->loadArchive( __DIR__ . DS . "TestResources/well_formatted.zip" -======= - $this->loadedZip = $this->zip->loadArchive( - __DIR__ . DS . "TestResources/well_formatted.zip", - "dev" ->>>>>>> Define archive builders and formatters -======= - $this->zip->setEnvironment("dev"); - - $this->loadedZip = $this->zip->loadArchive( - __DIR__ . DS . "TestResources/well_formatted.zip" ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); } /** * This method formats a path to be compatible with \ZipArchive -<<<<<<< HEAD -<<<<<<< HEAD */ public function testFormatFilePath() { $this->assertEquals( "foo", $this->zip->formatFilePath("foo") -======= - * - * -======= ->>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources - */ - public function testFormatFilePath() - { - $this->assertEquals( - "foo", -<<<<<<< HEAD - $this->zip->getFilePath("foo") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatFilePath("foo") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "foo", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatFilePath("/foo") -======= - $this->zip->getFilePath("/foo") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatFilePath("/foo") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "foo", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatFilePath("foo/") -======= - $this->zip->getFilePath("foo/") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatFilePath("foo/") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "foo", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatFilePath("/foo/") -======= - $this->zip->getFilePath("/foo/") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatFilePath("/foo/") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatFilePath("foo/bar") -======= - $this->zip->getFilePath("foo/bar") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatFilePath("foo/bar") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatFilePath("/foo/bar") -======= - $this->zip->getFilePath("/foo/bar") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatFilePath("/foo/bar") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatFilePath("/foo//bar/") -======= - $this->zip->getFilePath("/foo//bar/") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatFilePath("/foo//bar/") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatFilePath("/foo/bar/") -======= - $this->zip->getFilePath("/foo/bar/") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatFilePath("/foo/bar/") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/baz", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatFilePath("foo/bar/baz") -======= - $this->zip->getFilePath("foo/bar/baz") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatFilePath("foo/bar/baz") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/baz", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatFilePath("//foo/bar///baz/") ); } public function testFormatDirectoryPath() -<<<<<<< HEAD { $this->assertEquals( "/foo/", $this->zip->formatDirectoryPath("foo") -======= - $this->zip->getFilePath("//foo/bar///baz/") -======= - $this->zip->formatFilePath("//foo/bar///baz/") ->>>>>>> Finish implementing and testing zip - ); - } - - public function testGetDirectoryPath() -======= ->>>>>>> Finish Tar archive builder - { - $this->assertEquals( - "/foo/", -<<<<<<< HEAD - $this->zip->getDirectoryPath("foo") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatDirectoryPath("foo") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatDirectoryPath("/foo") -======= - $this->zip->getDirectoryPath("/foo") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatDirectoryPath("/foo") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatDirectoryPath("foo/") -======= - $this->zip->getDirectoryPath("foo/") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatDirectoryPath("foo/") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatDirectoryPath("/foo/") -======= - $this->zip->getDirectoryPath("/foo/") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatDirectoryPath("/foo/") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatDirectoryPath("foo/bar") -======= - $this->zip->getDirectoryPath("foo/bar") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatDirectoryPath("foo/bar") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatDirectoryPath("/foo/bar") -======= - $this->zip->getDirectoryPath("/foo/bar") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatDirectoryPath("/foo/bar") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatDirectoryPath("/foo//bar/") -======= - $this->zip->getDirectoryPath("/foo//bar/") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatDirectoryPath("/foo//bar/") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatDirectoryPath("/foo/bar/") -======= - $this->zip->getDirectoryPath("/foo/bar/") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatDirectoryPath("/foo/bar/") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/baz/", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatDirectoryPath("foo/bar/baz") -======= - $this->zip->getDirectoryPath("foo/bar/baz") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatDirectoryPath("foo/bar/baz") ->>>>>>> Finish implementing and testing zip ); $this->assertEquals( "/foo/bar/baz/", -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->formatDirectoryPath("//foo/bar///baz/") -======= - $this->zip->getDirectoryPath("//foo/bar///baz/") ->>>>>>> Define archive builders and formatters -======= - $this->zip->formatDirectoryPath("//foo/bar///baz/") ->>>>>>> Finish implementing and testing zip ); } public function testLoadValidZip() { $loadedZip = $this->zip->loadArchive( -<<<<<<< HEAD -<<<<<<< HEAD __DIR__ . DS . "TestResources/well_formatted.zip" -======= - __DIR__ . DS . "TestResources/well_formatted.zip", - "dev" ->>>>>>> Define archive builders and formatters -======= - __DIR__ . DS . "TestResources/well_formatted.zip" ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); $this->assertInstanceOf( @@ -368,30 +169,13 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase } /** -<<<<<<< HEAD -<<<<<<< HEAD * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException -======= - * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException ->>>>>>> Define archive builders and formatters -======= - * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException ->>>>>>> Finish implementing and testing zip * @expectedExceptionMessage [Zip Error] The file is not a zip archive */ public function testLoadNotValidZip() { $this->zip->loadArchive( -<<<<<<< HEAD -<<<<<<< HEAD __DIR__ . DS . "TestResources/bad_formatted.zip" -======= - __DIR__ . DS . "TestResources/bad_formatted.zip", - "dev" ->>>>>>> Define archive builders and formatters -======= - __DIR__ . DS . "TestResources/bad_formatted.zip" ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); } @@ -401,80 +185,31 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testLoadNotExistingFile() { $this->zip->loadArchive( -<<<<<<< HEAD -<<<<<<< HEAD __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip" -======= - __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", - "dev" ->>>>>>> Define archive builders and formatters -======= - __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip" ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); } public function testLoadOnlineAvailableAndValidFile() { -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); $this->zip->loadArchive( __DIR__ . DS . "TestResources/well_formatted.zip", true -======= - $this->zip->loadArchive( - __DIR__ . DS . "TestResources/well_formatted.zip", - "dev", - true, - FakeFileDownloader::getInstance() ->>>>>>> Define archive builders and formatters -======= - $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); - - $this->zip->loadArchive( - __DIR__ . DS . "TestResources/well_formatted.zip", - true ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); } /** -<<<<<<< HEAD -<<<<<<< HEAD * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException -======= - * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException ->>>>>>> Define archive builders and formatters -======= - * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException ->>>>>>> Finish implementing and testing zip * @expectedExceptionMessage [Zip Error] The file is not a zip archive */ public function testLoadOnlineAvailableAndNotValidFile() { -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); $this->zip->loadArchive( __DIR__ . DS . "TestResources/bad_formatted.zip", true -======= - $this->zip->loadArchive( - __DIR__ . DS . "TestResources/bad_formatted.zip", - "dev", - true, - FakeFileDownloader::getInstance() ->>>>>>> Define archive builders and formatters -======= - $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); - - $this->zip->loadArchive( - __DIR__ . DS . "TestResources/bad_formatted.zip", - true ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); } @@ -483,27 +218,11 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase */ public function testLoadOnlineNotExistingFile() { -<<<<<<< HEAD -<<<<<<< HEAD $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); $this->zip->loadArchive( __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", true -======= - $this->zip->loadArchive( - __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", - "dev", - true, - FakeFileDownloader::getInstance() ->>>>>>> Define archive builders and formatters -======= - $this->zip->setFileDownloader(FakeFileDownloader::getInstance()); - - $this->zip->loadArchive( - __DIR__ . DS . "TestResources/this_file_doesn_t_exist.zip", - true ->>>>>>> Finish tar, tar.gz, tar.bz2 and tests ); } @@ -606,15 +325,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase public function testBuildArchiveResponse() { $loadedArchiveResponse = $this->loadedZip -<<<<<<< HEAD -<<<<<<< HEAD ->buildArchiveResponse("test") -======= - ->buildArchiveResponse() ->>>>>>> Define archive builders and formatters -======= - ->buildArchiveResponse("test") ->>>>>>> Fix Test ; $loadedArchiveResponseContent = $loadedArchiveResponse->getContent(); @@ -626,10 +337,6 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase $loadedArchiveResponseContent ); } -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Finish implementing and testing zip public function testAddValidFileFromString() { @@ -645,10 +352,6 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase "foo", $this->loadedZip->getFileContent("bar") ); -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> Complete zip tests $this->loadedZip->addFileFromString( "foo", "bar", "baz" @@ -662,11 +365,6 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase "foo", $this->loadedZip->getFileContent("baz/bar") ); -<<<<<<< HEAD -======= ->>>>>>> Finish implementing and testing zip -======= ->>>>>>> Complete zip tests } /** @@ -697,15 +395,4 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase ); } -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Define archive builders and formatters -======= -} ->>>>>>> Finish implementing and testing zip -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php index f5907f49c..69fdfdb9a 100644 --- a/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php @@ -72,12 +72,4 @@ class ArchiveBuilderManagerTest extends \PHPUnit_Framework_TestCase $this->manager->delete("foo"); } -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Define archive builders and formatters -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Tests/FileFormat/Formatting/Formatter/XMLFormatterTest.php b/core/lib/Thelia/Tests/FileFormat/Formatting/Formatter/XMLFormatterTest.php new file mode 100644 index 000000000..2c34d6ebd --- /dev/null +++ b/core/lib/Thelia/Tests/FileFormat/Formatting/Formatter/XMLFormatterTest.php @@ -0,0 +1,178 @@ + + */ +class XMLFormatterTest extends \PHPUnit_Framework_TestCase +{ + /** @var XMLFormatter */ + protected $formatter; + + public function setUp() + { + new Translator(new Container()); + + $this->formatter = new XMLFormatter(); + } + + public function testMetaData() + { + $this->assertEquals( + "XML", + $this->formatter->getName() + ); + + $this->assertEquals( + "xml", + $this->formatter->getExtension() + ); + + $this->assertEquals( + "application/xml", + $this->formatter->getMimeType() + ); + } + + public function testSimpleEncode() + { + $data = new FormatterData(); + + $data->setData( + [ + "foo" => "bar" + ] + ); + + $dom = new \DOMDocument("1.0"); + $dom->appendChild(new \DOMElement("data")) + ->appendChild(new \DOMElement("foo", "bar")); + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + + $this->assertEquals( + $dom->saveXML(), + $this->formatter->encode($data) + ); + } + + public function testComplexEncode() + { + $data = new FormatterData(); + $this->formatter->nodeName = "baz"; + + $data->setData( + [ + "foo" => "bar", + [ + "name" => "banana", + "type" => "fruit", + ], + [ + "orange"=>[ + "type" => "fruit" + ], + "banana"=>[ + "like" => "Yes" + ] + ] + ] + ); + + $dom = new \DOMDocument("1.0"); + $base = $dom->appendChild(new \DOMElement("data")); + $base->appendChild(new \DOMElement("foo", "bar")); + + $baz = $base->appendChild(new \DOMElement("baz")); + $baz->appendChild(new \DOMElement("name", "banana")); + $baz->appendChild(new \DOMElement("type", "fruit")); + + $baz = $base->appendChild(new \DOMElement("baz")); + $orange = $baz->appendChild(new \DOMElement("orange")); + $orange->appendChild(new \DOMElement("type","fruit")); + $banana = $baz->appendChild(new \DOMElement("banana")); + $banana->appendChild(new \DOMElement("like", "Yes")); + + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + + $this->assertEquals( + $dom->saveXML(), + $this->formatter->encode($data) + ); + } + + public function testSimpleDecode() + { + $dom = new \DOMDocument("1.0"); + $dom->appendChild(new \DOMElement("data")) + ->appendChild(new \DOMElement("foo", "bar")); + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + + $raw = $dom->saveXML(); + + $data = $this->formatter->decode($raw); + + $this->assertEquals(["foo" => "bar"], $data->getData()); + } + + public function testComplexDecode() + { + $expectedData = + [ + "foo" => "bar", + [ + "name" => "banana", + "type" => "fruit", + ], + [ + "orange"=>[ + "type" => "fruit" + ], + "banana"=>[ + "like" => "Yes" + ] + ] + ]; + + $dom = new \DOMDocument("1.0"); + $base = $dom->appendChild(new \DOMElement("data")); + $base->appendChild(new \DOMElement("foo", "bar")); + + $baz = $base->appendChild(new \DOMElement("baz")); + $baz->appendChild(new \DOMElement("name", "banana")); + $baz->appendChild(new \DOMElement("type", "fruit")); + + $baz = $base->appendChild(new \DOMElement("baz")); + $orange = $baz->appendChild(new \DOMElement("orange")); + $orange->appendChild(new \DOMElement("type","fruit")); + $banana = $baz->appendChild(new \DOMElement("banana")); + $banana->appendChild(new \DOMElement("like", "Yes")); + + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + + $this->formatter->nodeName = "baz"; + $data = $this->formatter->decode($dom->saveXML()); + + $this->assertEquals($expectedData, $data->getData()); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php b/core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php index f2ae7542f..d9558e192 100644 --- a/core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php +++ b/core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php @@ -359,8 +359,6 @@ class FormatterDataTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedData,$formattedData); } -<<<<<<< HEAD -======= public function testSetRawDataMultipleDepthWithReverseAliases() { $aliases = [ "orange" => "foo", @@ -463,5 +461,4 @@ class FormatterDataTest extends \PHPUnit_Framework_TestCase $this->assertEquals($row, $data->popRow()); $this->assertFalse($data->getRow()); } ->>>>>>> Remove conflicts } diff --git a/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php b/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php index 524ef3aa7..20f4d4682 100644 --- a/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php +++ b/core/lib/Thelia/Tests/Tools/FakeFileDownloader.php @@ -22,18 +22,6 @@ use Thelia\Tools\FileDownload\FileDownloader; class FakeFileDownloader extends FileDownloader { /** -<<<<<<< HEAD -<<<<<<< HEAD - * @param string $url - * @param string $pathToStore -======= - * @param string $url - * @param string $pathToStore ->>>>>>> Define archive builders and formatters -======= - * @param string $url - * @param string $pathToStore ->>>>>>> Fix cs * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException * @throws \HttpUrlException @@ -50,13 +38,4 @@ class FakeFileDownloader extends FileDownloader throw new \ErrorException(); } } - -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Define archive builders and formatters -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php index 2c5a0c2a8..e62840494 100644 --- a/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php +++ b/core/lib/Thelia/Tests/Tools/FileDownloaderTest.php @@ -14,15 +14,7 @@ namespace Thelia\Tests\Type; use Symfony\Component\DependencyInjection\Container; use Thelia\Core\Translation\Translator; use Thelia\Log\Tlog; -<<<<<<< HEAD -<<<<<<< HEAD use Thelia\Tools\FileDownload\FileDownloader; -======= -use Thelia\Tools\FileDownloader; ->>>>>>> Define archive builders and formatters -======= -use Thelia\Tools\FileDownload\FileDownloader; ->>>>>>> Fix FileDownloader test /** * Class FileDownloaderTest @@ -68,12 +60,4 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase { $this->downloader->download("https://github.com/thelia/thelia", "php://temp"); } -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Define archive builders and formatters -======= -} ->>>>>>> Fix cs diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php index 95c54465d..2f77226cf 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloader.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloader.php @@ -17,14 +17,7 @@ use Thelia\Core\Translation\Translator as TheliaTranslator; use Thelia\Exception\FileNotFoundException; use Thelia\Exception\HttpUrlException; use Thelia\Log\Tlog; -<<<<<<< HEAD -<<<<<<< HEAD use Thelia\Tools\URL; -======= ->>>>>>> Define archive builders and formatters -======= -use Thelia\Tools\URL; ->>>>>>> Fix FileDownloader test /** * Class FileDownloader @@ -52,18 +45,8 @@ class FileDownloader implements FileDownloaderInterface } /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $url * @param string $pathToStore -======= - * @param string $url - * @param string $pathToStore ->>>>>>> Define archive builders and formatters -======= - * @param string $url - * @param string $pathToStore ->>>>>>> Fix cs and add get method in managers * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException * @throws \HttpUrlException @@ -142,15 +125,7 @@ class FileDownloader implements FileDownloaderInterface */ $file = @fopen($pathToStore, "w"); -<<<<<<< HEAD -<<<<<<< HEAD if ($file === false) { -======= - if($file === false) { ->>>>>>> Define archive builders and formatters -======= - if ($file === false) { ->>>>>>> Fix cs and add get method in managers $translatedErrorMessage = $this->translator->trans( "Failed to open a writing stream on the file: %file", [ @@ -165,12 +140,4 @@ class FileDownloader implements FileDownloaderInterface fputs($file, $response); fclose($file); } -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Define archive builders and formatters -======= -} ->>>>>>> Fix cs and add get method in managers diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php b/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php index 5ef7880e5..78347bdd9 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php @@ -35,15 +35,7 @@ trait FileDownloaderAwareTrait } /** -<<<<<<< HEAD -<<<<<<< HEAD * @param FileDownloaderInterface $fileDownloader -======= - * @param FileDownloaderInterface $fileDownloader ->>>>>>> Define archive builders and formatters -======= - * @param FileDownloaderInterface $fileDownloader ->>>>>>> Fix cs and add get method in managers * @return $this */ public function setFileDownloader(FileDownloaderInterface $fileDownloader) @@ -52,12 +44,4 @@ trait FileDownloaderAwareTrait return $this; } -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Define archive builders and formatters -======= -} ->>>>>>> Fix cs and add get method in managers diff --git a/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php b/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php index b9f1eaab3..4c29daf29 100644 --- a/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php +++ b/core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php @@ -14,13 +14,6 @@ namespace Thelia\Tools\FileDownload; use Psr\Log\LoggerInterface; use Symfony\Component\Translation\Translator; -<<<<<<< HEAD -<<<<<<< HEAD -======= - ->>>>>>> Define archive builders and formatters -======= ->>>>>>> Fix cs and add get method in managers /** * Class FileDownloader * @package Thelia\Tools\FileDownload @@ -29,18 +22,8 @@ use Symfony\Component\Translation\Translator; interface FileDownloaderInterface { /** -<<<<<<< HEAD -<<<<<<< HEAD * @param string $url * @param string $pathToStore -======= - * @param string $url - * @param string $pathToStore ->>>>>>> Define archive builders and formatters -======= - * @param string $url - * @param string $pathToStore ->>>>>>> Fix cs and add get method in managers * @throws \Thelia\Exception\FileNotFoundException * @throws \ErrorException * @throws \HttpUrlException @@ -57,12 +40,4 @@ interface FileDownloaderInterface * Returns an hydrated instance */ public static function getInstance(); -<<<<<<< HEAD -<<<<<<< HEAD } -======= -} ->>>>>>> Define archive builders and formatters -======= -} ->>>>>>> Fix cs and add get method in managers From ae468d71b6e1ce67470b63f659561e21595eb9f8 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 10 Jul 2014 14:14:32 +0200 Subject: [PATCH 054/158] =?UTF-8?q?Fix=20import=20loop=20and=20a=20resourc?= =?UTF-8?q?e=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/?= =?UTF-8?q?Core/Security/Resource/AdminResources.php=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Core/Template/Loop/Impo?= =?UTF-8?q?rt.php=20=09nouveau=20fichier:=20templates/backOffice/default/i?= =?UTF-8?q?mport.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/Security/Resource/AdminResources.php | 2 +- core/lib/Thelia/Core/Template/Loop/Import.php | 2 +- templates/backOffice/default/import.html | 127 ++++++++++++++++++ 3 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 templates/backOffice/default/import.html diff --git a/core/lib/Thelia/Core/Security/Resource/AdminResources.php b/core/lib/Thelia/Core/Security/Resource/AdminResources.php index 2ddea9877..532e8e5bc 100644 --- a/core/lib/Thelia/Core/Security/Resource/AdminResources.php +++ b/core/lib/Thelia/Core/Security/Resource/AdminResources.php @@ -105,7 +105,7 @@ final class AdminResources const EXPORT = "admin.export"; - const EXPORT_CUSTOMER_NEWSLETTER = "admin.export.customer.newsletter"; + const IMPORT = "admin.import"; const TOOLS = "admin.tools"; } diff --git a/core/lib/Thelia/Core/Template/Loop/Import.php b/core/lib/Thelia/Core/Template/Loop/Import.php index e15ec49b7..c730bd4f0 100644 --- a/core/lib/Thelia/Core/Template/Loop/Import.php +++ b/core/lib/Thelia/Core/Template/Loop/Import.php @@ -22,7 +22,7 @@ class Import extends ImportExportType { protected function getBaseUrl() { - return $this->container->getParameter("export.base_url"); + return $this->container->getParameter("import.base_url"); } protected function getQueryModel() diff --git a/templates/backOffice/default/import.html b/templates/backOffice/default/import.html new file mode 100644 index 000000000..bcd6fd972 --- /dev/null +++ b/templates/backOffice/default/import.html @@ -0,0 +1,127 @@ +{extends file="admin-layout.tpl"} + +{block name="no-return-functions"} + {$admin_current_location = 'tools'} +{/block} + +{block name="page-title"}{intl l='Imports'}{/block} + +{block name="check-resource"}admin.import{/block} +{block name="check-access"}view{/block} + +{block name="main-content"} +
+ +
+ + + + {module_include location='tools_top'} + + {loop name="import-category" type="import-category"} + {if $LOOP_COUNT % 3} +
+ {/if} + +
+ +
+ + {if $LOOP_COUNT % 3} +
+ {/if} + {/loop} + + {module_include location='configuration_bottom'} +
+
+{/block} + + +{block name="javascript-initialization"} + {javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} + + {/javascripts} +{/block} + +{block name="javascript-last-call"} + + + {module_include location='configuration-js'} +{/block} \ No newline at end of file From 7bd741edd138c88c0310ee61282d588a4b402c75 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 10 Jul 2014 14:36:26 +0200 Subject: [PATCH 055/158] =?UTF-8?q?Remove=20export=20form=20in=20the=20exp?= =?UTF-8?q?orts=20list=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20templa?= =?UTF-8?q?tes/backOffice/default/export.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/backOffice/default/export.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/templates/backOffice/default/export.html b/templates/backOffice/default/export.html index 889e74449..a0e6ece4c 100644 --- a/templates/backOffice/default/export.html +++ b/templates/backOffice/default/export.html @@ -11,7 +11,6 @@ {block name="main-content"} - {form name="thelia.admin.export"}
@@ -94,8 +93,6 @@
- {/form} - {/block} From bd1b64c3116bb6d90fd0d04e23d5827884d36312 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 10 Jul 2014 14:39:52 +0200 Subject: [PATCH 056/158] =?UTF-8?q?delete=20html=20form=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20templates/backOffice/default/export.?= =?UTF-8?q?html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/backOffice/default/export.html | 135 +++++++++++------------ 1 file changed, 66 insertions(+), 69 deletions(-) diff --git a/templates/backOffice/default/export.html b/templates/backOffice/default/export.html index a0e6ece4c..5f307c9fe 100644 --- a/templates/backOffice/default/export.html +++ b/templates/backOffice/default/export.html @@ -10,89 +10,86 @@ {block name="check-access"}view{/block} {block name="main-content"} +
-
-
+
-
+ - + {module_include location='tools_top'} - {module_include location='tools_top'} + {loop name="export-category" type="export-category"} + {if $LOOP_COUNT % 3} +
+ {/if} - {loop name="export-category" type="export-category"} - {if $LOOP_COUNT % 3} -
- {/if} - -
-
- - {if $LOOP_COUNT % 3}
- {/if} - {/loop} - {module_include location='configuration_bottom'} -
+ {if $LOOP_COUNT % 3} +
+ {/if} + {/loop} + + {module_include location='configuration_bottom'}
- +
{/block} From a1526620f4179dbfe65059b86f9fdf4f6780f48f Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 10 Jul 2014 14:42:03 +0200 Subject: [PATCH 057/158] =?UTF-8?q?Add=20import=20link=20in=20tools=20=09m?= =?UTF-8?q?odifi=C3=A9:=20=20=20=20=20=20=20=20=20templates/backOffice/def?= =?UTF-8?q?ault/tools.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/backOffice/default/tools.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/templates/backOffice/default/tools.html b/templates/backOffice/default/tools.html index 99a90b330..216643c44 100644 --- a/templates/backOffice/default/tools.html +++ b/templates/backOffice/default/tools.html @@ -54,6 +54,12 @@ {/loop} + {loop name="auth-import" type="auth" role="ADMIN" resource="admin.import" access="VIEW"} + + {intl l="Import"} + + + {/loop} {module_include location='tools_col1_bottom'}
From 178ed493f08da954452f8c698bee695b7405cbf6 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 10 Jul 2014 15:10:19 +0200 Subject: [PATCH 058/158] =?UTF-8?q?Update=20database,=20add=20export=20and?= =?UTF-8?q?=20import=20handle=20classes=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Model/Base/Export.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Model/Base/Ex?= =?UTF-8?q?portQuery.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core?= =?UTF-8?q?/lib/Thelia/Model/Base/Import.php=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/Model/Base/ImportQuery.php=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Mode?= =?UTF-8?q?l/Export.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/?= =?UTF-8?q?lib/Thelia/Model/Import.php=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Model/Map/ExportTableMap.php=20=09m?= =?UTF-8?q?odifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Model/Ma?= =?UTF-8?q?p/ImportTableMap.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20local/config/schema.xml=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20setup/thelia.sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Model/Base/Export.php | 76 ++++++++++++++-- core/lib/Thelia/Model/Base/ExportQuery.php | 35 +++++++- core/lib/Thelia/Model/Base/Import.php | 76 ++++++++++++++-- core/lib/Thelia/Model/Base/ImportQuery.php | 35 +++++++- core/lib/Thelia/Model/Export.php | 31 +++++++ core/lib/Thelia/Model/Import.php | 94 ++++++++++++++++++++ core/lib/Thelia/Model/Map/ExportTableMap.php | 36 +++++--- core/lib/Thelia/Model/Map/ImportTableMap.php | 36 +++++--- local/config/schema.xml | 2 + setup/thelia.sql | 2 + 10 files changed, 375 insertions(+), 48 deletions(-) diff --git a/core/lib/Thelia/Model/Base/Export.php b/core/lib/Thelia/Model/Base/Export.php index b5902b177..a2d8cb9a3 100644 --- a/core/lib/Thelia/Model/Base/Export.php +++ b/core/lib/Thelia/Model/Base/Export.php @@ -77,6 +77,12 @@ abstract class Export implements ActiveRecordInterface */ protected $position; + /** + * The value for the handleclass field. + * @var string + */ + protected $handleclass; + /** * The value for the created_at field. * @var string @@ -419,6 +425,17 @@ abstract class Export implements ActiveRecordInterface return $this->position; } + /** + * Get the [handleclass] column value. + * + * @return string + */ + public function getHandleclass() + { + + return $this->handleclass; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -526,6 +543,27 @@ abstract class Export implements ActiveRecordInterface return $this; } // setPosition() + /** + * Set the value of [handleclass] column. + * + * @param string $v new value + * @return \Thelia\Model\Export The current object (for fluent API support) + */ + public function setHandleclass($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->handleclass !== $v) { + $this->handleclass = $v; + $this->modifiedColumns[ExportTableMap::HANDLECLASS] = true; + } + + + return $this; + } // setHandleclass() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -614,13 +652,16 @@ abstract class Export implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ExportTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; $this->position = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ExportTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ExportTableMap::translateFieldName('Handleclass', TableMap::TYPE_PHPNAME, $indexType)]; + $this->handleclass = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ExportTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ExportTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ExportTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -633,7 +674,7 @@ abstract class Export implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 5; // 5 = ExportTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 6; // 6 = ExportTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\Export object", 0, $e); @@ -897,6 +938,9 @@ abstract class Export implements ActiveRecordInterface if ($this->isColumnModified(ExportTableMap::POSITION)) { $modifiedColumns[':p' . $index++] = '`POSITION`'; } + if ($this->isColumnModified(ExportTableMap::HANDLECLASS)) { + $modifiedColumns[':p' . $index++] = '`HANDLECLASS`'; + } if ($this->isColumnModified(ExportTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = '`CREATED_AT`'; } @@ -923,6 +967,9 @@ abstract class Export implements ActiveRecordInterface case '`POSITION`': $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); break; + case '`HANDLECLASS`': + $stmt->bindValue($identifier, $this->handleclass, PDO::PARAM_STR); + break; case '`CREATED_AT`': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; @@ -1001,9 +1048,12 @@ abstract class Export implements ActiveRecordInterface return $this->getPosition(); break; case 3: - return $this->getCreatedAt(); + return $this->getHandleclass(); break; case 4: + return $this->getCreatedAt(); + break; + case 5: return $this->getUpdatedAt(); break; default: @@ -1038,8 +1088,9 @@ abstract class Export implements ActiveRecordInterface $keys[0] => $this->getId(), $keys[1] => $this->getExportCategoryId(), $keys[2] => $this->getPosition(), - $keys[3] => $this->getCreatedAt(), - $keys[4] => $this->getUpdatedAt(), + $keys[3] => $this->getHandleclass(), + $keys[4] => $this->getCreatedAt(), + $keys[5] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { @@ -1097,9 +1148,12 @@ abstract class Export implements ActiveRecordInterface $this->setPosition($value); break; case 3: - $this->setCreatedAt($value); + $this->setHandleclass($value); break; case 4: + $this->setCreatedAt($value); + break; + case 5: $this->setUpdatedAt($value); break; } // switch() @@ -1129,8 +1183,9 @@ abstract class Export implements ActiveRecordInterface if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setExportCategoryId($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setPosition($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]); + if (array_key_exists($keys[3], $arr)) $this->setHandleclass($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setUpdatedAt($arr[$keys[5]]); } /** @@ -1145,6 +1200,7 @@ abstract class Export implements ActiveRecordInterface if ($this->isColumnModified(ExportTableMap::ID)) $criteria->add(ExportTableMap::ID, $this->id); if ($this->isColumnModified(ExportTableMap::EXPORT_CATEGORY_ID)) $criteria->add(ExportTableMap::EXPORT_CATEGORY_ID, $this->export_category_id); if ($this->isColumnModified(ExportTableMap::POSITION)) $criteria->add(ExportTableMap::POSITION, $this->position); + if ($this->isColumnModified(ExportTableMap::HANDLECLASS)) $criteria->add(ExportTableMap::HANDLECLASS, $this->handleclass); if ($this->isColumnModified(ExportTableMap::CREATED_AT)) $criteria->add(ExportTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(ExportTableMap::UPDATED_AT)) $criteria->add(ExportTableMap::UPDATED_AT, $this->updated_at); @@ -1212,6 +1268,7 @@ abstract class Export implements ActiveRecordInterface { $copyObj->setExportCategoryId($this->getExportCategoryId()); $copyObj->setPosition($this->getPosition()); + $copyObj->setHandleclass($this->getHandleclass()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); @@ -1556,6 +1613,7 @@ abstract class Export implements ActiveRecordInterface $this->id = null; $this->export_category_id = null; $this->position = null; + $this->handleclass = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/core/lib/Thelia/Model/Base/ExportQuery.php b/core/lib/Thelia/Model/Base/ExportQuery.php index 1a34da44f..65e266d73 100644 --- a/core/lib/Thelia/Model/Base/ExportQuery.php +++ b/core/lib/Thelia/Model/Base/ExportQuery.php @@ -25,12 +25,14 @@ use Thelia\Model\Map\ExportTableMap; * @method ChildExportQuery orderById($order = Criteria::ASC) Order by the id column * @method ChildExportQuery orderByExportCategoryId($order = Criteria::ASC) Order by the export_category_id column * @method ChildExportQuery orderByPosition($order = Criteria::ASC) Order by the position column + * @method ChildExportQuery orderByHandleclass($order = Criteria::ASC) Order by the handleClass column * @method ChildExportQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildExportQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * * @method ChildExportQuery groupById() Group by the id column * @method ChildExportQuery groupByExportCategoryId() Group by the export_category_id column * @method ChildExportQuery groupByPosition() Group by the position column + * @method ChildExportQuery groupByHandleclass() Group by the handleClass column * @method ChildExportQuery groupByCreatedAt() Group by the created_at column * @method ChildExportQuery groupByUpdatedAt() Group by the updated_at column * @@ -52,12 +54,14 @@ use Thelia\Model\Map\ExportTableMap; * @method ChildExport findOneById(int $id) Return the first ChildExport filtered by the id column * @method ChildExport findOneByExportCategoryId(int $export_category_id) Return the first ChildExport filtered by the export_category_id column * @method ChildExport findOneByPosition(int $position) Return the first ChildExport filtered by the position column + * @method ChildExport findOneByHandleclass(string $handleClass) Return the first ChildExport filtered by the handleClass column * @method ChildExport findOneByCreatedAt(string $created_at) Return the first ChildExport filtered by the created_at column * @method ChildExport findOneByUpdatedAt(string $updated_at) Return the first ChildExport filtered by the updated_at column * * @method array findById(int $id) Return ChildExport objects filtered by the id column * @method array findByExportCategoryId(int $export_category_id) Return ChildExport objects filtered by the export_category_id column * @method array findByPosition(int $position) Return ChildExport objects filtered by the position column + * @method array findByHandleclass(string $handleClass) Return ChildExport objects filtered by the handleClass column * @method array findByCreatedAt(string $created_at) Return ChildExport objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildExport objects filtered by the updated_at column * @@ -148,7 +152,7 @@ abstract class ExportQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT `ID`, `EXPORT_CATEGORY_ID`, `POSITION`, `CREATED_AT`, `UPDATED_AT` FROM `export` WHERE `ID` = :p0'; + $sql = 'SELECT `ID`, `EXPORT_CATEGORY_ID`, `POSITION`, `HANDLECLASS`, `CREATED_AT`, `UPDATED_AT` FROM `export` WHERE `ID` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -362,6 +366,35 @@ abstract class ExportQuery extends ModelCriteria return $this->addUsingAlias(ExportTableMap::POSITION, $position, $comparison); } + /** + * Filter the query on the handleClass column + * + * Example usage: + * + * $query->filterByHandleclass('fooValue'); // WHERE handleClass = 'fooValue' + * $query->filterByHandleclass('%fooValue%'); // WHERE handleClass LIKE '%fooValue%' + * + * + * @param string $handleclass The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildExportQuery The current query, for fluid interface + */ + public function filterByHandleclass($handleclass = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($handleclass)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $handleclass)) { + $handleclass = str_replace('*', '%', $handleclass); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ExportTableMap::HANDLECLASS, $handleclass, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Base/Import.php b/core/lib/Thelia/Model/Base/Import.php index e2b0e3cd6..180125c2e 100644 --- a/core/lib/Thelia/Model/Base/Import.php +++ b/core/lib/Thelia/Model/Base/Import.php @@ -77,6 +77,12 @@ abstract class Import implements ActiveRecordInterface */ protected $position; + /** + * The value for the handleclass field. + * @var string + */ + protected $handleclass; + /** * The value for the created_at field. * @var string @@ -419,6 +425,17 @@ abstract class Import implements ActiveRecordInterface return $this->position; } + /** + * Get the [handleclass] column value. + * + * @return string + */ + public function getHandleclass() + { + + return $this->handleclass; + } + /** * Get the [optionally formatted] temporal [created_at] column value. * @@ -526,6 +543,27 @@ abstract class Import implements ActiveRecordInterface return $this; } // setPosition() + /** + * Set the value of [handleclass] column. + * + * @param string $v new value + * @return \Thelia\Model\Import The current object (for fluent API support) + */ + public function setHandleclass($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->handleclass !== $v) { + $this->handleclass = $v; + $this->modifiedColumns[ImportTableMap::HANDLECLASS] = true; + } + + + return $this; + } // setHandleclass() + /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * @@ -614,13 +652,16 @@ abstract class Import implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : ImportTableMap::translateFieldName('Position', TableMap::TYPE_PHPNAME, $indexType)]; $this->position = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ImportTableMap::translateFieldName('Handleclass', TableMap::TYPE_PHPNAME, $indexType)]; + $this->handleclass = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ImportTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ImportTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ImportTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; if ($col === '0000-00-00 00:00:00') { $col = null; } @@ -633,7 +674,7 @@ abstract class Import implements ActiveRecordInterface $this->ensureConsistency(); } - return $startcol + 5; // 5 = ImportTableMap::NUM_HYDRATE_COLUMNS. + return $startcol + 6; // 6 = ImportTableMap::NUM_HYDRATE_COLUMNS. } catch (Exception $e) { throw new PropelException("Error populating \Thelia\Model\Import object", 0, $e); @@ -897,6 +938,9 @@ abstract class Import implements ActiveRecordInterface if ($this->isColumnModified(ImportTableMap::POSITION)) { $modifiedColumns[':p' . $index++] = '`POSITION`'; } + if ($this->isColumnModified(ImportTableMap::HANDLECLASS)) { + $modifiedColumns[':p' . $index++] = '`HANDLECLASS`'; + } if ($this->isColumnModified(ImportTableMap::CREATED_AT)) { $modifiedColumns[':p' . $index++] = '`CREATED_AT`'; } @@ -923,6 +967,9 @@ abstract class Import implements ActiveRecordInterface case '`POSITION`': $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT); break; + case '`HANDLECLASS`': + $stmt->bindValue($identifier, $this->handleclass, PDO::PARAM_STR); + break; case '`CREATED_AT`': $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); break; @@ -1001,9 +1048,12 @@ abstract class Import implements ActiveRecordInterface return $this->getPosition(); break; case 3: - return $this->getCreatedAt(); + return $this->getHandleclass(); break; case 4: + return $this->getCreatedAt(); + break; + case 5: return $this->getUpdatedAt(); break; default: @@ -1038,8 +1088,9 @@ abstract class Import implements ActiveRecordInterface $keys[0] => $this->getId(), $keys[1] => $this->getImportCategoryId(), $keys[2] => $this->getPosition(), - $keys[3] => $this->getCreatedAt(), - $keys[4] => $this->getUpdatedAt(), + $keys[3] => $this->getHandleclass(), + $keys[4] => $this->getCreatedAt(), + $keys[5] => $this->getUpdatedAt(), ); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { @@ -1097,9 +1148,12 @@ abstract class Import implements ActiveRecordInterface $this->setPosition($value); break; case 3: - $this->setCreatedAt($value); + $this->setHandleclass($value); break; case 4: + $this->setCreatedAt($value); + break; + case 5: $this->setUpdatedAt($value); break; } // switch() @@ -1129,8 +1183,9 @@ abstract class Import implements ActiveRecordInterface if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setImportCategoryId($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setPosition($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setCreatedAt($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setUpdatedAt($arr[$keys[4]]); + if (array_key_exists($keys[3], $arr)) $this->setHandleclass($arr[$keys[3]]); + if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]); + if (array_key_exists($keys[5], $arr)) $this->setUpdatedAt($arr[$keys[5]]); } /** @@ -1145,6 +1200,7 @@ abstract class Import implements ActiveRecordInterface if ($this->isColumnModified(ImportTableMap::ID)) $criteria->add(ImportTableMap::ID, $this->id); if ($this->isColumnModified(ImportTableMap::IMPORT_CATEGORY_ID)) $criteria->add(ImportTableMap::IMPORT_CATEGORY_ID, $this->import_category_id); if ($this->isColumnModified(ImportTableMap::POSITION)) $criteria->add(ImportTableMap::POSITION, $this->position); + if ($this->isColumnModified(ImportTableMap::HANDLECLASS)) $criteria->add(ImportTableMap::HANDLECLASS, $this->handleclass); if ($this->isColumnModified(ImportTableMap::CREATED_AT)) $criteria->add(ImportTableMap::CREATED_AT, $this->created_at); if ($this->isColumnModified(ImportTableMap::UPDATED_AT)) $criteria->add(ImportTableMap::UPDATED_AT, $this->updated_at); @@ -1212,6 +1268,7 @@ abstract class Import implements ActiveRecordInterface { $copyObj->setImportCategoryId($this->getImportCategoryId()); $copyObj->setPosition($this->getPosition()); + $copyObj->setHandleclass($this->getHandleclass()); $copyObj->setCreatedAt($this->getCreatedAt()); $copyObj->setUpdatedAt($this->getUpdatedAt()); @@ -1556,6 +1613,7 @@ abstract class Import implements ActiveRecordInterface $this->id = null; $this->import_category_id = null; $this->position = null; + $this->handleclass = null; $this->created_at = null; $this->updated_at = null; $this->alreadyInSave = false; diff --git a/core/lib/Thelia/Model/Base/ImportQuery.php b/core/lib/Thelia/Model/Base/ImportQuery.php index 7fa735844..883783ebb 100644 --- a/core/lib/Thelia/Model/Base/ImportQuery.php +++ b/core/lib/Thelia/Model/Base/ImportQuery.php @@ -25,12 +25,14 @@ use Thelia\Model\Map\ImportTableMap; * @method ChildImportQuery orderById($order = Criteria::ASC) Order by the id column * @method ChildImportQuery orderByImportCategoryId($order = Criteria::ASC) Order by the import_category_id column * @method ChildImportQuery orderByPosition($order = Criteria::ASC) Order by the position column + * @method ChildImportQuery orderByHandleclass($order = Criteria::ASC) Order by the handleClass column * @method ChildImportQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column * @method ChildImportQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * * @method ChildImportQuery groupById() Group by the id column * @method ChildImportQuery groupByImportCategoryId() Group by the import_category_id column * @method ChildImportQuery groupByPosition() Group by the position column + * @method ChildImportQuery groupByHandleclass() Group by the handleClass column * @method ChildImportQuery groupByCreatedAt() Group by the created_at column * @method ChildImportQuery groupByUpdatedAt() Group by the updated_at column * @@ -52,12 +54,14 @@ use Thelia\Model\Map\ImportTableMap; * @method ChildImport findOneById(int $id) Return the first ChildImport filtered by the id column * @method ChildImport findOneByImportCategoryId(int $import_category_id) Return the first ChildImport filtered by the import_category_id column * @method ChildImport findOneByPosition(int $position) Return the first ChildImport filtered by the position column + * @method ChildImport findOneByHandleclass(string $handleClass) Return the first ChildImport filtered by the handleClass column * @method ChildImport findOneByCreatedAt(string $created_at) Return the first ChildImport filtered by the created_at column * @method ChildImport findOneByUpdatedAt(string $updated_at) Return the first ChildImport filtered by the updated_at column * * @method array findById(int $id) Return ChildImport objects filtered by the id column * @method array findByImportCategoryId(int $import_category_id) Return ChildImport objects filtered by the import_category_id column * @method array findByPosition(int $position) Return ChildImport objects filtered by the position column + * @method array findByHandleclass(string $handleClass) Return ChildImport objects filtered by the handleClass column * @method array findByCreatedAt(string $created_at) Return ChildImport objects filtered by the created_at column * @method array findByUpdatedAt(string $updated_at) Return ChildImport objects filtered by the updated_at column * @@ -148,7 +152,7 @@ abstract class ImportQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT `ID`, `IMPORT_CATEGORY_ID`, `POSITION`, `CREATED_AT`, `UPDATED_AT` FROM `import` WHERE `ID` = :p0'; + $sql = 'SELECT `ID`, `IMPORT_CATEGORY_ID`, `POSITION`, `HANDLECLASS`, `CREATED_AT`, `UPDATED_AT` FROM `import` WHERE `ID` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -362,6 +366,35 @@ abstract class ImportQuery extends ModelCriteria return $this->addUsingAlias(ImportTableMap::POSITION, $position, $comparison); } + /** + * Filter the query on the handleClass column + * + * Example usage: + * + * $query->filterByHandleclass('fooValue'); // WHERE handleClass = 'fooValue' + * $query->filterByHandleclass('%fooValue%'); // WHERE handleClass LIKE '%fooValue%' + * + * + * @param string $handleclass The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildImportQuery The current query, for fluid interface + */ + public function filterByHandleclass($handleclass = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($handleclass)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $handleclass)) { + $handleclass = str_replace('*', '%', $handleclass); + $comparison = Criteria::LIKE; + } + } + + return $this->addUsingAlias(ImportTableMap::HANDLECLASS, $handleclass, $comparison); + } + /** * Filter the query on the created_at column * diff --git a/core/lib/Thelia/Model/Export.php b/core/lib/Thelia/Model/Export.php index 1abef0932..ef48cbf45 100644 --- a/core/lib/Thelia/Model/Export.php +++ b/core/lib/Thelia/Model/Export.php @@ -3,6 +3,8 @@ namespace Thelia\Model; use Propel\Runtime\ActiveQuery\Criteria; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Thelia\ImportExport\ExportHandlerInterface; use Thelia\Model\Base\Export as BaseExport; use Thelia\Model\Map\ExportTableMap; @@ -10,6 +12,7 @@ class Export extends BaseExport { public function upPosition() { + if (($position = $this->getPosition()) > 1) { $previous = ExportQuery::create() @@ -70,4 +73,32 @@ class Export extends BaseExport $this->setPosition($position)->save(); } + + public function getHandleClassInstance(ContainerInterface $container) + { + $class = $this->getHandleClass(); + + if (!class_exists($class)) { + throw new \ErrorException( + "The class \"%class\" doesn't exist", + [ + "%class" => $class + ] + ); + } + + $instance = new $class($container); + + if (!$class instanceof ExportHandlerInterface) { + throw new \ErrorException( + "The class \"%class\" must implement %interface", + [ + "%class" => $class, + "%interface" => "\\Thelia\\ImportExport\\ExportHandlerInterface", + ] + ); + } + + return $instance; + } } diff --git a/core/lib/Thelia/Model/Import.php b/core/lib/Thelia/Model/Import.php index b0a589ff0..b54829fb0 100644 --- a/core/lib/Thelia/Model/Import.php +++ b/core/lib/Thelia/Model/Import.php @@ -2,9 +2,103 @@ namespace Thelia\Model; +use Propel\Runtime\ActiveQuery\Criteria; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Thelia\ImportExport\ExportHandlerInterface; use Thelia\Model\Base\Import as BaseImport; +use Thelia\Model\Map\ImportTableMap; class Import extends BaseImport { + public function upPosition() + { + if (($position = $this->getPosition()) > 1) { + + $previous = ImportQuery::create() + ->filterByPosition($position - 1) + ->findOneByImportCategoryId($this->getImportCategoryId()); + + if (null !== $previous) { + $previous->setPosition($position)->save(); + } + + $this->setPosition($position - 1)->save(); + } + + return $this; + } + + public function downPosition() + { + $max = ImportQuery::create() + ->orderByPosition(Criteria::DESC) + ->select(ImportTableMap::POSITION) + ->findOne() + ; + + $count = $this->getImportCategory()->countImports(); + + if ($count > $max) { + $max = $count; + } + + $position = $this->getPosition(); + + if ($position < $max) { + + $next = ImportQuery::create() + ->filterByPosition($position + 1) + ->findOneByImportCategoryId($this->getImportCategoryId()); + + if (null !== $next) { + $next->setPosition($position)->save(); + } + + $this->setPosition($position + 1)->save(); + } + + return $this; + } + + public function updatePosition($position) + { + $reverse = ImportQuery::create() + ->findOneByPosition($position) + ; + + if (null !== $reverse) { + $reverse->setPosition($this->getPosition())->save(); + } + + $this->setPosition($position)->save(); + } + + public function getHandleClassInstance(ContainerInterface $container) + { + $class = $this->getHandleClass(); + + if (!class_exists($class)) { + throw new \ErrorException( + "The class \"%class\" doesn't exist", + [ + "%class" => $class + ] + ); + } + + $instance = new $class($container); + + if (!$class instanceof ExportHandlerInterface) { + throw new \ErrorException( + "The class \"%class\" must implement %interface", + [ + "%class" => $class, + "%interface" => "\\Thelia\\ImportExport\\ExportHandlerInterface", + ] + ); + } + + return $instance; + } } diff --git a/core/lib/Thelia/Model/Map/ExportTableMap.php b/core/lib/Thelia/Model/Map/ExportTableMap.php index f9ead6b5b..58b667b9d 100644 --- a/core/lib/Thelia/Model/Map/ExportTableMap.php +++ b/core/lib/Thelia/Model/Map/ExportTableMap.php @@ -58,7 +58,7 @@ class ExportTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 5; + const NUM_COLUMNS = 6; /** * The number of lazy-loaded columns @@ -68,7 +68,7 @@ class ExportTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 5; + const NUM_HYDRATE_COLUMNS = 6; /** * the column name for the ID field @@ -85,6 +85,11 @@ class ExportTableMap extends TableMap */ const POSITION = 'export.POSITION'; + /** + * the column name for the HANDLECLASS field + */ + const HANDLECLASS = 'export.HANDLECLASS'; + /** * the column name for the CREATED_AT field */ @@ -116,12 +121,12 @@ class ExportTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'ExportCategoryId', 'Position', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'exportCategoryId', 'position', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(ExportTableMap::ID, ExportTableMap::EXPORT_CATEGORY_ID, ExportTableMap::POSITION, ExportTableMap::CREATED_AT, ExportTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'EXPORT_CATEGORY_ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'export_category_id', 'position', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + self::TYPE_PHPNAME => array('Id', 'ExportCategoryId', 'Position', 'Handleclass', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'exportCategoryId', 'position', 'handleclass', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(ExportTableMap::ID, ExportTableMap::EXPORT_CATEGORY_ID, ExportTableMap::POSITION, ExportTableMap::HANDLECLASS, ExportTableMap::CREATED_AT, ExportTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'EXPORT_CATEGORY_ID', 'POSITION', 'HANDLECLASS', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'export_category_id', 'position', 'handleClass', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) ); /** @@ -131,12 +136,12 @@ class ExportTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'ExportCategoryId' => 1, 'Position' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'exportCategoryId' => 1, 'position' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), - self::TYPE_COLNAME => array(ExportTableMap::ID => 0, ExportTableMap::EXPORT_CATEGORY_ID => 1, ExportTableMap::POSITION => 2, ExportTableMap::CREATED_AT => 3, ExportTableMap::UPDATED_AT => 4, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'EXPORT_CATEGORY_ID' => 1, 'POSITION' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), - self::TYPE_FIELDNAME => array('id' => 0, 'export_category_id' => 1, 'position' => 2, 'created_at' => 3, 'updated_at' => 4, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + self::TYPE_PHPNAME => array('Id' => 0, 'ExportCategoryId' => 1, 'Position' => 2, 'Handleclass' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'exportCategoryId' => 1, 'position' => 2, 'handleclass' => 3, 'createdAt' => 4, 'updatedAt' => 5, ), + self::TYPE_COLNAME => array(ExportTableMap::ID => 0, ExportTableMap::EXPORT_CATEGORY_ID => 1, ExportTableMap::POSITION => 2, ExportTableMap::HANDLECLASS => 3, ExportTableMap::CREATED_AT => 4, ExportTableMap::UPDATED_AT => 5, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'EXPORT_CATEGORY_ID' => 1, 'POSITION' => 2, 'HANDLECLASS' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ), + self::TYPE_FIELDNAME => array('id' => 0, 'export_category_id' => 1, 'position' => 2, 'handleClass' => 3, 'created_at' => 4, 'updated_at' => 5, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) ); /** @@ -158,6 +163,7 @@ class ExportTableMap extends TableMap $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addForeignKey('EXPORT_CATEGORY_ID', 'ExportCategoryId', 'INTEGER', 'export_category', 'ID', true, null, null); $this->addColumn('POSITION', 'Position', 'INTEGER', true, null, null); + $this->addColumn('HANDLECLASS', 'Handleclass', 'CLOB', true, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -335,12 +341,14 @@ class ExportTableMap extends TableMap $criteria->addSelectColumn(ExportTableMap::ID); $criteria->addSelectColumn(ExportTableMap::EXPORT_CATEGORY_ID); $criteria->addSelectColumn(ExportTableMap::POSITION); + $criteria->addSelectColumn(ExportTableMap::HANDLECLASS); $criteria->addSelectColumn(ExportTableMap::CREATED_AT); $criteria->addSelectColumn(ExportTableMap::UPDATED_AT); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.EXPORT_CATEGORY_ID'); $criteria->addSelectColumn($alias . '.POSITION'); + $criteria->addSelectColumn($alias . '.HANDLECLASS'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/core/lib/Thelia/Model/Map/ImportTableMap.php b/core/lib/Thelia/Model/Map/ImportTableMap.php index 873b4d196..735c20236 100644 --- a/core/lib/Thelia/Model/Map/ImportTableMap.php +++ b/core/lib/Thelia/Model/Map/ImportTableMap.php @@ -58,7 +58,7 @@ class ImportTableMap extends TableMap /** * The total number of columns */ - const NUM_COLUMNS = 5; + const NUM_COLUMNS = 6; /** * The number of lazy-loaded columns @@ -68,7 +68,7 @@ class ImportTableMap extends TableMap /** * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */ - const NUM_HYDRATE_COLUMNS = 5; + const NUM_HYDRATE_COLUMNS = 6; /** * the column name for the ID field @@ -85,6 +85,11 @@ class ImportTableMap extends TableMap */ const POSITION = 'import.POSITION'; + /** + * the column name for the HANDLECLASS field + */ + const HANDLECLASS = 'import.HANDLECLASS'; + /** * the column name for the CREATED_AT field */ @@ -116,12 +121,12 @@ class ImportTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'ImportCategoryId', 'Position', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'importCategoryId', 'position', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(ImportTableMap::ID, ImportTableMap::IMPORT_CATEGORY_ID, ImportTableMap::POSITION, ImportTableMap::CREATED_AT, ImportTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'IMPORT_CATEGORY_ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'import_category_id', 'position', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + self::TYPE_PHPNAME => array('Id', 'ImportCategoryId', 'Position', 'Handleclass', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'importCategoryId', 'position', 'handleclass', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(ImportTableMap::ID, ImportTableMap::IMPORT_CATEGORY_ID, ImportTableMap::POSITION, ImportTableMap::HANDLECLASS, ImportTableMap::CREATED_AT, ImportTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'IMPORT_CATEGORY_ID', 'POSITION', 'HANDLECLASS', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'import_category_id', 'position', 'handleClass', 'created_at', 'updated_at', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) ); /** @@ -131,12 +136,12 @@ class ImportTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'ImportCategoryId' => 1, 'Position' => 2, 'CreatedAt' => 3, 'UpdatedAt' => 4, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'importCategoryId' => 1, 'position' => 2, 'createdAt' => 3, 'updatedAt' => 4, ), - self::TYPE_COLNAME => array(ImportTableMap::ID => 0, ImportTableMap::IMPORT_CATEGORY_ID => 1, ImportTableMap::POSITION => 2, ImportTableMap::CREATED_AT => 3, ImportTableMap::UPDATED_AT => 4, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'IMPORT_CATEGORY_ID' => 1, 'POSITION' => 2, 'CREATED_AT' => 3, 'UPDATED_AT' => 4, ), - self::TYPE_FIELDNAME => array('id' => 0, 'import_category_id' => 1, 'position' => 2, 'created_at' => 3, 'updated_at' => 4, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + self::TYPE_PHPNAME => array('Id' => 0, 'ImportCategoryId' => 1, 'Position' => 2, 'Handleclass' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'importCategoryId' => 1, 'position' => 2, 'handleclass' => 3, 'createdAt' => 4, 'updatedAt' => 5, ), + self::TYPE_COLNAME => array(ImportTableMap::ID => 0, ImportTableMap::IMPORT_CATEGORY_ID => 1, ImportTableMap::POSITION => 2, ImportTableMap::HANDLECLASS => 3, ImportTableMap::CREATED_AT => 4, ImportTableMap::UPDATED_AT => 5, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'IMPORT_CATEGORY_ID' => 1, 'POSITION' => 2, 'HANDLECLASS' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ), + self::TYPE_FIELDNAME => array('id' => 0, 'import_category_id' => 1, 'position' => 2, 'handleClass' => 3, 'created_at' => 4, 'updated_at' => 5, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) ); /** @@ -158,6 +163,7 @@ class ImportTableMap extends TableMap $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addForeignKey('IMPORT_CATEGORY_ID', 'ImportCategoryId', 'INTEGER', 'import_category', 'ID', true, null, null); $this->addColumn('POSITION', 'Position', 'INTEGER', true, null, null); + $this->addColumn('HANDLECLASS', 'Handleclass', 'CLOB', true, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); } // initialize() @@ -335,12 +341,14 @@ class ImportTableMap extends TableMap $criteria->addSelectColumn(ImportTableMap::ID); $criteria->addSelectColumn(ImportTableMap::IMPORT_CATEGORY_ID); $criteria->addSelectColumn(ImportTableMap::POSITION); + $criteria->addSelectColumn(ImportTableMap::HANDLECLASS); $criteria->addSelectColumn(ImportTableMap::CREATED_AT); $criteria->addSelectColumn(ImportTableMap::UPDATED_AT); } else { $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.IMPORT_CATEGORY_ID'); $criteria->addSelectColumn($alias . '.POSITION'); + $criteria->addSelectColumn($alias . '.HANDLECLASS'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); } diff --git a/local/config/schema.xml b/local/config/schema.xml index a62929ec3..b21b9526e 100644 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1536,6 +1536,7 @@ + @@ -1553,6 +1554,7 @@ + diff --git a/setup/thelia.sql b/setup/thelia.sql index c5fa24f45..92456c51b 100644 --- a/setup/thelia.sql +++ b/setup/thelia.sql @@ -1914,6 +1914,7 @@ CREATE TABLE `import` `id` INTEGER NOT NULL AUTO_INCREMENT, `import_category_id` INTEGER NOT NULL, `position` INTEGER NOT NULL, + `handleClass` LONGTEXT NOT NULL, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), @@ -1936,6 +1937,7 @@ CREATE TABLE `export` `id` INTEGER NOT NULL AUTO_INCREMENT, `export_category_id` INTEGER NOT NULL, `position` INTEGER NOT NULL, + `handleClass` LONGTEXT NOT NULL, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), From 4e5bbd7f607f5bf284a122a09c7543c892d74727 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Thu, 10 Jul 2014 15:12:40 +0200 Subject: [PATCH 059/158] Define interfaces for import and export handle class nouveau fichier: core/lib/Thelia/ImportExport/ExportHandlerInterface.php nouveau fichier: core/lib/Thelia/ImportExport/ImportHandlerInterface.php --- .../ImportExport/ExportHandlerInterface.php | 36 ++++++++++++++++++ .../ImportExport/ImportHandlerInterface.php | 37 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 core/lib/Thelia/ImportExport/ExportHandlerInterface.php create mode 100644 core/lib/Thelia/ImportExport/ImportHandlerInterface.php diff --git a/core/lib/Thelia/ImportExport/ExportHandlerInterface.php b/core/lib/Thelia/ImportExport/ExportHandlerInterface.php new file mode 100644 index 000000000..4d637201b --- /dev/null +++ b/core/lib/Thelia/ImportExport/ExportHandlerInterface.php @@ -0,0 +1,36 @@ + + */ +interface ExportHandlerInterface +{ + /** + * @param ContainerInterface $container + * + * Dependency injection: load the container to be able to get parameters and services + */ + public function __construct(ContainerInterface $container); + + /** + * @return \Thelia\Core\FileFormat\Formatting\FormatterData + * + * The method builds + */ + public function buildFormatterData(); +} \ No newline at end of file diff --git a/core/lib/Thelia/ImportExport/ImportHandlerInterface.php b/core/lib/Thelia/ImportExport/ImportHandlerInterface.php new file mode 100644 index 000000000..1faba3786 --- /dev/null +++ b/core/lib/Thelia/ImportExport/ImportHandlerInterface.php @@ -0,0 +1,37 @@ + + */ +interface ImportHandlerInterface +{ + /** + * @param ContainerInterface $container + * + * Dependency injection: load the container to be able to get parameters and services + */ + public function __construct(ContainerInterface $container); + + /** + * @return \Thelia\Core\FileFormat\Formatting\FormatterData + * + * The method builds + */ + public function importFromFormatterData(FormatterData $data); +} \ No newline at end of file From 6bc3ed214bcf30ee4bf9053f71310211a898bb65 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 11 Jul 2014 09:56:06 +0200 Subject: [PATCH 060/158] =?UTF-8?q?Finish=20Import=20/=20Export=20categori?= =?UTF-8?q?es=20management=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20co?= =?UTF-8?q?re/lib/Thelia/Config/Resources/routing/admin.xml=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Controller/Ad?= =?UTF-8?q?min/ExportController.php=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/Controller/Admin/ImportExportControlle?= =?UTF-8?q?r.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/The?= =?UTF-8?q?lia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php=20?= =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core?= =?UTF-8?q?/FileFormat/Formatting/Formatter/XMLFormatter.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileForm?= =?UTF-8?q?at/Formatting/FormatterInterface.php=20=09modifi=C3=A9:=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20core/lib/Thelia/Core/Template/Loop/Export.?= =?UTF-8?q?php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Theli?= =?UTF-8?q?a/Core/Template/Loop/Formatter.php=20=09nouveau=20fichier:=20co?= =?UTF-8?q?re/lib/Thelia/ImportExport/Both/NewsletterImportExport.php=20?= =?UTF-8?q?=09nouveau=20fichier:=20core/lib/Thelia/ImportExport/Export/Exp?= =?UTF-8?q?ortType.php=20=09nouveau=20fichier:=20core/lib/Thelia/ImportExp?= =?UTF-8?q?ort/Export/MailingExport.php=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/ImportExport/ExportHandlerInterface?= =?UTF-8?q?.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thel?= =?UTF-8?q?ia/Model/Export.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20core/lib/Thelia/Model/ExportCategory.php=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Model/ImportCategory?= =?UTF-8?q?.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20templates/bac?= =?UTF-8?q?kOffice/default/export-page.html=20=09modifi=C3=A9:=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20templates/backOffice/default/export.html=20=09mo?= =?UTF-8?q?difi=C3=A9:=20=20=20=20=20=20=20=20=20templates/backOffice/defa?= =?UTF-8?q?ult/import.html=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20te?= =?UTF-8?q?mplates/backOffice/default/includes/export-form-definition.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Thelia/Config/Resources/routing/admin.xml | 14 +- .../Controller/Admin/ExportController.php | 88 ++++++++++-- .../Admin/ImportExportController.php | 26 +++- .../Formatting/Formatter/JsonFormatter.php | 8 ++ .../Formatting/Formatter/XMLFormatter.php | 9 ++ .../Formatting/FormatterInterface.php | 13 ++ core/lib/Thelia/Core/Template/Loop/Export.php | 1 - .../Thelia/Core/Template/Loop/Formatter.php | 25 ++-- .../Both/NewsletterImportExport.php | 58 ++++++++ .../Thelia/ImportExport/Export/ExportType.php | 33 +++++ .../ImportExport/Export/MailingExport.php | 47 +++++++ .../ImportExport/ExportHandlerInterface.php | 17 +++ core/lib/Thelia/Model/Export.php | 5 + core/lib/Thelia/Model/ExportCategory.php | 66 ++++++++- core/lib/Thelia/Model/ImportCategory.php | 63 +++++++++ templates/backOffice/default/export-page.html | 46 ++++++ templates/backOffice/default/export.html | 93 ++++++------- templates/backOffice/default/import.html | 131 +++++++++++------- .../includes/export-form-definition.html | 2 +- 19 files changed, 610 insertions(+), 135 deletions(-) create mode 100644 core/lib/Thelia/ImportExport/Both/NewsletterImportExport.php create mode 100644 core/lib/Thelia/ImportExport/Export/ExportType.php create mode 100644 core/lib/Thelia/ImportExport/Export/MailingExport.php diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 52d4d6ca3..e10e4fbcb 100644 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -1158,7 +1158,7 @@ Thelia\Controller\Admin\TranslationsController::updateAction
- + Thelia\Controller\Admin\ExportController::indexAction @@ -1176,6 +1176,18 @@ \d+ + + Thelia\Controller\Admin\ExportController::changeCategoryPosition + up|down + \d+ + + + + Thelia\Controller\Admin\ExportController::updateCategoryPosition + \d+ + \d+ + + Thelia\Controller\Admin\ImportExportController::export \d+ diff --git a/core/lib/Thelia/Controller/Admin/ExportController.php b/core/lib/Thelia/Controller/Admin/ExportController.php index 69832b9e8..8f20d61a7 100644 --- a/core/lib/Thelia/Controller/Admin/ExportController.php +++ b/core/lib/Thelia/Controller/Admin/ExportController.php @@ -16,6 +16,7 @@ use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\Resource\AdminResources; use Thelia\Core\Template\Loop\ImportExportType; use Thelia\Core\Translation\Translator; +use Thelia\Model\ExportCategoryQuery; use Thelia\Model\ExportQuery; /** @@ -31,15 +32,7 @@ class ExportController extends BaseAdminController return $response; } - $export_order = $this->getRequest()->query->get("export_order"); - - if (!in_array($export_order, ImportExportType::getAllowedOrders())) { - $export_order = ImportExportType::DEFAULT_ORDER; - } - - $this->getParserContext() - ->set("export_order", $export_order) - ; + $this->setOrders(); return $this->render('export'); } @@ -58,9 +51,7 @@ class ExportController extends BaseAdminController $export->downPosition(); } - $this->getParserContext() - ->set("export_order", "manual") - ; + $this->setOrders(null, "manual"); return $this->render('export'); } @@ -75,13 +66,63 @@ class ExportController extends BaseAdminController $export->updatePosition($value); - $this->getParserContext() - ->set("export_order", "manual") - ; + $this->setOrders(null, "manual"); return $this->render('export'); } + public function changeCategoryPosition($action, $id) + { + if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::UPDATE])) { + return $response; + } + + $category = $this->getCategory($id); + + if ($action === "up") { + $category->upPosition(); + } elseif ($action === "down") { + $category->downPosition(); + } + + $this->setOrders("manual"); + + return $this->render('export'); + } + + public function updateCategoryPosition($id, $value) + { + if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::UPDATE])) { + return $response; + } + + $category = $this->getCategory($id); + + $category->updatePosition($value); + + $this->setOrders("manual"); + + return $this->render('export'); + } + + protected function setOrders($category = null, $export = null) + { + if ($category === null) { + $category = $this->getRequest()->query->get("category_order"); + } + + if ($export === null) { + $export = $this->getRequest()->query->get("export_order"); + } + + $this->getParserContext() + ->set("category_order", $category) + ; + + $this->getParserContext() + ->set("export_order", $export) + ; + } protected function getExport($id) { @@ -99,4 +140,21 @@ class ExportController extends BaseAdminController } return $export; } + + protected function getCategory($id) + { + $category = ExportCategoryQuery::create()->findPk($id); + + if (null === $category) { + throw new \ErrorException( + Translator::getInstance()->trans( + "There is no id \"%id\" in the export categories", + [ + "%id" => $id + ] + ) + ); + } + return $category; + } } diff --git a/core/lib/Thelia/Controller/Admin/ImportExportController.php b/core/lib/Thelia/Controller/Admin/ImportExportController.php index 4226ef0e4..c9ab79e86 100644 --- a/core/lib/Thelia/Controller/Admin/ImportExportController.php +++ b/core/lib/Thelia/Controller/Admin/ImportExportController.php @@ -12,6 +12,7 @@ namespace Thelia\Controller\Admin; use Thelia\Core\HttpFoundation\Response; +use Thelia\Model\ExportQuery; /** * Class ImportExportController @@ -20,23 +21,40 @@ use Thelia\Core\HttpFoundation\Response; */ class ImportExportController extends BaseAdminController { - public function import() + public function import($id) { } - public function export() + public function export($id) { } - public function importView() + public function importView($id) { + if (null === $export = $this->getExport($id)) { + return $this->render("404"); + } + return $this->render("import-page"); } - public function exportView() + public function exportView($id) { + if (null === $export = $this->getExport($id)) { + return $this->render("404"); + } + return $this->render("export-page"); } + + protected function getExport($id) + { + $export = ExportQuery::create() + ->findPk($id) + ; + + return $export; + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php index 06f182a00..04612bfdb 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php @@ -13,6 +13,7 @@ namespace Thelia\Core\FileFormat\Formatting\Formatter; use Thelia\Core\FileFormat\Formatting\AbstractFormatter; use Thelia\Core\FileFormat\Formatting\FormatterData; +use Thelia\ImportExport\Export\ExportType; /** * Class JsonFormatter @@ -87,4 +88,11 @@ class JsonFormatter extends AbstractFormatter ); } + public function getExportType() + { + return array( + ExportType::EXPORT_TABLE, + ExportType::EXPORT_UNBOUNDED, + ); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php index 3ab3f7de4..45046af96 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php @@ -14,6 +14,7 @@ namespace Thelia\Core\FileFormat\Formatting\Formatter; use Thelia\Core\FileFormat\Formatter\Exception\BadFormattedStringException; use Thelia\Core\FileFormat\Formatting\AbstractFormatter; use Thelia\Core\FileFormat\Formatting\FormatterData; +use Thelia\ImportExport\Export\ExportType; /** * Class XMLFormatter @@ -141,4 +142,12 @@ class XMLFormatter extends AbstractFormatter $data = new FormatterData($this->getAliases()); return $data->setData($array); } + + public function getExportType() + { + return array( + ExportType::EXPORT_TABLE, + ExportType::EXPORT_UNBOUNDED, + ); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/FormatterInterface.php b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterInterface.php index c88c36c54..a68daac2d 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/FormatterInterface.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterInterface.php @@ -36,4 +36,17 @@ interface FormatterInterface * a FormatterData object. */ public function decode($rawData); + + /** + * @return string + * + * return a string that defines the handled format type. + * + * Thelia types are defined in \Thelia\ImportExport\Export\ExportType + * + * examples: + * return ExportType::EXPORT_TABLE; + * return ExportType::EXPORT_UNBOUNDED; + */ + public function getExportType(); } diff --git a/core/lib/Thelia/Core/Template/Loop/Export.php b/core/lib/Thelia/Core/Template/Loop/Export.php index 1815b15d5..1975832e5 100644 --- a/core/lib/Thelia/Core/Template/Loop/Export.php +++ b/core/lib/Thelia/Core/Template/Loop/Export.php @@ -12,7 +12,6 @@ namespace Thelia\Core\Template\Loop; use Thelia\Model\ExportQuery; -use Thelia\Model\Map\ExportTableMap; /** * Class Export diff --git a/core/lib/Thelia/Core/Template/Loop/Formatter.php b/core/lib/Thelia/Core/Template/Loop/Formatter.php index 0c77e4de6..15cac4399 100644 --- a/core/lib/Thelia/Core/Template/Loop/Formatter.php +++ b/core/lib/Thelia/Core/Template/Loop/Formatter.php @@ -17,6 +17,7 @@ use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Model\ExportQuery; use Thelia\Type\EnumType; use Thelia\Type\TypeCollection; @@ -39,19 +40,27 @@ class Formatter extends BaseLoop implements ArraySearchLoopInterface $rawFormatters = array_change_key_case($service->getAll()); - $allowedFormatter = $this->getAllowed_formatter(); + $exportId = $this->getExport(); $formatters = []; - if ($allowedFormatter !== null) { - $allowedFormatter = explode(",", $allowedFormatter); + if ($exportId !== null) { + $export = ExportQuery::create()->findPk($exportId); + if (null !== $export) { + $types = $export->getHandleClassInstance($this->container) + ->getHandledType(); - foreach($allowedFormatter as $formatter) { - $formatter = trim(strtolower($formatter)); + if (is_scalar($types)) { + $types = [$types]; + } - if (isset($rawFormatters[$formatter])) { - $formatters[$formatter] = $rawFormatters[$formatter]; + /** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */ + foreach ($rawFormatters as $key=>$formatter) { + if (in_array($formatter->getExportType(), $types)) { + $formatters[$key] = $formatter; + } } } + } else { $formatters = $rawFormatters; } @@ -118,7 +127,7 @@ class Formatter extends BaseLoop implements ArraySearchLoopInterface protected function getArgDefinitions() { return new ArgumentCollection( - Argument::createAnyTypeArgument("allowed_formatter"), + Argument::createIntTypeArgument("export"), new Argument( "order", new TypeCollection( diff --git a/core/lib/Thelia/ImportExport/Both/NewsletterImportExport.php b/core/lib/Thelia/ImportExport/Both/NewsletterImportExport.php new file mode 100644 index 000000000..ffa220e38 --- /dev/null +++ b/core/lib/Thelia/ImportExport/Both/NewsletterImportExport.php @@ -0,0 +1,58 @@ + + */ +class NewsletterImportExport implements ExportHandlerInterface, ImportHandlerInterface +{ + protected $container; + + /** + * @param ContainerInterface $container + * + * Dependency injection: load the container to be able to get parameters and services + */ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + /** + * @return \Thelia\Core\FileFormat\Formatting\FormatterData + * + * The method builds + */ + public function buildFormatterData() + { + // TODO: Implement buildFormatterData() method. + } + + /** + * @return \Thelia\Core\FileFormat\Formatting\FormatterData + * + * The method builds + */ + public function importFromFormatterData(FormatterData $data) + { + // TODO: Implement importFromFormatterData() method. + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/ImportExport/Export/ExportType.php b/core/lib/Thelia/ImportExport/Export/ExportType.php new file mode 100644 index 000000000..7b98edd4a --- /dev/null +++ b/core/lib/Thelia/ImportExport/Export/ExportType.php @@ -0,0 +1,33 @@ + + */ +class ExportType +{ + /** + * This type is for unbounded formats, in general serialization formats + * example: XML, json, yaml + */ + const EXPORT_UNBOUNDED = "export.unbounded"; + + /** + * This type is for tabled format ( matrix ), most used by spreadsheet application. + * example: CSV, ODS, XLS + */ + const EXPORT_TABLE = "export.table"; +} \ No newline at end of file diff --git a/core/lib/Thelia/ImportExport/Export/MailingExport.php b/core/lib/Thelia/ImportExport/Export/MailingExport.php new file mode 100644 index 000000000..01e73eb8e --- /dev/null +++ b/core/lib/Thelia/ImportExport/Export/MailingExport.php @@ -0,0 +1,47 @@ + + */ +class MailingExport implements ExportHandlerInterface +{ + protected $container; + + /** + * @param ContainerInterface $container + * + * Dependency injection: load the container to be able to get parameters and services + */ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + /** + * @return \Thelia\Core\FileFormat\Formatting\FormatterData + * + * The method builds + */ + public function buildFormatterData() + { + $data = new FormatterData(); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/ImportExport/ExportHandlerInterface.php b/core/lib/Thelia/ImportExport/ExportHandlerInterface.php index 4d637201b..64348ff3b 100644 --- a/core/lib/Thelia/ImportExport/ExportHandlerInterface.php +++ b/core/lib/Thelia/ImportExport/ExportHandlerInterface.php @@ -33,4 +33,21 @@ interface ExportHandlerInterface * The method builds */ public function buildFormatterData(); + + /** + * @return string|array + * + * Define all the type of export/formatters that this can handle + * return a string if it handle a single type ( specific exports ), + * or an array if multiple. + * + * Thelia types are defined in \Thelia\ImportExport\Export\ExportType + * + * example: + * return array( + * ExportType::EXPORT_TABLE, + * ExportType::EXPORT_UNBOUNDED, + * ); + */ + public function getHandledType(); } \ No newline at end of file diff --git a/core/lib/Thelia/Model/Export.php b/core/lib/Thelia/Model/Export.php index ef48cbf45..529aeba54 100644 --- a/core/lib/Thelia/Model/Export.php +++ b/core/lib/Thelia/Model/Export.php @@ -74,6 +74,11 @@ class Export extends BaseExport $this->setPosition($position)->save(); } + /** + * @param ContainerInterface $container + * @return ExportHandlerInterface + * @throws \ErrorException + */ public function getHandleClassInstance(ContainerInterface $container) { $class = $this->getHandleClass(); diff --git a/core/lib/Thelia/Model/ExportCategory.php b/core/lib/Thelia/Model/ExportCategory.php index 49c205e39..2e3726e31 100644 --- a/core/lib/Thelia/Model/ExportCategory.php +++ b/core/lib/Thelia/Model/ExportCategory.php @@ -2,9 +2,73 @@ namespace Thelia\Model; +use Propel\Runtime\ActiveQuery\Criteria; +use Thelia\Model\Base\CategoryQuery; use Thelia\Model\Base\ExportCategory as BaseExportCategory; +use Thelia\Model\Map\ExportCategoryTableMap; class ExportCategory extends BaseExportCategory { + public function upPosition() + { + if (($position = $this->getPosition()) > 1) { -} + $previous = ExportCategoryQuery::create() + ->findOneByPosition($position - 1) + ; + + if (null !== $previous) { + $previous->setPosition($position)->save(); + } + + $this->setPosition($position - 1)->save(); + } + + return $this; + } + + public function downPosition() + { + $max = CategoryQuery::create() + ->orderByPosition(Criteria::DESC) + ->select(ExportCategoryTableMap::POSITION) + ->findOne() + ; + + $count = CategoryQuery::create()->count(); + + if ($count > $max) { + $max = $count; + } + + $position = $this->getPosition(); + + if ($position < $max) { + + $next = ExportCategoryQuery::create() + ->findOneByPosition($position + 1) + ; + + if (null !== $next) { + $next->setPosition($position)->save(); + } + + $this->setPosition($position + 1)->save(); + } + + return $this; + } + + public function updatePosition($position) + { + $reverse = ExportCategoryQuery::create() + ->findOneByPosition($position) + ; + + if (null !== $reverse) { + $reverse->setPosition($this->getPosition())->save(); + } + + $this->setPosition($position)->save(); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Model/ImportCategory.php b/core/lib/Thelia/Model/ImportCategory.php index 9fac04af6..7eec69306 100644 --- a/core/lib/Thelia/Model/ImportCategory.php +++ b/core/lib/Thelia/Model/ImportCategory.php @@ -2,9 +2,72 @@ namespace Thelia\Model; +use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Model\Base\ImportCategory as BaseImportCategory; +use Thelia\Model\Map\ImportCategoryTableMap; class ImportCategory extends BaseImportCategory { + public function upPosition() + { + if (($position = $this->getPosition()) > 1) { + $previous = ImportCategoryQuery::create() + ->findOneByPosition($position - 1) + ; + + if (null !== $previous) { + $previous->setPosition($position)->save(); + } + + $this->setPosition($position - 1)->save(); + } + + return $this; + } + + public function downPosition() + { + $max = CategoryQuery::create() + ->orderByPosition(Criteria::DESC) + ->select(ImportCategoryTableMap::POSITION) + ->findOne() + ; + + $count = CategoryQuery::create()->count(); + + if ($count > $max) { + $max = $count; + } + + $position = $this->getPosition(); + + if ($position < $max) { + + $next = ImportCategoryQuery::create() + ->findOneByPosition($position + 1) + ; + + if (null !== $next) { + $next->setPosition($position)->save(); + } + + $this->setPosition($position + 1)->save(); + } + + return $this; + } + + public function updatePosition($position) + { + $reverse = ImportCategoryQuery::create() + ->findOneByPosition($position) + ; + + if (null !== $reverse) { + $reverse->setPosition($this->getPosition())->save(); + } + + $this->setPosition($position)->save(); + } } diff --git a/templates/backOffice/default/export-page.html b/templates/backOffice/default/export-page.html index e69de29bb..f1b49c6ef 100644 --- a/templates/backOffice/default/export-page.html +++ b/templates/backOffice/default/export-page.html @@ -0,0 +1,46 @@ +{extends file="admin-layout.tpl"} + +{block name="no-return-functions"} + {$admin_current_location = 'tools'} +{/block} + +{block name="page-title"}{intl l='Export: %name' name=$NAME}{/block} + +{block name="check-resource"}admin.export{/block} +{block name="check-access"}view{/block} + +{block name="main-content"} +{/block} + +{block name="javascript-initialization"} + {javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} + + {/javascripts} +{/block} + +{block name="javascript-last-call"} + + + {module_include location='configuration-js'} +{/block} \ No newline at end of file diff --git a/templates/backOffice/default/export.html b/templates/backOffice/default/export.html index 5f307c9fe..beccb4987 100644 --- a/templates/backOffice/default/export.html +++ b/templates/backOffice/default/export.html @@ -10,6 +10,14 @@ {block name="check-access"}view{/block} {block name="main-content"} + {if $category_order != "manual"} + {assign url_category "category_order="|cat:$category_order} + {/if} + {if $export_order != "manual"} + {assign url_export "export_order="|cat:$export_order} + {/if} + +
@@ -24,36 +32,42 @@ {module_include location='tools_top'} - {loop name="export-category" type="export-category"} - {if $LOOP_COUNT % 3} + {loop name="export-category" type="export-category" order=$category_order}
- {/if} - -
-