From 6e9451a1103b43750fa70ad576de36af25ca29cb Mon Sep 17 00:00:00 2001
From: Yassine Doghri <yassine@doghri.fr>
Date: Tue, 4 Jan 2022 16:37:59 +0000
Subject: [PATCH] fix: define podcast_id and platform_slug as foreign keys in
 podcasts_plaforms table

update discord logo
---
 ... => 2020-06-05-200000_add_podcasts_platforms.php} |  4 +++-
 app/Entities/Platform.php                            |  4 ++--
 app/Helpers/rss_helper.php                           | 12 ++++--------
 app/Models/PlatformModel.php                         |  4 ++--
 app/Resources/icons/social/discord.svg               |  2 +-
 .../Admin/Controllers/PodcastImportController.php    |  2 +-
 .../Admin/Controllers/PodcastPlatformController.php  |  2 +-
 themes/cp_admin/podcast/platforms.php                |  9 ++++-----
 .../cp_app/podcast/_partials/funding_links_modal.php |  2 +-
 9 files changed, 19 insertions(+), 22 deletions(-)
 rename app/Database/Migrations/{2017-12-01-160000_add_podcasts_platforms.php => 2020-06-05-200000_add_podcasts_platforms.php} (88%)
 mode change 100755 => 100644 app/Resources/icons/social/discord.svg

diff --git a/app/Database/Migrations/2017-12-01-160000_add_podcasts_platforms.php b/app/Database/Migrations/2020-06-05-200000_add_podcasts_platforms.php
similarity index 88%
rename from app/Database/Migrations/2017-12-01-160000_add_podcasts_platforms.php
rename to app/Database/Migrations/2020-06-05-200000_add_podcasts_platforms.php
index febec48182..8476dc0efb 100644
--- a/app/Database/Migrations/2017-12-01-160000_add_podcasts_platforms.php
+++ b/app/Database/Migrations/2020-06-05-200000_add_podcasts_platforms.php
@@ -31,7 +31,7 @@ class AddPodcastsPlatforms extends Migration
                 'type' => 'VARCHAR',
                 'constraint' => 512,
             ],
-            'link_content' => [
+            'account_id' => [
                 'type' => 'VARCHAR',
                 'constraint' => 128,
                 'null' => true,
@@ -49,6 +49,8 @@ class AddPodcastsPlatforms extends Migration
         ]);
 
         $this->forge->addPrimaryKey(['podcast_id', 'platform_slug']);
+        $this->forge->addForeignKey('podcast_id', 'podcasts', 'id', '', 'CASCADE');
+        $this->forge->addForeignKey('platform_slug', 'platforms', 'slug', 'CASCADE');
         $this->forge->createTable('podcasts_platforms');
     }
 
diff --git a/app/Entities/Platform.php b/app/Entities/Platform.php
index 0d43f89f34..899e9afcac 100644
--- a/app/Entities/Platform.php
+++ b/app/Entities/Platform.php
@@ -19,7 +19,7 @@ use CodeIgniter\Entity\Entity;
  * @property string $home_url
  * @property string|null $submit_url
  * @property string|null $link_url
- * @property string|null $link_content
+ * @property string|null $account_id
  * @property bool|null $is_visible
  * @property bool|null $is_on_embed
  */
@@ -35,7 +35,7 @@ class Platform extends Entity
         'home_url' => 'string',
         'submit_url' => '?string',
         'link_url' => '?string',
-        'link_content' => '?string',
+        'account_id' => '?string',
         'is_visible' => '?boolean',
         'is_on_embed' => '?boolean',
     ];
diff --git a/app/Helpers/rss_helper.php b/app/Helpers/rss_helper.php
index d30520986e..1a85bb7fb6 100644
--- a/app/Helpers/rss_helper.php
+++ b/app/Helpers/rss_helper.php
@@ -93,8 +93,8 @@ if (! function_exists('get_rss_feed')) {
         foreach ($podcast->podcasting_platforms as $podcastingPlatform) {
             $podcastingPlatformElement = $channel->addChild('id', null, $podcastNamespace);
             $podcastingPlatformElement->addAttribute('platform', $podcastingPlatform->slug);
-            if ($podcastingPlatform->link_content !== null) {
-                $podcastingPlatformElement->addAttribute('id', $podcastingPlatform->link_content);
+            if ($podcastingPlatform->account_id !== null) {
+                $podcastingPlatformElement->addAttribute('id', $podcastingPlatform->account_id);
             }
             if ($podcastingPlatform->link_url !== null) {
                 $podcastingPlatformElement->addAttribute('url', htmlspecialchars($podcastingPlatform->link_url));
@@ -102,11 +102,7 @@ if (! function_exists('get_rss_feed')) {
         }
 
         foreach ($podcast->social_platforms as $socialPlatform) {
-            $socialPlatformElement = $channel->addChild(
-                'social',
-                $socialPlatform->link_content,
-                $podcastNamespace,
-            );
+            $socialPlatformElement = $channel->addChild('social', $socialPlatform->account_id, $podcastNamespace,);
             $socialPlatformElement->addAttribute('platform', $socialPlatform->slug);
             if ($socialPlatform->link_url !== null) {
                 $socialPlatformElement->addAttribute('url', htmlspecialchars($socialPlatform->link_url));
@@ -116,7 +112,7 @@ if (! function_exists('get_rss_feed')) {
         foreach ($podcast->funding_platforms as $fundingPlatform) {
             $fundingPlatformElement = $channel->addChild(
                 'funding',
-                $fundingPlatform->link_content,
+                $fundingPlatform->account_id,
                 $podcastNamespace,
             );
             $fundingPlatformElement->addAttribute('platform', $fundingPlatform->slug);
diff --git a/app/Models/PlatformModel.php b/app/Models/PlatformModel.php
index fb88923c1f..652f664dbe 100644
--- a/app/Models/PlatformModel.php
+++ b/app/Models/PlatformModel.php
@@ -102,7 +102,7 @@ class PlatformModel extends Model
             ! ($found = cache("podcast#{$podcastId}_platforms_{$platformType}_withLinks"))
         ) {
             $found = $this->select(
-                'platforms.*, podcasts_platforms.link_url, podcasts_platforms.link_content, podcasts_platforms.is_visible, podcasts_platforms.is_on_embed',
+                'platforms.*, podcasts_platforms.link_url, podcasts_platforms.account_id, podcasts_platforms.is_visible, podcasts_platforms.is_on_embed',
             )
                 ->join(
                     'podcasts_platforms',
@@ -127,7 +127,7 @@ class PlatformModel extends Model
         $cacheName = "podcast#{$podcastId}_platforms_{$platformType}";
         if (! ($found = cache($cacheName))) {
             $found = $this->select(
-                'platforms.*, podcasts_platforms.link_url, podcasts_platforms.link_content, podcasts_platforms.is_visible, podcasts_platforms.is_on_embed',
+                'platforms.*, podcasts_platforms.link_url, podcasts_platforms.account_id, podcasts_platforms.is_visible, podcasts_platforms.is_on_embed',
             )
                 ->join('podcasts_platforms', 'podcasts_platforms.platform_slug = platforms.slug')
                 ->where('podcasts_platforms.podcast_id', $podcastId)
diff --git a/app/Resources/icons/social/discord.svg b/app/Resources/icons/social/discord.svg
old mode 100755
new mode 100644
index ad22eebd4c..52ee5fa35c
--- a/app/Resources/icons/social/discord.svg
+++ b/app/Resources/icons/social/discord.svg
@@ -1 +1 @@
-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0,0H24V24H0Z" fill="none"/><path d="M10.08,11a1,1,0,1,1,0,2,1,1,0,1,1,0-2Zm3.84,0a1,1,0,1,1-1.07,1A1,1,0,0,1,13.92,11Zm5-9A2.14,2.14,0,0,1,21,4.16V23l-2.21-2-1.25-1.17-1.31-1.25.54,1.94H5.11A2.13,2.13,0,0,1,3,18.36V4.16A2.14,2.14,0,0,1,5.11,2Zm-4,13.71a3.75,3.75,0,0,0,3.15-1.59A14.29,14.29,0,0,0,16.59,8,5,5,0,0,0,13.7,6.89l-.15.17A6.79,6.79,0,0,1,16.11,8.4a8,8,0,0,0-3.09-1,8.52,8.52,0,0,0-2.08,0l-.17,0a7.66,7.66,0,0,0-2.34.66c-.38.18-.61.31-.61.31A7,7,0,0,1,10.53,7l-.1-.13A5,5,0,0,0,7.54,8a14.21,14.21,0,0,0-1.49,6.12,3.73,3.73,0,0,0,3.14,1.59l.69-.87a3.19,3.19,0,0,1-1.8-1.24,2,2,0,0,0,.29.18l0,0,.09.06a7,7,0,0,0,.75.35,7.9,7.9,0,0,0,1.52.45,6.8,6.8,0,0,0,2.66,0,6.56,6.56,0,0,0,1.49-.45,5.2,5.2,0,0,0,1.18-.62,3.24,3.24,0,0,1-1.86,1.25c.31.4.68.85.68.85Z"/></svg>
\ No newline at end of file
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0Z"/><path d="M18.93 5.26A16.5 16.5 0 0 0 14.86 4c-.03 0-.05 0-.07.03a11 11 0 0 0-.5 1.04 15.23 15.23 0 0 0-4.57 0 11.2 11.2 0 0 0-.52-1.04.06.06 0 0 0-.06-.03 16.45 16.45 0 0 0-4.1 1.29A16.88 16.88 0 0 0 2.1 16.72a16.58 16.58 0 0 0 5 2.52c.02.01.05 0 .06-.02.39-.53.73-1.08 1.02-1.66a.06.06 0 0 0-.03-.1c-.54-.2-1.06-.45-1.56-.73a.06.06 0 0 1 0-.11l.3-.24a.06.06 0 0 1 .07-.01c3.27 1.5 6.81 1.5 10.05 0h.06l.32.25c.03.03.03.08-.01.1-.5.3-1.02.54-1.56.75a.06.06 0 0 0-.04.09c.3.58.65 1.13 1.03 1.66.01.02.04.03.07.02a16.53 16.53 0 0 0 5.02-2.57 16.77 16.77 0 0 0-2.98-11.4ZM8.68 14.4c-.98 0-1.8-.9-1.8-2.02 0-1.1.8-2.01 1.8-2.01 1.01 0 1.82.9 1.8 2.01 0 1.11-.8 2.02-1.8 2.02Zm6.65 0c-.99 0-1.8-.9-1.8-2.02 0-1.1.8-2.01 1.8-2.01s1.81.9 1.8 2.01c0 1.11-.8 2.02-1.8 2.02Z"/></svg>
diff --git a/modules/Admin/Controllers/PodcastImportController.php b/modules/Admin/Controllers/PodcastImportController.php
index a24af7fc79..de9e90d92c 100644
--- a/modules/Admin/Controllers/PodcastImportController.php
+++ b/modules/Admin/Controllers/PodcastImportController.php
@@ -227,7 +227,7 @@ class PodcastImportController extends BaseController
                         'platform_slug' => $platformSlug,
                         'podcast_id' => $newPodcastId,
                         'link_url' => $platform->attributes()['url'],
-                        'link_content' => $platform->attributes()['id'],
+                        'account_id' => $platform->attributes()['id'],
                         'is_visible' => false,
                     ];
                 }
diff --git a/modules/Admin/Controllers/PodcastPlatformController.php b/modules/Admin/Controllers/PodcastPlatformController.php
index d22b626c19..28879beb16 100644
--- a/modules/Admin/Controllers/PodcastPlatformController.php
+++ b/modules/Admin/Controllers/PodcastPlatformController.php
@@ -81,7 +81,7 @@ class PodcastPlatformController extends BaseController
                 'platform_slug' => $platformSlug,
                 'podcast_id' => $this->podcast->id,
                 'link_url' => $podcastPlatformUrl,
-                'link_content' => $podcastPlatform['content'],
+                'account_id' => $podcastPlatform['account_id'],
                 'is_visible' =>
                     array_key_exists('visible', $podcastPlatform) &&
                     $podcastPlatform['visible'] === 'yes',
diff --git a/themes/cp_admin/podcast/platforms.php b/themes/cp_admin/podcast/platforms.php
index 7be39713f4..38d589d5e6 100644
--- a/themes/cp_admin/podcast/platforms.php
+++ b/themes/cp_admin/podcast/platforms.php
@@ -90,12 +90,11 @@
                 placeholder="https://…" />
             <Forms.Input
                 class="w-full mb-1"
-                id="<?= $platform->slug . '_link_content' ?>"
-                name="<?= 'platforms[' . $platform->slug . '][content]' ?>"
-                value="<?= $platform->link_content ?>"
+                id="<?= $platform->slug . '_account_id' ?>"
+                name="<?= 'platforms[' . $platform->slug . '][account_id]' ?>"
+                value="<?= $platform->account_id ?>"
                 placeholder="<?= lang("Platforms.description.{$platform->type}") ?>" />
-            <Forms.Toggler size="small" class="text-sm" id="<?= $platform->slug . '_visible' ?>" name="<?= 'platforms[' . $platform->slug . '][visible]'?>" value="yes" checked="<?= old($platform->slug . '_visible', $platform->is_visible ? $platform->is_visible : false) ?>"><?= lang('Platforms.visible') ?></Forms.Toggler>
-            <Forms.Toggler size="small" class="text-sm" id="<?= $platform->slug . '_on_embed' ?>" name="<?= 'platforms[' . $platform->slug . '][on_embed]'?>" value="yes" checked="<?= old($platform->slug . '_on_embed', $platform->is_on_embed ? $platform->is_on_embed : false) ?>"><?= lang('Platforms.on_embed') ?></Forms.Toggler>
+            <Forms.Toggler size="small" class="text-sm" id="<?= $platform->slug . '_visible' ?>" name="<?= 'platforms[' . $platform->slug . '][visible]'?>" value="yes" checked="<?= old($platform->slug . '_visible', $platform->is_visible ? 'true' : 'false') ?>"><?= lang('Platforms.visible') ?></Forms.Toggler>
         </fieldset>
     </div>
 </div>
diff --git a/themes/cp_app/podcast/_partials/funding_links_modal.php b/themes/cp_app/podcast/_partials/funding_links_modal.php
index aff193c455..4c4a4cb47a 100644
--- a/themes/cp_app/podcast/_partials/funding_links_modal.php
+++ b/themes/cp_app/podcast/_partials/funding_links_modal.php
@@ -21,7 +21,7 @@
                 <?php if ($fundingPlatform->is_visible): ?>
                     <a
                     href="<?= $fundingPlatform->link_url ?>"
-                    title="<?= $fundingPlatform->link_content ?>"
+                    title="<?= $fundingPlatform->account_id ?>"
                     target="_blank"
                     rel="noopener noreferrer"
                     class="inline-flex items-center font-semibold text-accent-base hover:text-accent-hover focus:ring-accent">
-- 
GitLab