Skip to content

Commit

Permalink
fix: corrected check on category ID
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Apr 1, 2024
1 parent 99e9db1 commit 5a79d27
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions phpmyfaq/src/phpMyFAQ/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -915,11 +915,10 @@ public function getModeratorGroupId(int $categoryId): int
/**
* Creates a new category
*/
public function create(CategoryEntity $categoryEntity): ?int
public function create(CategoryEntity $category): ?int
{
if (is_null($categoryEntity->getId())) {
$categoryEntity->setId($this->configuration->getDb()
->nextId(Database::getTablePrefix() . 'faqcategories', 'id'));
if ($category->getId() === 0) {
$category->setId($this->configuration->getDb()->nextId(Database::getTablePrefix() . 'faqcategories', 'id'));
}

$query = sprintf(
Expand All @@ -930,35 +929,35 @@ public function create(CategoryEntity $categoryEntity): ?int
VALUES
(%d, '%s', %d, '%s', '%s', %d, %d, %d, '%s', %d)",
Database::getTablePrefix(),
$categoryEntity->getId(),
$this->configuration->getDb()->escape($categoryEntity->getLang()),
$categoryEntity->getParentId(),
$this->configuration->getDb()->escape($categoryEntity->getName()),
$this->configuration->getDb()->escape($categoryEntity->getDescription()),
$categoryEntity->getUserId(),
$categoryEntity->getGroupId(),
$categoryEntity->getActive(),
$this->configuration->getDb()->escape($categoryEntity->getImage()),
$categoryEntity->getShowHome()
$category->getId(),
$this->configuration->getDb()->escape($category->getLang()),
$category->getParentId(),
$this->configuration->getDb()->escape($category->getName()),
$this->configuration->getDb()->escape($category->getDescription()),
$category->getUserId(),
$category->getGroupId(),
$category->getActive(),
$this->configuration->getDb()->escape($category->getImage()),
$category->getShowHome()
);

$this->configuration->getDb()->query($query);

return $categoryEntity->getId();
return $category->getId();
}

/**
* Check if category already exists.
*
* @param CategoryEntity $categoryData Array of category data
* @param CategoryEntity $category Array of category data
*/
public function checkIfCategoryExists(CategoryEntity $categoryData): int
public function checkIfCategoryExists(CategoryEntity $category): int
{
$query = sprintf(
"SELECT name from %sfaqcategories WHERE name = '%s' AND lang = '%s'",
Database::getTablePrefix(),
$this->configuration->getDb()->escape($categoryData->getName()),
$this->configuration->getDb()->escape($categoryData->getLang())
$this->configuration->getDb()->escape($category->getName()),
$this->configuration->getDb()->escape($category->getLang())
);

$result = $this->configuration->getDb()->query($query);
Expand All @@ -969,9 +968,9 @@ public function checkIfCategoryExists(CategoryEntity $categoryData): int
/**
* Updates an existent category entry.
*
* @param CategoryEntity $categoryData CategoryEntity object
* @param CategoryEntity $category CategoryEntity object
*/
public function update(CategoryEntity $categoryData): bool
public function update(CategoryEntity $category): bool
{
$query = sprintf(
"
Expand All @@ -990,15 +989,15 @@ public function update(CategoryEntity $categoryData): bool
AND
lang = '%s'",
Database::getTablePrefix(),
$this->configuration->getDb()->escape($categoryData->getName()),
$this->configuration->getDb()->escape($categoryData->getDescription()),
$categoryData->getUserId(),
$categoryData->getGroupId(),
$categoryData->getActive(),
$categoryData->getShowHome(),
$this->configuration->getDb()->escape($categoryData->getImage()),
$categoryData->getId(),
$this->configuration->getDb()->escape($categoryData->getLang())
$this->configuration->getDb()->escape($category->getName()),
$this->configuration->getDb()->escape($category->getDescription()),
$category->getUserId(),
$category->getGroupId(),
$category->getActive(),
$category->getShowHome(),
$this->configuration->getDb()->escape($category->getImage()),
$category->getId(),
$this->configuration->getDb()->escape($category->getLang())
);

return (bool)$this->configuration->getDb()->query($query);
Expand Down

0 comments on commit 5a79d27

Please sign in to comment.