@@ -26,3 +26,52 @@ SET @sql = IF(@col_exists = 0,
2626PREPARE stmt FROM @sql;
2727EXECUTE stmt;
2828DEALLOCATE PREPARE stmt;
29+
30+ -- =============================================================================
31+ -- Add default sharing providers setting
32+ -- =============================================================================
33+ -- Enables Facebook, X, WhatsApp and Email share buttons on the book detail page.
34+ -- Admins can customise the selection in Settings > Sharing.
35+
36+ INSERT IGNORE INTO system_settings (category, setting_key, setting_value, updated_at)
37+ VALUES (' sharing' , ' enabled_providers' , ' facebook,x,whatsapp,email' , NOW());
38+
39+ -- =============================================================================
40+ -- Add unique index on plugin_hooks for atomic upsert registration
41+ -- =============================================================================
42+ -- Prevents duplicate hook rows from concurrent registerHooks() calls.
43+ -- First, deduplicate existing rows (keep the one with the smallest id).
44+
45+ DELETE ph1
46+ FROM plugin_hooks ph1
47+ JOIN plugin_hooks ph2
48+ ON ph1 .plugin_id = ph2 .plugin_id
49+ AND ph1 .hook_name = ph2 .hook_name
50+ AND ph1 .callback_method = ph2 .callback_method
51+ AND ph1 .id > ph2 .id ;
52+
53+ -- Drop old 4-column unique key if it exists (included callback_class which
54+ -- is NOT part of the runtime identity — the dispatcher deduplicates by
55+ -- plugin_id + hook_name + callback_method only)
56+ SET @old_idx = (SELECT COUNT (* ) FROM INFORMATION_SCHEMA .STATISTICS
57+ WHERE TABLE_SCHEMA = DATABASE()
58+ AND TABLE_NAME = ' plugin_hooks'
59+ AND INDEX_NAME = ' uk_plugin_hook_callback' );
60+ SET @sql = IF(@old_idx > 0 ,
61+ ' ALTER TABLE plugin_hooks DROP INDEX uk_plugin_hook_callback' ,
62+ ' SELECT 1' );
63+ PREPARE stmt FROM @sql;
64+ EXECUTE stmt;
65+ DEALLOCATE PREPARE stmt;
66+
67+ -- Re-create with correct 3-column key
68+ SET @new_idx = (SELECT COUNT (* ) FROM INFORMATION_SCHEMA .STATISTICS
69+ WHERE TABLE_SCHEMA = DATABASE()
70+ AND TABLE_NAME = ' plugin_hooks'
71+ AND INDEX_NAME = ' uk_plugin_hook_callback' );
72+ SET @sql = IF(@new_idx = 0 ,
73+ ' ALTER TABLE plugin_hooks ADD UNIQUE KEY uk_plugin_hook_callback (plugin_id, hook_name, callback_method)' ,
74+ ' SELECT 1' );
75+ PREPARE stmt FROM @sql;
76+ EXECUTE stmt;
77+ DEALLOCATE PREPARE stmt;
0 commit comments