News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

New group uses previously deleted group ID

Started by OCJ, November 30, 2015, 11:50:17 AM

Previous topic - Next topic

OCJ

Well, might be a bug depending on your point of view. I considered it just a Simple Portal bug as their block permissions remembers the deleted groups block settings and used it for the newly created group with the same ID:
http://simpleportal.net/index.php?topic=14186


After creating a new group and deleting, then creating a new group again, it used the same ID. Some people over there suggested it was an SMF bug.


margarett

It's not a bug, it's explicitly by design
$request = $smcFunc['db_query']('', '
SELECT MAX(id_group)
FROM {db_prefix}membergroups',
array(
)
);
list ($id_group) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
$id_group++;

;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

margarett

#2
Just to add a bit ;)

SMF doesn't store the id of the group. What you see only happens when you create a group, delete it, then create a new one. In that case, the group gets the ID of the previously created one. It's actually a good way of saving unnecessary unused IDs, especially because the field is a SMALLINT.
But if you create 2 membergroups, delete the first and then create a new one, that will get a new ID ;)

From a "cleanness" point of view, SP should be removing the associated data when the membergroup is deleted. By not doing so, you'll keep unused content in the database (whether it will be of use or not is debatable), which is always undesirable. SMF does so:
// Remove the permissions of the membergroups.
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}permissions
WHERE id_group IN ({array_int:group_list})',
array(
'group_list' => $groups,
)
);
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}board_permissions
WHERE id_group IN ({array_int:group_list})',
array(
'group_list' => $groups,
)
);
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}group_moderators
WHERE id_group IN ({array_int:group_list})',
array(
'group_list' => $groups,
)
);


edit: about your findings at SP:
QuoteNew boards  have incremented IDs
New groups do not!
This actually serves a purpose. There is no public data associated with membergroups, which can be misguiding if archived somewhere and then the membergroup ID changes.
Board numbers, topics, posts, etc, is different. If you create a board (or a topic, for what matters), then delete it, any associated content should explicitly become noted as not valid. Of course, before you remove the board you must have either deleted or moved the content. But the point is: the board becomes non existent.
That's why content gets unique IDs and membergroups don't ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

OCJ

Don't bother about it. Some people commented over on the Simple Portal site it was an SMF bug (which I doubted) but I thought I would post here just in case.
http://simpleportal.net/index.php?topic=14186

But its bahaviour is different from board Ids which don't not work in the same way - they are incremented.

margarett

I edited my post above and explained that too ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

OCJ

Uhm... even small integer is 32,767...?  If board IDs are incremented then you would expect Member groups to follow the same pattern I think.
Ah, I posted just after you did.

margarett

Yeah, I can't debate that because I didn't wrote it. I'm just looking at what the code tells me ;)

edit: I'm also not saying that the behavior should absolutely be this (or that it shouldn't). All I can say that it's not a bug because it's not an unexpected behavior, it was designed that way ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Eliana Tamerin

Quote from: margarett on November 30, 2015, 12:31:15 PM
Yeah, I can't debate that because I didn't wrote it. I'm just looking at what the code tells me ;)

edit: I'm also not saying that the behavior should absolutely be this (or that it shouldn't). All I can say that it's not a bug because it's not an unexpected behavior, it was designed that way ;)

You and [Unknown] should get together sometime. He'd like you. He always said "they're not bugs, they're just undocumented features." :P

As for SimplePortal, this one is definitely an oops, but it's also a very niche case. Judging by how long it's taken to appear as a bug.
Do NOT PM me for support.

SimplePortal 2.3.6 is OUT!
SimplePortal Project Manager
Download | Docs
SimplePortal: Power of Simplicity!

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Kindred

I dont call it a bug or seexthe need to change it...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Eliana Tamerin

Quote from: Kindred on November 30, 2015, 05:51:48 PM
I dont call it a bug or seexthe need to change it...

Well, not only is it good practice, but it makes it easier for custom coding/mods who don't have to clean up SMF data for their purposes. Mods should never need to clean up after the mother software.
Do NOT PM me for support.

SimplePortal 2.3.6 is OUT!
SimplePortal Project Manager
Download | Docs
SimplePortal: Power of Simplicity!

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

OCJ

QuoteWell, not only is it good practice...

I agree, there should be consistency and uniformity in how things are handled. If board IDs are incremented even if deleted so should member groups.




Also inconsistent behaviour with the calendar and posting topics. Permissions are not checked posting through the calendar so topics cannot be announced as there is no checkbox. It has to be opened again from the board for editing before visible. Users do not deal well with inconsistent behaviour like this and it makes life a lot harder for admins.

Advertisement: