Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUGGESTION] Update Player deletion to handle tables that do not use 'citizenid' as the column name #1174

Open
tlsharkie opened this issue Feb 5, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@tlsharkie
Copy link

The problem

Update player deletion code in server/player.lua to accommodate tables that do not use the column name citizenid
Many scripts use other column names to store the citizenid but contain data that should be deleted upon character deletion. This leads to excess data build up in the database that is no longer needed and currently requires manual effort to clean out the database.

Ideal solution

Sample code below for your review:

New format for playertables:
Starting @ line 532:

local playertables = { -- Add tables as needed 
    ---
    --- 'table' is the SQL table name
    --- 'key' is the column name which contains the 'citizenid'
    --- 
    --Tables where primary key = 'citizenid'
    { table = 'players', key = 'citizenid' },
    { table = 'apartments', key = 'citizenid' },
...
    { table = 'player_contacts', key = 'identifier' },
    { table = 'bank_cards', key = 'identifier' },
    { table = 'bank_history', key = 'identifier' },
...
    { table = 'bank_process',  key = 'owner' },
    { table = 'mail_accounts', key = 'owner' },
    { table = 'lation_chopshop', key = 'player_identifier' },

Edits to the SQL calls for DeleteCharacter (and similar change for ForceDeleteCharacter):
starting @ line 547:

function QBCore.Player.DeleteCharacter(source, citizenid)
    local license = QBCore.Functions.GetIdentifier(source, 'license')
    local result = MySQL.scalar.await('SELECT license FROM players where citizenid = ?', { citizenid })
    if license == result then
        -- old call
        -- local query = 'DELETE FROM %s WHERE citizenid = ?'
        local query = 'DELETE FROM %s WHERE %s = ?'  -- updated query
        local tableCount = #playertables
        local queries = table.create(tableCount, 0)

        for i = 1, tableCount do
            local v = playertables[i]
            -- old call
            -- queries[i] = { query = query:format(v.table), values = { citizenid } }
            queries[i] = { query = query:format(v.table, v.key), values = { citizenid } }  -- updated query
        end

Alternative solutions

No response

Additional context

No response

@tlsharkie tlsharkie added the enhancement New feature or request label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant