10
10
use Minds \Core \MultiTenant \Configs \Image \Manager as ConfigImageManager ;
11
11
use Minds \Core \MultiTenant \MobileConfigs \Enums \MobileConfigImageTypeEnum ;
12
12
use Minds \Core \MultiTenant \MobileConfigs \Services \MobileConfigAssetsService ;
13
+ use Minds \Exceptions \ServerErrorException ;
13
14
14
15
/**
15
16
* Delegate for updating the logos.
16
17
*/
17
18
class UpdateLogosDelegate
18
19
{
20
+ /** Whether any uploads failed. */
21
+ private bool $ failedUpload = false ;
22
+
19
23
public function __construct (
20
24
private ConfigImageManager $ configImageManager ,
21
25
private MobileConfigAssetsService $ mobileConfigAssetsService ,
@@ -31,14 +35,16 @@ public function __construct(
31
35
* @param string $faviconBlob - The blob of the favicon.
32
36
* @param string $horizontalLogoBlob - The blob of the horizontal logo.
33
37
* @param string $splashBlob - The blob of the splash.
34
- * @return void
38
+ * @return bool - Whether the upload was successful.
35
39
*/
36
40
public function onUpdate (
37
41
string $ squareLogoBlob = null ,
38
42
string $ faviconBlob = null ,
39
43
string $ horizontalLogoBlob = null ,
40
44
string $ splashBlob = null
41
- ) {
45
+ ): bool {
46
+ $ this ->failedUpload = false ;
47
+
42
48
if ($ squareLogoBlob ) {
43
49
$ this ->uploadSquareLogo ($ squareLogoBlob );
44
50
$ this ->uploadMobileIcon ($ squareLogoBlob );
@@ -57,6 +63,14 @@ public function onUpdate(
57
63
if ($ splashBlob ) {
58
64
$ this ->uploadMobileSplash ($ splashBlob );
59
65
}
66
+
67
+ if ($ this ->failedUpload ) {
68
+ $ this ->logger ->error ("Failed to upload all logos, some may have been saved. " );
69
+ } else {
70
+ $ this ->logger ->info ("Done uploading logos " );
71
+ }
72
+
73
+ return !$ this ->failedUpload ;
60
74
}
61
75
62
76
/**
@@ -67,9 +81,13 @@ public function onUpdate(
67
81
private function uploadSquareLogo (string $ bigIconBlob ): void
68
82
{
69
83
try {
70
- $ this ->configImageManager ->uploadBlob ($ bigIconBlob , MultiTenantConfigImageType::SQUARE_LOGO );
71
- $ this ->logger ->info ("Uploaded web square logo " );
84
+ if ($ this ->configImageManager ->uploadBlob ($ bigIconBlob , MultiTenantConfigImageType::SQUARE_LOGO )) {
85
+ $ this ->logger ->info ("Uploaded web square logo " );
86
+ } else {
87
+ throw new ServerErrorException ("Upload failed " );
88
+ }
72
89
} catch (\Exception $ e ) {
90
+ $ this ->failedUpload = true ;
73
91
$ this ->logger ->error ("Failed to upload web square logo: " . $ e ->getMessage ());
74
92
}
75
93
}
@@ -82,9 +100,13 @@ private function uploadSquareLogo(string $bigIconBlob): void
82
100
private function uploadHorizontalLogo (string $ logoBlob ): void
83
101
{
84
102
try {
85
- $ this ->configImageManager ->uploadBlob ($ logoBlob , MultiTenantConfigImageType::HORIZONTAL_LOGO );
86
- $ this ->logger ->info ("Uploaded web horizontal logo " );
103
+ if ($ this ->configImageManager ->uploadBlob ($ logoBlob , MultiTenantConfigImageType::HORIZONTAL_LOGO )) {
104
+ $ this ->logger ->info ("Uploaded web horizontal logo " );
105
+ } else {
106
+ throw new ServerErrorException ("Upload failed " );
107
+ }
87
108
} catch (\Exception $ e ) {
109
+ $ this ->failedUpload = true ;
88
110
$ this ->logger ->error ("Failed to upload web horizontal logo: " . $ e ->getMessage ());
89
111
}
90
112
}
@@ -97,9 +119,13 @@ private function uploadHorizontalLogo(string $logoBlob): void
97
119
private function uploadFavicon (string $ faviconBlob ): void
98
120
{
99
121
try {
100
- $ this ->configImageManager ->uploadBlob ($ faviconBlob , MultiTenantConfigImageType::FAVICON );
101
- $ this ->logger ->info ("Uploaded web favicon " );
122
+ if ($ this ->configImageManager ->uploadBlob ($ faviconBlob , MultiTenantConfigImageType::FAVICON )) {
123
+ $ this ->logger ->info ("Uploaded web favicon " );
124
+ } else {
125
+ throw new ServerErrorException ("Upload failed " );
126
+ }
102
127
} catch (\Exception $ e ) {
128
+ $ this ->failedUpload = true ;
103
129
$ this ->logger ->error ("Failed to upload web favicon: " . $ e ->getMessage ());
104
130
}
105
131
}
@@ -112,9 +138,13 @@ private function uploadFavicon(string $faviconBlob): void
112
138
private function uploadMobileHorizontalLogo (string $ logoBlob ): void
113
139
{
114
140
try {
115
- $ this ->mobileConfigAssetsService ->uploadBlob ($ logoBlob , MobileConfigImageTypeEnum::HORIZONTAL_LOGO );
116
- $ this ->logger ->info ("Uploaded mobile horizontal logo " );
141
+ if ($ this ->mobileConfigAssetsService ->uploadBlob ($ logoBlob , MobileConfigImageTypeEnum::HORIZONTAL_LOGO )) {
142
+ $ this ->logger ->info ("Uploaded mobile horizontal logo " );
143
+ } else {
144
+ throw new ServerErrorException ("Upload failed " );
145
+ }
117
146
} catch (\Exception $ e ) {
147
+ $ this ->failedUpload = true ;
118
148
$ this ->logger ->error ("Failed to upload mobile horizontal logo: " . $ e ->getMessage ());
119
149
}
120
150
}
@@ -127,9 +157,13 @@ private function uploadMobileHorizontalLogo(string $logoBlob): void
127
157
private function uploadMobileIcon (string $ bigIconBlob ): void
128
158
{
129
159
try {
130
- $ this ->mobileConfigAssetsService ->uploadBlob ($ bigIconBlob , MobileConfigImageTypeEnum::ICON );
131
- $ this ->logger ->info ("Uploaded mobile icon " );
160
+ if ($ this ->mobileConfigAssetsService ->uploadBlob ($ bigIconBlob , MobileConfigImageTypeEnum::ICON )) {
161
+ $ this ->logger ->info ("Uploaded mobile icon " );
162
+ } else {
163
+ throw new ServerErrorException ("Upload failed " );
164
+ }
132
165
} catch (\Exception $ e ) {
166
+ $ this ->failedUpload = true ;
133
167
$ this ->logger ->error ("Failed to upload mobile icon: " . $ e ->getMessage ());
134
168
}
135
169
}
@@ -142,9 +176,13 @@ private function uploadMobileIcon(string $bigIconBlob): void
142
176
private function uploadMobileSquareLogo (string $ bigIconBlob ): void
143
177
{
144
178
try {
145
- $ this ->mobileConfigAssetsService ->uploadBlob ($ bigIconBlob , MobileConfigImageTypeEnum::SQUARE_LOGO );
146
- $ this ->logger ->info ("Uploaded mobile square logo " );
179
+ if ($ this ->mobileConfigAssetsService ->uploadBlob ($ bigIconBlob , MobileConfigImageTypeEnum::SQUARE_LOGO )) {
180
+ $ this ->logger ->info ("Uploaded mobile square logo " );
181
+ } else {
182
+ throw new ServerErrorException ("Upload failed " );
183
+ }
147
184
} catch (\Exception $ e ) {
185
+ $ this ->failedUpload = true ;
148
186
$ this ->logger ->error ("Failed to upload mobile square logo: " . $ e ->getMessage ());
149
187
}
150
188
}
@@ -157,9 +195,13 @@ private function uploadMobileSquareLogo(string $bigIconBlob): void
157
195
private function uploadMobileSplash (string $ splashBlob ): void
158
196
{
159
197
try {
160
- $ this ->mobileConfigAssetsService ->uploadBlob ($ splashBlob , MobileConfigImageTypeEnum::SPLASH );
161
- $ this ->logger ->info ("Uploaded mobile splash " );
198
+ if ($ this ->mobileConfigAssetsService ->uploadBlob ($ splashBlob , MobileConfigImageTypeEnum::SPLASH )) {
199
+ $ this ->logger ->info ("Uploaded mobile splash " );
200
+ } else {
201
+ throw new ServerErrorException ("Upload failed " );
202
+ }
162
203
} catch (\Exception $ e ) {
204
+ $ this ->failedUpload = true ;
163
205
$ this ->logger ->error ("Failed to upload mobile splash: " . $ e ->getMessage ());
164
206
}
165
207
}
0 commit comments