Skip to content

Commit

Permalink
fix: corrected error that prevents updating news
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Oct 5, 2024
1 parent 93ca9a5 commit b7f70f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
4 changes: 0 additions & 4 deletions phpmyfaq/admin/assets/src/content/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export const handleAddNews = () => {
});

const data = {
dateStart: document.getElementById('dateStart').value,
dateEnd: document.getElementById('dateEnd').value,
news: tinymce.get('editor').getContent(),
newsHeader: document.getElementById('newsheader').value,
authorName: document.getElementById('authorName').value,
Expand Down Expand Up @@ -91,8 +89,6 @@ export const handleEditNews = () => {
const data = {
id: document.getElementById('id').value,
csrfToken: document.getElementById('pmf-csrf-token').value,
dateStart: document.getElementById('dateStart').value,
dateEnd: document.getElementById('dateEnd').value,
news: tinymce.get('editor').getContent(),
newsHeader: document.getElementById('newsheader').value,
authorName: document.getElementById('authorName').value,
Expand Down
32 changes: 14 additions & 18 deletions phpmyfaq/src/phpMyFAQ/Controller/Administration/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class NewsController extends AbstractController
{
Expand All @@ -49,8 +50,6 @@ public function create(Request $request): JsonResponse
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
}

$dateStart = Filter::filterVar($data->dateStart, FILTER_SANITIZE_SPECIAL_CHARS);
$dateEnd = Filter::filterVar($data->dateEnd, FILTER_SANITIZE_SPECIAL_CHARS);
$header = Filter::filterVar($data->newsHeader, FILTER_SANITIZE_SPECIAL_CHARS);
$content = Filter::filterVar($data->news, FILTER_SANITIZE_SPECIAL_CHARS);
$author = Filter::filterVar($data->authorName, FILTER_SANITIZE_SPECIAL_CHARS);
Expand All @@ -71,18 +70,16 @@ public function create(Request $request): JsonResponse
->setEmail($email)
->setActive($active)
->setComment($comment)
->setDateStart(new DateTime($dateStart))
->setDateEnd(new DateTime($dateEnd))
->setLink($link ?? '')
->setLinkTitle($linkTitle ?? '')
->setLinkTarget($target ?? '')
->setCreated(new DateTime());

if ($news->create($newsMessage)) {
return $this->json(['success' => Translation::get('ad_news_updatesuc')], Response::HTTP_OK);
} else {
return $this->json(['error' => Translation::get('ad_news_insertfail')], Response::HTTP_BAD_GATEWAY);
}

return $this->json(['error' => Translation::get('ad_news_insertfail')], Response::HTTP_BAD_GATEWAY);
}

/**
Expand All @@ -105,9 +102,9 @@ public function delete(Request $request): JsonResponse

if ($news->delete((int)$deleteId)) {
return $this->json(['success' => Translation::get('ad_news_delsuc')], Response::HTTP_OK);
} else {
return $this->json(['error' => Translation::get('ad_news_updatefail')], Response::HTTP_BAD_GATEWAY);
}

return $this->json(['error' => Translation::get('ad_news_updatefail')], Response::HTTP_BAD_GATEWAY);
}

/**
Expand All @@ -127,8 +124,6 @@ public function update(Request $request): JsonResponse
}

$newsId = Filter::filterVar($data->id, FILTER_VALIDATE_INT);
$dateStart = Filter::filterVar($data->dateStart, FILTER_SANITIZE_SPECIAL_CHARS);
$dateEnd = Filter::filterVar($data->dateEnd, FILTER_SANITIZE_SPECIAL_CHARS);
$header = Filter::filterVar($data->newsHeader, FILTER_SANITIZE_SPECIAL_CHARS);
$content = Filter::filterVar($data->news, FILTER_SANITIZE_SPECIAL_CHARS);
$author = Filter::filterVar($data->authorName, FILTER_SANITIZE_SPECIAL_CHARS);
Expand All @@ -150,20 +145,21 @@ public function update(Request $request): JsonResponse
->setEmail($email)
->setActive($active)
->setComment($comment)
->setDateStart(new DateTime($dateStart))
->setDateEnd(new DateTime($dateEnd))
->setLink($link ?? '')
->setLinkTitle($linkTitle ?? '')
->setLinkTarget($target ?? '')
->setCreated(new DateTime());

if ($news->update($newsMessage)) {
return $this->json(['success' => Translation::get('ad_news_updatesuc')], Response::HTTP_OK);
} else {
return $this->json(['error' => Translation::get('ad_news_updatefail')], Response::HTTP_BAD_GATEWAY);
}

return $this->json(['error' => Translation::get('ad_news_updatefail')], Response::HTTP_BAD_GATEWAY);
}

/**
* @throws Exception
*/
#[Route('admin/api/news/activate')]
public function activate(Request $request): JsonResponse
{
Expand All @@ -176,13 +172,13 @@ public function activate(Request $request): JsonResponse
return $this->json(['error' => Translation::get('err_NotAuth')], Response::HTTP_UNAUTHORIZED);
}

$id = Filter::filterVar($data->id, FILTER_VALIDATE_INT);
$newsId = Filter::filterVar($data->id, FILTER_VALIDATE_INT);
$status = Filter::filterVar($data->status, FILTER_SANITIZE_SPECIAL_CHARS);

if ($news->activate($id, $status)) {
if ($news->activate($newsId, $status)) {
return $this->json(['success' => Translation::get('ad_news_updatesuc')], Response::HTTP_OK);
} else {
return $this->json(['error' => Translation::get('ad_news_updatefail')], Response::HTTP_BAD_GATEWAY);
}

return $this->json(['error' => Translation::get('ad_news_updatefail')], Response::HTTP_BAD_GATEWAY);
}
}

0 comments on commit b7f70f7

Please sign in to comment.