* Declare sensitive parameters as sensitive
... just so that they don't show up in logs
* Remove unnecessary null-coalescing
* Simplify return
* Merge isset() calls
* Inline return
* Use nullsafe operator
* Simplify if-else branches
* Use direct empty string comparison instead of strlen()
* Add missing type
* Change interface as events expect a TenantWithDatabase not just a Tenant
* Narrow typehint
* Remove redundant type casts
* Fix style with php-cs-fixer
* Fix typos
* Revert unwanted if-else simplification
* fix phpstan errors
* narrow type
---------
Co-authored-by: Samuel Štancl <samuel@archte.ch>
This makes it possible to have Domain records in both `foo` and
`foo.{centralDomain}` format when using the combined domain/subdomain
identification middleware, or the origin header id mw which extends it.
This commit also refactors some related logic.
* Only retrieve domains if the relationship and the domains table exist (DomianTenantResolver)
* Resolve todo, add other todos
* Use constructor promotion in DeleteDomains
* Fix imports + domain deletion test
* Confirm that turning on resolver caching doesn't break the tests
* Fix Tenant model imports
* Fix code style (php-cs-fixer)
* remove runtime schema check
* temp: enable resolver cache
* make 'autoincrement ids are supported' pass
* disable resolver cache
---------
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
* Run cache tests on all supported drivers
* update ci healthcheck for memcached
* remove memcached healthcheck
* fix typos in test comments, expand internal.md [ci skip]
* add empty line [ci skip]
* switch to using $store->setPrefix()
* add dynamodb
* refactor try-finally to try-catch
* remove unnecessary clearResolvedInstances() call
* add dual Cache:: and cache() assertions
* add apc
* Flush APCu cache in test setup
* Revert "add dual Cache:: and cache() assertions"
This reverts commit a0bab162fbe2dd0d25e7056ceca4fb7ce54efc77.
* phpstan fix
* Add logic for scoping 'file' disks to FilesystemTenancyBootstrapper
* minor changes, add todos
* refactor how the session.connection is used in the DB session bootstrapper
* add session forgery prevention logic to the db session bootstrapper
* only use the fs bootstrapper for file disk in 'cache data is separated' dataset
* minor session scoping test changes
* Add session scoping logic to FilesystemTenancyBootstrapper, correctly update disk roots even with storage_path_tenancy disabled
* Fix code style (php-cs-fixer)
* update docblock
* make not-null check more explicit
* separate bootstrapper tests, fix swapped test names for two tests
* refactor cache bootstrapper tests
* resolve global cache todo
* expand tests: session separation tests, more filesystem separation assertions; change prefix_base-type config keys to templates/formats
* add apc session scoping test, various session separation bugfixes
* phpstan + minor logic fixes
* prefix_format -> prefix
* fix database session separation test
* revert composer.json changes, update laravel dependencies to expected next release
* only run session scoping logic in cache bootstrapper for redis, memcached, dynamodb, apc; update gitattributes
* tenancy.central_domains -> tenancy.identification.central_domains
* db session separation test: add datasets
---------
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
* wip
* bump jobpipeline dependency
* bump pest dependency
* fix composer.json syntax
* minor changes to docker setup
* more docker changes
* compact pest output, remove unnecessary env vars from composer.json
* minor pest tweaks
* mssql fix
* try enabling colors in CI
* try setting --columns=max for pest in CI
* try setting columns using env var instead of --columns in CI
* Revert "try setting columns using env var instead of --columns in CI"
This reverts commit eb3c177aefa97b0a3140d7f0e89c5012a854ff42.
* replace --compact with --no-progress
* try setting a hardcoded columns value in CI
* remove --columns (doesn't work), add back --compact
* try setting COLUMNS to a hardcoded value in CI
* remove alternative env syntax from CI
* fix PrefixCacheBootstrapperTest on L11, skip on L10
* add one more skip() call
* fix validate.yml
* Simplify schema dump, skip dump-related tests in L10
* Rename 'dump' table to 'example'
* Bring schema dump-related tests together, add comments
* Merge schema path-related tests into one, add comments
* Rename dataset parameter
---------
Co-authored-by: lukinovec <lukinovec@gmail.com>
* Add SingleDomainTenant
* Add logic for single domain tenants
* Test that the single domain approach works (wip)
* Fix code style (php-cs-fixer)
* Simplify SubdomainTest tests
* Add single domain tenant conditions to DomainTenantResolver
* Test single domain tenants in resolver test
* Fix test name typo
* Improve runUsingBothDomainApproaches()
* Delete extra tenancy()->end()
* Test early identification with both domain approaches
* Test that things work with both domain approaches in the rest of the tests
* Fix falsely passing test
* Fix PHPStan errors
* Change SingleDomainTenant to a contract, add SingleDomainTenant test model
* Fix TenantList domainsCLI()
* Improve setCurrentDomain() check
* Fix code style (php-cs-fixer)
* Add annotation
* Revert getCustomColumns() change
* Add comments
* Use the domain returned by the closure in runUsingBoth..()
* Delete `migrate` from test
* Improve test names
* Use variable instead of repeating the same string multiple times
* Update comment
* Add comment
* Clean up PreventAccess test
* Don't assign domain to a single-use variable
* Update comments
* Uncomment datasets
* Add todo
* Fix user impersonation test
* Don't specify tenant key when creating tenant in runUsingBoth..()
* Improve universal route test
* Improve `runUsingBothDomainApproaches()`
* Add tests specific to single domain tenants
* Get rid of the runUsingBothDomainApproaches method
* Add test file specific for the single domain tenant feature
* Rename test
* Make getCustomColumns() function static
* Positiopn datasets differently
* Fix early id test
* Add prevent MW to route MW in test
* Fix single domain tenant tests
* Delete SingleDomainTenantTest (CI testing)
* Add the test file back
* TUrn APP_DEBUG on temporarily
* Turn debug off
* Try creating tenant with non-unique domain (CI testing)
* dd duplicate tenant records
* Revert testing change
* Make SingleDomainTenant not extend base tenant (VirtualColumn issues)
* Fix early id test
* add todo
* Use dev-master stancl/virtualcolumn
* Make SingleDomainTenant extend the tenant base model
* remove todo
* Clean up EarlyIdentificationTest changes
* Finish test file cleanup
* Fix test
* improve test
---------
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
* cache prefix
* prefix cache bootstrapper and tests
* remove comment
* DI app
* cache prefix base from config
* Create PrefixCacheBootstrapperTest.php
* remove `null` check
* fix phpstan error
* Update PrefixCacheTenancyBootstrapper.php
* Update PrefixCacheBootstrapperTest.php
* add comments
* Update PrefixCacheTenancyBootstrapper.php
* Update PrefixCacheBootstrapperTest.php
* Update config.php
* test names grammar
* user `getTenantKey` method
* assert tenants' data is accessible using the prefix from the central context
* remove unused line
* use proper DI
* build prefix using original prefix
* fix prefix test according to prefix changes
* fix test
* CacheManager dependency injection test
* CacheService class as singleton
* introduce second tenant in test
* use Repository in service class DI
* Update CacheAction.php
* Rename CacheAction to CacheService
* Update prefix bootstrapper and test (`setStore()` in CacheManager and Repository needed)
* Add macro
* Fix code style (php-cs-fixer)
* Simplify cache store refreshing
* Make Tenancy override CacheManager
* Update CacheManager, add refreshStore()
* Fix code style (php-cs-fixer)
* Uncomment cache tagging
* Revert condition in CacheManager to avoid excessive nesting
* Move `Cache::macro()` to a slightly more appropriate place
* Fix code style (php-cs-fixer)
* Use better class for the macro
* Toggle cache tags
* Make CacheManager::$addTags default to `true`
* Add changes to PR to Laravel
* Fix code style (php-cs-fixer)
* Revert changes, add comment
* Add test
* Make `$cache` non-nullable
Co-authored-by: Samuel Štancl <samuel@archte.ch>
* Add and test `nonTenantCacheDrivers`
* Add nonTenantCacheDrivers check
* Test that the prefix stays the same
* Change nonTenantCacheDrivers to tenantCacheStores
* Remove redundant CacheManager extend() call
* Make 'redis' the only tenant cache store in beforeEach, test that tenantCacheStores works
* Remove unused import, change word
* Make CacheService a singleton in a test
* Update test name
* Remove group('prefix')
* Rename CacheManagerService
* Improve specific cache store in a service test
* Improve comment
* Improve tests
* Use my Laravel fork
* Fix code style (php-cs-fixer)
* Downgrade Laravel
* Upgrade Laravel
* Hint Repository implementation instead of contract
* Fix types
* Fix code style (php-cs-fixer)
* Fix test
* Use Laravel fork in ci.yml
* use dev-master before our changes are released in L10
* remove laravel fork from repositories
* use 10.x-dev instead of master
* remove L9 support
* 10.x-dev (fix conflict resolution)
* use the laravel version from the ci matrix for the phpstan job as well
* Revert "use the laravel version from the ci matrix for the phpstan job as well"
This reverts commit 5f3079d2ff.
* Test that non-default stores get prefixed too
* Use new Laravel release, remove L9 support
* Complete L9 support removal
* Specify 10.1.1 as the minimal Laravel version in ci.yml
* Use 10.x-dev
* Prefix all cache stores specified in `$tenantCacheStores`
* Update Laravel
* Use tmpfs in docker-compose
* Add customizing cache store prefixes
* Test cache prefixing customization
* Fix code style (php-cs-fixer)
* Update ci.yml
* Delete tmpfs from docker-compose.yml (there were no benefits)
* Use default prefix generator inline, delete the 'default' key logic
* Fix original prefix logic
* Update tests
* Delete CacheTenancyBootstrapper
* Reset static properties in afterEach
* Use `$this->config` instead of `config()`
* Disable cache tagging by default, add CacheTagBootstrapper
* Fix code style (php-cs-fixer)
* Rename bootstrapper
* Improve CacheManager
* Move logic from separate method to __call
* Make original prefixes customizable
* Add info in comment
* Add defaultPrefix property
* Use `$this->app` instead of `app()`
* Rename bootstrapper
* Fix code style (php-cs-fixer)
* Use a single original prefix
* Update prefix generator logic + tests
* Correct `$addTags` reset in a test
* Update cache tests so that both prefixing and tagging is covered
* Simplify cache tests
* Delete afterEach
* Small testing improvements
* Set `cache.default` in beforeEach
* Update cache prefixing and tests
* Add assertion
* Refactor assertion
* Refactor assertions
* Delete TTL from cache put calls
* Add re-initialization cache assertion
* Assert that cache is null from the beginning
* Merge the tenantCacheStores tests
* Fix formatting
* Improve test name
* Improve tests
* Add cache manager config key
* Fix code style (php-cs-fixer)
* Update defaulting test
* Add todo
* Update comments
* Extract duplicate assertions into a closure
* Update comment
* Add assertions + comment
* Delete redundant config put calls
* Use `tenancy.cache.manager` config instead of `Stancl\Tenancy\CacheManager`
* Change setting to assertion, add comment
* Inline variable & config key assignment
* Delete `cache.default` assertion
* Override cache manager only in CacheTagsBootstrapper
* Fix code style (php-cs-fixer)
* Prefix both drivers by default, add assertions for the second driver where missing
* Clean up global state (static properties) in before/afterEach
* Add docblock to tags bootstrapper
* Delete extra dependency
* Add `illuminate/support` dependency back
* Use `$addTags` approach again
* Fix code style (php-cs-fixer)
* Revert "Fix code style (php-cs-fixer)"
This reverts commit ea805fa231.
* Revert "Use `$addTags` approach again"
This reverts commit 8f5a4e4eb6.
* Add commented CacheTagsBootstrapper with info to the bootstrappers config
* Delete legacy bootstrapper from the bootstrappers config, add info to the bootstrapper's docblock
* Delete "?" from `tenant()?->getTenantKey()
* call generatePrefix() on $bootstrapper
* misc improvements
---------
Co-authored-by: lukinovec <lukinovec@gmail.com>
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
* Add BroadcastTenancyBootstrapper and TenancyBroadcastManager
* Fix code style (php-cs-fixer)
* Bind original BroadcastManager again on `revert()`
* Fix code style (php-cs-fixer)
* Move manager to correct directory
* Fix property type
* Make BroadcastTenancyBootstrapper a singleton in tests
* Fix code style (php-cs-fixer)
* Bind the original broadcaster instance on `revert()`
* Instead of just forgetting the old broadcaster instance, bind the new one
* Add BroadcastTenancyBootstrapper tests
* Separate the test
* Fix code style (php-cs-fixer)
* Add bootstrapper test
* Add broadcaster channels test
* Clean up BootstrapperTest
* Fix BroadcastingTest
* Add comments to TenancyBroadcastManager
* Add BroadcastTenancyBootstrapper comments
* Simplify BroadcastManager extension, remove setDriver method
* Add comment
* Fix PHPStan errors
* Fix PHPStan errors
* Remove duplicate import
* Fix test
* Delete `::class` from test name
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
* Create databases for newly created tenants in BroadcastingTest
* move spatie/invade to require
---------
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
* 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>
* Add readied tenants
Add config for readied tenants
Add `create` and `clear` command
Add Readied scope and static functions
Add tests
* Fix initialize function name
* Add readied events
* Fix readied column cast
* Laravel 6 compatible
* Add readied scope tests
* Rename config from include_in_scope to include_in_queries
* Change terminology to pending
* Update CreatePendingTenants.php
* Laravel 6 compatible
* Update CreatePendingTenants.php
* runForMultiple can scope pending tenants
* Fix issues
* Code and comment style improvements
* Change 'tenant' to 'tenants' in command signature
* Fix code style (php-cs-fixer)
* Rename variables in CreatePendingTenants
* Remove withPending from runForMultiple
* Update tenants option trait
* Update command that use tenants
* Fix code style (php-cs-fixer)
* Improve getTenants condition
* Update config comments
* Minor config comment corrections
* Grammar fix
* Update comments and naming
* Correct comments
* Improve writing
* Remove pending tenant clearing time constraints
* Allow using only one time constraint for clearing the pending tenants
* phpunit to pest
* Fix code style (php-cs-fixer)
* Fix code style (php-cs-fixer)
* [4.x] Optionally delete storage after tenant deletion (#938)
* Add test for deleting storage after tenant deletion
* Save `storage_path()` in a variable after initializing tenant in test
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
* Add DeleteTenantStorage listener
* Update test name
* Remove storage deletion config key
* Remove tenant storage deletion events
* Move tenant storage deletion to the DeletingTenant event
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
* [4.x] Finish incomplete and missing tests (#947)
* complete test sqlite manager customize path
* complete test seed command works
* complete uniqe exists test
* Update SingleDatabaseTenancyTest.php
* refactor the ternary into if condition
* custom path
* simplify if condition
* random dir name
* Update SingleDatabaseTenancyTest.php
* Update CommandsTest.php
* prefix random DB name with custom_
Co-authored-by: Samuel Štancl <samuel@archte.ch>
* [4.x] Add batch tenancy queue bootstrapper (#874)
* exclude master from CI
* Add batch tenancy queue bootstrapper
* add test case
* skip tests for old versions
* variable docblocks
* use Laravel's connection getter and setter
* convert test to pest
* bottom space
* singleton regis in TestCase
* Update src/Bootstrappers/BatchTenancyBootstrapper.php
Co-authored-by: Samuel Štancl <samuel@archte.ch>
* convert batch class resolution to property level
* enabled BatchTenancyBootstrapper by default
* typehint DatabaseBatchRepository
* refactore name
* DI DB manager
* typehint
* Update config.php
* use initialize() twice without end()ing tenancy to assert that previousConnection logic works correctly
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
Co-authored-by: Abrar Ahmad <abrar.dev99@gmail.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
* [4.x] Storage::url() support (modified #689) (#909)
* This adds support for tenancy aware Storage::url() method
* Trigger CI build
* Fixed Link command for Laravel v6, added StorageLink Events, more StorageLink tests, added RemoveStorageSymlinks Job, added Storage Jobs to TenancyServiceProvider stub, renamed misleading config example.
* Fix typo
* Fix code style (php-cs-fixer)
* Update config comments
* Format code in Link command, make writing more concise
* Change "symLinks" to "symlinks"
* Refactor Link command
* Fix test name typo
* Test fetching files using the public URL
* Extract Link command logic into actions
* Fix code style (php-cs-fixer)
* Check if closure is null in CreateStorageSymlinksAction
* Stop using command terminology in CreateStorageSymlinksAction
* Separate the Storage::url() test cases
* Update url_override comments
* Remove afterLink closures, add types, move actions, add usage explanation to the symlink trait
* Fix code style (php-cs-fixer)
* Update public storage URL test
* Fix issue with using str()
* Improve url_override comment, add todos
* add todo comment
* fix docblock style
* Add link command tests back
* Add types to $tenants in the action handle() methods
* Fix typo, update variable name formatting
* Add tests for the symlink actions
* Change possibleTenantSymlinks not to prefix the paths twice while tenancy is initialized
* Fix code style (php-cs-fixer)
* Stop testing storage directory existence in symlink test
* Don't specify full namespace for Tenant model annotation
* Don't specify full namespace in ActionTest
* Remove "change to DI" todo
* Remove possibleTenantSymlinks return annotation
* Remove symlink-related jobs, instantiate and use actions
* Revert "Remove symlink-related jobs, instantiate and use actions"
This reverts commit 547440c887.
* Add a comment line about the possible tenant symlinks
* Correct storagePath and publicPath variables
* Revert "Correct storagePath and publicPath variables"
This reverts commit e3aa8e2086.
* add a todo
Co-authored-by: Martin Vlcek <martin@dontfreakout.eu>
Co-authored-by: lukinovec <lukinovec@gmail.com>
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
* Use HasTenantOptions in Link
* Correct the tenant order in Run command
* Fix code style (php-cs-fixer)
* Fix formatting issue
* Add missing imports
* Fix code style (php-cs-fixer)
* Use HasTenantOptions instead of the old trait name in Up/Down commands
* Fix test name typo
* Remove redundant passing of $withPending to runForMultiple in TenantCollection's runForEach
* Make `with-pending` default to `config('tenancy.pending.include_in_queries')` in HasTenantOptions
* Make `createPending()` return the created tenant
* Fix code style (php-cs-fixer)
* Remove tenant ordering
* Fix code style (php-cs-fixer)
* Remove duplicate tenancy bootstrappers config setting
* Add and use getWithPendingOption method
* Fix code style (php-cs-fixer)
* Add optionNotPassedValue property
* Test using --with-pending and the include_in_queries config value
* Make with-pending VALUE_NONE
* use plural in test names
* fix test names
* add pullPendingTenantFromPool
* Add docblock type
* Import commands
* Fix code style (php-cs-fixer)
* Move pending tenant tests to a more appropriate file
* Delete queuetest from gitignore
* Delete queuetest file
* Add queuetest to gitignore
* Rename pullPendingTenant to pullPending and don't pass bool to that method
* Add a test that checks if pulling a pending tenant removes it from the pool
* bump stancl/virtualcolumn to ^1.3
* Update pending tenant pulling test
* Dynamically get columns for pending queries
* Dynamically get virtual column name in ClearPendingTenants
* Fix ClearPendingTenants bug
* Make test name more accurate
* Update test name
* add a todo
* Update include in queries test name
* Remove `Tenant::query()->delete()` from pending tenant check test
* Rename the pending tenant check test name
* Update HasPending.php
* fix all() call
* code style
* all() -> get()
* Remove redundant `Tenant::all()` call
Co-authored-by: j.stein <joristein@gmail.com>
Co-authored-by: lukinovec <lukinovec@gmail.com>
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Abrar Ahmad <abrar.dev99@gmail.com>
Co-authored-by: Riley19280 <rileyaven88@gmail.com>
Co-authored-by: Martin Vlcek <martin@dontfreakout.eu>
* Add bring up from maintenance function
* Add up and down tenant maintenance commands
* Rename commands signatures
* Update TenancyServiceProvider.php
* Complying to Laravel maintenance code and parameters
* Update MaintenanceModeTest.php
* Add maintenance mode via commands test
* Update CheckTenantForMaintenanceMode.php
* Update MaintenanceModeTest.php
* Cookie bypass only for > Laravel 8
* minor formatting change, trigger CI
* clean
* Update MaintenanceModeTest.php
* Add comments for using the 'tenants' option in runForMultiple
* improve code
* php-cs-fixer
* fix php cs fixer config
* improve test logic
* remove version check since v4 will be L9+
Co-authored-by: Samuel Štancl <samuel@archte.ch>
Co-authored-by: lukinovec <lukinovec@gmail.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
* Add Pest dependencies
* Add base Pest file
* Convert test cases
* Remove non-compound imports
* Adopt expectation API
* Optimize uses
* Shift cleanup
* phpunit -> pest
* Fix tests in PR #884 PHPUnit to Pest Converter (#885)
* fixed tests, remove method duplications, restore necessary inner classes
* Update CommandsTest.php
* temporary checks run on `shift-64622` on branch.
* fixed `TestSeeder` class not resolved
* fixed messed up names
* removed `uses` from individual files and add it in `Pest`
* extract tests to helpers
* use pest dataset
* Update AutomaticModeTest.php
* newline
* todo convention
* resolve reviews
* added `// todo@tests`
* remove shift branch from CI workflow
Co-authored-by: Samuel Štancl <samuel@archte.ch>
* check if I have write permission
* Convert newly added tests to Pest
Co-authored-by: Shift <shift@laravelshift.com>
Co-authored-by: Abrar Ahmad <abrar.dev99@gmail.com>
* Test on Laravel 9
* Don't extend final Kernel class
* Make FilesystemTenancyBootstrapper compatible with Flysystem v3
Co-authored-by: George <jiri.zizka@funfirst.cz>
* Update tenant maintenance mode te be in line with Laravel
* Exclude PHP 7.4 <> L9 combination from testing
* add root_override-related assertions
* getPrefix -> getPathPrefix
* handle / inconsistency in s3 prefix
* Refactor Storage facade changes
Co-authored-by: George <jiri.zizka@funfirst.cz>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>