Quellcode durchsuchen

#3384 Automatic redirect from local storage to remote storage if some references still point to local storage

Alex Trofimov vor 5 Jahren
Ursprung
Commit
1fb4d069c4
2 geänderte Dateien mit 32 neuen und 3 gelöschten Zeilen
  1. 16 0
      inc/classes/BxDolStorage.php
  2. 16 3
      storage.php

+ 16 - 0
inc/classes/BxDolStorage.php

@@ -659,6 +659,22 @@ abstract class BxDolStorage extends BxDolFactory implements iBxDolFactoryObject
         return true;
     }
 
+    /**
+     * Get file url.
+     * @param $sRemoteId file remote id
+     * @return file url or false on error
+     */
+    public function getFileUrlByRemoteId($sRemoteId)
+    {
+        $aFile = $this->_oDb->getFileByRemoteId($sRemoteId);
+        if (!$aFile) {
+            $this->setErrorCode(BX_DOL_STORAGE_ERR_FILE_NOT_FOUND);
+            return false;
+        }
+
+        return $this->getFileUrlById($aFile['id']);
+    }
+
     /**
      * Get file url.
      * @param $iFileId file id

+ 16 - 3
storage.php

@@ -7,8 +7,6 @@
  * @{
  */
 
-//ob_start();
-
 require_once('./inc/header.inc.php');
 
 $sStorageObject = bx_process_input(bx_get('o'));
@@ -31,7 +29,22 @@ if (!$sRemoteId) {
     exit;
 }
 
-//ob_end_clean();
+// redirect for remote storage in case if some references still pointing to local storage
+$aObject = $oStorage->getObjectData();
+if ('Local' != $aObject['engine']) {
+    if (!($sUrl = $oStorage->getFileUrlByRemoteId($sFile))) {
+        // Tmp fix for storages renaming in the past
+        if ('bx_posts_files' == $sStorageObject && ($oStorage = BxDolStorage::getObjectInstance('bx_posts_covers'))) {
+            $sFile = preg_replace("/\.[A-Za-z0-9]+$/", '', $sFile);
+            $sUrl = $oStorage->getFileUrlByRemoteId($sFile);
+        }
+        if (!$sUrl) {
+            bx_storage_download_error_occured();
+            exit;
+        }
+    }
+    header("Location: " . $sUrl);
+}
 
 if (!$oStorage->download($sRemoteId, $sToken)) {
     $iError = $oStorage->getErrorCode();