mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-19 13:01:19 +00:00
fix(podcast-import): rollback transaction before exception is thrown
This allows errors' messages to resurface and prevent the script of having the generic "Process was killed." error. fixes #429, closes #319, #443, #438
This commit is contained in:
parent
d0a94dd2cb
commit
419bb04716
@ -28,7 +28,7 @@ if (! function_exists('hint_tooltip')) {
|
||||
{
|
||||
$tooltip =
|
||||
'<span data-tooltip="bottom" tabindex="0" title="' .
|
||||
$hintText .
|
||||
esc($hintText) .
|
||||
'" class="inline-block align-middle opacity-75 focus:ring-accent';
|
||||
|
||||
if ($class !== '') {
|
||||
|
@ -100,9 +100,9 @@ class PodcastImport extends BaseCommand
|
||||
// FIXME: getting named routes doesn't work from v4.3 anymore, so loading all routes before importing
|
||||
Services::routes()->loadRoutes();
|
||||
|
||||
$this->init();
|
||||
|
||||
try {
|
||||
$this->init();
|
||||
|
||||
CLI::write('All good! Feed was parsed successfully!');
|
||||
|
||||
CLI::write(
|
||||
@ -173,7 +173,7 @@ class PodcastImport extends BaseCommand
|
||||
$this->error($exception->getMessage());
|
||||
log_message(
|
||||
'critical',
|
||||
'Error when importing ' . $this->importTask->feed_url . PHP_EOL . $exception->getTraceAsString()
|
||||
'Error when importing ' . $this->importTask?->feed_url . PHP_EOL . $exception->getMessage() . PHP_EOL . $exception->getTraceAsString()
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -196,9 +196,6 @@ class PodcastImport extends BaseCommand
|
||||
|
||||
private function importPodcast(): Podcast
|
||||
{
|
||||
$db = db_connect();
|
||||
$db->transStart();
|
||||
|
||||
$location = null;
|
||||
if ($this->podcastFeed->channel->podcast_location->getValue() !== null) {
|
||||
$location = new Location(
|
||||
@ -213,7 +210,19 @@ class PodcastImport extends BaseCommand
|
||||
}
|
||||
|
||||
if (($coverUrl = $this->getCoverUrl($this->podcastFeed->channel)) === null) {
|
||||
throw new Exception('Missing podcast cover. Please include an <itunes:image> tag');
|
||||
throw new Exception('Missing podcast cover. Please include an <itunes:image> tag.');
|
||||
}
|
||||
|
||||
if (($ownerName = $this->podcastFeed->channel->itunes_owner->itunes_name->getValue() === null)) {
|
||||
throw new Exception(
|
||||
'Missing podcast owner name. Please include an <itunes:name> tag inside the <itunes:owner> tag.'
|
||||
);
|
||||
}
|
||||
|
||||
if (($ownerEmail = $this->podcastFeed->channel->itunes_owner->itunes_email->getValue() === null)) {
|
||||
throw new Exception(
|
||||
'Missing podcast owner email. Please include an <itunes:email> tag inside the <itunes:owner> tag.'
|
||||
);
|
||||
}
|
||||
|
||||
$parentalAdvisory = null;
|
||||
@ -221,6 +230,9 @@ class PodcastImport extends BaseCommand
|
||||
$parentalAdvisory = $this->podcastFeed->channel->itunes_explicit->getValue() ? 'explicit' : 'clean';
|
||||
}
|
||||
|
||||
$db = db_connect();
|
||||
$db->transStart();
|
||||
|
||||
$htmlConverter = new HtmlConverter();
|
||||
$podcast = new Podcast([
|
||||
'created_by' => $this->user->id,
|
||||
@ -237,8 +249,8 @@ class PodcastImport extends BaseCommand
|
||||
'language_code' => $this->importTask->language,
|
||||
'category_id' => $this->importTask->category,
|
||||
'parental_advisory' => $parentalAdvisory,
|
||||
'owner_name' => $this->podcastFeed->channel->itunes_owner->itunes_name->getValue(),
|
||||
'owner_email' => $this->podcastFeed->channel->itunes_owner->itunes_email->getValue(),
|
||||
'owner_name' => $ownerName,
|
||||
'owner_email' => $ownerEmail,
|
||||
'publisher' => $this->podcastFeed->channel->itunes_author->getValue(),
|
||||
'type' => $this->podcastFeed->channel->itunes_type->getValue(),
|
||||
'copyright' => $this->podcastFeed->channel->copyright->getValue(),
|
||||
@ -446,6 +458,7 @@ class PodcastImport extends BaseCommand
|
||||
}
|
||||
|
||||
if (($showNotes = $this->getShowNotes($item)) === null) {
|
||||
$db->transRollback();
|
||||
throw new Exception('Missing item show notes. Please include a <description> tag to item ' . $key);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ use Modules\PodcastImport\Entities\TaskStatus;
|
||||
'passed' => '',
|
||||
];
|
||||
|
||||
$errorHint = $importTask->status === TaskStatus::Failed ? hint_tooltip($importTask->error, 'ml-1') : '';
|
||||
$errorHint = $importTask->status === TaskStatus::Failed ? hint_tooltip(esc($importTask->error), 'ml-1') : '';
|
||||
|
||||
return '<div class="flex items-center"><Pill variant="' . $pillVariantMap[$importTask->status->value] . '" icon="' . $pillIconMap[$importTask->status->value] . '" iconClass="' . $pillIconClassMap[$importTask->status->value] . '" hint="' . lang('PodcastImport.queue.status.' . $importTask->status->value . '_hint') . '">' . lang('PodcastImport.queue.status.' . $importTask->status->value) . '</Pill>' . $errorHint . '</div>';
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user