Apply fixes from StyleCI
This commit is contained in:

committed by
StyleCI Bot

parent
4ec6000d69
commit
7b8ee415be
@@ -9,8 +9,8 @@ use App\Model\helpdesk\Ticket\Ticket_Thread;
|
||||
use Config;
|
||||
use Storage;
|
||||
|
||||
class StorageController extends Controller {
|
||||
|
||||
class StorageController extends Controller
|
||||
{
|
||||
protected $default;
|
||||
protected $driver;
|
||||
protected $root;
|
||||
@@ -25,7 +25,8 @@ class StorageController extends Controller {
|
||||
protected $rackspace_endpoint;
|
||||
protected $rackspace_url_type;
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$this->default = $this->defaults();
|
||||
$this->driver = $this->driver();
|
||||
$this->root = $this->root();
|
||||
@@ -40,7 +41,8 @@ class StorageController extends Controller {
|
||||
$this->rackspace_username = $this->rackspaceUsername();
|
||||
}
|
||||
|
||||
protected function settings($option) {
|
||||
protected function settings($option)
|
||||
{
|
||||
$settings = new CommonSettings();
|
||||
$setting = $settings->getOptionValue('storage', $option);
|
||||
$value = '';
|
||||
@@ -51,7 +53,8 @@ class StorageController extends Controller {
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function defaults() {
|
||||
public function defaults()
|
||||
{
|
||||
$default = 'local';
|
||||
if ($this->settings('default')) {
|
||||
$default = $this->settings('default');
|
||||
@@ -60,11 +63,13 @@ class StorageController extends Controller {
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function driver() {
|
||||
public function driver()
|
||||
{
|
||||
return $this->settings('default');
|
||||
}
|
||||
|
||||
public function root() {
|
||||
public function root()
|
||||
{
|
||||
$root = storage_path('app');
|
||||
if ($this->settings('root')) {
|
||||
$root = $this->settings('root');
|
||||
@@ -73,47 +78,58 @@ class StorageController extends Controller {
|
||||
return $root;
|
||||
}
|
||||
|
||||
public function s3Key() {
|
||||
public function s3Key()
|
||||
{
|
||||
return $this->settings('s3_key');
|
||||
}
|
||||
|
||||
public function s3Region() {
|
||||
public function s3Region()
|
||||
{
|
||||
return $this->settings('s3_region');
|
||||
}
|
||||
|
||||
public function s3Secret() {
|
||||
public function s3Secret()
|
||||
{
|
||||
return $this->settings('s3_secret');
|
||||
}
|
||||
|
||||
public function s3Bucket() {
|
||||
public function s3Bucket()
|
||||
{
|
||||
return $this->settings('s3_bucket');
|
||||
}
|
||||
|
||||
public function rackspaceKey() {
|
||||
public function rackspaceKey()
|
||||
{
|
||||
return $this->settings('root');
|
||||
}
|
||||
|
||||
public function rackspaceRegion() {
|
||||
public function rackspaceRegion()
|
||||
{
|
||||
return $this->settings('rackspace_region');
|
||||
}
|
||||
|
||||
public function rackspaceUsername() {
|
||||
public function rackspaceUsername()
|
||||
{
|
||||
return $this->settings('rackspace_username');
|
||||
}
|
||||
|
||||
public function rackspaceContainer() {
|
||||
public function rackspaceContainer()
|
||||
{
|
||||
return $this->settings('rackspace_container');
|
||||
}
|
||||
|
||||
public function rackspaceEndpoint() {
|
||||
public function rackspaceEndpoint()
|
||||
{
|
||||
return $this->settings('rackspace_endpoint');
|
||||
}
|
||||
|
||||
public function rackspaceUrlType() {
|
||||
public function rackspaceUrlType()
|
||||
{
|
||||
return $this->settings('rackspace_url_type');
|
||||
}
|
||||
|
||||
protected function setFileSystem() {
|
||||
protected function setFileSystem()
|
||||
{
|
||||
$config = $this->config();
|
||||
//dd($config);
|
||||
foreach ($config as $key => $con) {
|
||||
@@ -128,40 +144,43 @@ class StorageController extends Controller {
|
||||
return Config::get('filesystem');
|
||||
}
|
||||
|
||||
protected function config() {
|
||||
protected function config()
|
||||
{
|
||||
return [
|
||||
'default' => $this->default,
|
||||
'cloud' => 's3',
|
||||
'disks' => $this->disks(),
|
||||
'cloud' => 's3',
|
||||
'disks' => $this->disks(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function disks() {
|
||||
protected function disks()
|
||||
{
|
||||
return [
|
||||
'local' => [
|
||||
'driver' => 'local',
|
||||
'root' => $this->root . '/attachments',
|
||||
'root' => $this->root.'/attachments',
|
||||
],
|
||||
's3' => [
|
||||
'driver' => 's3',
|
||||
'key' => $this->s3_key,
|
||||
'key' => $this->s3_key,
|
||||
'secret' => $this->s3_secret,
|
||||
'region' => $this->s3_region,
|
||||
'bucket' => $this->s3_bucket,
|
||||
],
|
||||
'rackspace' => [
|
||||
'driver' => 'rackspace',
|
||||
'username' => $this->rackspace_username,
|
||||
'key' => $this->rackspace_key,
|
||||
'driver' => 'rackspace',
|
||||
'username' => $this->rackspace_username,
|
||||
'key' => $this->rackspace_key,
|
||||
'container' => $this->rackspace_container,
|
||||
'endpoint' => $this->rackspace_endpoint,
|
||||
'region' => $this->rackspace_region,
|
||||
'url_type' => $this->rackspace_url_type,
|
||||
'endpoint' => $this->rackspace_endpoint,
|
||||
'region' => $this->rackspace_region,
|
||||
'url_type' => $this->rackspace_url_type,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function upload($data, $filename, $type, $size, $disposition, $thread_id) {
|
||||
public function upload($data, $filename, $type, $size, $disposition, $thread_id)
|
||||
{
|
||||
$upload = new Ticket_attachments();
|
||||
$upload->thread_id = $thread_id;
|
||||
$upload->name = $filename;
|
||||
@@ -169,11 +188,11 @@ class StorageController extends Controller {
|
||||
$upload->size = $size;
|
||||
$upload->poster = $disposition;
|
||||
$upload->driver = $this->default;
|
||||
$upload->path = $this->root. DIRECTORY_SEPARATOR.'attachments';
|
||||
$upload->path = $this->root.DIRECTORY_SEPARATOR.'attachments';
|
||||
if ($this->default !== 'database') {
|
||||
$this->setFileSystem();
|
||||
Storage::disk($this->default)->put($filename, $data);
|
||||
$storagePath = Storage::disk($this->default)->getDriver()->getAdapter()->getPathPrefix() . $filename;
|
||||
$storagePath = Storage::disk($this->default)->getDriver()->getAdapter()->getPathPrefix().$filename;
|
||||
if (mime(\File::mimeType($storagePath)) != 'image' || mime(\File::extension($storagePath)) != 'image') {
|
||||
chmod($storagePath, 1204);
|
||||
}
|
||||
@@ -185,23 +204,23 @@ class StorageController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function saveAttachments($thread_id, $attachments = []) {
|
||||
public function saveAttachments($thread_id, $attachments = [])
|
||||
{
|
||||
$disposition = 'ATTACHMENT';
|
||||
$thread = '';
|
||||
foreach ($attachments as $attachment) {
|
||||
if (is_object($attachment)) {
|
||||
if (method_exists($attachment, 'getStructure')) {
|
||||
|
||||
$structure = $attachment->getStructure();
|
||||
if (isset($structure->disposition)) {
|
||||
$disposition = $structure->disposition;
|
||||
}
|
||||
$filename = rand(1111, 9999) . "_" . $attachment->getFileName();
|
||||
$filename = rand(1111, 9999).'_'.$attachment->getFileName();
|
||||
$type = $attachment->getMimeType();
|
||||
$size = $attachment->getSize();
|
||||
$data = $attachment->getData();
|
||||
} else {
|
||||
$filename = rand(1111, 9999) . "_" . $attachment->getClientOriginalName();
|
||||
$filename = rand(1111, 9999).'_'.$attachment->getClientOriginalName();
|
||||
$type = $attachment->getMimeType();
|
||||
$size = $attachment->getSize();
|
||||
$data = file_get_contents($attachment->getRealPath());
|
||||
@@ -210,10 +229,12 @@ class StorageController extends Controller {
|
||||
$thread = $this->updateBody($attachment, $thread_id, $filename);
|
||||
}
|
||||
}
|
||||
|
||||
return $thread;
|
||||
}
|
||||
|
||||
public function updateBody($attachment, $thread_id, $filename) {
|
||||
public function updateBody($attachment, $thread_id, $filename)
|
||||
{
|
||||
$threads = new Ticket_Thread();
|
||||
$thread = $threads->find($thread_id);
|
||||
$disposition = 'ATTACHMENT';
|
||||
@@ -225,27 +246,29 @@ class StorageController extends Controller {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($disposition == 'INLINE' || $disposition == 'inline') {
|
||||
$id = str_replace('>', '', str_replace('<', '', $structure->id));
|
||||
$body = $thread->body;
|
||||
// dd($id,$filename,$body);
|
||||
$body = str_replace('cid:' . $id, $filename, $body);
|
||||
$body = str_replace('cid:'.$id, $filename, $body);
|
||||
// dd($body);
|
||||
$thread->body = $body;
|
||||
$thread->save();
|
||||
}
|
||||
|
||||
return $thread;
|
||||
}
|
||||
|
||||
public function getFile($drive, $name, $root) {
|
||||
if ($drive != "database") {
|
||||
$root = $root . DIRECTORY_SEPARATOR . $name;
|
||||
public function getFile($drive, $name, $root)
|
||||
{
|
||||
if ($drive != 'database') {
|
||||
$root = $root.DIRECTORY_SEPARATOR.$name;
|
||||
if (\File::exists($root)) {
|
||||
chmod($root, 0755);
|
||||
|
||||
return \File::get($root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user