From 567161ccc7eeb90ad85d25b758f1bd0a338d39d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Andr=C3=A9s?= Date: Thu, 19 May 2022 19:47:45 -0500 Subject: [PATCH] v5.3.4 fix issues when deleting membergroups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Diego Andrés --- CHANGELOG.md | 4 ++++ Sources/TeamPage/Groups.php | 32 +++++++++++++++++++++++++++----- Sources/TeamPage/Helper.php | 15 ++++++++++----- Sources/TeamPage/Settings.php | 2 +- package-info.xml | 2 +- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 909b801..1e65151 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +#### 5.3.4 19 May 2022 +- ![Bug Fix](https://smftricks.com/assets/changelog/bug--minus.png) Fixed a bug preventing the removal of member groups. +- ![Bug Fix](https://smftricks.com/assets/changelog/bug--minus.png) Fixed a strange scenario where the page could have 'ghost' groups. + #### 5.3.3 18 May 2022 - ![Translation](https://smftricks.com/assets/changelog/language.png) Italian translation provided by [Max22](https://www.simplemachines.org/community/index.php?action=profile;u=44765) - ![Bug Fix](https://smftricks.com/assets/changelog/bug--minus.png) Added missing language strings. diff --git a/Sources/TeamPage/Groups.php b/Sources/TeamPage/Groups.php index 101662a..96c7266 100644 --- a/Sources/TeamPage/Groups.php +++ b/Sources/TeamPage/Groups.php @@ -38,6 +38,10 @@ public function PageSort($id) $this->groups['all'] = []; foreach ($context['page_groups_all'] as $group) { + // Empty? + if (empty($group['id_group'])) + continue; + // All $this->groups['all'][] += $group['id_group']; // Left @@ -77,15 +81,22 @@ public function Save() { // Data foreach ($this->groups as $position => $group) + { + // No ghost groups + if (empty($group)) + continue; + $this->fields_data[$position] = [ 'id_group' => (int) $group, 'id_page' => (int) $_REQUEST['page'], 'placement' => (string) $_REQUEST['placement'], 'position' => (int) $position, ]; + } // Type for insert - foreach($this->fields_data as $group) { + foreach($this->fields_data as $group) + { $this->fields_update[$group['position']] = ''; foreach($group as $column => $type) { $this->fields_insert[$group['position']][$column] = str_replace('integer', 'int', gettype($type)); @@ -94,7 +105,8 @@ public function Save() } // Update! - foreach($this->fields_data as $group) { + foreach($this->fields_data as $group) + { Helper::Insert($this->table, $this->fields_data[$group['position']], $this->fields_insert[$group['position']], 'replace', ['id_group', 'id_page']); Helper::Update($this->table . ' AS tp', $this->fields_data[$group['position']], $this->fields_update[$group['position']], 'WHERE tp.id_group = {int:id_group} AND tp.id_page = {int:id_page}'); @@ -102,15 +114,25 @@ public function Save() } // We are deleting this group! else - self::Delete($this->groups, ' AND id_page = ' . $_REQUEST['page']); + $this->groupsDelete($this->groups, $_REQUEST['page']); // Exit die; } - public function Delete($delete_groups, $query = '') + public function groupsDelete(&$groups, $page) + { + // Make sure the groups are integer, in case we have an unexpected guest. + foreach ($groups as $position => $group) + $groups[$position] = (int) $group; + + // Delete + Helper::Delete($this->table, 'id_group', $groups, ' AND id_page = {int:page}', ['page' => (int) $page]); + } + + public function Delete($delete_groups) { // sooo basically delete the groups from team page as well - Helper::Delete($this->table, 'id_group', $delete_groups, $query); + Helper::Delete($this->table, 'id_group', $delete_groups); } } \ No newline at end of file diff --git a/Sources/TeamPage/Helper.php b/Sources/TeamPage/Helper.php index d223154..cb54f05 100644 --- a/Sources/TeamPage/Helper.php +++ b/Sources/TeamPage/Helper.php @@ -187,17 +187,22 @@ public static function Find($table, $column, $search = '', $additional_query = ' return $result; } - public static function Delete($table, $column, $search, $additional_query = '') + public static function Delete($table, $column, $search, $additional_query = '', $values =[]) { global $smcFunc; - $smcFunc['db_query']('', ' - DELETE FROM {db_prefix}{raw:table} - WHERE '. $column . (is_array($search) ? ' IN ({array_int:search})' : (' = ' . $search)) . $additional_query, + $data = array_merge( [ 'table' => $table, 'search' => $search, - ] + ], + $values + ); + + $smcFunc['db_query']('', ' + DELETE FROM {db_prefix}{raw:table} + WHERE '. $column . (is_array($search) ? ' IN ({array_int:search})' : (' = ' . $search)) . $additional_query, + $data ); } diff --git a/Sources/TeamPage/Settings.php b/Sources/TeamPage/Settings.php index 1e6c91c..29c1df0 100644 --- a/Sources/TeamPage/Settings.php +++ b/Sources/TeamPage/Settings.php @@ -41,7 +41,7 @@ public static function hookAreas(&$admin_areas) // Permissions add_integration_function('integrate_load_permissions', __CLASS__.'::Permissions', false); // Delete membergroup - add_integration_function('integrate_delete_membergroups', __NAMESPACE__ . '\Groups::Delete', false); + add_integration_function('integrate_delete_membergroups', __NAMESPACE__ . '\Groups::Delete#', false); } /** diff --git a/package-info.xml b/package-info.xml index 4a9f099..c970ce2 100644 --- a/package-info.xml +++ b/package-info.xml @@ -3,7 +3,7 @@ smftricks:teampage Team Page - 5.3.3 + 5.3.4 modification