mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Fixed transformers to use new singleton upload urls
This commit is contained in:
parent
84a717c6ad
commit
b748e7ed5e
|
@ -148,17 +148,38 @@ class CategoriesController extends Controller
|
||||||
$category->require_acceptance = $request->input('require_acceptance', '0');
|
$category->require_acceptance = $request->input('require_acceptance', '0');
|
||||||
$category->checkin_email = $request->input('checkin_email', '0');
|
$category->checkin_email = $request->input('checkin_email', '0');
|
||||||
|
|
||||||
|
$old_image = $category->image;
|
||||||
|
|
||||||
|
|
||||||
|
// Set the model's image property to null if the image is being deleted
|
||||||
|
if ($request->input('image_delete') == 1) {
|
||||||
|
$category->image = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a new file is being uploaded, resize it and save it
|
||||||
if ($request->file('image')) {
|
if ($request->file('image')) {
|
||||||
$image = $request->file('image');
|
$image = $request->file('image');
|
||||||
$file_name = str_random(25).".".$image->getClientOriginalExtension();
|
$file_name = $category->id.'-'.str_slug($image->getClientOriginalName()) . "." . $image->getClientOriginalExtension();
|
||||||
$path = public_path('uploads/categories/'.$file_name);
|
|
||||||
Image::make($image->getRealPath())->resize(200, null, function ($constraint) {
|
if ($image->getClientOriginalExtension()!='svg') {
|
||||||
$constraint->aspectRatio();
|
Image::make($image->getRealPath())->resize(500, null, function ($constraint) {
|
||||||
$constraint->upsize();
|
$constraint->aspectRatio();
|
||||||
})->save($path);
|
$constraint->upsize();
|
||||||
|
})->save(app('categories_upload_path').$file_name);
|
||||||
|
} else {
|
||||||
|
$image->move(app('categories_upload_path'), $file_name);
|
||||||
|
}
|
||||||
$category->image = $file_name;
|
$category->image = $file_name;
|
||||||
} elseif ($request->input('image_delete')=='1') {
|
|
||||||
$category->image = null;
|
}
|
||||||
|
|
||||||
|
// If there is a new file being uploaded
|
||||||
|
if ((($request->file('image')) && (isset($old_image)) && ($old_image!='')) || ($request->input('image_delete') == 1)) {
|
||||||
|
try {
|
||||||
|
unlink(app('categories_upload_path').$old_image);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
\Log::error($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class AssetModelsTransformer
|
||||||
'id' => (int) $assetmodel->manufacturer->id,
|
'id' => (int) $assetmodel->manufacturer->id,
|
||||||
'name'=> e($assetmodel->manufacturer->name)
|
'name'=> e($assetmodel->manufacturer->name)
|
||||||
] : null,
|
] : null,
|
||||||
'image' => ($assetmodel->image!='') ? url('/').'/uploads/models/'.e($assetmodel->image) : null,
|
'image' => ($assetmodel->image!='') ? app('models_upload_url').e($assetmodel->image) : null,
|
||||||
'model_number' => e($assetmodel->model_number),
|
'model_number' => e($assetmodel->model_number),
|
||||||
'depreciation' => ($assetmodel->depreciation) ? [
|
'depreciation' => ($assetmodel->depreciation) ? [
|
||||||
'id' => (int) $assetmodel->depreciation->id,
|
'id' => (int) $assetmodel->depreciation->id,
|
||||||
|
|
|
@ -25,7 +25,7 @@ class CategoriesTransformer
|
||||||
$array = [
|
$array = [
|
||||||
'id' => (int) $category->id,
|
'id' => (int) $category->id,
|
||||||
'name' => e($category->name),
|
'name' => e($category->name),
|
||||||
'image' => ($category->image) ? e(url('/').'/uploads/categories/'.e($category->image)) : null,
|
'image' => ($category->image) ? app('categories_upload_url').e($category->image) : null,
|
||||||
'type' => e($category->category_type),
|
'type' => e($category->category_type),
|
||||||
'eula' => ($category->getEula()) ? true : false,
|
'eula' => ($category->getEula()) ? true : false,
|
||||||
'checkin_email' => ($category->checkin_email =='1') ? true : false,
|
'checkin_email' => ($category->checkin_email =='1') ? true : false,
|
||||||
|
|
|
@ -25,7 +25,7 @@ class CompaniesTransformer
|
||||||
$array = [
|
$array = [
|
||||||
'id' => (int) $company->id,
|
'id' => (int) $company->id,
|
||||||
'name' => e($company->name),
|
'name' => e($company->name),
|
||||||
'image' => ($company->image) ? e(url('/').'/uploads/companies/'.e($company->image)) : null,
|
'image' => ($company->image) ? app('companies_upload_url').e($company->image) : null,
|
||||||
"created_at" => Helper::getFormattedDateObject($company->created_at, 'datetime'),
|
"created_at" => Helper::getFormattedDateObject($company->created_at, 'datetime'),
|
||||||
"updated_at" => Helper::getFormattedDateObject($company->updated_at, 'datetime'),
|
"updated_at" => Helper::getFormattedDateObject($company->updated_at, 'datetime'),
|
||||||
"assets_count" => (int) $company->assets_count,
|
"assets_count" => (int) $company->assets_count,
|
||||||
|
|
|
@ -25,7 +25,7 @@ class DepartmentsTransformer
|
||||||
$array = [
|
$array = [
|
||||||
'id' => (int) $department->id,
|
'id' => (int) $department->id,
|
||||||
'name' => e($department->name),
|
'name' => e($department->name),
|
||||||
'image' => ($department->image) ? e(url('/').'/uploads/departments/'.e($department->image)) : null,
|
'image' => ($department->image) ? app('departments_upload_url').e($department->image) : null,
|
||||||
'company' => ($department->company) ? [
|
'company' => ($department->company) ? [
|
||||||
'id' => (int) $department->company->id,
|
'id' => (int) $department->company->id,
|
||||||
'name'=> e($department->company->name)
|
'name'=> e($department->company->name)
|
||||||
|
|
|
@ -33,7 +33,7 @@ class LocationsTransformer
|
||||||
$array = [
|
$array = [
|
||||||
'id' => (int) $location->id,
|
'id' => (int) $location->id,
|
||||||
'name' => e($location->name),
|
'name' => e($location->name),
|
||||||
'image' => ($location->image) ? e(url('/').'/uploads/locations/'.e($location->image)) : null,
|
'image' => ($location->image) ? app('locations_upload_url').e($location->image) : null,
|
||||||
'address' => e($location->address),
|
'address' => e($location->address),
|
||||||
'city' => e($location->city),
|
'city' => e($location->city),
|
||||||
'state' => e($location->state),
|
'state' => e($location->state),
|
||||||
|
|
|
@ -26,7 +26,7 @@ class ManufacturersTransformer
|
||||||
'id' => (int) $manufacturer->id,
|
'id' => (int) $manufacturer->id,
|
||||||
'name' => e($manufacturer->name),
|
'name' => e($manufacturer->name),
|
||||||
'url' => e($manufacturer->url),
|
'url' => e($manufacturer->url),
|
||||||
'image' => ($manufacturer->image) ? e(url('/').'/uploads/manufacturers/'.e($manufacturer->image)) : null,
|
'image' => ($manufacturer->image) ? app('manufacturers_upload_url').e($manufacturer->image) : null,
|
||||||
'support_url' => e($manufacturer->support_url),
|
'support_url' => e($manufacturer->support_url),
|
||||||
'support_phone' => e($manufacturer->support_phone),
|
'support_phone' => e($manufacturer->support_phone),
|
||||||
'support_email' => e($manufacturer->support_email),
|
'support_email' => e($manufacturer->support_email),
|
||||||
|
|
|
@ -25,7 +25,7 @@ class SuppliersTransformer
|
||||||
$array = [
|
$array = [
|
||||||
'id' => (int) $supplier->id,
|
'id' => (int) $supplier->id,
|
||||||
'name' => e($supplier->name),
|
'name' => e($supplier->name),
|
||||||
'image' => ($supplier->image) ? e(url('/').'/uploads/suppliers/'.e($supplier->image)) : null,
|
'image' => ($supplier->image) ? app('suppliers_upload_url').e($supplier->image) : null,
|
||||||
'address' => ($supplier->address) ? e($supplier->address) : null,
|
'address' => ($supplier->address) ? e($supplier->address) : null,
|
||||||
'address2' => ($supplier->address2) ? e($supplier->address2) : null,
|
'address2' => ($supplier->address2) ? e($supplier->address2) : null,
|
||||||
'city' => ($supplier->city) ? e($supplier->city) : null,
|
'city' => ($supplier->city) ? e($supplier->city) : null,
|
||||||
|
|
Loading…
Reference in a new issue