refs #164 models update
This commit is contained in:
parent
e65743c7c3
commit
87b327d9b8
@ -3,6 +3,8 @@
|
||||
namespace App\Listeners\Updates;
|
||||
|
||||
use App\Events\UpdateFinished;
|
||||
use App\Models\Auth\Role;
|
||||
use App\Models\Auth\Permission;
|
||||
use MediaUploader;
|
||||
use Storage;
|
||||
use Artisan;
|
||||
@ -26,6 +28,26 @@ class Version117 extends Listener
|
||||
return;
|
||||
}
|
||||
|
||||
// Create permission
|
||||
$permission = Permission::firstOrCreate([
|
||||
'name' => 'delete-common-uploads',
|
||||
'display_name' => 'Delete Common Uploads',
|
||||
'description' => 'Delete Common Uploads',
|
||||
]);
|
||||
|
||||
// Attach permission to roles
|
||||
$roles = Role::all();
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$allowed = ['admin'];
|
||||
|
||||
if (!in_array($role->name, $allowed)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$role->attachPermission($permission);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
$migrations = [
|
||||
@ -77,10 +99,11 @@ class Version117 extends Listener
|
||||
}
|
||||
}
|
||||
|
||||
$settings['company_logo'] = \App\Models\Setting\Setting::where('key', '=', 'general.company_logo')->get();
|
||||
$settings['invoice_logo'] = \App\Models\Setting\Setting::where('key', '=', 'general.invoice_logo')->get();
|
||||
$settings['company_logo'] = \App\Models\Setting\Setting::where('key', '=', 'general.company_logo')->where('company_id', '<>', '0')->get();
|
||||
$settings['invoice_logo'] = \App\Models\Setting\Setting::where('key', '=', 'general.invoice_logo')->where('company_id', '<>', '0')->get();
|
||||
|
||||
foreach ($settings as $name => $item) {
|
||||
foreach ($settings as $name => $items) {
|
||||
foreach ($items as $item) {
|
||||
if ($item->value) {
|
||||
$path = explode('uploads/', $item->value);
|
||||
|
||||
@ -91,9 +114,24 @@ class Version117 extends Listener
|
||||
}
|
||||
|
||||
if (!empty($path) && Storage::exists($path)) {
|
||||
$company = \App\Models\Company\Company::find($item->company_id);
|
||||
|
||||
$media = \App\Models\Common\Media::where('filename', '=', pathinfo(basename($path), PATHINFO_FILENAME))->first();
|
||||
|
||||
if ($company && !$media) {
|
||||
$media = MediaUploader::importPath(config('mediable.default_disk'), $path);
|
||||
|
||||
$item->attachMedia($media, $name);
|
||||
$company->attachMedia($media, $name);
|
||||
|
||||
$item->update(['value' => $media->id]);
|
||||
} elseif ($media) {
|
||||
$item->update(['value' => $media->id]);
|
||||
} else {
|
||||
$item->update(['value' => '']);
|
||||
}
|
||||
} else {
|
||||
$item->update(['value' => '']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,11 +88,9 @@ class User extends Authenticatable
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($value)) {
|
||||
if (!empty($value) && !$this->hasMedia('picture')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!$this->hasMedia('picture')) {
|
||||
} elseif (!$this->hasMedia('picture')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -238,11 +238,9 @@ class Company extends Eloquent
|
||||
*/
|
||||
public function getCompanyLogoAttribute($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (!empty($value) && !$this->hasMedia('company_logo')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!$this->hasMedia('company_logo')) {
|
||||
} elseif (!$this->hasMedia('company_logo')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -137,11 +137,9 @@ class Bill extends Model
|
||||
*/
|
||||
public function getAttachmentAttribute($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (!empty($value) && !$this->hasMedia('attachment')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!$this->hasMedia('attachment')) {
|
||||
} elseif (!$this->hasMedia('attachment')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -87,11 +87,9 @@ class BillPayment extends Model
|
||||
*/
|
||||
public function getAttachmentAttribute($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (!empty($value) && !$this->hasMedia('attachment')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!$this->hasMedia('attachment')) {
|
||||
} elseif (!$this->hasMedia('attachment')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -100,11 +100,9 @@ class Payment extends Model
|
||||
*/
|
||||
public function getAttachmentAttribute($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (!empty($value) && !$this->hasMedia('attachment')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!$this->hasMedia('attachment')) {
|
||||
} elseif (!$this->hasMedia('attachment')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -146,11 +146,9 @@ class Invoice extends Model
|
||||
*/
|
||||
public function getAttachmentAttribute($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (!empty($value) && !$this->hasMedia('attachment')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!$this->hasMedia('attachment')) {
|
||||
} elseif (!$this->hasMedia('attachment')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -87,11 +87,9 @@ class InvoicePayment extends Model
|
||||
*/
|
||||
public function getAttachmentAttribute($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (!empty($value) && !$this->hasMedia('attachment')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!$this->hasMedia('attachment')) {
|
||||
} elseif (!$this->hasMedia('attachment')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -106,11 +106,9 @@ class Revenue extends Model
|
||||
*/
|
||||
public function getAttachmentAttribute($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (!empty($value) && !$this->hasMedia('attachment')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!$this->hasMedia('attachment')) {
|
||||
} elseif (!$this->hasMedia('attachment')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -120,11 +120,9 @@ class Item extends Model
|
||||
*/
|
||||
public function getPictureAttribute($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (!empty($value) && !$this->hasMedia('picture')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!$this->hasMedia('picture')) {
|
||||
} elseif (!$this->hasMedia('picture')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,8 @@ class Setting extends Model
|
||||
|
||||
protected $table = 'settings';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user