feat: Add SEMSTORM domain input and SEO panel links
- Added optional SEMSTORM domain input field in site creation and editing forms. - Introduced SEO panel links in site dashboard and edit pages. - Created a new cron job for SEMSTORM data synchronization. - Implemented database migrations for cron logs and site SEO metrics. - Developed SiteSeoSyncService to handle SEMSTORM data fetching and storage. - Added logging functionality for cron events. - Created a new LogController to display cron logs with filtering options. - Added SEO statistics dashboard with visual representation of metrics. - Implemented site SEO metrics model for data retrieval and manipulation.
This commit is contained in:
@@ -41,6 +41,12 @@ class PublisherService
|
||||
{
|
||||
Logger::info("Publikacja dla strony: {$site['name']} (ID: {$site['id']})", 'publish');
|
||||
|
||||
// 0. Najpierw uzupelnij obrazki w juz opublikowanych artykulach bez miniatury.
|
||||
$publishedWithoutImage = Article::findNextPublishedWithoutImageBySite((int) $site['id']);
|
||||
if ($publishedWithoutImage) {
|
||||
return $this->attachMissingImageToPublishedArticle($site, $publishedWithoutImage);
|
||||
}
|
||||
|
||||
// 1. Najpierw publikuj gotowe, nieopublikowane artykuly.
|
||||
$retryArticle = Article::findNextRetryableBySite((int) $site['id']);
|
||||
if ($retryArticle) {
|
||||
@@ -104,6 +110,7 @@ class PublisherService
|
||||
if ($image) {
|
||||
$mediaId = $this->wordpress->uploadMedia($site, $image['data'], $image['filename']);
|
||||
if ($mediaId) {
|
||||
$imageUrl = 'wp_media:' . $mediaId;
|
||||
Logger::info("Upload obrazka: media_id={$mediaId}", 'publish');
|
||||
}
|
||||
} else {
|
||||
@@ -215,4 +222,63 @@ class PublisherService
|
||||
|
||||
Logger::error("Publikacja nieudana: {$error}", 'publish');
|
||||
}
|
||||
|
||||
private function attachMissingImageToPublishedArticle(array $site, array $article): array
|
||||
{
|
||||
$articleId = (int) $article['id'];
|
||||
$wpPostId = (int) ($article['wp_post_id'] ?? 0);
|
||||
|
||||
if ($wpPostId <= 0) {
|
||||
Logger::warning("Artykul ID {$articleId} oznaczony jako published bez wp_post_id - pomijam", 'publish');
|
||||
return ['success' => false, 'message' => 'Brak wp_post_id dla opublikowanego artykulu.'];
|
||||
}
|
||||
|
||||
$existingFeaturedMediaId = $this->wordpress->getPostFeaturedMedia($site, $wpPostId);
|
||||
if ($existingFeaturedMediaId !== null) {
|
||||
Article::update($articleId, ['image_url' => 'wp_media:' . $existingFeaturedMediaId]);
|
||||
$message = "Artykul ID {$articleId} juz mial miniaturke (media_id={$existingFeaturedMediaId}) - zaktualizowano marker lokalny.";
|
||||
Logger::info($message, 'publish');
|
||||
return ['success' => true, 'message' => $message];
|
||||
}
|
||||
|
||||
$topic = Topic::find((int) ($article['topic_id'] ?? 0));
|
||||
$topicName = $topic['name'] ?? (string) $article['title'];
|
||||
$title = (string) ($article['title'] ?? 'Artykul bez tytulu');
|
||||
|
||||
Article::markRetryAttempt($articleId);
|
||||
|
||||
Logger::info("Proba uzupelnienia obrazka dla artykulu ID {$articleId}: {$title}", 'publish');
|
||||
|
||||
$image = $this->imageService->generate($title, (string) $topicName);
|
||||
if (!$image) {
|
||||
$message = "Nie udalo sie wygenerowac obrazka dla opublikowanego artykulu ID {$articleId}.";
|
||||
Logger::warning($message, 'publish');
|
||||
return ['success' => false, 'message' => $message];
|
||||
}
|
||||
|
||||
$mediaId = $this->wordpress->uploadMedia($site, $image['data'], $image['filename']);
|
||||
if (!$mediaId) {
|
||||
$message = "Nie udalo sie wyslac obrazka do WordPress dla artykulu ID {$articleId}.";
|
||||
Logger::warning($message, 'publish');
|
||||
return ['success' => false, 'message' => $message];
|
||||
}
|
||||
|
||||
$updated = $this->wordpress->updatePostFeaturedMedia($site, $wpPostId, $mediaId);
|
||||
if (!$updated) {
|
||||
$this->wordpress->deleteMedia($site, $mediaId);
|
||||
$message = "Nie udalo sie podpiac miniaturki (media_id={$mediaId}) do wpisu wp_post_id={$wpPostId}.";
|
||||
Logger::warning($message, 'publish');
|
||||
return ['success' => false, 'message' => $message];
|
||||
}
|
||||
|
||||
Article::update($articleId, [
|
||||
'image_url' => 'wp_media:' . $mediaId,
|
||||
'error_message' => null,
|
||||
]);
|
||||
|
||||
$message = "Uzupelniono miniaturke dla artykulu ID {$articleId} (wp_post_id={$wpPostId}, media_id={$mediaId}).";
|
||||
Logger::info($message, 'publish');
|
||||
|
||||
return ['success' => true, 'message' => $message];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user