Skip to content

Commit 567161c

Browse files
v5.3.4 fix issues when deleting membergroups
Signed-off-by: Diego Andrés <diegoandres_cortes@outlook.com>
1 parent 0192c1a commit 567161c

5 files changed

Lines changed: 43 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
#### 5.3.4 19 May 2022
4+
- ![Bug Fix](https://smftricks.com/assets/changelog/bug--minus.png) Fixed a bug preventing the removal of member groups.
5+
- ![Bug Fix](https://smftricks.com/assets/changelog/bug--minus.png) Fixed a strange scenario where the page could have 'ghost' groups.
6+
37
#### 5.3.3 18 May 2022
48
- ![Translation](https://smftricks.com/assets/changelog/language.png) Italian translation provided by [Max22](https://www.simplemachines.org/community/index.php?action=profile;u=44765)
59
- ![Bug Fix](https://smftricks.com/assets/changelog/bug--minus.png) Added missing language strings.

Sources/TeamPage/Groups.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public function PageSort($id)
3838
$this->groups['all'] = [];
3939
foreach ($context['page_groups_all'] as $group)
4040
{
41+
// Empty?
42+
if (empty($group['id_group']))
43+
continue;
44+
4145
// All
4246
$this->groups['all'][] += $group['id_group'];
4347
// Left
@@ -77,15 +81,22 @@ public function Save()
7781
{
7882
// Data
7983
foreach ($this->groups as $position => $group)
84+
{
85+
// No ghost groups
86+
if (empty($group))
87+
continue;
88+
8089
$this->fields_data[$position] = [
8190
'id_group' => (int) $group,
8291
'id_page' => (int) $_REQUEST['page'],
8392
'placement' => (string) $_REQUEST['placement'],
8493
'position' => (int) $position,
8594
];
95+
}
8696

8797
// Type for insert
88-
foreach($this->fields_data as $group) {
98+
foreach($this->fields_data as $group)
99+
{
89100
$this->fields_update[$group['position']] = '';
90101
foreach($group as $column => $type) {
91102
$this->fields_insert[$group['position']][$column] = str_replace('integer', 'int', gettype($type));
@@ -94,23 +105,34 @@ public function Save()
94105
}
95106

96107
// Update!
97-
foreach($this->fields_data as $group) {
108+
foreach($this->fields_data as $group)
109+
{
98110
Helper::Insert($this->table, $this->fields_data[$group['position']], $this->fields_insert[$group['position']], 'replace', ['id_group', 'id_page']);
99111
Helper::Update($this->table . ' AS tp', $this->fields_data[$group['position']], $this->fields_update[$group['position']], 'WHERE tp.id_group = {int:id_group}
100112
AND tp.id_page = {int:id_page}');
101113
}
102114
}
103115
// We are deleting this group!
104116
else
105-
self::Delete($this->groups, ' AND id_page = ' . $_REQUEST['page']);
117+
$this->groupsDelete($this->groups, $_REQUEST['page']);
106118

107119
// Exit
108120
die;
109121
}
110122

111-
public function Delete($delete_groups, $query = '')
123+
public function groupsDelete(&$groups, $page)
124+
{
125+
// Make sure the groups are integer, in case we have an unexpected guest.
126+
foreach ($groups as $position => $group)
127+
$groups[$position] = (int) $group;
128+
129+
// Delete
130+
Helper::Delete($this->table, 'id_group', $groups, ' AND id_page = {int:page}', ['page' => (int) $page]);
131+
}
132+
133+
public function Delete($delete_groups)
112134
{
113135
// sooo basically delete the groups from team page as well
114-
Helper::Delete($this->table, 'id_group', $delete_groups, $query);
136+
Helper::Delete($this->table, 'id_group', $delete_groups);
115137
}
116138
}

Sources/TeamPage/Helper.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,22 @@ public static function Find($table, $column, $search = '', $additional_query = '
187187
return $result;
188188
}
189189

190-
public static function Delete($table, $column, $search, $additional_query = '')
190+
public static function Delete($table, $column, $search, $additional_query = '', $values =[])
191191
{
192192
global $smcFunc;
193193

194-
$smcFunc['db_query']('', '
195-
DELETE FROM {db_prefix}{raw:table}
196-
WHERE '. $column . (is_array($search) ? ' IN ({array_int:search})' : (' = ' . $search)) . $additional_query,
194+
$data = array_merge(
197195
[
198196
'table' => $table,
199197
'search' => $search,
200-
]
198+
],
199+
$values
200+
);
201+
202+
$smcFunc['db_query']('', '
203+
DELETE FROM {db_prefix}{raw:table}
204+
WHERE '. $column . (is_array($search) ? ' IN ({array_int:search})' : (' = ' . $search)) . $additional_query,
205+
$data
201206
);
202207
}
203208

Sources/TeamPage/Settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static function hookAreas(&$admin_areas)
4141
// Permissions
4242
add_integration_function('integrate_load_permissions', __CLASS__.'::Permissions', false);
4343
// Delete membergroup
44-
add_integration_function('integrate_delete_membergroups', __NAMESPACE__ . '\Groups::Delete', false);
44+
add_integration_function('integrate_delete_membergroups', __NAMESPACE__ . '\Groups::Delete#', false);
4545
}
4646

4747
/**

package-info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
44
<id>smftricks:teampage</id>
55
<name>Team Page</name>
6-
<version>5.3.3</version>
6+
<version>5.3.4</version>
77
<type>modification</type>
88
<install for="2.1 - 2.1.99">
99
<!-- Mod Readme -->

0 commit comments

Comments
 (0)