Skip to content

Commit

Permalink
added prefix to source
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Sep 9, 2021
1 parent 640cafb commit 2b680f0
Show file tree
Hide file tree
Showing 27 changed files with 227 additions and 29 deletions.
6 changes: 3 additions & 3 deletions app/Abstracts/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
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;
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;
Expand All @@ -23,7 +23,7 @@

abstract class Import implements HasLocalePreference, ShouldQueue, SkipsEmptyRows, WithChunkReading, WithHeadingRow, WithLimit, WithMapping, WithValidation, ToModel
{
use Importable, ImportHelper;
use Importable, ImportHelper, Sources;

public $user;

Expand All @@ -36,7 +36,7 @@ public function map($row): array
{
$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'])) {
Expand Down
30 changes: 30 additions & 0 deletions app/Listeners/Update/V21/Version2125.php
Original file line number Diff line number Diff line change
@@ -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]);
}
}
1 change: 1 addition & 0 deletions app/Providers/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
38 changes: 34 additions & 4 deletions app/Traits/Sources.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Traits;

use Illuminate\Support\Str;

trait Sources
{
public function isSourcable(): bool
Expand All @@ -16,22 +18,50 @@ public function isNotSourcable(): bool
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;
}
}
6 changes: 4 additions & 2 deletions app/Utilities/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,17 @@ function should_queue() {
/**
* 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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function definition()
'bank_phone' => $this->faker->phoneNumber,
'bank_address' => $this->faker->address,
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function definition()
'type' => $this->faker->randomElement($types),
'color' => $this->faker->hexColor,
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function definition()
'currency_code' => setting('default.currency'),
'reference' => $this->faker->text(5),
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function definition()
'decimal_mark' => $currency['decimal_mark'],
'thousands_separator' => $currency['thousands_separator'],
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function definition()
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function definition()
'currency_rate' => '1',
'notes' => $this->faker->text(5),
'amount' => '0',
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function definition()
'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',
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Reconciliation.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function definition()
'started_at' => $started_at,
'ended_at' => $ended_at,
'reconcile' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function definition()
'name' => strtolower($name),
'display_name' => $name,
'description' => $name,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function definition()
'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',
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function definition()
'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',
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function definition()
'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, [
Expand Down
2 changes: 1 addition & 1 deletion database/factories/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function definition()
'companies' => ['1'],
'roles' => ['1'],
'enabled' => $this->faker->boolean ? 1 : 0,
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}

Expand Down
2 changes: 1 addition & 1 deletion database/factories/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function definition()
'dashboard_id' => $dashboard->id,
'name' => $this->faker->text(15),
'class' => $this->faker->randomElement($this->classes),
'created_from' => 'factory',
'created_from' => 'core::factory',
];
}
}

0 comments on commit 2b680f0

Please sign in to comment.