Commit 6173dc59 by Krzysztof Kuźniar

Update module - fix media asset import path #3

parent fa14ac42
......@@ -149,33 +149,38 @@ class DamServices
if (filter_var($value, FILTER_VALIDATE_URL)) {
$media[] = $this->changeUrlToContent($value, $code, $index);
} else {
$dataFilePath = $value;
// $mediapath[$index]['data'] = sprintf(
// '%s%s%s',
// $filePath,
// DIRECTORY_SEPARATOR,
// $dataFilePath
// );
$mediapath = sprintf(
'%s%s%s',
$filePath,
DIRECTORY_SEPARATOR,
$dataFilePath
);
$mediapath = $this->clean($mediapath);
// dd($filePath, $mediapath);
try {
$link_array = explode('/', $filePath);
$page = str_replace(' ', '', end($link_array));
$newFilePath = $page.'/'.$dataFilePath;
$newFileDirectory = substr($newFilePath, 0, strrpos($newFilePath, '/'));
if (!file_exists($newFilePath) || $this->overrideImages) {
$fileSystemProvide = $this->fileSystem;
$fs = $fileSystemProvide->getFilesystem('tmpStorage');
$content = fopen($mediapath, 'r');
// if ($version > '3.0' && $version < '4.0') {
// $fs = $this->fileSystem->getFilesystem('tmpStorage');
// } else {
// $fs = $this->fileSystem->getFilesystem(\FileStorage::CATALOG_STORAGE_ALIAS);
// }
$fs = $this->fileSystem->getFilesystem('catalogStorage');
$content = fopen($mediapath, 'r');
try {
$content = fopen($mediapath, 'r');
} catch (\Exception $e) {
dump('Exception : ', $e->getMessage());
}
$fs->put($newFilePath, $content);
$newFilePath = $fs->getAdapter()->getPathPrefix() . $newFilePath;
......@@ -183,15 +188,26 @@ class DamServices
$media[] = $newFilePath;
} catch (\Exception $e) {
echo $e->getMessage();
$newFilePath = null;
}
}
}
}
return $media;
}
public function clean($full_path){
return str_replace(array(
"\\\\",
"\\/",
"//",
"\\/",
"/\\"), DIRECTORY_SEPARATOR, $full_path);
}
public function getMetricUnits()
{
$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