1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 16:24:04 +00:00
Commit graph

1328 commits

Author SHA1 Message Date
lukinovec
fbdb13f392
[4.x] Set app.url config in UrlTenancyBootstrapper (#1068)
* Set `app.url` config in UrlTenancyBootstrapper

* Add assertions

* Set base app URL in config

* Make UrlTenancyBootstrapper a singleton
2023-02-18 13:01:17 +01:00
lukinovec
617e9a7a73
[4.x] Allow user to customize tenant's URL root in CLI (#1044)
* Add UrlTenancyBootstrapper

* Fix code style (php-cs-fixer)

* Move URL overriding to a separate method, call it in `boot()`

* Test URL root overriding

* Change parameter formatting

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>

* Fix code style (php-cs-fixer)

* Improve URL bootstrapper test

* Move `$scheme` and `$hostname` to the closure

* Update code example comment

* Hardcode values instead of referencing variables

* Delete extra line

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-02-17 10:56:43 +01:00
Guilherme Saade
d4a99011e6
[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>
2023-02-16 17:21:06 +01:00
Samuel Štancl
a006e49881
specify version of odbc libraries 2023-02-16 17:20:55 +01:00
Abrar Ahmad
758fbc8a75
Use polymorphic table for mapping resources to tenants (#997)
* wip

* Fix code style (php-cs-fixer)

* adjust tests

* Update ResourceSyncingPolymorphicTest.php

* Update SyncMaster.php

* correct method name

* Update ResourceSyncingPolymorphicTest.php

* use BelongsToMany return type

* separate pivot model for each approach

* ability to publish migrations

* remove unsed import

* use resource migrations from asset

* anonymous migration for `tenant_resources` table

* rename file

* rename classes

* trait

* add back using statement

* revert to unset change

* use unset approach

* use unset approach

* Assert `tenants` are accessible

* Update ResourceSyncingUsingPolymorphicTest.php

* improve `tenants` assertions

* improve assertions

* remove `getResourceTenantModelName` method and use config

* use `BelongsToMany` for `tenants` method return type

* Fix code style (php-cs-fixer)

* revert type

* use correct key

* test right resources are accessible from the tenant

* Update tests/ResourceSyncingUsingPolymorphicTest.php

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
2023-02-02 06:39:35 +01:00
Abrar Ahmad
087733d5db
Allow defining the tenant connection template using array syntax in config (#1040)
* `template_tenant_connection` can be array or string

* Update TenantDatabaseManagerTest.php

* Update TenantDatabaseManagerTest.php

* Update TenantDatabaseManagerTest.php

* Update DatabaseConfig.php

* partial database config for template

* Update tests/TenantDatabaseManagerTest.php

Co-authored-by: lukinovec <lukinovec@gmail.com>

* update test name

* improve test names

* add comments

---------

Co-authored-by: lukinovec <lukinovec@gmail.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
2023-02-01 07:02:03 +01:00
lukinovec
342c67fe02
Add skip-failing option to the Migrate command (#945)
* Add and test Migrate command's skip-failing option

* Improve naming

* Move migration event dispatching inside try block

* Change test name

* Fix skip-failing test

* Use QueryException instead of Exception

* Correct TenantDatabaseDoesNotExistException import

* Correct test

* Check for the the testing env in DB bootstrapper

* Correct the Migrate command

* Fix code style (php-cs-fixer)

* add docs todo

* Add QueryException to the Migrat command try/catch

* Return status codes in Migrate

* Fix code style (php-cs-fixer)

* Add test for not stopping tenants:migrate after the first failure

* Update Migrate command

* Fix code style (php-cs-fixer)

* Fix code style (php-cs-fixer)

* Use `getTenants()`

* Use withtenantDatabases where needed

* Add withTenantDatabases to test

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-02-01 06:55:26 +01:00
Joel Stein
7d59ff180f
Don't prevent accessing missing Tenant attributes. (#1045) 2023-02-01 06:24:53 +01:00
Samuel Štancl
d7437c42d2 Merge branch 'master' of github.com:tenancy-for-laravel/v4 2023-02-01 06:20:27 +01:00
Samuel Štancl
f741f44527 Merge branch 'master' of github.com:archtechx/tenancy 2023-02-01 06:17:27 +01:00
Samuel Štancl
0a205dd817 resolve phpstan issues 2023-02-01 06:17:19 +01:00
PHP CS Fixer
7767fea5ba Fix code style (php-cs-fixer) 2023-02-01 05:05:50 +00:00
Samuel Štancl
66c7d6a066 fix PhpParser exception 2023-02-01 06:05:26 +01:00
PHP CS Fixer
864add9ade Fix code style (php-cs-fixer) 2023-01-31 03:00:43 +00:00
Samuel Štancl
5ceee3b9b4 Merge branch 'master' of github.com:archtechx/tenancy 2023-01-31 04:00:11 +01:00
Samuel Štancl
c74a7b6fd4 remove debuggable trait, update larastan 2023-01-31 03:59:33 +01:00
lukinovec
26b8569761
Cache crash fix (#1048) 2023-01-27 08:17:14 +01:00
Roman
3e13e62806
CachedTenantResolver missing cache case crash fix. (#1005)
* CachedTenantResolver missing cache case crash fix.

* Check if cached tenant is truthy

Co-authored-by: rty <rty@interlogic.com.ua>
Co-authored-by: lukinovec <lukinovec@gmail.com>
2023-01-18 18:46:47 +01:00
Samuel Štancl
87c08cebc4 Merge branch 'master' of github.com:archtechx/tenancy 2023-01-06 02:48:40 +01:00
Samuel Štancl
21d55ef472 add setup-php to phpstan job 2023-01-06 02:44:37 +01:00
Samuel Štancl
48fc63fe02 switch to PHP 8.2 2023-01-06 02:38:31 +01:00
Samuel Štancl
a0256fd5f3 Merge branch 'master' of github.com:archtechx/tenancy 2023-01-04 03:27:04 +01:00
Samuel Štancl
24d71230e8 comment out php 8.2 phpstan ignores 2023-01-04 03:18:52 +01:00
Samuel Štancl
32a128d657 lower required php version back to 8.1 2023-01-04 03:08:56 +01:00
Samuel Štancl
db1dc334a6 add todo 2023-01-04 03:04:56 +01:00
Samuel Štancl
9078280a44 revert to 8.1 in CI for now 2023-01-04 03:04:00 +01:00
Samuel Štancl
da817cebe5 Merge branch 'master' of github.com:archtechx/tenancy 2023-01-04 02:43:24 +01:00
Samuel Štancl
d0dd87ab07 bump PHP to 8.2, minor ci fixes 2023-01-04 02:43:10 +01:00
PHP CS Fixer
d4c6c34e7c Fix code style (php-cs-fixer) 2023-01-04 01:24:21 +00:00
Samuel Štancl
03ac1ef127 fix phpstan errors (seems like it started ignoring @property annotations on interfaces and abstract classes) 2023-01-04 02:23:48 +01:00
lukinovec
0f892f1585
Make tenants able to have custom mail credentials (#989)
* Replace MailManager singleton with an instance of a custom mail manager which always resolves the mailers instead of getting the cached ones

* Fix code style (php-cs-fixer)

* Add MailTenancyBootstrapper

* Add MailTenancyBootstrapper to tenancy.bootstrappers config (commented out)

* Fix code style (php-cs-fixer)

* Make credentials map a public static property

* Always resolve only the mailers specified in the mailersToNotCache public static property

* Fix typo in comment

* Update TenancyServiceProvider comment

* add todo

* Add comments to TenancyMailManager, rename property

* Remove the configKey array check

* Simplify bootstrap method

* Change $credentialsMap so that config keys are the keys, and the tenant property names are the values

* Rename $mailersToAlwaysResolve to $tenantMailers

* Update comment

* Update comment

* Rename variable in TenancyServiceProvider comment

* Scaffold tests

* Update comments after review

* Uncomment MailTenancyBootstrapper in config

* Use array_key_exists instead of null check

* Split config logic into methods

* Update mapping credentials

* Add tests for the added logic

* Fix code style (php-cs-fixer)

* Delete default 'smtp' mailer in $tenantMailers

* Add separate method to pick the appropriate mail credentials map preset

* Specify test name

* Move mail bootstrapper tests to BootstrapperTest

* Depend less on the default mailer by adding a static `$mailer` property

* Use static property for map presets

* Comment out MailTenancyBootstrapper from config

* Add return types to MailTenancyBootstrapper methods

* Update test name

* Move MailManager extension to MailTenancyBootstrapper

* Fix code style (php-cs-fixer)

* Update config reverting test

* Use `invade()` instead of ReflectionClass

* Fix constructor parameter formatting

* Delete TenancyMailManager, update tests

* Add return type

* Update comment

* Update MailTest

* Delete `group('mailer')`

* Delete bindNewMailManagerInstance()

* Delete remaining `group('mailer')`

* Fix comment

* Fix comment

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2023-01-04 02:12:25 +01:00
Samuel Štancl
82fa6cb292 fix tenant() relationship in Domain 2022-12-20 15:10:29 +01:00
Abrar Ahmad
f42f08cb87
Add session state when impersonating tenant (#1029)
* wip

* Fix code style (php-cs-fixer)

* Update TenantUserImpersonationTest.php

* renamed method

* update method name in test

* rename session key

* fix test

* Update src/Features/UserImpersonation.php

Co-authored-by: Samuel Štancl <samuel@archte.ch>

* Update UserImpersonation.php

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
2022-12-17 02:08:03 +01:00
lukinovec
21dc69e358
Use invade in BootstrapperTest (#1033) 2022-12-15 15:03:03 +01:00
Abrar Ahmad
68de3600bd
Improve commands CLI output (#1030)
* use component info/error methods

* Update src/Commands/ClearPendingTenants.php

Co-authored-by: lukinovec <lukinovec@gmail.com>

Co-authored-by: lukinovec <lukinovec@gmail.com>
2022-12-14 15:08:00 +01:00
Samuel Štancl
a7ad8287e6 disable new jobs/listeners by default, add CreateTenantStorage job 2022-12-02 19:43:20 +01:00
Samuel Štancl
45aac1a718 phpstan fixes 2022-11-29 10:31:37 +01:00
Samuel Štancl
ad29909a16 Make $tenantId nullable in initializeTenancyForQueue (revert phpstan change) 2022-11-29 10:25:22 +01:00
Samuel Štancl
b2dc0844eb Merge branch 'master' of github.com:tenancy-for-laravel/v4 2022-11-29 10:19:12 +01:00
lukinovec
7d3298c6bb
Improve code of pending tenants (#1025)
* Remove `--all` option from ClearPendingTenants

* Improve query formatting

* Remove redundant test

* Convert time constrait options to int

* Improve CreatePendingTenants success message
2022-11-29 09:31:07 +01:00
Abrar Ahmad
73c5655bc8
Manual mode improvements (use correct event type, add new listeners) (#1013)
* fix issue and add test

* Update CreateTenantConnection.php

* add purge call

* Update ManualModeTest.php

* use tenant connection and central connection listener

* Update ManualModeTest.php

* fix test

* improvements

* Update ManualModeTest.php

* add comment

* simplify comment

Co-authored-by: Samuel Štancl <samuel@archte.ch>
2022-11-25 03:09:31 +01:00
lukinovec
ea19117870
Use the hardcoded default path in TenantDump only if the path isn't configured (#1019)
* Use the hardcoded tenant dump path only if the path isn't configured

* Test generating tenant dump at the configured path
2022-11-23 13:12:29 +01:00
lukinovec
cb7567a88a
[4.x] Make TenantDump work when called outside the tenant context (#1015)
* Run TenantDump as passed tenant

* Fix code style (php-cs-fixer)

* Fix `tenants:dump` tests

* Update dump command test

* Remove redundant `tenant-schema.dump` unlinking

* Delete duplicate test

* Update test name

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
2022-11-23 08:38:20 +01:00
Samuel Štancl
5849089373
Add SessionTenancyBootstrapper (#2)
* Add SessionTenancyBootstrapper

* Fix code style (php-cs-fixer)

* add value to bootstrappers config

* tenant aware call test

* reproduce issue in tests

* fix logic for calling tenant run from central context, finish tests

* change laravel version back

* bump laravel to ^9.38

* add listener to create tenant DBs

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Abrar Ahmad <abrar.dev99@gmail.com>
2022-11-20 02:32:25 +01:00
Abrar Ahmad
ff46bcfe20
Early identification support (#1)
* wip

* Improve tests

* rename class

* wip

* improve tests

* introduce early identification middlewares

* Update PreventAccessFromCentralDomains.php

* method rename

* method rename

* Update UniversalRouteTest.php

* Update UniversalRouteTest.php

* Update EarlyIdentificationTest.php

* remove early classes and add check in existing classes

* MWs improvements

* Update UniversalRouteTest.php

* Fix code style (php-cs-fixer)

* trigger ci

* fix failing test after merge

* add test for universal route in early identification

* Update InitializeTenancyByDomain.php

* Update UniversalRouteTest.php

* remove `routeHasMiddleware` method from MW and use the UniversalRoutes class method

* helper dockblock

* add test

* handle universal routes in early identification

* remove UniversalRoute class because we are not using it anymore

* rename class from PreventAccessFromCentralDomains to PreventAccessFromUnwantedDomains

* improvements after self review

* Update PreventAccessFromUnwantedDomains.php

* remove inline class namespaces

* remove DomainTenant class and use the Tenant class

* update comment

* removed custom expection and add method

* Update tests/EarlyIdentificationTest.php

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>

* use ltrim and simplify the comment

* remove comments and typhint

* dataset and keys rename

* rename $route parameter

* removed helper functions

* fix style

* Update InitializeTenancyByPath.php

* Update tests/EarlyIdentificationTest.php

* code style

* improve subdomain test

* use TenancyInitialized event and remove DomainTenant alias

* remove comment and move expectException below

* code style

* use TenancyInitialized event

* improve test

* improve datasets

* Initialized -> Initializing

* Update InitializeTenancyByPath.php

* remove todo

* Fix code style (php-cs-fixer)

* refactor helper method

* Update UniversalRouteTest.php

* add note above test

* remove after each hook

* renamed universal_middleware to global_middleware

* remove helper and improve url names

* change check position

* Revert "change check position"

This reverts commit e4371d2f3aa8ad7ae5e5b7d15781b72a5f1be03c.

* repositioned central check

* add comment

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2022-11-20 02:31:37 +01:00
lukinovec
9520cbc811
Only delete tenants in MigrateFreshOverride if the tenants table exists (#1007)
* Don't drop tenant databases on `migrate:fresh` if the tenants table doesn't exist

* Fix code style (php-cs-fixer)

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
2022-11-18 15:58:04 +01:00
Samuel Štancl
1db2f0913f add todo 2022-11-17 03:39:57 +01:00
Abrar Ahmad
fb2369dc11
anonymous publishable migrations (#1001) 2022-11-11 13:02:13 +01:00
Samuel Štancl
2a39b0526a Fix #998, properly replace ALL tenant_id literals 2022-11-10 16:44:52 +01:00
Samuel Štancl
8a00a105d0 Merge branch 'master' of github.com:archtechx/tenancy 2022-11-10 16:03:28 +01:00