Commit 6173dc59 by Krzysztof Kuźniar

Update module - fix media asset import path #3

parent fa14ac42
...@@ -149,33 +149,38 @@ class DamServices ...@@ -149,33 +149,38 @@ class DamServices
if (filter_var($value, FILTER_VALIDATE_URL)) { if (filter_var($value, FILTER_VALIDATE_URL)) {
$media[] = $this->changeUrlToContent($value, $code, $index); $media[] = $this->changeUrlToContent($value, $code, $index);
} else { } else {
$dataFilePath = $value; $dataFilePath = $value;
// $mediapath[$index]['data'] = sprintf(
// '%s%s%s',
// $filePath,
// DIRECTORY_SEPARATOR,
// $dataFilePath
// );
$mediapath = sprintf( $mediapath = sprintf(
'%s%s%s', '%s%s%s',
$filePath, $filePath,
DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR,
$dataFilePath $dataFilePath
); );
$mediapath = $this->clean($mediapath);
// dd($filePath, $mediapath);
try { try {
$link_array = explode('/', $filePath); $link_array = explode('/', $filePath);
$page = str_replace(' ', '', end($link_array)); $page = str_replace(' ', '', end($link_array));
$newFilePath = $page.'/'.$dataFilePath; $newFilePath = $page.'/'.$dataFilePath;
$newFileDirectory = substr($newFilePath, 0, strrpos($newFilePath, '/')); $newFileDirectory = substr($newFilePath, 0, strrpos($newFilePath, '/'));
if (!file_exists($newFilePath) || $this->overrideImages) {
if (!file_exists($newFilePath) || $this->overrideImages) {
$fileSystemProvide = $this->fileSystem; // if ($version > '3.0' && $version < '4.0') {
$fs = $fileSystemProvide->getFilesystem('tmpStorage'); // $fs = $this->fileSystem->getFilesystem('tmpStorage');
// } else {
// $fs = $this->fileSystem->getFilesystem(\FileStorage::CATALOG_STORAGE_ALIAS);
// }
$fs = $this->fileSystem->getFilesystem('catalogStorage');
$content = fopen($mediapath, 'r'); $content = fopen($mediapath, 'r');
try {
$content = fopen($mediapath, 'r');
} catch (\Exception $e) {
dump('Exception : ', $e->getMessage());
}
$fs->put($newFilePath, $content); $fs->put($newFilePath, $content);
$newFilePath = $fs->getAdapter()->getPathPrefix() . $newFilePath; $newFilePath = $fs->getAdapter()->getPathPrefix() . $newFilePath;
...@@ -183,15 +188,26 @@ class DamServices ...@@ -183,15 +188,26 @@ class DamServices
$media[] = $newFilePath; $media[] = $newFilePath;
} catch (\Exception $e) { } catch (\Exception $e) {
echo $e->getMessage();
$newFilePath = null; $newFilePath = null;
} }
} }
} }
} }
return $media; return $media;
} }
public function clean($full_path){
return str_replace(array(
"\\\\",
"\\/",
"//",
"\\/",
"/\\"), DIRECTORY_SEPARATOR, $full_path);
}
public function getMetricUnits() public function getMetricUnits()
{ {
$measure = $this->metric->indexAction(); $measure = $this->metric->indexAction();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment