| | |
| | | /****************************************************** |
| | | * Table Definitions |
| | | *****************************************************/ |
| | | |
| | | // MOVED TO Queue.php |
| | | // protected function queueTables():array |
| | | // { |
| | | // |
| | |
| | | // ]; |
| | | // } |
| | | |
| | | protected function errorLogTables():array |
| | | { |
| | | return [ |
| | | 'error_log'=> "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `error_type` varchar(50) NOT NULL, |
| | | `component` varchar(100) NOT NULL, |
| | | `method` varchar(100) DEFAULT NULL, |
| | | `page_url` varchar(255) DEFAULT NULL, |
| | | `message` text NOT NULL, |
| | | `context` JSON, |
| | | `severity` varchar(20) NOT NULL, |
| | | `user_id` {$this->userIDType} DEFAULT NULL, |
| | | `user_was_logged_in` tinyint(1) NOT NULL, |
| | | `source` enum('frontend','backend') NOT NULL, |
| | | `created_at` timestamp DEFAULT CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | KEY `created_at` (`created_at`), |
| | | KEY `component_severity_date` (`component`, `severity`, `created_at`), |
| | | KEY `error_type_date` (`error_type`, `created_at`), |
| | | KEY `severity_date` (`severity`, `created_at`) |
| | | )" |
| | | ]; |
| | | } |
| | | //MOVED TO ErrorHandler.php |
| | | // protected function errorLogTables():array |
| | | // { |
| | | // return [ |
| | | // 'error_log'=> "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `error_type` varchar(50) NOT NULL, |
| | | // `component` varchar(100) NOT NULL, |
| | | // `method` varchar(100) DEFAULT NULL, |
| | | // `page_url` varchar(255) DEFAULT NULL, |
| | | // `message` text NOT NULL, |
| | | // `context` JSON, |
| | | // `severity` varchar(20) NOT NULL, |
| | | // `user_id` {$this->userIDType} DEFAULT NULL, |
| | | // `user_was_logged_in` tinyint(1) NOT NULL, |
| | | // `source` enum('frontend','backend') NOT NULL, |
| | | // `created_at` timestamp DEFAULT CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // KEY `created_at` (`created_at`), |
| | | // KEY `component_severity_date` (`component`, `severity`, `created_at`), |
| | | // KEY `error_type_date` (`error_type`, `created_at`), |
| | | // KEY `severity_date` (`severity`, `created_at`) |
| | | // )" |
| | | // ]; |
| | | // } |
| | | |
| | | protected function userIntegrationsTable():array |
| | | { |
| | |
| | | )" |
| | | ]; |
| | | } |
| | | //MOVED TO NotificationManger.php |
| | | // protected function notificationTables():array |
| | | // { |
| | | // |
| | | // return [ |
| | | // // Main notifications table |
| | | // 'notifications' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `owner_id` {$this->userIDType} NOT NULL, |
| | | // `action_user_id` {$this->userIDType} NOT NULL, |
| | | // `target_id` bigint(20) DEFAULT NULL, |
| | | // `target_type` varchar(30) DEFAULT NULL, |
| | | // `type` enum('new_favourite','new_artist','artist_approved','artist_invitation', |
| | | // 'new_term','term_approved','term_rejected','list_shared', |
| | | // 'system_message','shop_invitation') NOT NULL, |
| | | // `status` enum('unread','read','actioned','dismissed') NOT NULL DEFAULT 'unread', |
| | | // `priority` enum('low','normal','high') NOT NULL DEFAULT 'normal', |
| | | // `message` varchar(255) DEFAULT NULL, |
| | | // `context` JSON DEFAULT NULL, |
| | | // `requires_action` tinyint(1) NOT NULL DEFAULT 0, |
| | | // `action_taken` tinyint(1) NOT NULL DEFAULT 0, |
| | | // `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | // `read_at` datetime DEFAULT NULL, |
| | | // `actioned_at` datetime DEFAULT NULL, |
| | | // `emailed_at` datetime DEFAULT NULL, |
| | | // `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // KEY `user_status` (`owner_id`, `status`), |
| | | // KEY `target_lookup` (`target_id`, `target_type`), |
| | | // KEY `unread_notifications` (`owner_id`, `status`, `created_at`), |
| | | // KEY `requires_action` (`owner_id`, `requires_action`, `action_taken`), |
| | | // KEY `acting_user_lookup` (`owner_id`, `action_user_id`, `type`, `status`, `created_at`), |
| | | // CONSTRAINT `{$this->base}notify_owner` FOREIGN KEY (`owner_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}action_id` FOREIGN KEY (`action_user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | // )", |
| | | // |
| | | // |
| | | // 'notifications_content' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `date` date NOT NULL, |
| | | // `frequency` enum('daily','weekly','monthly') NOT NULL, |
| | | // `tattoo_count` int unsigned NOT NULL DEFAULT 0, |
| | | // `artwork_count` int unsigned NOT NULL DEFAULT 0, |
| | | // `piercing_count` int unsigned NOT NULL DEFAULT 0, |
| | | // `event_count` int unsigned NOT NULL DEFAULT 0, |
| | | // `news_count` int unsigned NOT NULL DEFAULT 0, |
| | | // `offer_count` int unsigned NOT NULL DEFAULT 0, |
| | | // `total_items` int unsigned NOT NULL DEFAULT 0, |
| | | // `has_profile_update` tinyint(1) NOT NULL DEFAULT 0, |
| | | // `new_items` JSON DEFAULT NULL, |
| | | // `updated_items` JSON DEFAULT NULL, |
| | | // `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | // `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `artist_date_frequency` (`user_id`, `date`, `frequency`), |
| | | // KEY `recent_content` (`date`, `frequency`), |
| | | // KEY `artist_frequency` (`user_id`, `frequency`), |
| | | // CONSTRAINT `{$this->base}content_artist` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | // )", |
| | | // |
| | | // 'notifications_user_seen' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `content_notification_id` bigint(20) unsigned NOT NULL, |
| | | // `status` enum('unread','read','dismissed') NOT NULL DEFAULT 'unread', |
| | | // `read_at` datetime DEFAULT NULL, |
| | | // `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `user_content_notif` (`user_id`, `content_notification_id`), |
| | | // KEY `user_status` (`user_id`, `status`), |
| | | // CONSTRAINT `{$this->base}user_content_user` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}user_content_notification` FOREIGN KEY (`content_notification_id`) |
| | | // REFERENCES `{$this->prefixed}notifications_content` (`id`) ON DELETE CASCADE |
| | | // )", |
| | | // |
| | | // // User notification preferences |
| | | // 'notification_preferences' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `item_id` bigint(20) NOT NULL, |
| | | // `notification_type` varchar(50) NOT NULL, |
| | | // `frequency` enum('never','daily','weekly','monthly') DEFAULT 'never', |
| | | // `last_sent` datetime DEFAULT NULL, |
| | | // `created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | // `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `user_type` (`user_id`, `item_id`), |
| | | // KEY `user_frequency` (`user_id`, `frequency`), |
| | | // KEY `frequency_lookup` (`frequency`, `last_sent`), |
| | | // CONSTRAINT `{$this->base}notification_pref_user` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | // )", |
| | | // |
| | | // // Notification digest scheduling and tracking |
| | | // 'notification_digests' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `frequency` enum('daily','weekly','monthly') NOT NULL, |
| | | // `scheduled_at` datetime NOT NULL, |
| | | // `sent_at` datetime DEFAULT NULL, |
| | | // `status` enum('pending','processing','sent','failed') DEFAULT 'pending', |
| | | // `notification_count` int unsigned DEFAULT 0, |
| | | // `created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // KEY `scheduled_digests` (`frequency`, `scheduled_at`, `status`), |
| | | // KEY `user_digests` (`user_id`, `frequency`), |
| | | // CONSTRAINT `{$this->base}digest_user` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | // )", |
| | | // |
| | | // // Analytics on notification interactions |
| | | // 'stats__notifications' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `notification_id` bigint(20) unsigned NOT NULL, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `action` varchar(30) NOT NULL, |
| | | // `action_source` enum('web','email','app') DEFAULT 'web', |
| | | // `action_details` JSON DEFAULT NULL, |
| | | // `created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // KEY `notification_lookup` (`notification_id`), |
| | | // KEY `user_actions` (`user_id`, `action`), |
| | | // KEY `action_analysis` (`action`, `action_source`), |
| | | // CONSTRAINT `{$this->base}metrics_user` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}metrics_notification` FOREIGN KEY (`notification_id`) |
| | | // REFERENCES `{$this->prefixed}notifications` (`id`) ON DELETE CASCADE |
| | | // )" |
| | | // ]; |
| | | // } |
| | | |
| | | protected function notificationTables():array |
| | | { |
| | | |
| | | return [ |
| | | // Main notifications table |
| | | 'notifications' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `owner_id` {$this->userIDType} NOT NULL, |
| | | `action_user_id` {$this->userIDType} NOT NULL, |
| | | `target_id` bigint(20) DEFAULT NULL, |
| | | `target_type` varchar(30) DEFAULT NULL, |
| | | `type` enum('new_favourite','new_artist','artist_approved','artist_invitation', |
| | | 'new_term','term_approved','term_rejected','list_shared', |
| | | 'system_message','shop_invitation') NOT NULL, |
| | | `status` enum('unread','read','actioned','dismissed') NOT NULL DEFAULT 'unread', |
| | | `priority` enum('low','normal','high') NOT NULL DEFAULT 'normal', |
| | | `message` varchar(255) DEFAULT NULL, |
| | | `context` JSON DEFAULT NULL, |
| | | `requires_action` tinyint(1) NOT NULL DEFAULT 0, |
| | | `action_taken` tinyint(1) NOT NULL DEFAULT 0, |
| | | `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | `read_at` datetime DEFAULT NULL, |
| | | `actioned_at` datetime DEFAULT NULL, |
| | | `emailed_at` datetime DEFAULT NULL, |
| | | `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | KEY `user_status` (`owner_id`, `status`), |
| | | KEY `target_lookup` (`target_id`, `target_type`), |
| | | KEY `unread_notifications` (`owner_id`, `status`, `created_at`), |
| | | KEY `requires_action` (`owner_id`, `requires_action`, `action_taken`), |
| | | KEY `acting_user_lookup` (`owner_id`, `action_user_id`, `type`, `status`, `created_at`), |
| | | CONSTRAINT `{$this->base}notify_owner` FOREIGN KEY (`owner_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}action_id` FOREIGN KEY (`action_user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )", |
| | | //MOVED TO ApprovalManager.php |
| | | // protected function approvalTables($types):array |
| | | // { |
| | | // $tables = []; |
| | | // $save = []; |
| | | // |
| | | // foreach ($types as $type => $config) { |
| | | // $save[$type] = ($type === 'term') ? $config : 'user'; |
| | | // $tables['approval_'.$type.'_requests'] = "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `status` enum('pending','approved','rejected','appealed','expired') DEFAULT 'pending', |
| | | // `required_approvals` int unsigned DEFAULT 3, |
| | | // `current_approvals` int unsigned DEFAULT 0, |
| | | // `current_rejections` int unsigned DEFAULT 0, |
| | | // `expires_at` datetime DEFAULT NULL, |
| | | // `created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | // `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | // `approved_by` json DEFAULT NULL, |
| | | // `rejected_by` json DEFAULT NULL, |
| | | // `created_item` json DEFAULT NULL, |
| | | // PRIMARY KEY (`id`), |
| | | // KEY `status` (`status`), |
| | | // KEY `expiring_requests` (`status`, `expires_at`), |
| | | // CONSTRAINT `{$this->base}{$type}_approval_requester` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | // )"; |
| | | // $tables['approval_'.$type.'_votes'] = "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `request_id` bigint(20) unsigned NOT NULL, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `vote` enum('approve','reject','dismissed') NOT NULL, |
| | | // `notes` text DEFAULT NULL, |
| | | // `created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `unique_vote` (`request_id`, `user_id`), |
| | | // KEY `user_votes` (`user_id`), |
| | | // CONSTRAINT `{$this->base}{$type}_user_approval_request` FOREIGN KEY (`request_id`) |
| | | // REFERENCES `{$this->prefixed}approval_{$type}_requests` (`id`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}{$type}_user_approval_voter` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | // )"; |
| | | // } |
| | | // if (!empty($save)) { |
| | | // update_option(BASE.'approvals_types', $save); |
| | | // } |
| | | // return $tables; |
| | | // } |
| | | |
| | | |
| | | 'notifications_content' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `date` date NOT NULL, |
| | | `frequency` enum('daily','weekly','monthly') NOT NULL, |
| | | `tattoo_count` int unsigned NOT NULL DEFAULT 0, |
| | | `artwork_count` int unsigned NOT NULL DEFAULT 0, |
| | | `piercing_count` int unsigned NOT NULL DEFAULT 0, |
| | | `event_count` int unsigned NOT NULL DEFAULT 0, |
| | | `news_count` int unsigned NOT NULL DEFAULT 0, |
| | | `offer_count` int unsigned NOT NULL DEFAULT 0, |
| | | `total_items` int unsigned NOT NULL DEFAULT 0, |
| | | `has_profile_update` tinyint(1) NOT NULL DEFAULT 0, |
| | | `new_items` JSON DEFAULT NULL, |
| | | `updated_items` JSON DEFAULT NULL, |
| | | `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `artist_date_frequency` (`user_id`, `date`, `frequency`), |
| | | KEY `recent_content` (`date`, `frequency`), |
| | | KEY `artist_frequency` (`user_id`, `frequency`), |
| | | CONSTRAINT `{$this->base}content_artist` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )", |
| | | // protected function taxonomyRelationshipsTables():array |
| | | // { |
| | | // $tables = [ |
| | | // 'taxonomy_relationships' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `term_id` {$this->termIDType} NOT NULL, |
| | | // `related_term_id` {$this->termIDType} NOT NULL, |
| | | // `taxonomy` varchar(32) NOT NULL, |
| | | // `related_taxonomy` varchar(32) NOT NULL, |
| | | // `post_count` int(11) NOT NULL DEFAULT 0, |
| | | // `is_direct` tinyint(1) NOT NULL DEFAULT 1, |
| | | // `is_hierarchical` tinyint(1) NOT NULL DEFAULT 0, |
| | | // `last_updated` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // KEY `term_id` (`term_id`), |
| | | // KEY `related_term_id` (`related_term_id`), |
| | | // KEY `taxonomy` (`taxonomy`), |
| | | // KEY `related_taxonomy` (`related_taxonomy`), |
| | | // UNIQUE KEY `term_relation` (`term_id`, `related_term_id`, `taxonomy`, `related_taxonomy`), |
| | | // CONSTRAINT `{$this->base}tax_rel_term_id` FOREIGN KEY (`term_id`) |
| | | // REFERENCES `{$this->wpdb->terms}` (`term_id`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}tax_rel_related_id` FOREIGN KEY (`related_term_id`) |
| | | // REFERENCES `{$this->wpdb->terms}` (`term_id`) ON DELETE CASCADE |
| | | // )" |
| | | // ]; |
| | | // |
| | | //// if ((array_key_exists('dashboard', $this->JVB_SITE) && $this->JVB_SITE['dashboard'] === true) || array_key_exists('use_feed_block', $this->JVB_SITE) && $this->JVB_SITE['use_feed_block']) { |
| | | // $tables['user_term_index'] = "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `term_id` {$this->termIDType} NOT NULL, |
| | | // `taxonomy` varchar(32) NOT NULL, |
| | | // `post_count` int(11) NOT NULL DEFAULT 1, |
| | | // `is_parent` tinyint(1) NOT NULL DEFAULT 0, |
| | | // `last_used` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `user_term` (`user_id`, `term_id`, `taxonomy`), |
| | | // KEY `user_taxonomy` (`user_id`, `taxonomy`), |
| | | // KEY `taxonomy` (`taxonomy`), |
| | | // CONSTRAINT `{$this->base}user_term_user_fk` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}user_term_term_fk` FOREIGN KEY (`term_id`) |
| | | // REFERENCES `{$this->wpdb->terms}` (`term_id`) ON DELETE CASCADE |
| | | // )"; |
| | | //// } |
| | | // |
| | | // return $tables; |
| | | // } |
| | | //MOVED TO FavouritesManager.php |
| | | // protected function favouriteTables():array |
| | | // { |
| | | // |
| | | // return [ |
| | | // 'favourites' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `type` varchar(50) NOT NULL, |
| | | // `target_id` bigint(20) NOT NULL, |
| | | // `notes` text DEFAULT NULL, |
| | | // `date_added` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `unique_favourite` (`user_id`, `type`, `target_id`), |
| | | // KEY `user_type` (`user_id`, `type`), |
| | | // KEY `target_type` (`target_id`, `type`), |
| | | // CONSTRAINT `{$this->base}favourites_user` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | // )", |
| | | // 'favourites_lists' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `name` varchar(255) NOT NULL, |
| | | // `description` text, |
| | | // `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | // `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // KEY `user_lists` (`user_id`), |
| | | // CONSTRAINT `{$this->base}list_user` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | // )", |
| | | // 'favourites_list_items' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `list_id` bigint(20) unsigned NOT NULL, |
| | | // `item_type` varchar(50) NOT NULL, |
| | | // `item_id` bigint(20) NOT NULL, |
| | | // `favourite_id` bigint(20) unsigned DEFAULT NULL, |
| | | // `added_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `unique_list_item` (`list_id`, `item_type`, `item_id`), |
| | | // KEY `list_items` (`list_id`), |
| | | // KEY `favourite_id` (`favourite_id`), |
| | | // CONSTRAINT `{$this->base}list_items` FOREIGN KEY (`list_id`) |
| | | // REFERENCES `{$this->prefixed}favourites_lists` (`id`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}list_favourite` FOREIGN KEY (`favourite_id`) |
| | | // REFERENCES `{$this->prefixed}favourites` (`id`) ON DELETE SET NULL |
| | | // )", |
| | | // 'favourites_list_shares' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `list_id` bigint(20) unsigned NOT NULL, |
| | | // `user_id` {$this->userIDType} NULL, |
| | | // `email` varchar(255) NOT NULL, |
| | | // `permission_type` enum('view', 'edit') NOT NULL DEFAULT 'view', |
| | | // `status` enum('pending', 'accepted', 'rejected', 'revoked') NOT NULL DEFAULT 'pending', |
| | | // `invitation_token` varchar(64) NULL, |
| | | // `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | // `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `unique_share_user` (`list_id`, `user_id`, `status`), |
| | | // UNIQUE KEY `unique_share_email` (`list_id`, `email`, `status`), |
| | | // KEY `list_shares` (`list_id`), |
| | | // KEY `status_index` (`status`), |
| | | // CONSTRAINT `{$this->base}share_list` FOREIGN KEY (`list_id`) |
| | | // REFERENCES `{$this->prefixed}favourites_lists` (`id`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}share_user` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | // )", |
| | | // 'favourites_list_stats' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `item_type` varchar(50) NOT NULL, |
| | | // `item_id` bigint(20) NOT NULL, |
| | | // `list_count` int NOT NULL DEFAULT 0, |
| | | // `last_added` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `unique_item_stat` (`item_type`, `item_id`), |
| | | // KEY `item_stats` (`item_type`, `item_id`) |
| | | // )", |
| | | // ]; |
| | | // } |
| | | |
| | | 'notifications_user_seen' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `content_notification_id` bigint(20) unsigned NOT NULL, |
| | | `status` enum('unread','read','dismissed') NOT NULL DEFAULT 'unread', |
| | | `read_at` datetime DEFAULT NULL, |
| | | `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `user_content_notif` (`user_id`, `content_notification_id`), |
| | | KEY `user_status` (`user_id`, `status`), |
| | | CONSTRAINT `{$this->base}user_content_user` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}user_content_notification` FOREIGN KEY (`content_notification_id`) |
| | | REFERENCES `{$this->prefixed}notifications_content` (`id`) ON DELETE CASCADE |
| | | )", |
| | | //MOVED TO ForumManager.php |
| | | // protected function newsRelationshipsTable():array |
| | | // { |
| | | // return [ |
| | | // 'news_relationships' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `shop_id` {$this->termIDType} NOT NULL, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `artist_id` {$this->postIDType} NOT NULL, |
| | | // `news_count` int(10) unsigned NOT NULL DEFAULT 0, |
| | | // `last_post_date` datetime DEFAULT NULL, |
| | | // `last_updated` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `shop_user` (`shop_id`, `user_id`), |
| | | // KEY `shop_id` (`shop_id`), |
| | | // KEY `user_id` (`user_id`), |
| | | // KEY `artist_id` (`artist_id`), |
| | | // CONSTRAINT `{$this->base}nr_shop_news_shop` FOREIGN KEY (`shop_id`) |
| | | // REFERENCES `{$this->wpdb->terms}` (`term_id`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}nr_shop_news_user` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}nr_shop_news_artist` FOREIGN KEY (`artist_id`) |
| | | // REFERENCES `{$this->wpdb->posts}` (`ID`) ON DELETE SET NULL |
| | | // )" |
| | | // ]; |
| | | // } |
| | | |
| | | // User notification preferences |
| | | 'notification_preferences' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `item_id` bigint(20) NOT NULL, |
| | | `notification_type` varchar(50) NOT NULL, |
| | | `frequency` enum('never','daily','weekly','monthly') DEFAULT 'never', |
| | | `last_sent` datetime DEFAULT NULL, |
| | | `created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `user_type` (`user_id`, `item_id`), |
| | | KEY `user_frequency` (`user_id`, `frequency`), |
| | | KEY `frequency_lookup` (`frequency`, `last_sent`), |
| | | CONSTRAINT `{$this->base}notification_pref_user` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )", |
| | | //MOVED TO ResponseManager.php |
| | | // protected function responseTable():array |
| | | // { |
| | | // return [ |
| | | // 'responses' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `item_id` {$this->postIDType} NOT NULL, |
| | | // `content` text NOT NULL, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `parent_id` bigint(20) unsigned DEFAULT NULL, |
| | | // `response` text NOT NULL, |
| | | // `status` enum('published','hidden','flagged','deleted') DEFAULT 'published', |
| | | // `is_user_deleted` tinyint(1) DEFAULT 0, |
| | | // `upvotes` int NOT NULL DEFAULT 0, |
| | | // `downvotes` int NOT NULL DEFAULT 0, |
| | | // `karma` int NOT NULL DEFAULT 0, |
| | | // `created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | // `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // KEY `item_lookup` (`item_id`, `status`), |
| | | // KEY `user_comments` (`user_id`), |
| | | // KEY `parent_child` (`parent_id`), |
| | | // KEY `karma_order` (`karma`), |
| | | // CONSTRAINT `{$this->base}re_responses_news` FOREIGN KEY (`item_id`) |
| | | // REFERENCES `{$this->wpdb->posts}` (`ID`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}re_responses_parent` FOREIGN KEY (`parent_id`) |
| | | // REFERENCES `{$this->prefixed}responses` (`id`) ON DELETE SET NULL |
| | | // )", |
| | | // 'karma_response' => "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `item_id` bigint(20) NOT NULL, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `vote` enum('up','down') NOT NULL, |
| | | // `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `user_post` (`user_id`,`item_id`), |
| | | // KEY `item_id` (`item_id`), |
| | | // KEY `user_id` (`user_id`), |
| | | // CONSTRAINT `{$this->base}_response_item_id` FOREIGN KEY (`item_id`) |
| | | // REFERENCES `{$this->prefixed}responses` (`id`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}_response_user_id` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | // )" |
| | | // ]; |
| | | // } |
| | | |
| | | // Notification digest scheduling and tracking |
| | | 'notification_digests' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `frequency` enum('daily','weekly','monthly') NOT NULL, |
| | | `scheduled_at` datetime NOT NULL, |
| | | `sent_at` datetime DEFAULT NULL, |
| | | `status` enum('pending','processing','sent','failed') DEFAULT 'pending', |
| | | `notification_count` int unsigned DEFAULT 0, |
| | | `created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | KEY `scheduled_digests` (`frequency`, `scheduled_at`, `status`), |
| | | KEY `user_digests` (`user_id`, `frequency`), |
| | | CONSTRAINT `{$this->base}digest_user` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )", |
| | | |
| | | // Analytics on notification interactions |
| | | 'stats__notifications' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `notification_id` bigint(20) unsigned NOT NULL, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `action` varchar(30) NOT NULL, |
| | | `action_source` enum('web','email','app') DEFAULT 'web', |
| | | `action_details` JSON DEFAULT NULL, |
| | | `created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | KEY `notification_lookup` (`notification_id`), |
| | | KEY `user_actions` (`user_id`, `action`), |
| | | KEY `action_analysis` (`action`, `action_source`), |
| | | CONSTRAINT `{$this->base}metrics_user` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}metrics_notification` FOREIGN KEY (`notification_id`) |
| | | REFERENCES `{$this->prefixed}notifications` (`id`) ON DELETE CASCADE |
| | | )" |
| | | ]; |
| | | } |
| | | |
| | | protected function approvalTables($types):array |
| | | { |
| | | $tables = []; |
| | | $save = []; |
| | | |
| | | foreach ($types as $type => $config) { |
| | | $save[$type] = ($type === 'term') ? $config : 'user'; |
| | | $tables['approval_'.$type.'_requests'] = "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `status` enum('pending','approved','rejected','appealed','expired') DEFAULT 'pending', |
| | | `required_approvals` int unsigned DEFAULT 3, |
| | | `current_approvals` int unsigned DEFAULT 0, |
| | | `current_rejections` int unsigned DEFAULT 0, |
| | | `expires_at` datetime DEFAULT NULL, |
| | | `created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | `approved_by` json DEFAULT NULL, |
| | | `rejected_by` json DEFAULT NULL, |
| | | `created_item` json DEFAULT NULL, |
| | | PRIMARY KEY (`id`), |
| | | KEY `status` (`status`), |
| | | KEY `expiring_requests` (`status`, `expires_at`), |
| | | CONSTRAINT `{$this->base}{$type}_approval_requester` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )"; |
| | | $tables['approval_'.$type.'_votes'] = "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `request_id` bigint(20) unsigned NOT NULL, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `vote` enum('approve','reject','dismissed') NOT NULL, |
| | | `notes` text DEFAULT NULL, |
| | | `created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `unique_vote` (`request_id`, `user_id`), |
| | | KEY `user_votes` (`user_id`), |
| | | CONSTRAINT `{$this->base}{$type}_user_approval_request` FOREIGN KEY (`request_id`) |
| | | REFERENCES `{$this->prefixed}approval_{$type}_requests` (`id`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}{$type}_user_approval_voter` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )"; |
| | | } |
| | | if (!empty($save)) { |
| | | update_option(BASE.'approvals_types', $save); |
| | | } |
| | | return $tables; |
| | | } |
| | | |
| | | |
| | | protected function taxonomyRelationshipsTables():array |
| | | { |
| | | $tables = [ |
| | | 'taxonomy_relationships' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `term_id` {$this->termIDType} NOT NULL, |
| | | `related_term_id` {$this->termIDType} NOT NULL, |
| | | `taxonomy` varchar(32) NOT NULL, |
| | | `related_taxonomy` varchar(32) NOT NULL, |
| | | `post_count` int(11) NOT NULL DEFAULT 0, |
| | | `is_direct` tinyint(1) NOT NULL DEFAULT 1, |
| | | `is_hierarchical` tinyint(1) NOT NULL DEFAULT 0, |
| | | `last_updated` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | KEY `term_id` (`term_id`), |
| | | KEY `related_term_id` (`related_term_id`), |
| | | KEY `taxonomy` (`taxonomy`), |
| | | KEY `related_taxonomy` (`related_taxonomy`), |
| | | UNIQUE KEY `term_relation` (`term_id`, `related_term_id`, `taxonomy`, `related_taxonomy`), |
| | | CONSTRAINT `{$this->base}tax_rel_term_id` FOREIGN KEY (`term_id`) |
| | | REFERENCES `{$this->wpdb->terms}` (`term_id`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}tax_rel_related_id` FOREIGN KEY (`related_term_id`) |
| | | REFERENCES `{$this->wpdb->terms}` (`term_id`) ON DELETE CASCADE |
| | | )" |
| | | ]; |
| | | |
| | | if ((array_key_exists('dashboard', $this->JVB_SITE) && $this->JVB_SITE['dashboard'] === true) || array_key_exists('use_feed_block', $this->JVB_SITE) && $this->JVB_SITE['use_feed_block']) { |
| | | $tables['user_term_index'] = "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `term_id` {$this->termIDType} NOT NULL, |
| | | `taxonomy` varchar(32) NOT NULL, |
| | | `post_count` int(11) NOT NULL DEFAULT 1, |
| | | `is_parent` tinyint(1) NOT NULL DEFAULT 0, |
| | | `last_used` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `user_term` (`user_id`, `term_id`, `taxonomy`), |
| | | KEY `user_taxonomy` (`user_id`, `taxonomy`), |
| | | KEY `taxonomy` (`taxonomy`), |
| | | CONSTRAINT `{$this->base}user_term_user_fk` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}user_term_term_fk` FOREIGN KEY (`term_id`) |
| | | REFERENCES `{$this->wpdb->terms}` (`term_id`) ON DELETE CASCADE |
| | | )"; |
| | | } |
| | | |
| | | return $tables; |
| | | } |
| | | |
| | | protected function favouriteTables():array |
| | | { |
| | | |
| | | return [ |
| | | 'favourites' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `type` varchar(50) NOT NULL, |
| | | `target_id` bigint(20) NOT NULL, |
| | | `notes` text DEFAULT NULL, |
| | | `date_added` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `unique_favourite` (`user_id`, `type`, `target_id`), |
| | | KEY `user_type` (`user_id`, `type`), |
| | | KEY `target_type` (`target_id`, `type`), |
| | | CONSTRAINT `{$this->base}favourites_user` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )", |
| | | 'favourites_lists' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `name` varchar(255) NOT NULL, |
| | | `description` text, |
| | | `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | KEY `user_lists` (`user_id`), |
| | | CONSTRAINT `{$this->base}list_user` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )", |
| | | 'favourites_list_items' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `list_id` bigint(20) unsigned NOT NULL, |
| | | `item_type` varchar(50) NOT NULL, |
| | | `item_id` bigint(20) NOT NULL, |
| | | `favourite_id` bigint(20) unsigned DEFAULT NULL, |
| | | `added_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `unique_list_item` (`list_id`, `item_type`, `item_id`), |
| | | KEY `list_items` (`list_id`), |
| | | KEY `favourite_id` (`favourite_id`), |
| | | CONSTRAINT `{$this->base}list_items` FOREIGN KEY (`list_id`) |
| | | REFERENCES `{$this->prefixed}favourites_lists` (`id`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}list_favourite` FOREIGN KEY (`favourite_id`) |
| | | REFERENCES `{$this->prefixed}favourites` (`id`) ON DELETE SET NULL |
| | | )", |
| | | 'favourites_list_shares' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `list_id` bigint(20) unsigned NOT NULL, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `email` varchar(255) NOT NULL, |
| | | `permission_type` enum('view', 'edit') NOT NULL DEFAULT 'view', |
| | | `status` enum('pending', 'accepted', 'rejected', 'revoked') NOT NULL DEFAULT 'pending', |
| | | `invitation_token` varchar(64) NULL, |
| | | `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `unique_share_user` (`list_id`, `user_id`, `status`), |
| | | UNIQUE KEY `unique_share_email` (`list_id`, `email`, `status`), |
| | | KEY `list_shares` (`list_id`), |
| | | KEY `status_index` (`status`), |
| | | CONSTRAINT `{$this->base}share_list` FOREIGN KEY (`list_id`) |
| | | REFERENCES `{$this->prefixed}favourites_lists` (`id`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}share_user` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )", |
| | | 'favourites_list_stats' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `item_type` varchar(50) NOT NULL, |
| | | `item_id` bigint(20) NOT NULL, |
| | | `list_count` int NOT NULL DEFAULT 0, |
| | | `last_added` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `unique_item_stat` (`item_type`, `item_id`), |
| | | KEY `item_stats` (`item_type`, `item_id`) |
| | | )", |
| | | ]; |
| | | } |
| | | |
| | | protected function newsRelationshipsTable():array |
| | | { |
| | | return [ |
| | | 'news_relationships' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `shop_id` {$this->termIDType} NOT NULL, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `artist_id` {$this->postIDType} NOT NULL, |
| | | `news_count` int(10) unsigned NOT NULL DEFAULT 0, |
| | | `last_post_date` datetime DEFAULT NULL, |
| | | `last_updated` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `shop_user` (`shop_id`, `user_id`), |
| | | KEY `shop_id` (`shop_id`), |
| | | KEY `user_id` (`user_id`), |
| | | KEY `artist_id` (`artist_id`), |
| | | CONSTRAINT `{$this->base}nr_shop_news_shop` FOREIGN KEY (`shop_id`) |
| | | REFERENCES `{$this->wpdb->terms}` (`term_id`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}nr_shop_news_user` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}nr_shop_news_artist` FOREIGN KEY (`artist_id`) |
| | | REFERENCES `{$this->wpdb->posts}` (`ID`) ON DELETE SET NULL |
| | | )" |
| | | ]; |
| | | } |
| | | |
| | | protected function responseTable():array |
| | | { |
| | | return [ |
| | | 'responses' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `item_id` {$this->postIDType} NOT NULL, |
| | | `content` text NOT NULL, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `parent_id` bigint(20) unsigned DEFAULT NULL, |
| | | `response` text NOT NULL, |
| | | `status` enum('published','hidden','flagged','deleted') DEFAULT 'published', |
| | | `is_user_deleted` tinyint(1) DEFAULT 0, |
| | | `upvotes` int NOT NULL DEFAULT 0, |
| | | `downvotes` int NOT NULL DEFAULT 0, |
| | | `karma` int NOT NULL DEFAULT 0, |
| | | `created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | KEY `item_lookup` (`item_id`, `status`), |
| | | KEY `user_comments` (`user_id`), |
| | | KEY `parent_child` (`parent_id`), |
| | | KEY `karma_order` (`karma`), |
| | | CONSTRAINT `{$this->base}re_responses_news` FOREIGN KEY (`item_id`) |
| | | REFERENCES `{$this->wpdb->posts}` (`ID`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}re_responses_parent` FOREIGN KEY (`parent_id`) |
| | | REFERENCES `{$this->prefixed}responses` (`id`) ON DELETE SET NULL |
| | | )", |
| | | 'karma_response' => "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `item_id` bigint(20) NOT NULL, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `vote` enum('up','down') NOT NULL, |
| | | `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `user_post` (`user_id`,`item_id`), |
| | | KEY `item_id` (`item_id`), |
| | | KEY `user_id` (`user_id`), |
| | | CONSTRAINT `{$this->base}_response_item_id` FOREIGN KEY (`item_id`) |
| | | REFERENCES `{$this->prefixed}responses` (`id`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}_response_user_id` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )" |
| | | ]; |
| | | } |
| | | |
| | | protected function karmaTables(array $types):array |
| | | { |
| | | $tables = []; |
| | | foreach ($types as $type => $config) { |
| | | $t = false; |
| | | if (array_key_exists($type, $this->JVB_CONTENT)) { |
| | | $t = 'posts'; |
| | | } elseif (array_key_exists($type, $this->JVB_TAXONOMY)) { |
| | | $t = 'terms'; |
| | | } elseif (array_key_exists($type, $this->JVB_USER)) { |
| | | $t = 'users'; |
| | | } |
| | | |
| | | if (!$t) { |
| | | continue; |
| | | } |
| | | |
| | | switch ($t) { |
| | | case 'posts': |
| | | $referenceType = $this->postIDType; |
| | | $reference_table = $this->wpdb->posts; |
| | | $reference_column = 'ID'; |
| | | break; |
| | | case 'terms': |
| | | $referenceType = $this->termIDType; |
| | | $reference_table = $this->wpdb->terms; |
| | | $reference_column = 'term_id'; |
| | | break; |
| | | case 'users': |
| | | $referenceType = $this->userIDType; |
| | | $reference_table = $this->userTable; |
| | | $reference_column = 'ID'; |
| | | break; |
| | | } |
| | | |
| | | $tables['karma_'.$type] = "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `item_id` {$referenceType} NOT NULL, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `vote` enum('up','down') NOT NULL, |
| | | `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `user_post` (`user_id`,`item_id`), |
| | | KEY `item_id` (`item_id`), |
| | | KEY `user_id` (`user_id`), |
| | | CONSTRAINT `{$this->base}kt_{$type}_item_id` FOREIGN KEY (`item_id`) |
| | | REFERENCES `{$reference_table}` (`{$reference_column}`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}kt_{$type}_user_id` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )"; |
| | | |
| | | } |
| | | |
| | | return $tables; |
| | | } |
| | | //MOVED TO KarmaManager.php |
| | | // protected function karmaTables(array $types):array |
| | | // { |
| | | // $tables = []; |
| | | // foreach ($types as $type => $config) { |
| | | // $t = false; |
| | | // if (array_key_exists($type, $this->JVB_CONTENT)) { |
| | | // $t = 'posts'; |
| | | // } elseif (array_key_exists($type, $this->JVB_TAXONOMY)) { |
| | | // $t = 'terms'; |
| | | // } elseif (array_key_exists($type, $this->JVB_USER)) { |
| | | // $t = 'users'; |
| | | // } |
| | | // |
| | | // if (!$t) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // switch ($t) { |
| | | // case 'posts': |
| | | // $referenceType = $this->postIDType; |
| | | // $reference_table = $this->wpdb->posts; |
| | | // $reference_column = 'ID'; |
| | | // break; |
| | | // case 'terms': |
| | | // $referenceType = $this->termIDType; |
| | | // $reference_table = $this->wpdb->terms; |
| | | // $reference_column = 'term_id'; |
| | | // break; |
| | | // case 'users': |
| | | // $referenceType = $this->userIDType; |
| | | // $reference_table = $this->userTable; |
| | | // $reference_column = 'ID'; |
| | | // break; |
| | | // } |
| | | // |
| | | // $tables['karma_'.$type] = "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `item_id` {$referenceType} NOT NULL, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `vote` enum('up','down') NOT NULL, |
| | | // `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `user_post` (`user_id`,`item_id`), |
| | | // KEY `item_id` (`item_id`), |
| | | // KEY `user_id` (`user_id`), |
| | | // CONSTRAINT `{$this->base}kt_{$type}_item_id` FOREIGN KEY (`item_id`) |
| | | // REFERENCES `{$reference_table}` (`{$reference_column}`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}kt_{$type}_user_id` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | // )"; |
| | | // |
| | | // } |
| | | // |
| | | // return $tables; |
| | | // } |
| | | |
| | | protected function calendarTables(array $types):array |
| | | { |
| | |
| | | ]; |
| | | } |
| | | |
| | | protected function invitationTables(array $config): array |
| | | /*protected function invitationTables(array $config): array |
| | | { |
| | | if (empty($config['roles']) && empty($config['terms'])) { |
| | | return []; |
| | |
| | | $definitions .= ")"; |
| | | |
| | | return ['invitations' => $definitions]; |
| | | } |
| | | }*/ |
| | | |
| | | protected function trackChangesTables($types) |
| | | { |
| | | $tables = []; |
| | | foreach ($types as $type => $config) { |
| | | $contents = $config['for_content']; |
| | | foreach ($contents as $content) { |
| | | $tables['history_'.$content.'_'.$type] = "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `content_id` bigint(20) NOT NULL, |
| | | `term_id` {$this->termIDType} NOT NULL, |
| | | `role` varchar(50) DEFAULT 'artist', |
| | | `is_primary` tinyint(1) DEFAULT 0, |
| | | `start_date` date DEFAULT NULL, |
| | | `end_date` date DEFAULT NULL, |
| | | `created_at` timestamp DEFAULT CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `content_term` (`content_id`, `term_id`), |
| | | KEY content_role (`term_id`, `role`), |
| | | CONSTRAINT `{$this->base}{$content}_{$type}_history_user` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}{$content}_{$type}_history_term` FOREIGN KEY (`term_id`) |
| | | REFERENCES `{$this->wpdb->terms}` (`term_id`) ON DELETE CASCADE |
| | | )"; |
| | | } |
| | | } |
| | | //MOVED TO MakeTrackChanges.php |
| | | // protected function trackChangesTables($types) |
| | | // { |
| | | // $tables = []; |
| | | // foreach ($types as $type => $config) { |
| | | // $contents = $config['for_content']; |
| | | // foreach ($contents as $content) { |
| | | // $tables['history_'.$content.'_'.$type] = "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `content_id` bigint(20) NOT NULL, |
| | | // `term_id` {$this->termIDType} NOT NULL, |
| | | // `role` varchar(50) DEFAULT 'artist', |
| | | // `is_primary` tinyint(1) DEFAULT 0, |
| | | // `start_date` date DEFAULT NULL, |
| | | // `end_date` date DEFAULT NULL, |
| | | // `created_at` timestamp DEFAULT CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `content_term` (`content_id`, `term_id`), |
| | | // KEY content_role (`term_id`, `role`), |
| | | // CONSTRAINT `{$this->base}{$content}_{$type}_history_user` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}{$content}_{$type}_history_term` FOREIGN KEY (`term_id`) |
| | | // REFERENCES `{$this->wpdb->terms}` (`term_id`) ON DELETE CASCADE |
| | | // )"; |
| | | // } |
| | | // } |
| | | // |
| | | // return $tables; |
| | | // } |
| | | |
| | | return $tables; |
| | | } |
| | | protected function requestEntryTables($types) |
| | | { |
| | | $tables = []; |
| | | foreach ($types as $type => $config) { |
| | | $contents = $config['for_content']; |
| | | foreach ($contents as $content) { |
| | | $tables[$content.'_'.$type.'_requests'] = "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `content_id` bigint(20) NOT NULL, |
| | | `term_id` {$this->termIDType} NOT NULL, |
| | | `managers` json DEFAULT NULL, |
| | | `status` ENUM('requested', 'rejected', 'accepted') DEFAULT 'requested', |
| | | `dismissed` smallint(1) unsigned DEFAULT NULL, |
| | | `created_date` timestamp DEFAULT CURRENT_TIMESTAMP, |
| | | `updated_date` timestamp DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, |
| | | `notes` text DEFAULT NULL, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `{$this->base}content_term` (`content_id`, `term_id`), |
| | | CONSTRAINT `{$this->base}{$content}_{$type}_request_user` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}{$content}_{$type}_request_term` FOREIGN KEY (`term_id`) |
| | | REFERENCES `{$this->wpdb->terms}` (`term_id`) ON DELETE CASCADE |
| | | )"; |
| | | } |
| | | } |
| | | //MOVED TO VerifyEntryManager.php |
| | | // protected function requestEntryTables($types) |
| | | // { |
| | | // $tables = []; |
| | | // foreach ($types as $type => $config) { |
| | | // $contents = $config['for_content']; |
| | | // foreach ($contents as $content) { |
| | | // $tables[$content.'_'.$type.'_requests'] = "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `content_id` bigint(20) NOT NULL, |
| | | // `term_id` {$this->termIDType} NOT NULL, |
| | | // `managers` json DEFAULT NULL, |
| | | // `status` ENUM('requested', 'rejected', 'accepted') DEFAULT 'requested', |
| | | // `dismissed` smallint(1) unsigned DEFAULT NULL, |
| | | // `created_date` timestamp DEFAULT CURRENT_TIMESTAMP, |
| | | // `updated_date` timestamp DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, |
| | | // `notes` text DEFAULT NULL, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `{$this->base}content_term` (`content_id`, `term_id`), |
| | | // CONSTRAINT `{$this->base}{$content}_{$type}_request_user` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}{$content}_{$type}_request_term` FOREIGN KEY (`term_id`) |
| | | // REFERENCES `{$this->wpdb->terms}` (`term_id`) ON DELETE CASCADE |
| | | // )"; |
| | | // } |
| | | // } |
| | | // |
| | | // return $tables; |
| | | // } |
| | | |
| | | return $tables; |
| | | } |
| | | |
| | | |
| | | // MOVED TO ReferralManager.php |
| | | /** |
| | | * Create referral tracking tables |
| | | * |
| | | * Call this from the main table creation method in CheckCustomTables.php: |
| | | * $tables = array_merge($tables, $this->referralTables()); |
| | | */ |
| | | protected function referralTables(): array |
| | | { |
| | | // Create tables in dependency order |
| | | // First: referrals (depends only on wp_users) |
| | | $mainTable['referrals'] = "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `referrer_id` {$this->userIDType} NOT NULL, |
| | | `referee_id` {$this->userIDType} NOT NULL, |
| | | `referee_name` varchar(255) NOT NULL, |
| | | `referee_email` varchar(255) NOT NULL, |
| | | `referee_phone` varchar(50) DEFAULT NULL, |
| | | `referral_code` varchar(50) NOT NULL, |
| | | `status` enum('pending', 'consulted', 'treated', 'cancelled') DEFAULT 'pending', |
| | | `referred_at` datetime NOT NULL, |
| | | `consulted_at` datetime DEFAULT NULL, |
| | | `treated_at` datetime DEFAULT NULL, |
| | | `treatment_count` int DEFAULT 0, |
| | | `notes` text DEFAULT NULL, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `referee_unique` (`referee_id`), |
| | | KEY `referrer_idx` (`referrer_id`), |
| | | KEY `status_idx` (`status`), |
| | | KEY `code_idx` (`referral_code`), |
| | | KEY `date_idx` (`referred_at`), |
| | | KEY `consult_idx` (`consulted_at`), |
| | | CONSTRAINT `{$this->base}referral_referrer_fk` FOREIGN KEY (`referrer_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}referral_referee_fk` FOREIGN KEY (`referee_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )"; |
| | | |
| | | // Create the main referrals table first |
| | | $this->createTables($mainTable); |
| | | |
| | | // Now create dependent tables |
| | | $dependentTables = []; |
| | | |
| | | // Second: jane_clients (depends only on wp_users) |
| | | $dependentTables['jane_clients'] = "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `patient_guid` varchar(50) NOT NULL, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `first_name` varchar(100) NOT NULL, |
| | | `last_name` varchar(100) NOT NULL, |
| | | `email` varchar(255) NOT NULL, |
| | | `imported_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | UNIQUE KEY `patient_guid_unique` (`patient_guid`), |
| | | KEY `user_idx` (`user_id`), |
| | | KEY `email_idx` (`email`), |
| | | CONSTRAINT `{$this->base}jane_client_user_fk` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )"; |
| | | |
| | | // Third: referral_treatments (depends on referrals AND wp_users) |
| | | $dependentTables['referral_treatments'] = "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `referral_id` bigint(20) unsigned NOT NULL, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `treatment_type` varchar(100) NOT NULL COMMENT 'Tier 1-6, Brows, etc', |
| | | `treatment_date` datetime NOT NULL, |
| | | `invoice_number` varchar(50) DEFAULT NULL, |
| | | `amount` decimal(10,2) DEFAULT NULL, |
| | | `status` enum('completed', 'no_show', 'cancelled') DEFAULT 'completed', |
| | | `imported_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | PRIMARY KEY (`id`), |
| | | KEY `referral_idx` (`referral_id`), |
| | | KEY `user_idx` (`user_id`), |
| | | KEY `date_idx` (`treatment_date`), |
| | | KEY `type_idx` (`treatment_type`), |
| | | CONSTRAINT `{$this->base}treatment_referral_fk` FOREIGN KEY (`referral_id`) |
| | | REFERENCES `{$this->prefixed}referrals` (`id`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}treatment_user_fk` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )"; |
| | | |
| | | // Fourth: referral_rewards (depends on referrals AND wp_users) |
| | | $dependentTables['referral_rewards'] = "( |
| | | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | `referral_id` bigint(20) unsigned NOT NULL, |
| | | `user_id` {$this->userIDType} NOT NULL, |
| | | `reward_type` enum('referrer', 'referee') NOT NULL, |
| | | `amount` decimal(10,2) NOT NULL, |
| | | `reward_calculation` varchar(20) DEFAULT NULL COMMENT 'percentage or fixed', |
| | | `status` enum('available', 'redeemed', 'expired', 'cancelled') DEFAULT 'available', |
| | | `created_at` datetime NOT NULL, |
| | | `redeemed_at` datetime DEFAULT NULL, |
| | | `expires_at` datetime DEFAULT NULL, |
| | | `notes` text DEFAULT NULL, |
| | | PRIMARY KEY (`id`), |
| | | KEY `referral_idx` (`referral_id`), |
| | | KEY `user_idx` (`user_id`), |
| | | KEY `status_idx` (`status`), |
| | | KEY `type_idx` (`reward_type`), |
| | | CONSTRAINT `{$this->base}reward_referral_fk` FOREIGN KEY (`referral_id`) |
| | | REFERENCES `{$this->prefixed}referrals` (`id`) ON DELETE CASCADE, |
| | | CONSTRAINT `{$this->base}reward_user_fk` FOREIGN KEY (`user_id`) |
| | | REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | )"; |
| | | |
| | | return $dependentTables; |
| | | } |
| | | // protected function referralTables(): array |
| | | // { |
| | | // // Create tables in dependency order |
| | | // // First: referrals (depends only on wp_users) |
| | | // $mainTable['referrals'] = "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `referrer_id` {$this->userIDType} NOT NULL, |
| | | // `referee_id` {$this->userIDType} NOT NULL, |
| | | // `referee_name` varchar(255) NOT NULL, |
| | | // `referee_email` varchar(255) NOT NULL, |
| | | // `referee_phone` varchar(50) DEFAULT NULL, |
| | | // `referral_code` varchar(50) NOT NULL, |
| | | // `status` enum('pending', 'consulted', 'treated', 'cancelled') DEFAULT 'pending', |
| | | // `referred_at` datetime NOT NULL, |
| | | // `consulted_at` datetime DEFAULT NULL, |
| | | // `treated_at` datetime DEFAULT NULL, |
| | | // `treatment_count` int DEFAULT 0, |
| | | // `notes` text DEFAULT NULL, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `referee_unique` (`referee_id`, `referral_code`), |
| | | // KEY `referrer_idx` (`referrer_id`), |
| | | // KEY `status_idx` (`status`), |
| | | // KEY `code_idx` (`referral_code`), |
| | | // KEY `date_idx` (`referred_at`), |
| | | // KEY `consult_idx` (`consulted_at`), |
| | | // CONSTRAINT `{$this->base}referral_referrer_fk` FOREIGN KEY (`referrer_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}referral_referee_fk` FOREIGN KEY (`referee_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | //)"; |
| | | // |
| | | // // Create the main referrals table first |
| | | // $this->createTables($mainTable); |
| | | // |
| | | // // Now create dependent tables |
| | | // $dependentTables = []; |
| | | // |
| | | // // Second: jane_clients (depends only on wp_users) |
| | | // $dependentTables['jane_clients'] = "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `patient_guid` varchar(50) NOT NULL, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `first_name` varchar(100) NOT NULL, |
| | | // `last_name` varchar(100) NOT NULL, |
| | | // `email` varchar(255) NOT NULL, |
| | | // `imported_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | // `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // UNIQUE KEY `patient_guid_unique` (`patient_guid`), |
| | | // KEY `user_idx` (`user_id`), |
| | | // KEY `email_idx` (`email`), |
| | | // CONSTRAINT `{$this->base}jane_client_user_fk` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | //)"; |
| | | // |
| | | // // Third: referral_treatments (depends on referrals AND wp_users) |
| | | // $dependentTables['referral_treatments'] = "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `referral_id` bigint(20) unsigned NOT NULL, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `treatment_type` varchar(100) NOT NULL COMMENT 'Tier 1-6, Brows, etc', |
| | | // `treatment_date` datetime NOT NULL, |
| | | // `invoice_number` varchar(50) DEFAULT NULL, |
| | | // `amount` decimal(10,2) DEFAULT NULL, |
| | | // `status` enum('completed', 'no_show', 'cancelled') DEFAULT 'completed', |
| | | // `imported_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| | | // PRIMARY KEY (`id`), |
| | | // KEY `referral_idx` (`referral_id`), |
| | | // KEY `user_idx` (`user_id`), |
| | | // KEY `date_idx` (`treatment_date`), |
| | | // KEY `type_idx` (`treatment_type`), |
| | | // CONSTRAINT `{$this->base}treatment_referral_fk` FOREIGN KEY (`referral_id`) |
| | | // REFERENCES `{$this->prefixed}referrals` (`id`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}treatment_user_fk` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | //)"; |
| | | // |
| | | // // Fourth: referral_rewards (depends on referrals AND wp_users) |
| | | // $dependentTables['referral_rewards'] = "( |
| | | // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| | | // `referral_id` bigint(20) unsigned NOT NULL, |
| | | // `user_id` {$this->userIDType} NOT NULL, |
| | | // `reward_type` enum('referrer', 'referee') NOT NULL, |
| | | // `amount` decimal(10,2) NOT NULL, |
| | | // `reward_calculation` varchar(20) DEFAULT NULL COMMENT 'percentage or fixed', |
| | | // `status` enum('available', 'redeemed', 'expired', 'cancelled') DEFAULT 'available', |
| | | // `created_at` datetime NOT NULL, |
| | | // `redeemed_at` datetime DEFAULT NULL, |
| | | // `expires_at` datetime DEFAULT NULL, |
| | | // `notes` text DEFAULT NULL, |
| | | // PRIMARY KEY (`id`), |
| | | // KEY `referral_idx` (`referral_id`), |
| | | // KEY `user_idx` (`user_id`), |
| | | // KEY `status_idx` (`status`), |
| | | // KEY `type_idx` (`reward_type`), |
| | | // CONSTRAINT `{$this->base}reward_referral_fk` FOREIGN KEY (`referral_id`) |
| | | // REFERENCES `{$this->prefixed}referrals` (`id`) ON DELETE CASCADE, |
| | | // CONSTRAINT `{$this->base}reward_user_fk` FOREIGN KEY (`user_id`) |
| | | // REFERENCES `{$this->userTable}` (`ID`) ON DELETE CASCADE |
| | | //)"; |
| | | // |
| | | // return $dependentTables; |
| | | // } |
| | | |
| | | /******************************************************************************************* |
| | | * These methods help create a content-type taxonomy, like the tattoo shops in edmonton.ink |