Minor StorageManager cleanups

This commit is contained in:
Lucas Bartholemy 2016-10-30 11:53:07 +01:00
parent d06bf8e75b
commit 6e167a0b4f
2 changed files with 26 additions and 26 deletions

View File

@ -34,7 +34,7 @@ class StorageManager extends \yii\base\Component implements StorageManagerInterf
/**
* @var integer file mode
*/
public $chmod = 0744;
public $fileMode = 0744;
/**
* @var File
@ -56,25 +56,6 @@ class StorageManager extends \yii\base\Component implements StorageManagerInterf
return $this->getPath() . DIRECTORY_SEPARATOR . $variant;
}
/**
* Returns the path where the files of this file are located
*
* @return string the path
*/
protected function getPath()
{
if ($this->file->guid == '') {
throw new \Exception('File GUID empty!');
}
$path = Yii::getAlias($this->path) . DIRECTORY_SEPARATOR . $this->file->guid;
if (!is_dir($path)) {
mkdir($path);
}
return $path;
}
/**
* Adds or overwrites the file by given UploadedFile in store
*
@ -85,7 +66,7 @@ class StorageManager extends \yii\base\Component implements StorageManagerInterf
{
if (is_uploaded_file($file->tempName)) {
move_uploaded_file($file->tempName, $this->get($variant));
@chmod($this->get($variant), 0744);
@chmod($this->get($variant), $this->fileMode);
}
/**
@ -106,7 +87,7 @@ class StorageManager extends \yii\base\Component implements StorageManagerInterf
public function setContent($content, $variant = null)
{
file_put_contents($this->get($variant), $this->content);
@chmod($this->get($variant), $this->chmod);
@chmod($this->get($variant), $this->fileMode);
}
/**
@ -142,4 +123,23 @@ class StorageManager extends \yii\base\Component implements StorageManagerInterf
$this->file = $file;
}
/**
* Returns the path where the files of this file are located
*
* @return string the path
*/
protected function getPath()
{
if ($this->file->guid == '') {
throw new \Exception('File GUID empty!');
}
$path = Yii::getAlias($this->path) . DIRECTORY_SEPARATOR . $this->file->guid;
if (!is_dir($path)) {
mkdir($path);
}
return $path;
}
}

View File

@ -1,9 +1,9 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\file\components;