Split migrated document posts into guides and story
This commit is contained in:
@@ -24,16 +24,24 @@ class ReclassifyDocumentContent extends Command
|
|||||||
'document-d34b35ab',
|
'document-d34b35ab',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move from document to blog/guides.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
private array $moveToGuidesSlugs = [
|
||||||
|
'document-b81734e3',
|
||||||
|
'document-25e793fb',
|
||||||
|
'document-48ec7f25',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move from document to blog/story.
|
* Move from document to blog/story.
|
||||||
*
|
*
|
||||||
* @var array<int, string>
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
private array $moveToStorySlugs = [
|
private array $moveToStorySlugs = [
|
||||||
'document-b81734e3',
|
|
||||||
'document-2f8fad62',
|
'document-2f8fad62',
|
||||||
'document-25e793fb',
|
|
||||||
'document-48ec7f25',
|
|
||||||
'document-f68da0b8',
|
'document-f68da0b8',
|
||||||
'document-a8bdf6d9',
|
'document-a8bdf6d9',
|
||||||
'document-694e4dd6',
|
'document-694e4dd6',
|
||||||
@@ -46,7 +54,11 @@ class ReclassifyDocumentContent extends Command
|
|||||||
{
|
{
|
||||||
$dryRun = (bool) $this->option('dry-run');
|
$dryRun = (bool) $this->option('dry-run');
|
||||||
|
|
||||||
$allSlugs = array_values(array_unique(array_merge($this->keepDocumentSlugs, $this->moveToStorySlugs)));
|
$allSlugs = array_values(array_unique(array_merge(
|
||||||
|
$this->keepDocumentSlugs,
|
||||||
|
$this->moveToGuidesSlugs,
|
||||||
|
$this->moveToStorySlugs
|
||||||
|
)));
|
||||||
$articles = Article::query()
|
$articles = Article::query()
|
||||||
->whereIn('slug', $allSlugs)
|
->whereIn('slug', $allSlugs)
|
||||||
->get()
|
->get()
|
||||||
@@ -63,10 +75,15 @@ class ReclassifyDocumentContent extends Command
|
|||||||
['slug' => 'story'],
|
['slug' => 'story'],
|
||||||
['name' => '故事', 'sort_order' => 30]
|
['name' => '故事', 'sort_order' => 30]
|
||||||
);
|
);
|
||||||
|
$guidesCategory = ArticleCategory::firstOrCreate(
|
||||||
|
['slug' => 'guides'],
|
||||||
|
['name' => '建議與指引', 'sort_order' => 25]
|
||||||
|
);
|
||||||
|
|
||||||
$this->newLine();
|
$this->newLine();
|
||||||
$this->info('Reclassification plan');
|
$this->info('Reclassification plan');
|
||||||
$this->line(' Keep as document: '.count($this->keepDocumentSlugs));
|
$this->line(' Keep as document: '.count($this->keepDocumentSlugs));
|
||||||
|
$this->line(' Move to guides/blog: '.count($this->moveToGuidesSlugs));
|
||||||
$this->line(' Move to story/blog: '.count($this->moveToStorySlugs));
|
$this->line(' Move to story/blog: '.count($this->moveToStorySlugs));
|
||||||
$this->line(' Found in DB: '.$articles->count());
|
$this->line(' Found in DB: '.$articles->count());
|
||||||
|
|
||||||
@@ -80,12 +97,13 @@ class ReclassifyDocumentContent extends Command
|
|||||||
collect($allSlugs)->map(function (string $slug) use ($articles) {
|
collect($allSlugs)->map(function (string $slug) use ($articles) {
|
||||||
$article = $articles->get($slug);
|
$article = $articles->get($slug);
|
||||||
$targetIsDocument = in_array($slug, $this->keepDocumentSlugs, true);
|
$targetIsDocument = in_array($slug, $this->keepDocumentSlugs, true);
|
||||||
|
$targetIsGuides = in_array($slug, $this->moveToGuidesSlugs, true);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
$slug,
|
$slug,
|
||||||
$article?->content_type ?? '(missing)',
|
$article?->content_type ?? '(missing)',
|
||||||
$targetIsDocument ? Article::CONTENT_TYPE_DOCUMENT : Article::CONTENT_TYPE_BLOG,
|
$targetIsDocument ? Article::CONTENT_TYPE_DOCUMENT : Article::CONTENT_TYPE_BLOG,
|
||||||
$targetIsDocument ? 'document' : 'story',
|
$targetIsDocument ? 'document' : ($targetIsGuides ? 'guides' : 'story'),
|
||||||
];
|
];
|
||||||
})->all()
|
})->all()
|
||||||
);
|
);
|
||||||
@@ -97,7 +115,7 @@ class ReclassifyDocumentContent extends Command
|
|||||||
return static::SUCCESS;
|
return static::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
DB::transaction(function () use ($articles, $documentCategory, $storyCategory): void {
|
DB::transaction(function () use ($articles, $documentCategory, $guidesCategory, $storyCategory): void {
|
||||||
foreach ($this->keepDocumentSlugs as $slug) {
|
foreach ($this->keepDocumentSlugs as $slug) {
|
||||||
$article = $articles->get($slug);
|
$article = $articles->get($slug);
|
||||||
if (! $article) {
|
if (! $article) {
|
||||||
@@ -108,6 +126,16 @@ class ReclassifyDocumentContent extends Command
|
|||||||
$article->categories()->sync([$documentCategory->id]);
|
$article->categories()->sync([$documentCategory->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($this->moveToGuidesSlugs as $slug) {
|
||||||
|
$article = $articles->get($slug);
|
||||||
|
if (! $article) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$article->update(['content_type' => Article::CONTENT_TYPE_BLOG]);
|
||||||
|
$article->categories()->sync([$guidesCategory->id]);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($this->moveToStorySlugs as $slug) {
|
foreach ($this->moveToStorySlugs as $slug) {
|
||||||
$article = $articles->get($slug);
|
$article = $articles->get($slug);
|
||||||
if (! $article) {
|
if (! $article) {
|
||||||
|
|||||||
Reference in New Issue
Block a user