Skip to content

Commit

Permalink
Merge pull request #50 from BioKIC/master
Browse files Browse the repository at this point in the history
Media Remapping tool dev
  • Loading branch information
egbot authored Feb 27, 2023
2 parents e31dcba + d4f6756 commit 0636cce
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions classes/MediaResolutionTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class MediaResolutionTools extends Manager {
private $imgRootUrl;
private $imgRootPath;
private $imgSubPath;
private $sourcePathPrefix;

private $debugMode = false;

Expand Down Expand Up @@ -288,8 +289,7 @@ public function migrateCollectionDerivatives($imgIdStart, $limit){
if($this->transferThumbnail){
$fileName = basename($r->thumbnailurl);
$targetPath = $this->imgRootPath.$pathFrag.$fileName;
$thumnPath = $r->thumbnailurl;
if(strpos($thumnPath, $GLOBALS['IMAGE_ROOT_URL']) !== false) $thumnPath = str_replace($GLOBALS['IMAGE_ROOT_URL'], $GLOBALS['IMAGE_ROOT_PATH'], $thumnPath);
$thumnPath = $this->getLocalPath($r->thumbnailurl);
if(copy($thumnPath, $targetPath)){
$imgArr[$r->imgid]['tn'] = $targetPath;
if($this->debugMode) $this->logOrEcho('Copied: '.$thumnPath.' => '.$targetPath,1);
Expand All @@ -303,8 +303,7 @@ public function migrateCollectionDerivatives($imgIdStart, $limit){
if($this->transferWeb){
$fileName = basename($r->url);
$targetPath = $this->imgRootPath.$pathFrag.$fileName;
$urlPath = $r->url;
if(strpos($urlPath, $GLOBALS['IMAGE_ROOT_URL']) !== false) $urlPath = str_replace($GLOBALS['IMAGE_ROOT_URL'], $GLOBALS['IMAGE_ROOT_PATH'], $urlPath);
$urlPath = $this->getLocalPath($r->url);
if(copy($urlPath, $targetPath)){
$imgArr[$r->imgid]['web'] = $targetPath;
if($this->debugMode) $this->logOrEcho('Copied: '.$urlPath.' => '.$targetPath,1);
Expand All @@ -318,8 +317,7 @@ public function migrateCollectionDerivatives($imgIdStart, $limit){
if($this->transferLarge){
$fileName = basename($r->originalurl);
$targetPath = $this->imgRootPath.$pathFrag.$fileName;
$origPath = $r->originalurl;
if(strpos($origPath, $GLOBALS['IMAGE_ROOT_URL']) !== false) $origPath = str_replace($GLOBALS['IMAGE_ROOT_URL'], $GLOBALS['IMAGE_ROOT_PATH'], $origPath);
$origPath = $this->getLocalPath($r->originalurl);
if(copy($origPath, $targetPath)){
$imgArr[$r->imgid]['lg'] = $targetPath;
if($this->debugMode) $this->logOrEcho('Copied: '.$origPath.' => '.$targetPath,1);
Expand Down Expand Up @@ -348,6 +346,31 @@ public function migrateCollectionDerivatives($imgIdStart, $limit){
return $imgIdStart;
}

private function getLocalPath($imageUrl){
if($this->sourcePathPrefix){
$adjustedUrl = str_replace($this->sourcePathPrefix, $GLOBALS['IMAGE_ROOT_PATH'], $imageUrl);
if(file_exists($adjustedUrl)) return $adjustedUrl;
}
if(file_exists($imageUrl)){
return $imageUrl;
}
if(strpos($imageUrl, $GLOBALS['IMAGE_ROOT_URL']) !== false){
$adjustedUrl = str_replace($GLOBALS['IMAGE_ROOT_URL'], $GLOBALS['IMAGE_ROOT_PATH'], $imageUrl);
if(file_exists($adjustedUrl)) return $adjustedUrl;
}
$sourcePathPrefix = '';
$fragArr = explode('/', $imageUrl);
while($fragArr){
$sourcePathPrefix .= '/'.array_shift($fragArr);
$testPath = $GLOBALS['IMAGE_ROOT_PATH'].'/'.implode('/', $fragArr);
if(file_exists($testPath)){
$this->sourcePathPrefix = $sourcePathPrefix;
return $testPath;
}
}
return $imageUrl;
}

private function databaseImageArr($imgArr){
foreach($imgArr as $imgID => $iArr){
$sqlFrag = '';
Expand Down

0 comments on commit 0636cce

Please sign in to comment.