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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -159,7 +159,7 @@ if (! function_exists('set_user_session_player')) {
]);
// Add to unknown list
try {
$db = Database::connect();
$db = db_connect();
$procedureNameAnalyticsUnknownUseragents = $db->prefixTable('analytics_unknown_useragents');
$db->query("CALL {$procedureNameAnalyticsUnknownUseragents}(?)", [$userAgent]);
// 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 ($downloadedBytes >= $bytesThreshold) {
$db = Database::connect();
$db = db_connect();
$procedureName = $db->prefixTable('analytics_podcasts');
$age = intdiv(time() - $publicationTime, 86400);