2021-03-29 13:58:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Command;
|
|
|
|
|
2021-03-30 13:40:46 +02:00
|
|
|
use App\Core\Manager\EntityManager;
|
|
|
|
use App\Entity\Blog\Category;
|
|
|
|
use App\Entity\Blog\Comment;
|
|
|
|
use App\Entity\Blog\Post;
|
2021-03-30 21:17:05 +02:00
|
|
|
use App\Repository\Blog\PostRepositoryQuery;
|
2021-03-29 13:58:05 +02:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
class MigrateDataCommand extends Command
|
|
|
|
{
|
|
|
|
protected static $defaultName = 'app:migrate-data';
|
|
|
|
protected static $defaultDescription = '';
|
|
|
|
|
2021-03-30 21:16:52 +02:00
|
|
|
public function __construct(EntityManager $entityManager, PostRepositoryQuery $postRepo)
|
2021-03-29 13:58:05 +02:00
|
|
|
{
|
|
|
|
$this->entityManager = $entityManager;
|
2021-03-30 21:16:52 +02:00
|
|
|
$this->postRepo = $postRepo;
|
2021-03-29 13:58:05 +02:00
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setDescription(self::$defaultDescription)
|
|
|
|
// ->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
|
|
|
|
// ->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
{
|
2021-03-30 21:16:52 +02:00
|
|
|
/*
|
|
|
|
foreach ($this->postRepo->create()->find() as $post)
|
|
|
|
{
|
|
|
|
$tags = $post->getTags();
|
2021-03-30 21:27:57 +02:00
|
|
|
$newTags = [];
|
|
|
|
|
|
|
|
foreach ($tags as $k => $v) {
|
|
|
|
if (!empty($v['label'])) {
|
|
|
|
$newTags[] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$post->setTags($newTags);
|
2021-03-30 21:16:52 +02:00
|
|
|
$this->entityManager->update($post);
|
|
|
|
}
|
|
|
|
|
2021-03-29 13:58:05 +02:00
|
|
|
require 'data/category.php';
|
|
|
|
require 'data/comment.php';
|
|
|
|
require 'data/post.php';
|
|
|
|
require 'data/post_has_category.php';
|
|
|
|
|
|
|
|
$categories = [];
|
|
|
|
$posts = [];
|
|
|
|
$comments = [];
|
|
|
|
|
|
|
|
foreach ($oldCategories as $v) {
|
|
|
|
$category = new Category();
|
|
|
|
$category->id = (int) $v['id'];
|
|
|
|
$category->setTitle($v['title']);
|
|
|
|
$category->setSubTitle(null);
|
|
|
|
$category->setDescription($v['description'] ?? '');
|
|
|
|
$category->setIsActive((bool) $v['active']);
|
|
|
|
|
|
|
|
$categories[$category->id] = $category;
|
|
|
|
|
|
|
|
$this->entityManager->create($category);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($oldPosts as $v) {
|
|
|
|
$post = new Post();
|
|
|
|
$post->id = (int) $v['id'];
|
|
|
|
$post->setTitle($v['title']);
|
|
|
|
$post->setContent(str_replace("\r\n", "\n", $v['content']));
|
|
|
|
$post->setContentFormat($v['content_format']);
|
|
|
|
$post->setTags(explode(',', str_replace(', ', ',', $v['tags'])));
|
|
|
|
$post->setStatus((int) $v['active']);
|
|
|
|
$post->setImage($v['picture'] ? ('uploads/posts/2007-2021/'.$v['picture']) : null);
|
|
|
|
$post->setCreatedAt(new \DateTime($v['created_at']));
|
|
|
|
$post->setPublishedAt($v['published_at'] ? new \DateTime($v['published_at']) : null);
|
|
|
|
$post->setIsQuick((int) $v['quick']);
|
|
|
|
$post->setQuickUrl($v['quick_url']);
|
|
|
|
$post->setQuickImage($v['quick_image']);
|
|
|
|
$post->setQuickVideo($v['quick_video']);
|
|
|
|
$post->setQuickVideoWidth($v['quick_video_width']);
|
|
|
|
$post->setQuickVideoHeight($v['quick_video_height']);
|
|
|
|
$post->setSlug($v['slug']);
|
|
|
|
|
|
|
|
$posts[$post->id] = $post;
|
|
|
|
|
|
|
|
$this->entityManager->create($post);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($post_has_category as $v) {
|
|
|
|
$posts[(int) $v['post_id']]->addCategory($categories[(int) $v['category_id']]);
|
|
|
|
|
|
|
|
$this->entityManager->update($posts[(int) $v['post_id']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($oldComments as $v) {
|
|
|
|
$comment = new Comment();
|
|
|
|
$comment->id = (int) $v['id'];
|
|
|
|
$comment->setPost($posts[(int) $v['post_id']]);
|
|
|
|
$comment->setParentComment($comments[(int) $v['parent_comment_id']] ?? null);
|
|
|
|
$comment->setAuthor($v['author']);
|
|
|
|
$comment->setWebsite($v['website']);
|
|
|
|
$comment->setEmail($v['email']);
|
|
|
|
$comment->setContent(str_replace("\r\n", "\n", $v['content']));
|
|
|
|
$comment->setIsActive((bool) $v['active']);
|
|
|
|
$comment->setCreatedAt(new \DateTime($v['created_at']));
|
|
|
|
|
|
|
|
$comments[$comment->id] = $comment;
|
|
|
|
|
|
|
|
$this->entityManager->create($comment);
|
|
|
|
}
|
2021-03-30 21:16:52 +02:00
|
|
|
*/
|
2021-03-29 13:58:05 +02:00
|
|
|
|
|
|
|
return Command::SUCCESS;
|
|
|
|
}
|
|
|
|
}
|