diff --git a/app/Listeners/Updates/Version116.php b/app/Listeners/Updates/Version116.php index 9dc267726..7fa0afead 100644 --- a/app/Listeners/Updates/Version116.php +++ b/app/Listeners/Updates/Version116.php @@ -24,5 +24,33 @@ class Version116 extends Listener return; } + $migrations = [ + '\App\Models\Auth\User' => 'picture', + '\App\Models\Item\Item' => 'picture', + '\App\Models\Expense\Bill' => 'attachment', + '\App\Models\Expense\BillPayment' => 'attachment', + '\App\Models\Expense\Payment' => 'attachment', + '\App\Models\Income\Invoice' => 'attachment', + '\App\Models\Income\InvoicePayment' => 'attachment', + '\App\Models\Income\Revenue' => 'attachment', + ]; + + foreach ($migrations as $model => $name) { + if ($model != '\App\Models\Auth\User') { + $items = $model::where('company_id', '<>', '0')->get(); + } else { + $items = $model::all(); + } + + foreach ($items as $item) { + if ($item->$name) { + $path = explode('uploads/', $item->$name); + + $media = MediaUploader::importPath(config('mediable.default_disk'), $path[1]); + + $item->attachMedia($media, $name); + } + } + } } } diff --git a/app/Models/Auth/User.php b/app/Models/Auth/User.php index ce0b5f87d..5367d36ff 100644 --- a/app/Models/Auth/User.php +++ b/app/Models/Auth/User.php @@ -89,6 +89,10 @@ class User extends Authenticatable } } + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('picture')) { return false; } diff --git a/app/Models/Company/Company.php b/app/Models/Company/Company.php index e04dfe1bc..59c28e13e 100644 --- a/app/Models/Company/Company.php +++ b/app/Models/Company/Company.php @@ -236,8 +236,12 @@ class Company extends Eloquent * * @return string */ - public function getCompanyLogoAttribute() + public function getCompanyLogoAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('company_logo')) { return false; } diff --git a/app/Models/Expense/Bill.php b/app/Models/Expense/Bill.php index 8a4eb4d76..10d6731bb 100644 --- a/app/Models/Expense/Bill.php +++ b/app/Models/Expense/Bill.php @@ -135,8 +135,12 @@ class Bill extends Model * * @return string */ - public function getAttachmentAttribute() + public function getAttachmentAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('attachment')) { return false; } diff --git a/app/Models/Expense/BillPayment.php b/app/Models/Expense/BillPayment.php index b0f9c6dca..e0d0c2702 100644 --- a/app/Models/Expense/BillPayment.php +++ b/app/Models/Expense/BillPayment.php @@ -85,8 +85,12 @@ class BillPayment extends Model * * @return string */ - public function getAttachmentAttribute() + public function getAttachmentAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('attachment')) { return false; } diff --git a/app/Models/Expense/Payment.php b/app/Models/Expense/Payment.php index f10133066..c61e8f767 100644 --- a/app/Models/Expense/Payment.php +++ b/app/Models/Expense/Payment.php @@ -98,8 +98,12 @@ class Payment extends Model * * @return string */ - public function getAttachmentAttribute() + public function getAttachmentAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('attachment')) { return false; } diff --git a/app/Models/Income/Invoice.php b/app/Models/Income/Invoice.php index 0cbd0c98f..7e88969ab 100644 --- a/app/Models/Income/Invoice.php +++ b/app/Models/Income/Invoice.php @@ -144,8 +144,12 @@ class Invoice extends Model * * @return string */ - public function getAttachmentAttribute() + public function getAttachmentAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('attachment')) { return false; } diff --git a/app/Models/Income/InvoicePayment.php b/app/Models/Income/InvoicePayment.php index ed7977ffd..ce59d42a6 100644 --- a/app/Models/Income/InvoicePayment.php +++ b/app/Models/Income/InvoicePayment.php @@ -85,8 +85,12 @@ class InvoicePayment extends Model * * @return string */ - public function getAttachmentAttribute() + public function getAttachmentAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('attachment')) { return false; } diff --git a/app/Models/Income/Revenue.php b/app/Models/Income/Revenue.php index 221c54632..7a363482d 100644 --- a/app/Models/Income/Revenue.php +++ b/app/Models/Income/Revenue.php @@ -104,8 +104,12 @@ class Revenue extends Model * * @return string */ - public function getAttachmentAttribute() + public function getAttachmentAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('attachment')) { return false; } diff --git a/app/Models/Item/Item.php b/app/Models/Item/Item.php index 8ab9706d3..c6dec6741 100644 --- a/app/Models/Item/Item.php +++ b/app/Models/Item/Item.php @@ -118,8 +118,12 @@ class Item extends Model * * @return string */ - public function getPictureAttribute() + public function getPictureAttribute($value) { + if (!empty($value)) { + return $value; + } + if (!$this->hasMedia('picture')) { return false; }