Skip to content

Commit c93e433

Browse files
committed
Fix dashboard compatibility on server
1 parent 35e527a commit c93e433

2 files changed

Lines changed: 89 additions & 32 deletions

File tree

kontrol-merkezi.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,23 @@
8181
"SELECT COUNT(DISTINCT k.id)
8282
FROM kpis k
8383
JOIN actions a ON a.id = k.action_id
84-
LEFT JOIN action_departments ad
85-
ON ad.action_id = a.id
86-
AND ad.department_id = :ad_dept_id
8784
WHERE k.is_active = 1
8885
AND k.deleted_at IS NULL
8986
AND a.deleted_at IS NULL
9087
AND a.status != 'cancelled'
91-
AND (a.responsible_department_id = :owner_dept_id OR ad.department_id IS NOT NULL)"
88+
AND (
89+
a.responsible_department_id = :dept_id
90+
OR EXISTS (
91+
SELECT 1
92+
FROM action_departments ad
93+
WHERE ad.action_id = a.id
94+
AND ad.department_id = :dept_id_extra
95+
)
96+
)"
9297
);
9398
$kpiStmt->execute([
94-
':ad_dept_id' => $deptId,
95-
':owner_dept_id' => $deptId,
99+
':dept_id' => $deptId,
100+
':dept_id_extra' => $deptId,
96101
]);
97102
$stats['total_kpis'] = (int) $kpiStmt->fetchColumn();
98103

@@ -107,12 +112,17 @@
107112
AND de.department_id = ?
108113
AND de.year = YEAR(NOW())
109114
AND de.deleted_at IS NULL
110-
LEFT JOIN action_departments ad
111-
ON ad.action_id = a.id
112-
AND ad.department_id = ?
113115
WHERE a.deleted_at IS NULL
114116
AND a.status != 'cancelled'
115-
AND (a.responsible_department_id = ? OR ad.department_id IS NOT NULL)
117+
AND (
118+
a.responsible_department_id = ?
119+
OR EXISTS (
120+
SELECT 1
121+
FROM action_departments ad
122+
WHERE ad.action_id = a.id
123+
AND ad.department_id = ?
124+
)
125+
)
116126
GROUP BY a.id
117127
ORDER BY a.code"
118128
);

uygulama/yardimcilar/bildirim-servisi.php

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
final class NotificationService
66
{
77
private const PRIORITIES = ['low', 'normal', 'high', 'critical'];
8+
private static ?bool $hasLinkColumn = null;
9+
10+
private static function hasLinkColumn(PDO $pdo): bool
11+
{
12+
if (self::$hasLinkColumn !== null) {
13+
return self::$hasLinkColumn;
14+
}
15+
16+
try {
17+
$stmt = $pdo->query("SHOW COLUMNS FROM notifications LIKE 'link'");
18+
self::$hasLinkColumn = $stmt !== false && $stmt->fetch() !== false;
19+
} catch (PDOException $e) {
20+
self::$hasLinkColumn = true;
21+
}
22+
23+
return self::$hasLinkColumn;
24+
}
825

926
public static function create(
1027
PDO $pdo,
@@ -46,26 +63,41 @@ public static function create(
4663
}
4764
}
4865

49-
$stmt = $pdo->prepare(
50-
"INSERT INTO notifications
51-
(recipient_user_id, event_key, title, message, link, priority,
52-
related_type, related_id, dedupe_key, email_status)
53-
VALUES
54-
(:uid, :event_key, :title, :message, :link, :priority,
55-
:related_type, :related_id, :dedupe_key, :email_status)"
56-
);
57-
$stmt->execute([
66+
$hasLinkColumn = self::hasLinkColumn($pdo);
67+
if ($hasLinkColumn) {
68+
$stmt = $pdo->prepare(
69+
"INSERT INTO notifications
70+
(recipient_user_id, event_key, title, message, link, priority,
71+
related_type, related_id, dedupe_key, email_status)
72+
VALUES
73+
(:uid, :event_key, :title, :message, :link, :priority,
74+
:related_type, :related_id, :dedupe_key, :email_status)"
75+
);
76+
} else {
77+
$stmt = $pdo->prepare(
78+
"INSERT INTO notifications
79+
(recipient_user_id, event_key, title, message, priority,
80+
related_type, related_id, dedupe_key, email_status)
81+
VALUES
82+
(:uid, :event_key, :title, :message, :priority,
83+
:related_type, :related_id, :dedupe_key, :email_status)"
84+
);
85+
}
86+
$params = [
5887
':uid' => $recipientUserId,
5988
':event_key' => $eventKey,
6089
':title' => $title,
6190
':message' => $message,
62-
':link' => self::sanitizeLink($link),
6391
':priority' => $priority,
6492
':related_type' => $relatedType !== null ? mb_substr($relatedType, 0, 80) : null,
6593
':related_id' => $relatedId,
6694
':dedupe_key' => $dedupeKey,
6795
':email_status' => $email ? 'skipped' : 'not_required',
68-
]);
96+
];
97+
if ($hasLinkColumn) {
98+
$params[':link'] = self::sanitizeLink($link);
99+
}
100+
$stmt->execute($params);
69101
$notificationId = (int) $pdo->lastInsertId();
70102

71103
if ($email) {
@@ -406,18 +438,33 @@ public static function unreadCount(PDO $pdo, int $userId): int
406438
public static function latest(PDO $pdo, int $userId, int $limit = 10): array
407439
{
408440
$limit = max(1, min(30, $limit));
409-
$stmt = $pdo->prepare(
410-
"SELECT id, event_key, title, message, link, priority, is_read, created_at
411-
FROM notifications
412-
WHERE recipient_user_id = :uid
413-
ORDER BY created_at DESC
414-
LIMIT :limit"
415-
);
416-
$stmt->bindValue(':uid', $userId, PDO::PARAM_INT);
417-
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
418-
$stmt->execute();
441+
try {
442+
if (self::hasLinkColumn($pdo)) {
443+
$stmt = $pdo->prepare(
444+
"SELECT id, event_key, title, message, link, priority, is_read, created_at
445+
FROM notifications
446+
WHERE recipient_user_id = :uid
447+
ORDER BY created_at DESC
448+
LIMIT :limit"
449+
);
450+
} else {
451+
$stmt = $pdo->prepare(
452+
"SELECT id, event_key, title, message, NULL AS link, priority, is_read, created_at
453+
FROM notifications
454+
WHERE recipient_user_id = :uid
455+
ORDER BY created_at DESC
456+
LIMIT :limit"
457+
);
458+
}
459+
$stmt->bindValue(':uid', $userId, PDO::PARAM_INT);
460+
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
461+
$stmt->execute();
419462

420-
return array_map([self::class, 'decorate'], $stmt->fetchAll());
463+
return array_map([self::class, 'decorate'], $stmt->fetchAll());
464+
} catch (PDOException $e) {
465+
error_log('[SECAP][NOTIFY] Bildirim listesi okunamadı: ' . $e->getMessage());
466+
return [];
467+
}
421468
}
422469

423470
public static function markRead(PDO $pdo, int $userId, int $notificationId): bool

0 commit comments

Comments
 (0)