-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwp_post_script.sql
More file actions
56 lines (45 loc) · 2.36 KB
/
Copy pathwp_post_script.sql
File metadata and controls
56 lines (45 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
CREATE TABLE `post_changes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`stamp` char(12) COLLATE utf8mb4_unicode_ci NOT NULL,
`post_id` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`activity` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'changed',
`post_type` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`post_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`post_title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`last_edited` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
###################TRIGGERS#########################
####################DELETE##########################
CREATE TRIGGER `after_wp_posts_delete` AFTER DELETE ON `wp_posts`
FOR EACH ROW BEGIN
set @current_time=now();
INSERT IGNORE INTO data_changes.post_changes(stamp,post_id,activity,post_type,post_name,post_title,last_edited)
select
concat( date_format(@current_time,'%Y%m%d%H'),IF(date_format(@current_time,'%i')>30, '30', '00')),
OLD.id,'changed','post',OLD.post_name,OLD.post_title,meta_value as last_edited
FROM wp_posts join wp_postmeta as pm on OLD.id = pm.post_id
WHERE meta_key = '_edit_last' and id=OLD.id;
END
####################INSERT##########################
CREATE TRIGGER `after_wp_posts_insert` AFTER INSERT ON `wp_posts`
FOR EACH ROW BEGIN
set @current_time=now();
INSERT IGNORE INTO data_changes.post_changes(stamp,post_id,activity,post_type,post_name,post_title,last_edited)
select
concat( date_format(@current_time,'%Y%m%d%H'),IF(date_format(@current_time,'%i')>30, '30', '00')),
NEW.id,'changed', 'post',NEW.post_name,NEW.post_title,meta_value as last_edited
FROM wp_posts join wp_postmeta as pm on NEW.id = pm.post_id AND post_id = NEW.id
WHERE meta_key = '_edit_last' and id=NEW.id;
END
####################UPDATE##########################
CREATE TRIGGER `after_wp_posts_update` AFTER UPDATE ON `wp_posts`
FOR EACH ROW Begin
set @current_time=now();
INSERT IGNORE INTO data_changes.post_changes(stamp,post_id,activity,post_type,post_name,post_title,last_edited)
select
concat( date_format(@current_time,'%Y%m%d%H'),IF(date_format(@current_time,'%i')>30, '30', '00')),
NEW.id,'changed', 'post',NEW.post_name,NEW.post_title,meta_value as last_edited
FROM wp_posts join wp_postmeta as pm on NEW.id = pm.post_id AND post_id = NEW.id
WHERE meta_key = '_edit_last' and id=NEW.id;
End