Skip to content

Commit 68025e9

Browse files
committed
Better handling of provider creation for social and ticket providers
1 parent 8f6f25d commit 68025e9

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

app/Services/SocialProviders/AbstractSocialProvider.php

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,26 @@ public function configMapping(): array
6060

6161
public function install(): SocialProvider
6262
{
63-
if ($this->provider) {
64-
return $this->provider;
65-
}
66-
67-
$provider = SocialProvider::whereCode($this->code)->first();
68-
$this->provider = $provider;
69-
if ($provider) {
70-
return $provider;
71-
}
72-
73-
$provider = new SocialProvider();
74-
$provider->name = $this->name;
75-
$provider->code = $this->code;
76-
$provider->provider_class = get_called_class();
77-
$provider->supports_auth = $this->supportsAuth;
78-
$provider->enabled = false;
79-
$provider->auth_enabled = false;
80-
$provider->can_be_renamed = $this->canBeRenamed;
63+
$this->provider = SocialProvider::whereCode($this->code)->first();
64+
if (!$this->provider) {
65+
$provider = new SocialProvider();
66+
$this->provider = $provider;
67+
$provider->name = $this->name;
68+
$provider->code = $this->code;
69+
$provider->provider_class = get_called_class();
70+
$provider->supports_auth = $this->supportsAuth;
71+
$provider->enabled = false;
72+
$provider->auth_enabled = false;
73+
$provider->can_be_renamed = $this->canBeRenamed;
74+
75+
DB::transaction(function () use ($provider) {
76+
$provider->save();
77+
$this->installSettings();
78+
});
8179

82-
DB::transaction(function() use ($provider) {
8380
$provider->save();
84-
$this->installSettings();
85-
});
86-
87-
$provider->save();
88-
return $provider;
81+
}
82+
return $this->provider;
8983
}
9084

9185
public function installSettings(): void

app/Services/TicketProviders/AbstractTicketProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public function configMapping(): array
4545

4646
public function install(): TicketProvider
4747
{
48-
$provider = TicketProvider::whereCode($this->code)->first();
49-
$this->provider = $provider;
50-
if (!$provider) {
48+
$this->provider = TicketProvider::whereCode($this->code)->first();
49+
if (!$this->provider) {
5150
$provider = new TicketProvider();
51+
$this->provider = $provider;
5252
$provider->name = $this->name;
5353
$provider->code = $this->code;
5454
$provider->provider_class = get_called_class();
@@ -59,7 +59,7 @@ public function install(): TicketProvider
5959
$this->installSettings();
6060
});
6161
}
62-
return $provider;
62+
return $this->provider;
6363
}
6464

6565
public function installSettings(): void

0 commit comments

Comments
 (0)