You've already forked Epicnabbo-Catalogus-Updated-Daily
🆙 Refactor Cleanup started 🆙
This commit is contained in:
+36
-22
@@ -77,6 +77,9 @@ class WebsiteDrawBadgeResource extends Resource
|
||||
->limit(35)
|
||||
->tooltip(function (TextColumn $column): ?string {
|
||||
$state = $column->getState();
|
||||
if (! is_string($state)) {
|
||||
return null;
|
||||
}
|
||||
if (strlen($state) <= $column->getCharacterLimit()) {
|
||||
return null;
|
||||
}
|
||||
@@ -91,7 +94,7 @@ class WebsiteDrawBadgeResource extends Resource
|
||||
->getStateUsing(function (WebsiteDrawBadgeModel $record): string {
|
||||
$appUrl = config('app.url');
|
||||
$appUrl = is_string($appUrl) ? $appUrl : '';
|
||||
$badgeUrl = is_string($record->badge_url) ? $record->badge_url : '';
|
||||
$badgeUrl = (string) $record->badge_url;
|
||||
return $appUrl . $badgeUrl;
|
||||
})
|
||||
->extraAttributes(['style' => 'image-rendering: pixelated'])
|
||||
@@ -102,7 +105,8 @@ class WebsiteDrawBadgeResource extends Resource
|
||||
->recordActions([
|
||||
DeleteAction::make()
|
||||
->before(function (DeleteAction $action, WebsiteDrawBadge $record): void {
|
||||
$badgeCode = pathinfo($record->badge_path, PATHINFO_FILENAME);
|
||||
$badgePath = (string) $record->badge_path;
|
||||
$badgeCode = pathinfo($badgePath, PATHINFO_FILENAME);
|
||||
|
||||
// Remove the badge from any user before deleting it.
|
||||
if ($record->published) {
|
||||
@@ -113,27 +117,34 @@ class WebsiteDrawBadgeResource extends Resource
|
||||
}
|
||||
|
||||
// Remove from JSON
|
||||
$filePath = DB::table('website_settings')->where('key', 'nitro_external_texts_file')->value('value');
|
||||
$filePathValue = DB::table('website_settings')->where('key', 'nitro_external_texts_file')->value('value');
|
||||
$filePath = is_string($filePathValue) ? $filePathValue : '';
|
||||
|
||||
if ($filePath && file_exists($filePath) && is_writable($filePath)) {
|
||||
$json = json_decode(file_get_contents($filePath), true);
|
||||
unset($json["badge_name_{$badgeCode}"]);
|
||||
unset($json["badge_desc_{$badgeCode}"]);
|
||||
file_put_contents($filePath, json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
if ($filePath !== '' && file_exists($filePath) && is_writable($filePath)) {
|
||||
$jsonRaw = @file_get_contents($filePath);
|
||||
$json = is_string($jsonRaw) ? json_decode($jsonRaw, true) : [];
|
||||
$data = is_array($json) ? $json : [];
|
||||
unset($data["badge_name_{$badgeCode}"]);
|
||||
unset($data["badge_desc_{$badgeCode}"]);
|
||||
file_put_contents($filePath, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
|
||||
// Delete the badge file from the filesystem
|
||||
$badgePath = $record->badge_path;
|
||||
if ($badgePath && file_exists($badgePath)) {
|
||||
unlink($badgePath);
|
||||
$badgePathFs = (string) $record->badge_path;
|
||||
if ($badgePathFs !== '' && file_exists($badgePathFs)) {
|
||||
unlink($badgePathFs);
|
||||
}
|
||||
}),
|
||||
])
|
||||
->toolbarActions([
|
||||
DeleteBulkAction::make()
|
||||
->before(function (DeleteBulkAction $action, $records): void {
|
||||
->before(function (DeleteBulkAction $action, iterable $records): void {
|
||||
foreach ($records as $record) {
|
||||
$badgeCode = pathinfo((string) $record->badge_path, PATHINFO_FILENAME);
|
||||
if (! ($record instanceof WebsiteDrawBadgeModel)) {
|
||||
continue;
|
||||
}
|
||||
$badgePath = (string) $record->badge_path;
|
||||
$badgeCode = pathinfo($badgePath, PATHINFO_FILENAME);
|
||||
|
||||
// Remove the badge from any user before deleting it.
|
||||
if ($record->published) {
|
||||
@@ -143,18 +154,21 @@ class WebsiteDrawBadgeResource extends Resource
|
||||
->delete();
|
||||
}
|
||||
|
||||
$filePath = DB::table('website_settings')->where('key', 'nitro_external_texts_file')->value('value');
|
||||
$filePathValue = DB::table('website_settings')->where('key', 'nitro_external_texts_file')->value('value');
|
||||
$filePath = is_string($filePathValue) ? $filePathValue : '';
|
||||
|
||||
if ($filePath && file_exists($filePath) && is_writable($filePath)) {
|
||||
$json = json_decode(file_get_contents($filePath), true);
|
||||
unset($json["badge_name_{$badgeCode}"]);
|
||||
unset($json["badge_desc_{$badgeCode}"]);
|
||||
file_put_contents($filePath, json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
if ($filePath !== '' && file_exists($filePath) && is_writable($filePath)) {
|
||||
$jsonRaw = @file_get_contents($filePath);
|
||||
$json = is_string($jsonRaw) ? json_decode($jsonRaw, true) : [];
|
||||
$data = is_array($json) ? $json : [];
|
||||
unset($data["badge_name_{$badgeCode}"]);
|
||||
unset($data["badge_desc_{$badgeCode}"]);
|
||||
file_put_contents($filePath, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
|
||||
$badgePath = $record->badge_path;
|
||||
if ($badgePath && file_exists($badgePath)) {
|
||||
unlink($badgePath);
|
||||
$badgePathFs = (string) $record->badge_path;
|
||||
if ($badgePathFs !== '' && file_exists($badgePathFs)) {
|
||||
unlink($badgePathFs);
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user