blog posts

This commit is contained in:
2025-05-25 08:59:30 +01:00
parent 87722cb95e
commit 20e604cf68
20 changed files with 509 additions and 123 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace DoctrineMigrations;
use DateTime;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\Yaml\Yaml;
@@ -38,17 +39,21 @@ final class Version20250522212300 extends AbstractMigration
$blogPostPath = 'scripts/blog-migrated/' . $slug . '.yaml';
$blogPost = Yaml::parseFile($blogPostPath);
$publishedDate = $blogPost['pubDate'];
$updatedDate = array_key_exists(array: $blogPost, key: 'updatedDate')
? $blogPost['updatedDate']
$publishedDateTime = DateTime::createFromFormat('U', strval($blogPost['pubDate']));
$publishedDate = $publishedDateTime->format('Y-m-d');
$updatedDateTime = array_key_exists(array: $blogPost, key: 'updatedDate')
? DateTime::createFromFormat('U', strval($blogPost['updatedDate']))
: null;
$updatedDate = $updatedDateTime == null
? 'NULL'
: "'" . $updatedDateTime->format('Y-m-d') . "'";
$title = str_replace("'", "''", $blogPost['title']);
$description = str_replace("'", "''", $blogPost['description']);
$content = str_replace("'", "''", $blogPost['content']);
$this->addSql(<<<SQL
INSERT INTO blog_post(slug, published_date, updated_date, title, description, content)
VALUES('$slug', '$publishedDate', '$updatedDate', '$title', '$description', '$content')
VALUES('$slug', '$publishedDate', $updatedDate, '$title', '$description', '$content')
SQL);
}
}