fix: set episode description footer to null when empty value

change Database connection import with db_connect helper
This commit is contained in:
Yassine Doghri 2021-06-11 08:03:54 +00:00
parent 33f1b91d55
commit 3a7d97d660
No known key found for this signature in database
GPG Key ID: 3E7F89498B960C9F
9 changed files with 47 additions and 29 deletions

View File

@ -22,7 +22,6 @@ use App\Models\SoundbiteModel;
use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\I18n\Time; use CodeIgniter\I18n\Time;
use Config\Database;
class EpisodeController extends BaseController class EpisodeController extends BaseController
{ {
@ -192,10 +191,12 @@ class EpisodeController extends BaseController
} }
// update podcast's episode_description_footer_markdown if changed // update podcast's episode_description_footer_markdown if changed
$podcastModel = new PodcastModel(); $this->podcast->episode_description_footer_markdown = $this->request->getPost(
'description_footer'
) === '' ? null : $this->request->getPost('description_footer');
if ($this->podcast->hasChanged('episode_description_footer_markdown')) { if ($this->podcast->hasChanged('episode_description_footer_markdown')) {
$this->podcast->episode_description_footer_markdown = $this->request->getPost('description_footer'); $podcastModel = new PodcastModel();
if (! $podcastModel->update($this->podcast->id, $this->podcast)) { if (! $podcastModel->update($this->podcast->id, $this->podcast)) {
return redirect() return redirect()
@ -313,9 +314,14 @@ class EpisodeController extends BaseController
$this->episode->chapters_file_remote_url = $chaptersFileRemoteUrl; $this->episode->chapters_file_remote_url = $chaptersFileRemoteUrl;
} }
$db = db_connect();
$db->transStart();
$episodeModel = new EpisodeModel(); $episodeModel = new EpisodeModel();
if (! $episodeModel->update($this->episode->id, $this->episode)) { if (! $episodeModel->update($this->episode->id, $this->episode)) {
$db->transRollback();
return redirect() return redirect()
->back() ->back()
->withInput() ->withInput()
@ -323,11 +329,15 @@ class EpisodeController extends BaseController
} }
// update podcast's episode_description_footer_markdown if changed // update podcast's episode_description_footer_markdown if changed
$this->podcast->episode_description_footer_markdown = $this->request->getPost('description_footer'); $this->podcast->episode_description_footer_markdown = $this->request->getPost(
'description_footer'
) === '' ? null : $this->request->getPost('description_footer');
if ($this->podcast->hasChanged('episode_description_footer_markdown')) { if ($this->podcast->hasChanged('episode_description_footer_markdown')) {
$podcastModel = new PodcastModel(); $podcastModel = new PodcastModel();
if (! $podcastModel->update($this->podcast->id, $this->podcast)) { if (! $podcastModel->update($this->podcast->id, $this->podcast)) {
$db->transRollback();
return redirect() return redirect()
->back() ->back()
->withInput() ->withInput()
@ -335,6 +345,8 @@ class EpisodeController extends BaseController
} }
} }
$db->transComplete();
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id]); return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id]);
} }
@ -407,7 +419,7 @@ class EpisodeController extends BaseController
->with('errors', $this->validator->getErrors()); ->with('errors', $this->validator->getErrors());
} }
$db = Database::connect(); $db = db_connect();
$db->transStart(); $db->transStart();
$newNote = new Note([ $newNote = new Note([
@ -503,7 +515,7 @@ class EpisodeController extends BaseController
->with('errors', $this->validator->getErrors()); ->with('errors', $this->validator->getErrors());
} }
$db = Database::connect(); $db = db_connect();
$db->transStart(); $db->transStart();
$publishMethod = $this->request->getPost('publication_method'); $publishMethod = $this->request->getPost('publication_method');
@ -589,7 +601,7 @@ class EpisodeController extends BaseController
->with('errors', $this->validator->getErrors()); ->with('errors', $this->validator->getErrors());
} }
$db = Database::connect(); $db = db_connect();
$db->transStart(); $db->transStart();

View File

@ -19,7 +19,6 @@ use App\Models\LanguageModel;
use App\Models\PodcastModel; use App\Models\PodcastModel;
use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use Config\Database;
use Config\Services; use Config\Services;
class PodcastController extends BaseController class PodcastController extends BaseController
@ -226,7 +225,7 @@ class PodcastController extends BaseController
]); ]);
$podcastModel = new PodcastModel(); $podcastModel = new PodcastModel();
$db = Database::connect(); $db = db_connect();
$db->transStart(); $db->transStart();
@ -334,7 +333,7 @@ class PodcastController extends BaseController
$this->podcast->is_locked = $this->request->getPost('lock') === 'yes'; $this->podcast->is_locked = $this->request->getPost('lock') === 'yes';
$this->podcast->updated_by = (int) user_id(); $this->podcast->updated_by = (int) user_id();
$db = Database::connect(); $db = db_connect();
$db->transStart(); $db->transStart();
$podcastModel = new PodcastModel(); $podcastModel = new PodcastModel();

View File

@ -23,7 +23,6 @@ use App\Models\PlatformModel;
use App\Models\PodcastModel; use App\Models\PodcastModel;
use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use Config\Database;
use Config\Services; use Config\Services;
use ErrorException; use ErrorException;
use League\HTMLToMarkdown\HtmlConverter; use League\HTMLToMarkdown\HtmlConverter;
@ -182,7 +181,7 @@ class PodcastImportController extends BaseController
} }
$podcastModel = new PodcastModel(); $podcastModel = new PodcastModel();
$db = Database::connect(); $db = db_connect();
$db->transStart(); $db->transStart();

View File

@ -303,7 +303,7 @@ class InstallController extends Controller
// Activate user // Activate user
$user->activate(); $user->activate();
$db = Database::connect(); $db = db_connect();
$db->transStart(); $db->transStart();
if (! ($userId = $userModel->insert($user, true))) { if (! ($userId = $userModel->insert($user, true))) {

View File

@ -299,7 +299,17 @@ class Podcast extends Entity
public function setEpisodeDescriptionFooterMarkdown(?string $episodeDescriptionFooterMarkdown = null): static public function setEpisodeDescriptionFooterMarkdown(?string $episodeDescriptionFooterMarkdown = null): static
{ {
if ($episodeDescriptionFooterMarkdown) { if ($episodeDescriptionFooterMarkdown === null || $episodeDescriptionFooterMarkdown === '') {
$this->attributes[
'episode_description_footer_markdown'
] = null;
$this->attributes[
'episode_description_footer_html'
] = null;
return $this;
}
$converter = new CommonMarkConverter([ $converter = new CommonMarkConverter([
'html_input' => 'strip', 'html_input' => 'strip',
'allow_unsafe_links' => false, 'allow_unsafe_links' => false,
@ -311,7 +321,6 @@ class Podcast extends Entity
$this->attributes[ $this->attributes[
'episode_description_footer_html' 'episode_description_footer_html'
] = $converter->convertToHtml($episodeDescriptionFooterMarkdown); ] = $converter->convertToHtml($episodeDescriptionFooterMarkdown);
}
return $this; return $this;
} }

View File

@ -386,9 +386,9 @@ if (! function_exists('array_to_rss')) {
$childXmlNode = $xmlNode->addChild( $childXmlNode = $xmlNode->addChild(
$childArrayNode['name'], $childArrayNode['name'],
$childArrayNode['content'] ?? null, $childArrayNode['content'] ?? null,
array_key_exists('namespace', $childArrayNode) $childArrayNode['namespace'] === []
? current($childArrayNode['namespace']) ? null
: null, : current($childArrayNode['namespace'])
); );
if (array_key_exists('attributes', $childArrayNode)) { if (array_key_exists('attributes', $childArrayNode)) {
foreach ( foreach (

View File

@ -67,7 +67,7 @@ if (! function_exists('accept_follow')) {
$acceptActivity->set('actor', $actor->uri) $acceptActivity->set('actor', $actor->uri)
->set('object', $objectId); ->set('object', $objectId);
$db = Database::connect(); $db = db_connect();
$db->transStart(); $db->transStart();
$activityModel = model('ActivityModel'); $activityModel = model('ActivityModel');

View File

@ -10,7 +10,6 @@ declare(strict_types=1);
namespace Analytics; namespace Analytics;
use Config\Database;
use Config\Services; use Config\Services;
trait AnalyticsTrait trait AnalyticsTrait
@ -28,7 +27,7 @@ trait AnalyticsTrait
$session->start(); $session->start();
if (! $session->get('denyListIp')) { if (! $session->get('denyListIp')) {
$db = Database::connect(); $db = db_connect();
$referer = $session->get('referer'); $referer = $session->get('referer');
$domain = $domain =

View File

@ -159,7 +159,7 @@ if (! function_exists('set_user_session_player')) {
]); ]);
// Add to unknown list // Add to unknown list
try { try {
$db = Database::connect(); $db = db_connect();
$procedureNameAnalyticsUnknownUseragents = $db->prefixTable('analytics_unknown_useragents'); $procedureNameAnalyticsUnknownUseragents = $db->prefixTable('analytics_unknown_useragents');
$db->query("CALL {$procedureNameAnalyticsUnknownUseragents}(?)", [$userAgent]); $db->query("CALL {$procedureNameAnalyticsUnknownUseragents}(?)", [$userAgent]);
// If things go wrong the show must go on and the user must be able to download the file // If things go wrong the show must go on and the user must be able to download the file
@ -321,7 +321,7 @@ if (! function_exists('podcast_hit')) {
// If more that 1mn was downloaded, that's a hit, we send that to the database: // If more that 1mn was downloaded, that's a hit, we send that to the database:
if ($downloadedBytes >= $bytesThreshold) { if ($downloadedBytes >= $bytesThreshold) {
$db = Database::connect(); $db = db_connect();
$procedureName = $db->prefixTable('analytics_podcasts'); $procedureName = $db->prefixTable('analytics_podcasts');
$age = intdiv(time() - $publicationTime, 86400); $age = intdiv(time() - $publicationTime, 86400);