From 7391795ac5d056cc52caa14db274c31f61e4e868 Mon Sep 17 00:00:00 2001
From: tomas <tomas@cfc7b370-4200-0410-a6e3-cb6bdb053afe>
Date: Mon, 14 Feb 2005 16:16:05 +0000
Subject: [PATCH] BasicStor: bsExistsFile added GreenBox: getFileType and
 existsFile added LocStor: minor changes

---
 .../modules/storageServer/var/BasicStor.php   | 29 ++++++++++++++--
 .../modules/storageServer/var/GreenBox.php    | 34 +++++++++++++++++--
 .../modules/storageServer/var/LocStor.php     | 21 +++---------
 3 files changed, 64 insertions(+), 20 deletions(-)

diff --git a/livesupport/modules/storageServer/var/BasicStor.php b/livesupport/modules/storageServer/var/BasicStor.php
index 1fc93e3d0..fb073094a 100644
--- a/livesupport/modules/storageServer/var/BasicStor.php
+++ b/livesupport/modules/storageServer/var/BasicStor.php
@@ -23,7 +23,7 @@
  
  
     Author   : $Author: tomas $
-    Version  : $Revision: 1.28 $
+    Version  : $Revision: 1.29 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/BasicStor.php,v $
 
 ------------------------------------------------------------------------------*/
@@ -52,7 +52,7 @@ require_once "Transport.php";
  *  Core of LiveSupport file storage module
  *
  *  @author  $Author: tomas $
- *  @version $Revision: 1.28 $
+ *  @version $Revision: 1.29 $
  *  @see Alib
  */
 class BasicStor extends Alib{
@@ -805,6 +805,31 @@ class BasicStor extends Alib{
         return $nid;
     }
     
+    /**
+     *  Check if file exists in the storage
+     *
+     *  @param id int, local id
+     *  @param ftype string, internal file type
+     *  @return boolean
+     */
+    function bsExistsFile($id, $ftype=NULL)
+    {
+        $ac =& StoredFile::recall($this, $id);
+        if(PEAR::isError($ac)){
+            // catch some exceptions
+            switch($ac->getCode()){
+                case GBERR_FILENEX:
+                case GBERR_FOBJNEX:
+                    return FALSE;
+                    break;
+                default: return $ac;
+            }
+        }
+        if(!is_null($ftype) && ($this->_getType($ac->gunid) != $ftype))
+            return FALSE;
+        return TRUE;
+    }
+
     /* ---------------------------------------------------- redefined methods */
     /**
      *  Get object type by id.
diff --git a/livesupport/modules/storageServer/var/GreenBox.php b/livesupport/modules/storageServer/var/GreenBox.php
index 758030ab2..c7f45f85d 100644
--- a/livesupport/modules/storageServer/var/GreenBox.php
+++ b/livesupport/modules/storageServer/var/GreenBox.php
@@ -23,7 +23,7 @@
  
  
     Author   : $Author: tomas $
-    Version  : $Revision: 1.32 $
+    Version  : $Revision: 1.33 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/GreenBox.php,v $
 
 ------------------------------------------------------------------------------*/
@@ -35,7 +35,7 @@ require_once "BasicStor.php";
  *  LiveSupport file storage module
  *
  *  @author  $Author: tomas $
- *  @version $Revision: 1.32 $
+ *  @version $Revision: 1.33 $
  *  @see BasicStor
  */
 class GreenBox extends BasicStor{
@@ -882,6 +882,36 @@ class GreenBox extends BasicStor{
         return $listArr;
     }
     
+    /**
+     *  Get type of stored file (by local id)
+     *
+     *  @param id int, local id
+     *  @return string/err
+     */
+    function getFileType($id)
+    {
+        // $id = $this->_idFromGunid($gunid);
+        $type = $this->getObjType($id);
+        return $type;
+    }
+
+    /**
+     *  Check if file exists in the storage and
+     *  user have permission to read it
+     *
+     *  @param gunid string
+     *  @param ftype string, internal file type
+     *  @return string/err
+     */
+    function existsFile($sessid, $gunid, $ftype=NULL)
+    {
+        $id = $this->_idFromGunid($gunid);
+        $ex = $this->bsExistsFile($id, $ftype);
+        if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
+            return $res;
+        return $ex;
+    }
+    
     /* ---------------------------------------------------- redefined methods */
 
     /**
diff --git a/livesupport/modules/storageServer/var/LocStor.php b/livesupport/modules/storageServer/var/LocStor.php
index 3b8aa2bf6..01d9a8dda 100644
--- a/livesupport/modules/storageServer/var/LocStor.php
+++ b/livesupport/modules/storageServer/var/LocStor.php
@@ -23,7 +23,7 @@
  
  
     Author   : $Author: tomas $
-    Version  : $Revision: 1.29 $
+    Version  : $Revision: 1.30 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/LocStor.php,v $
 
 ------------------------------------------------------------------------------*/
@@ -390,7 +390,6 @@ class LocStor extends BasicStor{
      *  @param sessid string
      *  @param gunid string
      *  @return boolean
-     *  @see GreenBox
      */
     function existsAudioClip($sessid, $gunid)
     {
@@ -412,23 +411,13 @@ class LocStor extends BasicStor{
      *  @param gunid string
      *  @param ftype string, internal file type
      *  @return boolean
-     *  @see GreenBox
      */
     function existsFile($sessid, $gunid, $ftype=NULL)
     {
-        $ac =& StoredFile::recallByGunid($this, $gunid);
-        if(PEAR::isError($ac)){
-            // catch some exceptions
-            switch($ac->getCode()){
-                case GBERR_FILENEX:
-                case GBERR_FOBJNEX:
-                    return FALSE;
-                    break;
-                default: return $ac;
-            }
-        }
-        if(!is_null($ftype) && ($this->_getType($gunid) != $ftype)) return FALSE;
-        if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE)
+        $id = $this->_idFromGunid($gunid);
+        if(is_null($id)) return FALSE;
+        $ex = $this->bsExistsFile($id, $ftype);
+        if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
             return $res;
         return TRUE;
     }