1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 03:02:34 +01:00
This commit is contained in:
David Bomba 2019-06-03 15:31:20 +10:00
parent c2791815a7
commit d057903229
6 changed files with 42 additions and 17 deletions

View File

@ -49,8 +49,8 @@ class QueryLogging
$time = $timeEnd - $timeStart; $time = $timeEnd - $timeStart;
Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time); Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
// if($count > 20) if($count > 20)
// Log::info($queries); Log::info($queries);
} }
} }

View File

@ -58,22 +58,25 @@ class UploadFile implements ShouldQueue
public function handle() : ?Document public function handle() : ?Document
{ {
//$path = $this->encodePrimaryKey($this->company->id) . '/' . sha1(time()) . '_' . str_replace(" ", "", $this->file->getClientOriginalName());
$path = $this->encodePrimaryKey($this->company->id); $path = $this->encodePrimaryKey($this->company->id);
$file_path = $path . '/' . $this->file->hashName();
// Storage::makeDirectory($path); $file_path = $path . '/' . $this->file->hashName();
Storage::put($path, $this->file); Storage::put($path, $this->file);
$width = 0; $width = 0;
$height = 0; $height = 0;
if (in_array($this->file->getClientOriginalExtension(),['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'psd'])) if (in_array($this->file->getClientOriginalExtension(),['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'psd']))
{ {
$imageSize = getimagesize($this->file); $imageSize = getimagesize($this->file);
$width = $imageSize[0]; $width = $imageSize[0];
$height = $imageSize[1]; $height = $imageSize[1];
} }
$document = new Document(); $document = new Document();
@ -88,7 +91,7 @@ class UploadFile implements ShouldQueue
$document->width = $width; $document->width = $width;
$document->height = $height; $document->height = $height;
$preview_path = $this->encodePrimaryKey($this->company->id) . '/' . sha1(time()) . '_preview_' . str_replace(" ", "", $this->file->getClientOriginalName()); $preview_path = $this->encodePrimaryKey($this->company->id);
$document->preview = $this->generatePreview($preview_path); $document->preview = $this->generatePreview($preview_path);
@ -100,9 +103,21 @@ class UploadFile implements ShouldQueue
private function generatePreview($preview_path) : string private function generatePreview($preview_path) : string
{ {
$extension = $this->file->getClientOriginalExtension();
if (empty(Document::$types[$extension]) && ! empty(Document::$extraExtensions[$extension])) {
$documentType = Document::$extraExtensions[$extension];
} else {
$documentType = $extension;
}
if (empty(Document::$types[$documentType])) {
return 'Unsupported file type';
}
$preview = ''; $preview = '';
if (in_array($this->file->getClientOriginalExtension(), ['jpeg', 'png', 'gif', 'bmp', 'tiff', 'psd'])) if (in_array($this->file->getClientOriginalExtension(),['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'psd']))
{ {
$makePreview = false; $makePreview = false;
$imageSize = getimagesize($this->file); $imageSize = getimagesize($this->file);
@ -135,7 +150,7 @@ class UploadFile implements ShouldQueue
// We haven't created a preview yet // We haven't created a preview yet
$imgManager = new ImageManager($imgManagerConfig); $imgManager = new ImageManager($imgManagerConfig);
$img = $imgManager->make($filePath); $img = $imgManager->make($preview_path);
if ($width <= Document::DOCUMENT_PREVIEW_SIZE && $height <= Document::DOCUMENT_PREVIEW_SIZE) { if ($width <= Document::DOCUMENT_PREVIEW_SIZE && $height <= Document::DOCUMENT_PREVIEW_SIZE) {
$previewWidth = $width; $previewWidth = $width;

View File

@ -18,6 +18,7 @@ use App\Models\Company;
use App\Models\Country; use App\Models\Country;
use App\Models\Filterable; use App\Models\Filterable;
use App\Models\Timezone; use App\Models\Timezone;
use App\Utils\Traits\GeneratesCounter;
use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Hashids\Hashids; use Hashids\Hashids;
@ -32,6 +33,7 @@ class Client extends BaseModel
use MakesDates; use MakesDates;
use SoftDeletes; use SoftDeletes;
use Filterable; use Filterable;
use GeneratesCounter;
protected $presenter = 'App\Models\Presenters\ClientPresenter'; protected $presenter = 'App\Models\Presenters\ClientPresenter';
@ -50,7 +52,7 @@ class Client extends BaseModel
'country', 'country',
'shipping_country' 'shipping_country'
]; ];
/*
protected $with = [ protected $with = [
'contacts', 'contacts',
'primary_contact', 'primary_contact',
@ -58,7 +60,7 @@ class Client extends BaseModel
'shipping_country', 'shipping_country',
'company' 'company'
]; ];
*/
protected $casts = [ protected $casts = [
'settings' => 'object' 'settings' => 'object'
]; ];

View File

@ -76,6 +76,15 @@ class Document extends BaseModel
], ],
]; ];
/**
* @var array
*/
public static $extraExtensions = [
'jpg' => 'jpeg',
'tif' => 'tiff',
];
public function documentable() public function documentable()
{ {
return $this->morphTo(); return $this->morphTo();

View File

@ -71,7 +71,7 @@ class RandomDataSeeder extends Seeder
]); ]);
factory(\App\Models\Client::class, 5)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){ factory(\App\Models\Client::class, 6)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
factory(\App\Models\ClientContact::class,1)->create([ factory(\App\Models\ClientContact::class,1)->create([
'user_id' => $user->id, 'user_id' => $user->id,
@ -92,14 +92,16 @@ class RandomDataSeeder extends Seeder
factory(\App\Models\Product::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id]); factory(\App\Models\Product::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id]);
/** Invoice Factory */ /** Invoice Factory */
factory(\App\Models\Invoice::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); factory(\App\Models\Invoice::class,500)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
$clients = Client::all(); $clients = Client::all();
foreach($clients as $client) foreach($clients as $client)
{ {
$client->getNextNumber($client); $client->getNextClientNumber($client);
$client->save(); $client->save();
} }
} }
} }

View File

@ -45,9 +45,6 @@ class UploadFileTest extends TestCase
$this->assertNotNull($document); $this->assertNotNull($document);
Log::error($document);
// $this->assertEquals($invoice->amount, $payment);
} }