From 259fe5f697a833e268cde88e959bc19bd662edf6 Mon Sep 17 00:00:00 2001 From: Yassine Doghri <yassine@doghri.fr> Date: Tue, 1 Nov 2022 15:15:39 +0000 Subject: [PATCH] fix(platforms): trim platform url before validation and storage --> Having a URL with spaces in the beginning or end would cause the platform to be deleted --- app/Models/PlatformModel.php | 7 +++++++ modules/Admin/Controllers/PodcastPlatformController.php | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Models/PlatformModel.php b/app/Models/PlatformModel.php index 29c7259fc0..74242821df 100644 --- a/app/Models/PlatformModel.php +++ b/app/Models/PlatformModel.php @@ -145,6 +145,8 @@ class PlatformModel extends Model /** * @param mixed[] $podcastsPlatformsData + * + * @return int|false Number of rows inserted or FALSE on failure */ public function savePodcastPlatforms( int $podcastId, @@ -165,6 +167,11 @@ class PlatformModel extends Model $this->db->query($deleteJoinQuery, [$podcastId, $platformType]); + if ($podcastsPlatformsData === []) { + // no rows inserted + return 0; + } + return $this->db ->table('podcasts_platforms') ->insertBatch($podcastsPlatformsData); diff --git a/modules/Admin/Controllers/PodcastPlatformController.php b/modules/Admin/Controllers/PodcastPlatformController.php index 6193642086..cfc76aa221 100644 --- a/modules/Admin/Controllers/PodcastPlatformController.php +++ b/modules/Admin/Controllers/PodcastPlatformController.php @@ -70,7 +70,7 @@ class PodcastPlatformController extends BaseController $this->request->getPost('platforms') as $platformSlug => $podcastPlatform ) { - $podcastPlatformUrl = $podcastPlatform['url']; + $podcastPlatformUrl = trim((string) $podcastPlatform['url']); if ($podcastPlatformUrl === null) { continue; } @@ -79,11 +79,12 @@ class PodcastPlatformController extends BaseController continue; } + $podcastPlatformAccountId = trim((string) $podcastPlatform['account_id']); $podcastsPlatformsData[] = [ 'platform_slug' => $platformSlug, 'podcast_id' => $this->podcast->id, 'link_url' => $podcastPlatformUrl, - 'account_id' => $podcastPlatform['account_id'] === '' ? null : $podcastPlatform['account_id'], + 'account_id' => $podcastPlatformAccountId === '' ? null : $podcastPlatformAccountId, 'is_visible' => array_key_exists('visible', $podcastPlatform) && $podcastPlatform['visible'] === 'yes', -- GitLab