mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 08:04:03 +00:00
Add L10 support to 4.x (merge 3.x to master) (#1071)
* exclude master from CI * Add space after 'up' in 'docker-compose up-d' (#900) * Fix ArgumentCountError on the TenantAssetsController (#894) * Fix ArgumentCount exception on the TenantAssetsController when no `$path` is provided * CS * CS * Handle null case explicitly * code style Co-authored-by: Bram Wubs <bram@sibi.nl> Co-authored-by: Samuel Štancl <samuel@archte.ch> * Add support for nested tenant config override (#920) * feat: add support for nested tenant config override * test: ensure nested tenant values are mapped * fix: typo mistake (#954) * [3.x] Add Vite helper for tenancy (#956) * Add Vite helper for tenancy * Move Vite bundler to an Optional Feature * Rename to foundation vite * Add ViteBundlerTest * Add missing end of file * Update tests * remove unnecessary end() call Co-authored-by: Samuel Štancl <samuel@archte.ch> * rewrite ViteBundlerTest to phpunit syntax * skip vite test in Laravel < 9 * convert ViteBundler to PHP 7 syntax * remove import of nonexistent class in older Laravel versions * remove import of Foundation\Vite in tests * try to exclude Vite.php from coverage report * remove typehint * update channel name * Cache crash fix (#1048) * Don't prevent accessing missing Tenant attributes. (#1045) * [3.x] L10 compatibility (#1065) * Bump dependencies for Laravel 10 * Update GitHub Actions for Laravel 10 * ci: do not test L10 using PHP 7.3 * drop < L9 support * use `dispatch_sync` instead of `dispatch_now` * migrate phpunit configuration * Update ci.yml * drop laravel < 9 support * misc L10 fixes, new docker image * specify odbc version * wip * properly list php versions as strings * minor changes * Add `getValue($queryGrammar)` to raw query * Clean up `isVersion8` code * rewrite hasFailed assertion * phpunit schema update * Upgrade `doctrine/dbal` --------- Co-authored-by: Samuel Štancl <samuel@archte.ch> Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com> Co-authored-by: lukinovec <lukinovec@gmail.com> * Update ci.yml * Fix code style (php-cs-fixer) * Update dependencies * Change invade version * Delete ViteBundlerTest * Fix PHPStan error * Delete PHPStan error ignore * Fix CONTRIBUTING.md * Delete ViteBundler remains * Bring back ViteBundler * Convert ViteBundlerTest to Pest * Update ci.yml --------- Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com> Co-authored-by: Bram Wubs <megawubs@users.noreply.github.com> Co-authored-by: Bram Wubs <bram@sibi.nl> Co-authored-by: Samuel Štancl <samuel@archte.ch> Co-authored-by: George Bishop <email.georgebishop@gmail.com> Co-authored-by: Anbuselvan Rocky <15264938+anburocky3@users.noreply.github.com> Co-authored-by: Wilsen Hernández <13445515+wilsenhc@users.noreply.github.com> Co-authored-by: Joel Stein <joel@mediatrix.digital> Co-authored-by: Guilherme Saade <saade@outlook.com.br> Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
This commit is contained in:
parent
d7a4982cd3
commit
e61a26d604
13 changed files with 107 additions and 24 deletions
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
|
|
@ -15,7 +15,11 @@ jobs:
|
|||
|
||||
strategy:
|
||||
matrix:
|
||||
laravel: ['^9.0']
|
||||
include:
|
||||
- laravel: 9
|
||||
php: "8.0"
|
||||
- laravel: 10
|
||||
php: "8.1"
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
|
|
@ -23,7 +27,7 @@ jobs:
|
|||
|
||||
- name: Install Composer dependencies
|
||||
run: |
|
||||
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
|
||||
composer require "laravel/framework:^${{ matrix.laravel }}.0" --no-interaction --no-update
|
||||
composer update --prefer-dist --no-interaction
|
||||
- name: Run tests
|
||||
run: ./vendor/bin/pest
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ return [
|
|||
],
|
||||
|
||||
/**
|
||||
* Redis tenancy config. Used by RedisTenancyBoostrapper.
|
||||
* Redis tenancy config. Used by RedisTenancyBootstrapper.
|
||||
*
|
||||
* Note: You need phpredis to use Redis tenancy.
|
||||
*
|
||||
|
|
@ -286,6 +286,7 @@ return [
|
|||
// Stancl\Tenancy\Features\TelescopeTags::class,
|
||||
// Stancl\Tenancy\Features\TenantConfig::class, // https://tenancyforlaravel.com/docs/v3/features/tenant-config
|
||||
// Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancyforlaravel.com/docs/v3/features/cross-domain-redirect
|
||||
// Stancl\Tenancy\Features\ViteBundler::class,
|
||||
],
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -17,18 +17,19 @@
|
|||
"require": {
|
||||
"php": "^8.2",
|
||||
"ext-json": "*",
|
||||
"illuminate/support": "^9.38",
|
||||
"illuminate/support": "^9.38|^10.0",
|
||||
"facade/ignition-contracts": "^1.0.2",
|
||||
"spatie/ignition": "^1.4",
|
||||
"ramsey/uuid": "^4.0",
|
||||
"stancl/jobpipeline": "^1.0",
|
||||
"stancl/virtualcolumn": "^1.3",
|
||||
"ramsey/uuid": "^4.7.3",
|
||||
"stancl/jobpipeline": "^1.6.2",
|
||||
"stancl/virtualcolumn": "^1.3.1",
|
||||
"spatie/invade": "^1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"laravel/framework": "^9.38",
|
||||
"orchestra/testbench": "^7.0",
|
||||
"league/flysystem-aws-s3-v3": "^3.0",
|
||||
"doctrine/dbal": "^2.10",
|
||||
"laravel/framework": "^9.38|^10.0",
|
||||
"orchestra/testbench": "^7.0|^8.0",
|
||||
"league/flysystem-aws-s3-v3": "^3.12.2",
|
||||
"doctrine/dbal": "^3.6.0",
|
||||
"spatie/valuestore": "^1.2.5",
|
||||
"pestphp/pest": "^1.21",
|
||||
"nunomaduro/larastan": "^2.4",
|
||||
|
|
|
|||
|
|
@ -40,10 +40,6 @@ parameters:
|
|||
message: '#Illuminate\\Routing\\UrlGenerator#'
|
||||
paths:
|
||||
- src/Bootstrappers/FilesystemTenancyBootstrapper.php
|
||||
-
|
||||
message: '#select\(\) expects string, Illuminate\\Database\\Query\\Expression given#'
|
||||
paths:
|
||||
- src/Database/TenantDatabaseManagers/PermissionControlledMySQLDatabaseManager.php
|
||||
-
|
||||
message: '#Trying to invoke Closure\|null but it might not be a callable#'
|
||||
paths:
|
||||
|
|
|
|||
|
|
@ -33,9 +33,8 @@ class ImpersonationToken extends Model
|
|||
public $incrementing = false;
|
||||
|
||||
protected $table = 'tenant_user_impersonation_tokens';
|
||||
|
||||
protected $dates = [
|
||||
'created_at',
|
||||
protected $casts = [
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
|
||||
public static function booted(): void
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ class Tenant extends Model implements Contracts\Tenant
|
|||
Concerns\InitializationHelpers,
|
||||
Concerns\InvalidatesResolverCache;
|
||||
|
||||
protected static $modelsShouldPreventAccessingMissingAttributes = false;
|
||||
|
||||
protected $table = 'tenants';
|
||||
protected $primaryKey = 'id';
|
||||
protected $guarded = [];
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ class PermissionControlledMySQLDatabaseManager extends MySQLDatabaseManager impl
|
|||
|
||||
protected function isVersion8(): bool
|
||||
{
|
||||
$version = $this->database()->select($this->database()->raw('select version()'))[0]->{'version()'};
|
||||
$versionSelect = (string) $this->database()->raw('select version()')->getValue($this->database()->getQueryGrammar());
|
||||
$version = $this->database()->select($versionSelect)[0]->{'version()'};
|
||||
|
||||
return version_compare($version, '8.0.0') >= 0;
|
||||
}
|
||||
|
|
|
|||
26
src/Features/ViteBundler.php
Normal file
26
src/Features/ViteBundler.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Features;
|
||||
|
||||
use Illuminate\Foundation\Application;
|
||||
use Stancl\Tenancy\Contracts\Feature;
|
||||
use Stancl\Tenancy\Tenancy;
|
||||
use Stancl\Tenancy\Vite;
|
||||
|
||||
class ViteBundler implements Feature
|
||||
{
|
||||
/** @var Application */
|
||||
protected $app;
|
||||
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
public function bootstrap(Tenancy $tenancy): void
|
||||
{
|
||||
$this->app->singleton(\Illuminate\Foundation\Vite::class, Vite::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -62,6 +62,7 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
$this->app->singleton(Commands\Rollback::class, function ($app) {
|
||||
return new Commands\Rollback($app['migrator']);
|
||||
});
|
||||
|
||||
$this->app->singleton(Commands\Seed::class, function ($app) {
|
||||
return new Commands\Seed($app['db']);
|
||||
});
|
||||
|
|
|
|||
22
src/Vite.php
Normal file
22
src/Vite.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy;
|
||||
|
||||
use Illuminate\Foundation\Vite as BaseVite;
|
||||
|
||||
class Vite extends BaseVite // todo move to a different directory in v4
|
||||
{
|
||||
/**
|
||||
* Generate an asset path for the application.
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool|null $secure
|
||||
* @return string
|
||||
*/
|
||||
protected function assetPath($path, $secure = null)
|
||||
{
|
||||
return global_asset($path);
|
||||
}
|
||||
}
|
||||
|
|
@ -79,7 +79,7 @@ test('ing events can be used to cancel db creation', function () {
|
|||
});
|
||||
|
||||
$tenant = Tenant::create();
|
||||
dispatch_now(new CreateDatabase($tenant));
|
||||
dispatch_sync(new CreateDatabase($tenant));
|
||||
|
||||
pest()->assertFalse($tenant->database()->manager()->databaseExists(
|
||||
$tenant->database()->getName()
|
||||
|
|
@ -171,12 +171,13 @@ test('database is not migrated if creation is disabled', function () {
|
|||
})->toListener()
|
||||
);
|
||||
|
||||
Tenant::create([
|
||||
$tenant = Tenant::create([
|
||||
'tenancy_create_database' => false,
|
||||
'tenancy_db_name' => 'already_created',
|
||||
]);
|
||||
|
||||
expect(pest()->hasFailed())->toBeFalse();
|
||||
// assert test didn't fail
|
||||
$this->assertTrue($tenant->exists());
|
||||
});
|
||||
|
||||
class FooListener extends QueueableListener
|
||||
|
|
|
|||
29
tests/Features/ViteBundlerTest.php
Normal file
29
tests/Features/ViteBundlerTest.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Foundation\Vite;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Stancl\Tenancy\Vite as StanclVite;
|
||||
use Stancl\Tenancy\Features\ViteBundler;
|
||||
|
||||
test('vite helper uses our custom class', function() {
|
||||
$vite = app(Vite::class);
|
||||
|
||||
expect($vite)->toBeInstanceOf(Vite::class);
|
||||
expect($vite)->not()->toBeInstanceOf(StanclVite::class);
|
||||
|
||||
config([
|
||||
'tenancy.features' => [ViteBundler::class],
|
||||
]);
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
app()->forgetInstance(Vite::class);
|
||||
|
||||
$vite = app(Vite::class);
|
||||
|
||||
expect($vite)->toBeInstanceOf(StanclVite::class);
|
||||
});
|
||||
|
|
@ -302,7 +302,7 @@ test('database credentials can be provided to PermissionControlledMySQLDatabaseM
|
|||
$mysql2DB->statement("CREATE USER `{$username}`@`%` IDENTIFIED BY '{$password}';");
|
||||
$mysql2DB->statement("GRANT ALL PRIVILEGES ON *.* TO `{$username}`@`%` identified by '{$password}' WITH GRANT OPTION;");
|
||||
$mysql2DB->statement("FLUSH PRIVILEGES;");
|
||||
|
||||
|
||||
DB::purge('mysql2'); // forget the mysql2 connection so that it uses the new credentials the next time
|
||||
|
||||
config(['database.connections.mysql2.username' => $username]);
|
||||
|
|
@ -347,7 +347,7 @@ test('tenant database can be created by using the username and password from ten
|
|||
$mysqlDB->statement("CREATE USER `{$username}`@`%` IDENTIFIED BY '{$password}';");
|
||||
$mysqlDB->statement("GRANT ALL PRIVILEGES ON *.* TO `{$username}`@`%` identified by '{$password}' WITH GRANT OPTION;");
|
||||
$mysqlDB->statement("FLUSH PRIVILEGES;");
|
||||
|
||||
|
||||
DB::purge('mysql2'); // forget the mysql2 connection so that it uses the new credentials the next time
|
||||
|
||||
// Remove `mysql` credentials to make sure we will be using the credentials from the tenant config
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue