diff --git a/app/Module/FamilyTreeNewsModule.php b/app/Module/FamilyTreeNewsModule.php index 546862da4a..b3df130aff 100644 --- a/app/Module/FamilyTreeNewsModule.php +++ b/app/Module/FamilyTreeNewsModule.php @@ -58,12 +58,7 @@ public function description(): string /** * Generate the HTML content of this block. * - * @param Tree $tree - * @param int $block_id - * @param string $context * @param array $config - * - * @return string */ public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string { @@ -173,38 +168,37 @@ public function postEditNewsAction(ServerRequestInterface $request): ResponseInt $news_id = Validator::queryParams($request)->integer('news_id', 0); $subject = Validator::parsedBody($request)->string('subject'); $body = Validator::parsedBody($request)->string('body'); - $now = Registry::timestampFactory()->now(); $subject = $this->html_service->sanitize($subject); $body = $this->html_service->sanitize($body); - if ($news_id !== 0) { - $use_current_timestamp = Validator::parsedBody($request)->boolean('use-current-timestamp', false); - - if ($use_current_timestamp) { - $updated = $now; - } else { - $timestamp = Validator::parsedBody($request)->string('timestamp'); - $timezone = new DateTimeZone(Auth::user()->getPreference(UserInterface::PREF_TIME_ZONE, 'UTC')); - $utc = new DateTimeZone('UTC'); - $updated = DateTimeImmutable::createFromFormat('Y-m-d\\TH:i:s', $timestamp, $timezone) - ->setTimezone($utc); - } + $use_current_timestamp = Validator::parsedBody($request)->boolean('use-current-timestamp', false); + if ($use_current_timestamp) { + $updated = Registry::timestampFactory()->now(); + } else { + $timestamp = Validator::parsedBody($request)->string('timestamp'); + $timezone = new DateTimeZone(Auth::user()->getPreference(UserInterface::PREF_TIME_ZONE, 'UTC')); + $utc = new DateTimeZone('UTC'); + $updated = DateTimeImmutable::createFromFormat('Y-m-d\\TH:i:s', $timestamp, $timezone) + ->setTimezone($utc); + } + + if ($news_id !== 0) { DB::table('news') ->where('news_id', '=', $news_id) ->where('gedcom_id', '=', $tree->id()) // Check this is our own tree - validates news_id ->update([ 'body' => $body, 'subject' => $subject, - 'updated' => $updated, + 'updated' => $updated->format('Y-m-d H:i:s'), ]); } else { DB::table('news')->insert([ 'body' => $body, 'subject' => $subject, 'gedcom_id' => $tree->id(), - 'updated' => $now, + 'updated' => $updated->format('Y-m-d H:i:s'), ]); } diff --git a/app/Module/UserJournalModule.php b/app/Module/UserJournalModule.php index 91c5429ed5..2f30ca1b27 100644 --- a/app/Module/UserJournalModule.php +++ b/app/Module/UserJournalModule.php @@ -58,12 +58,7 @@ public function description(): string /** * Generate the HTML content of this block. * - * @param Tree $tree - * @param int $block_id - * @param string $context * @param array $config - * - * @return string */ public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string { @@ -173,24 +168,23 @@ public function postEditJournalAction(ServerRequestInterface $request): Response $news_id = Validator::queryParams($request)->integer('news_id', 0); $subject = Validator::parsedBody($request)->string('subject'); $body = Validator::parsedBody($request)->string('body'); - $now = Registry::timestampFactory()->now(); $subject = $this->html_service->sanitize($subject); $body = $this->html_service->sanitize($body); - if ($news_id !== 0) { - $use_current_timestamp = Validator::parsedBody($request)->boolean('use-current-timestamp', false); - - if ($use_current_timestamp) { - $updated = $now; - } else { - $timestamp = Validator::parsedBody($request)->string('timestamp'); - $timezone = new DateTimeZone(Auth::user()->getPreference(UserInterface::PREF_TIME_ZONE, 'UTC')); - $utc = new DateTimeZone('UTC'); - $updated = DateTimeImmutable::createFromFormat('Y-m-d\\TH:i:s', $timestamp, $timezone) - ->setTimezone($utc); - } + $use_current_timestamp = Validator::parsedBody($request)->boolean('use-current-timestamp', false); + if ($use_current_timestamp) { + $updated = Registry::timestampFactory()->now(); + } else { + $timestamp = Validator::parsedBody($request)->string('timestamp'); + $timezone = new DateTimeZone(Auth::user()->getPreference(UserInterface::PREF_TIME_ZONE, 'UTC')); + $utc = new DateTimeZone('UTC'); + $updated = DateTimeImmutable::createFromFormat('Y-m-d\\TH:i:s', $timestamp, $timezone) + ->setTimezone($utc); + } + + if ($news_id !== 0) { DB::table('news') ->where('news_id', '=', $news_id) ->where('user_id', '=', Auth::id()) // Check this is our own page - validates news_id @@ -204,7 +198,7 @@ public function postEditJournalAction(ServerRequestInterface $request): Response 'body' => $body, 'subject' => $subject, 'user_id' => Auth::id(), - 'updated' => $now, + 'updated' => $updated->format('Y-m-d H:i:s'), ]); }