Skip to content

Commit

Permalink
fix: added missing entry for added categories in category order table,
Browse files Browse the repository at this point in the history
…closes #2408
  • Loading branch information
thorsten committed Apr 6, 2023
1 parent 5d3f365 commit b8f11a0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
17 changes: 11 additions & 6 deletions phpmyfaq/admin/category.main.php
Expand Up @@ -5,18 +5,19 @@
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
* obtain one at https://mozilla.org/MPL/2.0/.
*
* @package phpMyFAQ
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @package phpMyFAQ
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @copyright 2003-2022 phpMyFAQ Team
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2003-12-20
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2003-12-20
*/

use phpMyFAQ\Category;
use phpMyFAQ\Category\CategoryImage;
use phpMyFAQ\Category\CategoryOrder;
use phpMyFAQ\Category\CategoryPermission;
use phpMyFAQ\Category\CategoryRelation;
use phpMyFAQ\Database;
Expand Down Expand Up @@ -139,6 +140,10 @@

$categoryImage->upload();

// Category Order entry
$categoryOrder = new CategoryOrder($faqConfig);
$categoryOrder->add($categoryId);

// All the other translations
$languages = Filter::filterInput(INPUT_POST, 'used_translated_languages', FILTER_UNSAFE_RAW);
printf('<p class="alert alert-success">%s</p>', $PMF_LANG['ad_categ_added']);
Expand Down
34 changes: 26 additions & 8 deletions phpmyfaq/src/phpMyFAQ/Category/CategoryOrder.php
Expand Up @@ -39,11 +39,29 @@ public function __construct(Configuration $config)
$this->config = $config;
}

/**
* Adds a given category ID to the last position.
*
* @param int $categoryId
* @return bool
*/
public function add(int $categoryId): bool
{
$query = sprintf(
'INSERT INTO %sfaqcategory_order (category_id, position) VALUES (%d, %d)',
Database::getTablePrefix(),
$categoryId,
$this->config->getDb()->nextId(Database::getTablePrefix() . 'faqcategory_order', 'position')
);

return (bool) $this->config->getDb()->query($query);
}

/**
* Returns the current position for the given category ID
*
* @param int $categoryId
* @return mixed
* @return bool
*/
public function getPositionById(int $categoryId)
{
Expand All @@ -54,17 +72,17 @@ public function getPositionById(int $categoryId)
);
$result = $this->config->getDb()->query($query);

return $this->config->getDb()->fetchRow($result);
return (bool) $this->config->getDb()->fetchRow($result);
}

/**
* Inserts the position for the given category ID
*
* @param int $categoryId
* @param int $position
* @return mixed
* @return bool
*/
public function setPositionById(int $categoryId, int $position)
public function setPositionById(int $categoryId, int $position): bool
{
$query = sprintf(
'INSERT INTO %sfaqcategory_order (category_id, position) VALUES (%d, %d)',
Expand All @@ -73,17 +91,17 @@ public function setPositionById(int $categoryId, int $position)
$position
);

return $this->config->getDb()->query($query);
return (bool) $this->config->getDb()->query($query);
}

/**
* Updates the position for the given category ID
*
* @param int $categoryId
* @param int $position
* @return mixed
* @return bool
*/
public function updatePositionById(int $categoryId, int $position)
public function updatePositionById(int $categoryId, int $position): bool
{
$query = sprintf(
'UPDATE %sfaqcategory_order SET position = %d WHERE category_id = %d',
Expand All @@ -92,6 +110,6 @@ public function updatePositionById(int $categoryId, int $position)
$categoryId
);

return $this->config->getDb()->query($query);
return (bool) $this->config->getDb()->query($query);
}
}

0 comments on commit b8f11a0

Please sign in to comment.