Skip to content

Commit d818030

Browse files
committed
fix: use correct language to store questions, closes #3453
1 parent e3fdf66 commit d818030

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

phpmyfaq/src/phpMyFAQ/Controller/Api/QuestionController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public function create(Request $request): JsonResponse
114114
->setEmail($email)
115115
->setCategoryId($categoryId)
116116
->setQuestion($question)
117+
->setLanguage($this->configuration->getLanguage()->getLanguage())
117118
->setIsVisible($visibility === 'Y');
118119

119120
$questionObject = new Question($this->configuration);

phpmyfaq/src/phpMyFAQ/Controller/Frontend/QuestionController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
use phpMyFAQ\StopWords;
3333
use phpMyFAQ\Strings;
3434
use phpMyFAQ\Translation;
35-
use phpMyFAQ\User\CurrentUser;
3635
use Symfony\Component\HttpFoundation\JsonResponse;
3736
use Symfony\Component\HttpFoundation\Request;
3837
use Symfony\Component\HttpFoundation\Response;
@@ -65,6 +64,7 @@ public function create(Request $request): JsonResponse
6564
$author = trim((string) Filter::filterVar($data->name, FILTER_SANITIZE_SPECIAL_CHARS));
6665
$email = trim((string) Filter::filterVar($data->email, FILTER_VALIDATE_EMAIL));
6766
$selectedCategory = isset($data->category) ? Filter::filterVar($data->category, FILTER_VALIDATE_INT) : false;
67+
$language = trim((string) Filter::filterVar($data->lang, FILTER_SANITIZE_SPECIAL_CHARS));
6868
$userQuestion = trim(strip_tags((string) $data->question));
6969
$save = Filter::filterVar($data->save ?? 0, FILTER_VALIDATE_INT);
7070
$storeNow = Filter::filterVar($data->store ?? 'not', FILTER_SANITIZE_SPECIAL_CHARS);
@@ -95,6 +95,7 @@ public function create(Request $request): JsonResponse
9595
->setUsername($author)
9696
->setEmail($email)
9797
->setCategoryId($selectedCategory)
98+
->setLanguage($language)
9899
->setQuestion(Strings::htmlentities($userQuestion))
99100
->setIsVisible($visibility === 'Y');
100101

phpmyfaq/src/phpMyFAQ/Question.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function add(QuestionEntity $questionData): bool
5050
(%d, '%s', '%s', '%s', %d, '%s', '%s', '%s', %d)",
5151
Database::getTablePrefix(),
5252
$this->configuration->getDb()->nextId(Database::getTablePrefix() . 'faqquestions', 'id'),
53-
$this->configuration->getLanguage()->getLanguage(),
53+
$this->configuration->getDb()->escape($questionData->getLanguage()),
5454
$this->configuration->getDb()->escape($questionData->getUsername()),
5555
$this->configuration->getDb()->escape($questionData->getEmail()),
5656
$questionData->getCategoryId(),

tests/phpMyFAQ/QuestionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function testAdd(): void
3636
->setEmail('test@example.org')
3737
->setCategoryId(1)
3838
->setQuestion('Test question')
39+
->setLanguage('en')
3940
->setIsVisible(true);
4041

4142
$this->assertTrue($this->question->add($questionData));
@@ -49,6 +50,7 @@ public function testDelete(): void
4950
->setEmail('test@example.org')
5051
->setCategoryId(1)
5152
->setQuestion('Test question')
53+
->setLanguage('en')
5254
->setIsVisible(true);
5355

5456
$this->question->add($questionData);
@@ -63,6 +65,7 @@ public function testGet(): void
6365
->setEmail('test@example.org')
6466
->setCategoryId(1)
6567
->setQuestion('Test question')
68+
->setLanguage('en')
6669
->setIsVisible(true);
6770

6871
$this->question->add($questionData);
@@ -80,6 +83,7 @@ public function testGetAll(): void
8083
->setEmail('test@example.org')
8184
->setCategoryId(1)
8285
->setQuestion('Test question')
86+
->setLanguage('en')
8387
->setIsVisible(true);
8488

8589
$this->question->add($questionData);
@@ -90,6 +94,7 @@ public function testGetAll(): void
9094
->setEmail('test@example.org')
9195
->setCategoryId(1)
9296
->setQuestion('Test question')
97+
->setLanguage('en')
9398
->setIsVisible(true);
9499

95100
$this->question->add($questionData);
@@ -108,6 +113,7 @@ public function testGetVisibility(): void
108113
->setEmail('test@example.org')
109114
->setCategoryId(1)
110115
->setQuestion('Test question')
116+
->setLanguage('en')
111117
->setIsVisible(false);
112118

113119
$this->question->add($questionData);
@@ -123,6 +129,7 @@ public function testSetVisibility(): void
123129
->setEmail('test@example.org')
124130
->setCategoryId(1)
125131
->setQuestion('Test question')
132+
->setLanguage('en')
126133
->setIsVisible(true);
127134

128135
$this->question->add($questionData);

0 commit comments

Comments
 (0)