Inital commit
This commit is contained in:
@@ -41,12 +41,17 @@ use Thelia\Tools\URL;
|
||||
*/
|
||||
class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var string Config key for document delivery mode
|
||||
*/
|
||||
const CONFIG_DELIVERY_MODE = 'original_document_delivery_mode';
|
||||
|
||||
/**
|
||||
* @return string root of the document cache directory in web space
|
||||
*/
|
||||
protected function getCacheDirFromWebRoot()
|
||||
{
|
||||
return ConfigQuery::read('document_cache_dir_from_web_root', 'cache');
|
||||
return ConfigQuery::read('document_cache_dir_from_web_root', 'cache' . DS . 'documents');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,20 +79,19 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
$originalDocumentPathInCache = $this->getCacheFilePath($subdir, $sourceFile, true);
|
||||
|
||||
if (! file_exists($originalDocumentPathInCache)) {
|
||||
|
||||
if (! file_exists($sourceFile)) {
|
||||
throw new DocumentException(sprintf("Source document file %s does not exists.", $sourceFile));
|
||||
}
|
||||
|
||||
$mode = ConfigQuery::read('original_document_delivery_mode', 'symlink');
|
||||
$mode = ConfigQuery::read(self::CONFIG_DELIVERY_MODE, 'symlink');
|
||||
|
||||
if ($mode == 'symlink') {
|
||||
if (false == symlink($sourceFile, $originalDocumentPathInCache)) {
|
||||
throw new DocumentException(sprintf("Failed to create symbolic link for %s in %s document cache directory", basename($sourceFile), $subdir));
|
||||
if (false === symlink($sourceFile, $originalDocumentPathInCache)) {
|
||||
throw new DocumentException(sprintf("Failed to create symbolic link for %s in %s document cache directory", basename($sourceFile), $subdir));
|
||||
}
|
||||
} else {
|
||||
// mode = 'copy'
|
||||
if (false == @copy($sourceFile, $originalDocumentPathInCache)) {
|
||||
if (false === @copy($sourceFile, $originalDocumentPathInCache)) {
|
||||
throw new DocumentException(sprintf("Failed to copy %s in %s document cache directory", basename($sourceFile), $subdir));
|
||||
}
|
||||
}
|
||||
@@ -101,6 +105,9 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
$event->setDocumentUrl(URL::getInstance()->absoluteUrl($documentUrl, null, URL::PATH_TO_FILE));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
@@ -112,6 +119,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
TheliaEvents::DOCUMENT_SAVE => array("saveFile", 128),
|
||||
TheliaEvents::DOCUMENT_UPDATE => array("updateFile", 128),
|
||||
TheliaEvents::DOCUMENT_UPDATE_POSITION => array("updatePosition", 128),
|
||||
TheliaEvents::DOCUMENT_TOGGLE_VISIBILITY => array("toggleVisibility", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user