added prefix to source
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace App\Abstracts;
|
||||
|
||||
use App\Traits\Import as ImportHelper;
|
||||
use App\Traits\Sources;
|
||||
use App\Utilities\Date;
|
||||
use Carbon\Exceptions\InvalidFormatException;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -10,7 +11,6 @@ use Illuminate\Contracts\Translation\HasLocalePreference;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Maatwebsite\Excel\Concerns\Importable;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Maatwebsite\Excel\Concerns\ToModel;
|
||||
@ -23,7 +23,7 @@ use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate;
|
||||
|
||||
abstract class Import implements HasLocalePreference, ShouldQueue, SkipsEmptyRows, WithChunkReading, WithHeadingRow, WithLimit, WithMapping, WithValidation, ToModel
|
||||
{
|
||||
use Importable, ImportHelper;
|
||||
use Importable, ImportHelper, Sources;
|
||||
|
||||
public $user;
|
||||
|
||||
@ -36,7 +36,7 @@ abstract class Import implements HasLocalePreference, ShouldQueue, SkipsEmptyRow
|
||||
{
|
||||
$row['company_id'] = company_id();
|
||||
$row['created_by'] = $this->user->id;
|
||||
$row['created_from'] = 'import';
|
||||
$row['created_from'] = $this->getSourcePrefix() . 'import';
|
||||
|
||||
// Make enabled field integer
|
||||
if (isset($row['enabled'])) {
|
||||
|
30
app/Listeners/Update/V21/Version2125.php
Normal file
30
app/Listeners/Update/V21/Version2125.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Update\V21;
|
||||
|
||||
use App\Abstracts\Listeners\Update as Listener;
|
||||
use App\Events\Install\UpdateFinished as Event;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class Version2125 extends Listener
|
||||
{
|
||||
const ALIAS = 'core';
|
||||
|
||||
const VERSION = '2.1.25';
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
if ($this->skipThisUpdate($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Artisan::call('migrate', ['--force' => true]);
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@ class Event extends Provider
|
||||
'App\Listeners\Update\V21\Version2117',
|
||||
'App\Listeners\Update\V21\Version2118',
|
||||
'App\Listeners\Update\V21\Version2124',
|
||||
'App\Listeners\Update\V21\Version2125',
|
||||
],
|
||||
'Illuminate\Auth\Events\Login' => [
|
||||
'App\Listeners\Auth\Login',
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait Sources
|
||||
{
|
||||
public function isSourcable(): bool
|
||||
@ -16,22 +18,50 @@ trait Sources
|
||||
return ! $this->isSourcable();
|
||||
}
|
||||
|
||||
public function getSourceName($request = null): string
|
||||
public function getSourceName($request = null, $alias = null): string
|
||||
{
|
||||
$prefix = $this->getSourcePrefix($alias);
|
||||
|
||||
if (app()->runningInConsole()) {
|
||||
$source = 'console';
|
||||
$source = $prefix . 'console';
|
||||
}
|
||||
|
||||
if (empty($source)) {
|
||||
$request = $request ?: request();
|
||||
|
||||
$source = $request->isApi() ? 'api' : null;
|
||||
$source = $request->isApi() ? $prefix . 'api' : null;
|
||||
}
|
||||
|
||||
if (empty($source)) {
|
||||
$source = 'ui';
|
||||
$source = $prefix . 'ui';
|
||||
}
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
||||
public function getSourcePrefix($alias = null)
|
||||
{
|
||||
$alias = is_null($alias) ? $this->getSourceAlias() : $alias;
|
||||
|
||||
return $alias . '::';
|
||||
}
|
||||
|
||||
public function getSourceAlias()
|
||||
{
|
||||
$prefix = '';
|
||||
|
||||
$namespaces = explode('\\', get_class($this));
|
||||
|
||||
if (empty($namespaces[0]) || (empty($namespaces[1]))) {
|
||||
return $prefix;
|
||||
}
|
||||
|
||||
if ($namespaces[0] != 'Modules') {
|
||||
return 'core';
|
||||
}
|
||||
|
||||
$prefix = Str::kebab($namespaces[1]);
|
||||
|
||||
return $prefix;
|
||||
}
|
||||
}
|
||||
|
@ -132,15 +132,17 @@ if (!function_exists('source_name')) {
|
||||
/**
|
||||
* Get the current source.
|
||||
*
|
||||
* @param string|null $alias
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function source_name()
|
||||
function source_name($alias = null)
|
||||
{
|
||||
$tmp = new class() {
|
||||
use Sources;
|
||||
};
|
||||
|
||||
return $tmp->getSourceName();
|
||||
return $tmp->getSourceName(null, $alias);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user