adasd
All checks were successful
Deploy / deploy (push) Successful in 58s

This commit is contained in:
2026-07-30 00:04:51 +02:00
parent 76591569b6
commit f6cb211859
10 changed files with 261 additions and 22 deletions

View File

@@ -21,6 +21,8 @@ final class ProfileSettings
return;
}
$this->ensureSensitiveProfileColumns();
if (!$this->hasColumn('user_profiles', 'location_tracking_preference')) {
$this->pdo->exec(
"ALTER TABLE user_profiles
@@ -54,6 +56,32 @@ final class ProfileSettings
$this->schemaEnsured = true;
}
private function ensureSensitiveProfileColumns(): void
{
$columnDefinitions = [
'first_name' => 'VARBINARY(512) NULL',
'last_name' => 'VARBINARY(512) NULL',
'contact_phone' => 'VARBINARY(512) NULL',
'contact_email' => 'VARBINARY(512) NULL',
'profession' => 'VARBINARY(512) NULL',
'languages' => 'VARBINARY(1024) NULL',
'about' => 'VARBINARY(2048) NULL',
];
foreach ($columnDefinitions as $column => $definition) {
if (!$this->hasColumn('user_profiles', $column)) {
continue;
}
$dataType = $this->getColumnDataType('user_profiles', $column);
if ($dataType !== 'varbinary') {
$this->pdo->exec(sprintf('ALTER TABLE user_profiles MODIFY COLUMN %s %s', $column, $definition));
$this->columnCache['user_profiles.' . $column] = true;
$this->columnTypeCache['user_profiles.' . $column] = 'varbinary';
}
}
}
public function getLocationTrackingPreference(int $userId): string
{
if ($userId <= 0) {
@@ -146,4 +174,30 @@ final class ProfileSettings
return $this->columnCache[$cacheKey] = ((int)$stmt->fetchColumn() > 0);
}
private array $columnTypeCache = [];
private function getColumnDataType(string $table, string $column): ?string
{
$cacheKey = $table . '.' . $column;
if (array_key_exists($cacheKey, $this->columnTypeCache)) {
return $this->columnTypeCache[$cacheKey];
}
$stmt = $this->pdo->prepare("
SELECT DATA_TYPE
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = :tableName
AND COLUMN_NAME = :columnName
LIMIT 1
");
$stmt->execute([
'tableName' => $table,
'columnName' => $column,
]);
$value = $stmt->fetchColumn();
return $this->columnTypeCache[$cacheKey] = $value !== false ? strtolower((string)$value) : null;
}
}