Skip to content

Commit bd44036

Browse files
committed
By default, only override the config if the override tenant property is set (otherwise, just skip the override and keep the default config value)
1 parent 582243c commit bd44036

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/Bootstrappers/LogTenancyBootstrapper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ protected function overrideChannelConfig(string $channel, array|Closure $overrid
100100
if (is_array($override)) {
101101
// Map tenant properties to channel config keys
102102
foreach ($override as $configKey => $tenantProperty) {
103-
$this->config->set("logging.channels.{$channel}.{$configKey}", $tenant->$tenantProperty);
103+
if ($tenant->$tenantProperty) {
104+
$this->config->set("logging.channels.{$channel}.{$configKey}", $tenant->$tenantProperty);
105+
}
104106
}
105107
} elseif ($override instanceof Closure) {
106108
// Execute custom configuration closure

tests/Bootstrappers/LogTenancyBootstrapperTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@
150150
expect(config('logging.channels.slack.username'))->toBe('Default');
151151
});
152152

153+
test('channel config keys remains unchanged if the specified tenant override property is not set', function() {
154+
config(['logging.default' => 'slack']);
155+
config(['logging.channels.slack.username' => 'Default username']);
156+
157+
LogTenancyBootstrapper::$channelOverrides = [
158+
'slack' => ['username' => 'nonExistentProperty'], // $tenant->nonExistentProperty
159+
];
160+
161+
tenancy()->initialize(Tenant::create());
162+
163+
// The username should remain unchanged since the tenant property is not set
164+
expect(config('logging.channels.slack.username'))->toBe('Default username');
165+
});
166+
153167
test('channel overrides take precedence over the default storage path channel updating logic', function () {
154168
config(['logging.default' => 'single']);
155169

0 commit comments

Comments
 (0)