Skip to content

Commit

Permalink
v5.3.4 fix issues when deleting membergroups
Browse files Browse the repository at this point in the history
Signed-off-by: Diego Andrés <[email protected]>
  • Loading branch information
DiegoAndresCortes committed May 20, 2022
1 parent 0192c1a commit 567161c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
32 changes: 27 additions & 5 deletions Sources/TeamPage/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand All @@ -94,23 +105,34 @@ 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}');
}
}
// 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);
}
}
15 changes: 10 additions & 5 deletions Sources/TeamPage/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/TeamPage/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package-info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
<id>smftricks:teampage</id>
<name>Team Page</name>
<version>5.3.3</version>
<version>5.3.4</version>
<type>modification</type>
<install for="2.1 - 2.1.99">
<!-- Mod Readme -->
Expand Down

0 comments on commit 567161c

Please sign in to comment.