-
Notifications
You must be signed in to change notification settings - Fork 0
allows editing post pubished dates. Auto updates post slug. #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ public function create( Dto $request, array $categoryIds = [], string $tagNames | |
| $slug = $request->slug ?? null; | ||
| $excerpt = $request->excerpt ?? null; | ||
| $featuredImage = $request->featured_image ?? null; | ||
| $publishedAt = $request->published_at ?? null; | ||
|
|
||
| $post = new Post(); | ||
| $post->setTitle( $title ); | ||
|
|
@@ -67,9 +68,24 @@ public function create( Dto $request, array $categoryIds = [], string $tagNames | |
| $post->setStatus( $status ); | ||
| $post->setCreatedAt( new DateTimeImmutable() ); | ||
|
|
||
| // Business rule: auto-set published date for published posts | ||
| if( $status === ContentStatus::PUBLISHED->value ) | ||
| // Business rule: set published date | ||
| if( $status === ContentStatus::SCHEDULED->value ) | ||
| { | ||
| // Scheduled posts MUST have a published date | ||
| if( !$publishedAt || trim( $publishedAt ) === '' ) | ||
| { | ||
| throw new \InvalidArgumentException( 'Scheduled posts require a published date' ); | ||
| } | ||
| $post->setPublishedAt( $this->parseDateTime( $publishedAt ) ); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scheduled posts accept past dates, bypassing validationMedium Severity The new scheduling logic in Additional Locations (1) |
||
| elseif( $publishedAt && trim( $publishedAt ) !== '' ) | ||
| { | ||
| // Use provided published date | ||
| $post->setPublishedAt( $this->parseDateTime( $publishedAt ) ); | ||
| } | ||
| elseif( $status === ContentStatus::PUBLISHED->value ) | ||
| { | ||
| // Auto-set to now for published posts when not provided | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $post->setPublishedAt( new DateTimeImmutable() ); | ||
| } | ||
|
|
||
|
|
@@ -97,4 +113,27 @@ private function generateSlug( string $title ): string | |
| { | ||
| return $this->_slugGenerator->generate( $title, 'post' ); | ||
| } | ||
|
|
||
| /** | ||
| * Safely parse a datetime string into DateTimeImmutable | ||
| * | ||
| * @param string $dateTimeString The datetime string to parse | ||
| * @return DateTimeImmutable | ||
| * @throws \InvalidArgumentException If the datetime string is invalid | ||
| */ | ||
| private function parseDateTime( string $dateTimeString ): DateTimeImmutable | ||
| { | ||
| try | ||
| { | ||
| return new DateTimeImmutable( $dateTimeString ); | ||
| } | ||
| catch( \DateMalformedStringException | \Exception $e ) | ||
| { | ||
| throw new \InvalidArgumentException( | ||
| "Invalid published date format: '{$dateTimeString}'. Please provide a valid datetime.", | ||
| 0, | ||
| $e | ||
| ); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.