fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [6770] Added class and tests that operate with the po


From: Petur Bjorn Thorsteinsson
Subject: [Fmsystem-commits] [6770] Added class and tests that operate with the portico virtual file system
Date: Fri, 14 Jan 2011 13:49:32 +0000

Revision: 6770
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=6770
Author:   peturbjorn
Date:     2011-01-14 13:49:32 +0000 (Fri, 14 Jan 2011)
Log Message:
-----------
Added class and tests that operate with the portico virtual file system

Added Paths:
-----------
    branches/dev-bim2/property/inc/class.sovfs.inc.php
    branches/dev-bim2/property/tests/BIM/TestSOvfs.php

Added: branches/dev-bim2/property/inc/class.sovfs.inc.php
===================================================================
--- branches/dev-bim2/property/inc/class.sovfs.inc.php                          
(rev 0)
+++ branches/dev-bim2/property/inc/class.sovfs.inc.php  2011-01-14 13:49:32 UTC 
(rev 6770)
@@ -0,0 +1,186 @@
+<?php
+/*
+ * Class that interacts with the VFS system in portico
+ */
+phpgw::import_class('property.bimExceptions');
+       /*
+        * Interface for communicating with Portico estate's virtual file system
+        */
+       interface sovfs {
+               public function addFileToVfs();
+               public function getFileInformation();
+               public function getFileFromVfs();
+               public function removeFileFromVfs();
+               public function checkIfFileExists();
+               public function retrieveVfsFileId() ;
+               public function setFilename($filename);
+               public function setFileNameWithFullPath($fileNameWithFullPath);
+               /*
+                * Submodule is in effect the subdirectory under /property that 
the file is put into
+                */
+               public function setSubModule($subModule);
+               public function getSubModule();
+       }
+       
+       class sovfs_impl implements sovfs {
+               /* @var $bofiles property_bofiles */
+               private $bofiles;
+               private $filename;
+               private $fileNameWithFullPath;
+               private $subModule;
+               public $debug = false;
+               
+               public function __construct($filename = null, 
$fileNameWithFullPath = null, $subModule = null){
+                       $this->bofiles = CreateObject('property.bofiles');
+                       $this->filename = $filename;
+                       $this->fileNameWithFullPath = $fileNameWithFullPath;
+                       $this->subModule = $subModule;
+               }
+               /*
+                * code derived from class.uitts.inc.php, from the part where 
it says '//------------ files'
+                * This method will save files under the 'property' folder in 
the vfs structure
+                * @return The filename that was added
+                * @throws Exception
+                * @throws FileExistsException
+                * @throws CopyFailureException
+                */
+               public function addFileToVfs() {
+                       if(!$this->filename || !$this->fileNameWithFullPath) {
+                               $errorString = "Illegal arguments";
+                               $errorString = 
$errorString."filename:$this->filename \n";
+                               $errorString = 
$errorString."fileNameWithFullPath:$this->fileNameWithFullPath \n";
+                               throw new Exception($errorString);
+                       }
+                       if($this->debug) {
+                               echo "Starting add file to VFS with following 
arguments:";
+                               echo "filename: \t $this->filename \n";
+                               echo "filename with full path:\t 
$this->fileNameWithFullPath \n";
+                               echo "subModule: $this->subModule \n";
+                       }
+                       
+                       $filename = 
$this->convertSpacesToUnderscores($this->filename);
+                       $to_file = 
$this->createResultingFileName($this->subModule, $this->filename);
+                       
+                       
+                       try {
+                               if($this->checkIfFileExists()) {
+                                       throw new 
FileExistsException($filename);
+                               }
+                               if($this->subModule) {
+                                       
$this->bofiles->create_document_dir($this->subModule);
+                               }
+                               $this->bofiles->vfs->override_acl = 1;
+                               
+                               
$this->copyFileToVfs($this->fileNameWithFullPath, $to_file);
+                       } catch (FileExistsException $e) {
+                       throw $e;       
+                       } catch ( Exception $e) {
+                               throw new CopyFailureException("Copy failed, 
error:".$e);
+                       }
+                       $this->bofiles->vfs->override_acl = 0;
+                       
+                               
+                       
+                       return $filename;
+               }
+               private function copyFileToVfs($sourceFile, $destinationFile) {
+                       try {
+                               $this->bofiles->vfs->cp2(array (
+                               'from'  => $sourceFile,
+                               'to'    => $destinationFile,
+                               'relatives'     => array 
(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)));
+                       } catch ( Exception $e) {
+                               throw $e;
+                       }
+               }
+               /*
+                * Needs submodule and filename to work
+                */
+               public function checkIfFileExists() {
+                       $to_file = 
$this->createResultingFileName($this->subModule, $this->filename);
+                       if($this->bofiles->vfs->file_exists(array(
+                               'string' => $to_file,
+                               'relatives' => array(RELATIVE_NONE)
+                       )))
+                       {
+                               return true;
+                       }
+                       return false;
+               }
+               
+               private function createResultingFileName($subModule, $filename) 
{
+                       if($subModule) {
+                               return $this->bofiles->fakebase . 
'/'.$subModule.'/'.$filename;
+                       } else {
+                               return $this->bofiles->fakebase .'/'.$filename;
+                       }
+               }
+               
+               private function convertSpacesToUnderscores($string) {
+                       return @str_replace(' ','_',$string);
+               }
+               
+               public function getFileFromVfs() {
+                       
+               }
+               /*
+                * Needs the filename set, and the submodule ( if applicable)
+                */
+               public function removeFileFromVfs() {
+                       if(!$this->filename) {
+                               $errorString = "Illegal arguments";
+                               $errorString = 
$errorString."filename:$this->filename \n";
+                               throw new 
InvalidArgumentException($errorString);
+                       }
+                       $file = array();
+                       $file['file_action'][0] = $this->filename;
+                       if($this->subModule) {
+                               $path = "/$this->subModule/";
+                       } else {
+                               $path = "/";
+                       }
+                       $recieve = $this->bofiles->delete_file($path, $file);
+                       if($recieve['message']) {
+                               $result = $recieve['message'][0]["msg"];
+                       } else {
+                               $result = $recieve['error'][0]["msg"];
+                               throw new Exception("Error removing file from 
vfs:".$result);
+                       }
+                       return $result;
+               }
+               
+               public function getFileInformation() {
+                       if(!$this->filename) {
+                               $errorString = "Illegal arguments";
+                               $errorString = 
$errorString."filename:$this->filename \n";
+                               throw new 
InvalidArgumentException($errorString);
+                       }
+                       $to_file = 
$this->createResultingFileName($this->subModule, $this->filename);
+                       $data = array(
+                                       'string'                =>  $to_file,
+                                       'relatives'     => array(RELATIVE_NONE),
+                                       'checksubdirs'  => false,
+                                       'nofiles'               => true
+                               );
+                       return $this->bofiles->vfs->ls($data);
+               }
+               
+               public function retrieveVfsFileId() {
+                       $fileInfo = $this->getFileInformation();
+                       return $fileInfo[0]["file_id"];
+               }
+               
+               public function setFilename($filename) {
+                       $this->filename = $filename;
+               }
+               public function setFileNameWithFullPath($fileNameWithFullPath) {
+                       $this->fileNameWithFullPath = $fileNameWithFullPath;
+               }
+               public function setSubModule($subModule) {
+                       $this->subModule = $subModule;
+               }
+               public function getSubModule(){
+                       return $this->subModule;
+               }
+               
+       }
\ No newline at end of file

Added: branches/dev-bim2/property/tests/BIM/TestSOvfs.php
===================================================================
--- branches/dev-bim2/property/tests/BIM/TestSOvfs.php                          
(rev 0)
+++ branches/dev-bim2/property/tests/BIM/TestSOvfs.php  2011-01-14 13:49:32 UTC 
(rev 6770)
@@ -0,0 +1,93 @@
+<?php
+
+
+
+/*
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+include_once './TestBimCommon.php';
+class TestSOvfs extends TestBimCommon
+{
+
+       /*private $modelName = "unitTestModel";
+       private $vfsFileName = "dummyFile.txt";
+       private $vfsFileNameWithFullPath;
+       private $vfsFileContents = "This is a file made for unit testing, 
please ignore or delete";
+       private $vfsSubModule = "ifc";
+       private $vfsFileId = 10101010;*/
+       
+       /**
+        * @var boolean $backupGlobals disable backup of GLOBALS which breaks 
things
+        */
+       protected $backupGlobals = false;
+       /**
+        * Setup the environment for the tests
+        *
+        * @return void
+        */
+       protected function setUp()
+       {
+               $GLOBALS['phpgw_info']['user']['account_id'] = 7;
+               $this->vfsFileName = "soVfsTestDummyFile.txt"; // so that these 
tests will not interfere with the sobimmodel tests
+       }
+       
+       
+       public function testaddCheckDeleteFileToVfs() {
+               $this->createDummyFile();
+               
+               $sovfs = new sovfs_impl();
+               //$sovfs->debug = true;
+               $sovfs->setFilename($this->vfsFileName);
+               $sovfs->setFileNameWithFullPath($this->vfsFileNameWithFullPath);
+               $sovfs->setSubModule($this->vfsSubModule);
+               try {
+                       $sovfs->addFileToVfs();
+               } catch (FileExistsException $e) {
+                       echo "File already exists\n";
+               }
+               $this->assertTrue($sovfs->checkIfFileExists());
+               $sovfs->removeFileFromVfs();
+               $this->assertTrue(!$sovfs->checkIfFileExists());
+               
+               $this->removeDummyFile();
+       }
+       
+       /*private function createDummyFile() {
+               $currentDirectory = dirname(__FILE__);
+               $this->vfsFileNameWithFullPath = 
$currentDirectory.DIRECTORY_SEPARATOR.$this->vfsFileName;
+               
+               $fileHandle = fopen($this->vfsFileNameWithFullPath, 'w') or 
die("Can't open file");
+               $result = fwrite($fileHandle, $this->vfsFileContents);
+               fclose($fileHandle);
+       }
+       private function removeDummyFile() {
+               unlink($this->vfsFileNameWithFullPath);
+       }*/
+       
+       
+       private function removeDummyVfsFile() {
+               $sovfs = new sovfs_impl();
+               $sovfs->setFilename($this->vfsFileName);
+               $sovfs->setSubModule($this->vfsSubModule);
+               
+               $sovfs->removeFileFromVfs();
+               
+       }
+       
+       
+       
+       
+       
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]