Merge branch 'master_oss_wangjianhua' into 'master'
Modify file module to support OSS plug. See merge request easycorp/zentaopms!6367
This commit is contained in:
@@ -623,6 +623,7 @@ class doc extends control
|
||||
*/
|
||||
public function delete($docID, $confirm = 'no', $from = 'list')
|
||||
{
|
||||
$this->loadModel('file');
|
||||
if($confirm == 'no')
|
||||
{
|
||||
$type = $this->dao->select('type')->from(TABLE_DOC)->where('id')->eq($docID)->fetch('type');
|
||||
@@ -644,7 +645,7 @@ class doc extends control
|
||||
$this->loadModel('action')->create($file->objectType, $file->objectID, 'deletedFile', '', $extra=$file->title);
|
||||
|
||||
$fileRecord = $this->dao->select('id')->from(TABLE_FILE)->where('pathname')->eq($file->pathname)->fetch();
|
||||
if(empty($fileRecord)) @unlink($file->realPath);
|
||||
if(empty($fileRecord)) $this->file->unlinkFile($file);
|
||||
}
|
||||
|
||||
/* if ajax request, send result. */
|
||||
|
||||
@@ -643,9 +643,7 @@ class docModel extends model
|
||||
{
|
||||
foreach($files as $file)
|
||||
{
|
||||
$pathName = $this->file->getRealPathName($file->pathname);
|
||||
$file->webPath = $this->file->webPath . $pathName;
|
||||
$file->realPath = $this->file->savePath . $pathName;
|
||||
$this->loadModel('file')->setFileWebAndRealPaths($file);
|
||||
if(strpos(",{$docContent->files},", ",{$file->id},") !== false) $docFiles[$file->id] = $file;
|
||||
}
|
||||
}
|
||||
@@ -1740,9 +1738,7 @@ class docModel extends model
|
||||
|
||||
foreach($files as $fileID => $file)
|
||||
{
|
||||
$pathName = $this->file->getRealPathName($file->pathname);
|
||||
$file->realPath = $this->file->savePath . $pathName;
|
||||
$file->webPath = $this->file->webPath . $pathName;
|
||||
$this->file->setFileWebAndRealPaths($file);
|
||||
}
|
||||
|
||||
return $files;
|
||||
|
||||
@@ -84,12 +84,8 @@
|
||||
<div class='col'>
|
||||
<div class='lib-file'>
|
||||
<?php
|
||||
$imageWidth = 0;
|
||||
if(stripos('jpg|jpeg|gif|png|bmp', $file->extension) !== false and file_exists($file->realPath))
|
||||
{
|
||||
$imageSize = getimagesize($file->realPath);
|
||||
$imageWidth = $imageSize ? $imageSize[0] : 0;
|
||||
}
|
||||
$imageSize = $this->loadModel('file')->getImageSize($file);
|
||||
$imageWidth = $imageSize[0];
|
||||
|
||||
$fileID = $file->id;
|
||||
$url = helper::createLink('file', 'download', 'fileID=' . $fileID);
|
||||
|
||||
@@ -146,7 +146,7 @@ class file extends control
|
||||
$file->extension = $extension;
|
||||
}
|
||||
|
||||
if(file_exists($file->realPath))
|
||||
if($this->file->fileExists($file))
|
||||
{
|
||||
/* If the mode is open, locate directly. */
|
||||
if($mode == 'open')
|
||||
@@ -290,7 +290,7 @@ class file extends control
|
||||
|
||||
/* Fix Bug #1518. */
|
||||
$fileRecord = $this->dao->select('id')->from(TABLE_FILE)->where('pathname')->eq($file->pathname)->fetch();
|
||||
if(empty($fileRecord)) @unlink($file->realPath);
|
||||
if(empty($fileRecord)) $this->file->unlinkFile($file);
|
||||
|
||||
/* Update test case version for test case synchronization. */
|
||||
if($file->objectType == 'testcase') $this->file->updateTestcaseVersion($file);
|
||||
@@ -500,7 +500,7 @@ class file extends control
|
||||
public function read($fileID)
|
||||
{
|
||||
$file = $this->file->getById($fileID);
|
||||
if(empty($file) or !file_exists($file->realPath)) return false;
|
||||
if(empty($file) or !$this->file->fileExists($file)) return false;
|
||||
|
||||
$obLevel = ob_get_level();
|
||||
for($i = 0; $i < $obLevel; $i++) ob_end_clean();
|
||||
|
||||
+81
-12
@@ -60,9 +60,7 @@ class fileModel extends model
|
||||
continue;
|
||||
}
|
||||
|
||||
$realPathName = $this->getRealPathName($file->pathname);
|
||||
$file->realPath = $this->savePath . $realPathName;
|
||||
$file->webPath = $this->webPath . $realPathName;
|
||||
$this->setFileWebAndRealPaths($file);
|
||||
}
|
||||
|
||||
return $files;
|
||||
@@ -88,9 +86,7 @@ class fileModel extends model
|
||||
return $file;
|
||||
}
|
||||
|
||||
$realPathName = $this->getRealPathName($file->pathname);
|
||||
$file->realPath = $this->savePath . $realPathName;
|
||||
$file->webPath = $this->webPath . $realPathName;
|
||||
$this->setFileWebAndRealPaths($file);
|
||||
|
||||
return $file;
|
||||
}
|
||||
@@ -117,9 +113,7 @@ class fileModel extends model
|
||||
continue;
|
||||
}
|
||||
|
||||
$realPathName = $this->getRealPathName($file->pathname);
|
||||
$file->realPath = $this->savePath . $realPathName;
|
||||
$file->webPath = $this->webPath . $realPathName;
|
||||
$this->setFileWebAndRealPaths($file);
|
||||
}
|
||||
|
||||
return $files;
|
||||
@@ -487,6 +481,20 @@ class fileModel extends model
|
||||
$this->webPath = $this->app->getWebRoot() . "data/upload/{$this->app->company->id}/";
|
||||
}
|
||||
|
||||
/**
|
||||
* Set paths: realPath and webPath.
|
||||
*
|
||||
* @param object $file
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function setFileWebAndRealPaths(&$file)
|
||||
{
|
||||
$pathName = $this->getRealPathName($file->pathname);
|
||||
$file->realPath = $this->savePath . $pathName;
|
||||
$file->webPath = $this->webPath . $pathName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the set image size code.
|
||||
*
|
||||
@@ -512,6 +520,30 @@ class fileModel extends model
|
||||
return str_replace(' src="data/upload', ' onload="setImageSize(this,' . $maxSize . ')" src="data/upload', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check file exists or not.
|
||||
*
|
||||
* @param object $file
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function fileExists($file)
|
||||
{
|
||||
return file_exists($file->realPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlink file.
|
||||
*
|
||||
* @param object $file
|
||||
* @access public
|
||||
* @return bool|null
|
||||
*/
|
||||
public function unlinkFile($file)
|
||||
{
|
||||
return @unlink($file->realPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a file.
|
||||
*
|
||||
@@ -1021,7 +1053,7 @@ class fileModel extends model
|
||||
{
|
||||
$file = $this->getById($imageID);
|
||||
$this->dao->delete()->from(TABLE_FILE)->where('id')->eq($imageID)->exec();
|
||||
@unlink($file->realPath);
|
||||
$this->unlinkFile($file);
|
||||
}
|
||||
}
|
||||
unset($_SESSION['album'][$uid]);
|
||||
@@ -1089,7 +1121,7 @@ class fileModel extends model
|
||||
{
|
||||
if($this->config->file->storageType == 'fs')
|
||||
{
|
||||
return file_exists($file->realPath) ? getimagesize($file->realPath) : 0;
|
||||
return file_exists($file->realPath) ? getimagesize($file->realPath) : array(0, 0, $file->extension);
|
||||
}
|
||||
else if($this->config->file->storageType == 's3')
|
||||
{
|
||||
@@ -1155,7 +1187,7 @@ class fileModel extends model
|
||||
$this->dao->delete()->from(TABLE_FILE)->where('id')->in($deleteFiles)->exec();
|
||||
foreach($deleteFiles as $fileID)
|
||||
{
|
||||
@unlink($oldObject->files[$fileID]->realPath);
|
||||
$this->unlinkFile($oldObject->files[$fileID]);
|
||||
$oldFiles = empty($oldFiles) ? '' : trim(str_replace(",$fileID,", ',', ",$oldFiles,"), ',');
|
||||
}
|
||||
}
|
||||
@@ -1167,4 +1199,41 @@ class fileModel extends model
|
||||
$newObject->files = trim($oldFiles . $addedFiles, ',');
|
||||
$oldObject->files = join(',', array_keys($oldObject->files));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last modified timestamp of file.
|
||||
*
|
||||
* @param object $file
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function fileMTime($file)
|
||||
{
|
||||
return filemtime($file->realPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file size.
|
||||
*
|
||||
* @param object $file
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function fileSize($file)
|
||||
{
|
||||
return filesize($file->realPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save file to local storage temporarily.
|
||||
*
|
||||
* @param object $file
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function saveAsTempFile($file)
|
||||
{
|
||||
/* If the storage type is local, do nothing. */
|
||||
if($this->config->file->storageType == 'fs') return $file->realPath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,12 +54,9 @@
|
||||
$uploadDate = $lang->file->uploadDate . substr($file->addedDate, 0, 10);
|
||||
$fileTitle = "<i class='icon icon-file-text'></i> " . $file->title;
|
||||
if(strpos($file->title, ".{$file->extension}") === false && $file->extension != 'txt') $fileTitle .= ".{$file->extension}";
|
||||
$imageWidth = 0;
|
||||
if(stripos('jpg|jpeg|gif|png|bmp', $file->extension) !== false)
|
||||
{
|
||||
$imageSize = $this->file->getImageSize($file);
|
||||
$imageWidth = $imageSize ? $imageSize[0] : 0;
|
||||
}
|
||||
|
||||
$imageSize = $this->file->getImageSize($file);
|
||||
$imageWidth = $imageSize[0];
|
||||
|
||||
$fileSize = 0;
|
||||
/* Show size info. */
|
||||
|
||||
@@ -157,7 +157,7 @@ function setFileName(fileID)
|
||||
if(stripos('jpg|jpeg|gif|png|bmp', $file->extension) !== false)
|
||||
{
|
||||
$imageSize = $this->file->getImageSize($file);
|
||||
$imageWidth = $imageSize ? $imageSize[0] : 0;
|
||||
$imageWidth = $imageSize[0];
|
||||
}
|
||||
|
||||
$fileSize = 0;
|
||||
|
||||
@@ -1398,9 +1398,7 @@ class testtaskModel extends model
|
||||
$stepFiles = array();
|
||||
foreach($files as $file)
|
||||
{
|
||||
$pathName = $this->file->getRealPathName($file->pathname);
|
||||
$file->webPath = $this->file->webPath . $pathName;
|
||||
$file->realPath = $this->file->savePath . $pathName;
|
||||
$this->file->setFileWebAndRealPaths($file);
|
||||
if($file->objectType == 'caseResult')
|
||||
{
|
||||
$resultFiles[$file->objectID][$file->id] = $file;
|
||||
|
||||
Reference in New Issue
Block a user