refs #164 models update
This commit is contained in:
parent
e65743c7c3
commit
87b327d9b8
@ -3,6 +3,8 @@
|
|||||||
namespace App\Listeners\Updates;
|
namespace App\Listeners\Updates;
|
||||||
|
|
||||||
use App\Events\UpdateFinished;
|
use App\Events\UpdateFinished;
|
||||||
|
use App\Models\Auth\Role;
|
||||||
|
use App\Models\Auth\Permission;
|
||||||
use MediaUploader;
|
use MediaUploader;
|
||||||
use Storage;
|
use Storage;
|
||||||
use Artisan;
|
use Artisan;
|
||||||
@ -26,6 +28,26 @@ class Version117 extends Listener
|
|||||||
return;
|
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 = [];
|
$data = [];
|
||||||
|
|
||||||
$migrations = [
|
$migrations = [
|
||||||
@ -77,23 +99,39 @@ class Version117 extends Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$settings['company_logo'] = \App\Models\Setting\Setting::where('key', '=', 'general.company_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')->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) {
|
||||||
if ($item->value) {
|
foreach ($items as $item) {
|
||||||
$path = explode('uploads/', $item->value);
|
if ($item->value) {
|
||||||
|
$path = explode('uploads/', $item->value);
|
||||||
|
|
||||||
$path = end($path);
|
$path = end($path);
|
||||||
|
|
||||||
if (!empty($item->company_id) && (strpos($path, $item->company_id . '/') === false)) {
|
if (!empty($item->company_id) && (strpos($path, $item->company_id . '/') === false)) {
|
||||||
$path = $item->company_id . '/' . $path;
|
$path = $item->company_id . '/' . $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($path) && Storage::exists($path)) {
|
if (!empty($path) && Storage::exists($path)) {
|
||||||
$media = MediaUploader::importPath(config('mediable.default_disk'), $path);
|
$company = \App\Models\Company\Company::find($item->company_id);
|
||||||
|
|
||||||
$item->attachMedia($media, $name);
|
$media = \App\Models\Common\Media::where('filename', '=', pathinfo(basename($path), PATHINFO_FILENAME))->first();
|
||||||
|
|
||||||
|
if ($company && !$media) {
|
||||||
|
$media = MediaUploader::importPath(config('mediable.default_disk'), $path);
|
||||||
|
|
||||||
|
$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;
|
return $value;
|
||||||
}
|
} elseif (!$this->hasMedia('picture')) {
|
||||||
|
|
||||||
if (!$this->hasMedia('picture')) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,11 +238,9 @@ class Company extends Eloquent
|
|||||||
*/
|
*/
|
||||||
public function getCompanyLogoAttribute($value)
|
public function getCompanyLogoAttribute($value)
|
||||||
{
|
{
|
||||||
if (!empty($value)) {
|
if (!empty($value) && !$this->hasMedia('company_logo')) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
} elseif (!$this->hasMedia('company_logo')) {
|
||||||
|
|
||||||
if (!$this->hasMedia('company_logo')) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,11 +137,9 @@ class Bill extends Model
|
|||||||
*/
|
*/
|
||||||
public function getAttachmentAttribute($value)
|
public function getAttachmentAttribute($value)
|
||||||
{
|
{
|
||||||
if (!empty($value)) {
|
if (!empty($value) && !$this->hasMedia('attachment')) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
} elseif (!$this->hasMedia('attachment')) {
|
||||||
|
|
||||||
if (!$this->hasMedia('attachment')) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,11 +87,9 @@ class BillPayment extends Model
|
|||||||
*/
|
*/
|
||||||
public function getAttachmentAttribute($value)
|
public function getAttachmentAttribute($value)
|
||||||
{
|
{
|
||||||
if (!empty($value)) {
|
if (!empty($value) && !$this->hasMedia('attachment')) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
} elseif (!$this->hasMedia('attachment')) {
|
||||||
|
|
||||||
if (!$this->hasMedia('attachment')) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,11 +100,9 @@ class Payment extends Model
|
|||||||
*/
|
*/
|
||||||
public function getAttachmentAttribute($value)
|
public function getAttachmentAttribute($value)
|
||||||
{
|
{
|
||||||
if (!empty($value)) {
|
if (!empty($value) && !$this->hasMedia('attachment')) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
} elseif (!$this->hasMedia('attachment')) {
|
||||||
|
|
||||||
if (!$this->hasMedia('attachment')) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,11 +146,9 @@ class Invoice extends Model
|
|||||||
*/
|
*/
|
||||||
public function getAttachmentAttribute($value)
|
public function getAttachmentAttribute($value)
|
||||||
{
|
{
|
||||||
if (!empty($value)) {
|
if (!empty($value) && !$this->hasMedia('attachment')) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
} elseif (!$this->hasMedia('attachment')) {
|
||||||
|
|
||||||
if (!$this->hasMedia('attachment')) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,11 +87,9 @@ class InvoicePayment extends Model
|
|||||||
*/
|
*/
|
||||||
public function getAttachmentAttribute($value)
|
public function getAttachmentAttribute($value)
|
||||||
{
|
{
|
||||||
if (!empty($value)) {
|
if (!empty($value) && !$this->hasMedia('attachment')) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
} elseif (!$this->hasMedia('attachment')) {
|
||||||
|
|
||||||
if (!$this->hasMedia('attachment')) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,11 +106,9 @@ class Revenue extends Model
|
|||||||
*/
|
*/
|
||||||
public function getAttachmentAttribute($value)
|
public function getAttachmentAttribute($value)
|
||||||
{
|
{
|
||||||
if (!empty($value)) {
|
if (!empty($value) && !$this->hasMedia('attachment')) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
} elseif (!$this->hasMedia('attachment')) {
|
||||||
|
|
||||||
if (!$this->hasMedia('attachment')) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,11 +120,9 @@ class Item extends Model
|
|||||||
*/
|
*/
|
||||||
public function getPictureAttribute($value)
|
public function getPictureAttribute($value)
|
||||||
{
|
{
|
||||||
if (!empty($value)) {
|
if (!empty($value) && !$this->hasMedia('picture')) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
} elseif (!$this->hasMedia('picture')) {
|
||||||
|
|
||||||
if (!$this->hasMedia('picture')) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ class Setting extends Model
|
|||||||
|
|
||||||
protected $table = 'settings';
|
protected $table = 'settings';
|
||||||
|
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attributes that should be mass-assignable.
|
* Attributes that should be mass-assignable.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user