added prefix to source

This commit is contained in:
Denis Duliçi 2021-09-10 00:31:39 +03:00
parent 640cafb133
commit 2b680f0f8e
27 changed files with 227 additions and 29 deletions

View File

@ -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'])) {

View 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]);
}
}

View File

@ -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',

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -31,7 +31,7 @@ class Account extends Factory
'bank_phone' => $this->faker->phoneNumber,
'bank_address' => $this->faker->address,
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

View File

@ -29,7 +29,7 @@ class Category extends Factory
'type' => $this->faker->randomElement($types),
'color' => $this->faker->hexColor,
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

View File

@ -39,7 +39,7 @@ class Contact extends Factory
'currency_code' => setting('default.currency'),
'reference' => $this->faker->text(5),
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

View File

@ -47,7 +47,7 @@ class Currency extends Factory
'decimal_mark' => $currency['decimal_mark'],
'thousands_separator' => $currency['thousands_separator'],
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

View File

@ -25,7 +25,7 @@ class Dashboard extends Factory
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

View File

@ -45,7 +45,7 @@ class Document extends AbstractFactory
'currency_rate' => '1',
'notes' => $this->faker->text(5),
'amount' => '0',
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

View File

@ -29,7 +29,7 @@ class Item extends Factory
'sale_price' => $this->faker->randomFloat(2, 10, 20),
'category_id' => $this->company->categories()->item()->get()->random(1)->pluck('id')->first(),
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

View File

@ -34,7 +34,7 @@ class Reconciliation extends Factory
'started_at' => $started_at,
'ended_at' => $ended_at,
'reconcile' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

View File

@ -28,7 +28,7 @@ class Role extends Factory
'name' => strtolower($name),
'display_name' => $name,
'description' => $name,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

View File

@ -29,7 +29,7 @@ class Tax extends Factory
'rate' => $this->faker->randomFloat(2, 10, 20),
'type' => $this->faker->randomElement($types),
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

View File

@ -41,7 +41,7 @@ class Transaction extends Factory
'category_id' => $this->company->categories()->$category_type()->get()->random(1)->pluck('id')->first(),
'reference' => $this->faker->text(5),
'payment_method' => setting('default.payment_method'),
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

View File

@ -43,7 +43,7 @@ class Transfer extends Factory
'category_id' => Category::transfer(),
'description' => $this->faker->text(20),
'reference' => $this->faker->text(20),
'created_from' => 'factory',
'created_from' => 'core::factory',
];
$expense_transaction = Transaction::factory()->create(array_merge($request, [

View File

@ -34,7 +34,7 @@ class User extends Factory
'companies' => ['1'],
'roles' => ['1'],
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

View File

@ -42,7 +42,7 @@ class Widget extends Factory
'dashboard_id' => $dashboard->id,
'name' => $this->faker->text(15),
'class' => $this->faker->randomElement($this->classes),
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}
}

View File

@ -0,0 +1,134 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CoreV2125 extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('accounts', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('categories', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('companies', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('contacts', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('currencies', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('dashboards', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('documents', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('document_histories', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('document_items', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('document_item_taxes', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('document_totals', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('email_templates', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('items', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('item_taxes', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('media', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('mediables', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('modules', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('module_histories', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('reconciliations', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('recurring', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('reports', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('roles', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('taxes', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('transactions', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('transfers', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('users', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
Schema::table('widgets', function (Blueprint $table) {
$table->string('created_from', 100)->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -36,7 +36,7 @@ class Accounts extends Seeder
'currency_code' => 'USD',
'bank_name' => trans('demo.accounts.cash'),
'enabled' => '1',
'created_from' => 'seed',
'created_from' => 'core::seed',
]));
setting()->set('default.account', $account->id);

View File

@ -70,7 +70,7 @@ class Categories extends Seeder
$income_category_id = $expense_category_id = 0;
foreach ($rows as $row) {
$row['created_from'] = 'seed';
$row['created_from'] = 'core::seed';
$category = $this->dispatch(new CreateCategory($row));

View File

@ -78,7 +78,7 @@ class Currencies extends Seeder
];
foreach ($rows as $row) {
$row['created_from'] = 'seed';
$row['created_from'] = 'core::seed';
$this->dispatch(new CreateCurrency($row));
}

View File

@ -45,7 +45,7 @@ class Dashboards extends Seeder
'App\Widgets\LatestExpenses',
],
'users' => $user_id,
'created_from' => 'seed',
'created_from' => 'core::seed',
]));
}
}

View File

@ -90,7 +90,7 @@ class EmailTemplates extends Seeder
'name' => $template['name'],
'subject' => trans('email_templates.' . $template['alias'] . '.subject'),
'body' => trans('email_templates.' . $template['alias'] . '.body'),
'created_from' => 'seed',
'created_from' => 'core::seed',
]));
}
}

View File

@ -68,7 +68,7 @@ class Reports extends Seeder
];
foreach ($rows as $row) {
$row['created_from'] = 'seed';
$row['created_from'] = 'core::seed';
$this->dispatch(new CreateReport($row));
}

View File

@ -52,6 +52,7 @@ class TestCompany extends Seeder
'wizard.completed' => '1',
'email.protocol' => 'array',
],
'created_from' => 'core::seed',
]));
$company->makeCurrent(true);