Page MenuHomePhabricator
Paste P8059

Actor table triggers for T215445
ActivePublic

Authored by Anomie on Feb 6 2019, 8:12 PM.
delimiter //
CREATE FUNCTION wmcsActorShow(id BIGINT) RETURNS INT NOT DETERMINISTIC READS SQL DATA
BEGIN
RETURN COALESCE(
( SELECT 1 FROM actor JOIN user ON(actor_user=user_id) WHERE actor_id = id LIMIT 1 ) OR
( SELECT 1 FROM archive WHERE ar_actor = id AND ar_deleted&4 = 0 LIMIT 1 ) OR
( SELECT 1 FROM ipblocks WHERE ipb_by_actor = id and ipb_deleted = 0 LIMIT 1 ) OR
( SELECT 1 FROM image WHERE img_actor = id LIMIT 1 ) OR
( SELECT 1 FROM oldimage WHERE oi_actor = id AND oi_deleted&4 = 0 LIMIT 1 ) OR
( SELECT 1 FROM filearchive WHERE fa_actor = id AND fa_deleted&4 = 0 LIMIT 1 ) OR
( SELECT 1 FROM recentchanges WHERE rc_actor = id AND rc_deleted&4 = 0 LIMIT 1 ) OR
( SELECT 1 FROM logging WHERE log_actor = id AND log_deleted&4 = 0 AND log_type IN ($LOG_TYPE_LIST$) LIMIT 1 ) OR
( SELECT 1 FROM revision JOIN revision_actor_temp ON(revactor_rev = rev_id) WHERE revactor_actor = id AND rev_deleted&4 = 0 LIMIT 1 )
, 0);
END //
delimiter ;
delimiter //
CREATE PROCEDURE wmcsActorOnInsert(id BIGINT, del TINYINT) NOT DETERMINISTIC MODIFIES SQL DATA
BEGIN
IF NOT del THEN
UPDATE actor SET wmcs_is_visible = 1 WHERE actor_id = id;
END IF;
END //
delimiter ;
delimiter //
CREATE PROCEDURE wmcsActorOnDelete(id BIGINT, del TINYINT) NOT DETERMINISTIC MODIFIES SQL DATA
BEGIN
IF NOT del AND NOT wmcsActorShow(id) THEN
UPDATE actor SET wmcs_is_visible = 0 WHERE actor_id = id;
END IF;
END //
delimiter ;
delimiter //
CREATE PROCEDURE wmcsActorOnUpdate(oldId BIGINT, oldDel TINYINT, newId BIGINT, newDel TINYINT) NOT DETERMINISTIC MODIFIES SQL DATA
BEGIN
IF oldId != newId OR (NOT oldDel) != (NOT newDel) THEN
CALL wmcsActorOnDelete(oldId, oldDel);
CALL wmcsActorOnInsert(newId, newDel);
END IF;
END //
delimiter ;
CREATE TRIGGER archive_wmcsActorOnInsert AFTER INSERT ON archive
FOR EACH ROW CALL wmcsActorOnInsert( NEW.ar_actor, NEW.ar_deleted&4 );
CREATE TRIGGER archive_wmcsActorOnUpdate AFTER UPDATE ON archive
FOR EACH ROW CALL wmcsActorOnUpdate( OLD.ar_actor, OLD.ar_deleted&4, NEW.ar_actor, NEW.ar_deleted&4 );
CREATE TRIGGER archive_wmcsActorOnDelete AFTER DELETE ON archive
FOR EACH ROW CALL wmcsActorOnDelete( OLD.ar_actor, OLD.ar_deleted&4 );
CREATE TRIGGER ipblocks_wmcsActorOnInsert AFTER INSERT ON ipblocks
FOR EACH ROW CALL wmcsActorOnInsert( NEW.ipb_by_actor, NEW.ipb_deleted );
CREATE TRIGGER ipblocks_wmcsActorOnUpdate AFTER UPDATE ON ipblocks
FOR EACH ROW CALL wmcsActorOnUpdate( OLD.ipb_by_actor, OLD.ipb_deleted, NEW.ipb_by_actor, NEW.ipb_deleted );
CREATE TRIGGER ipblocks_wmcsActorOnDelete AFTER DELETE ON ipblocks
FOR EACH ROW CALL wmcsActorOnDelete( OLD.ipb_by_actor, OLD.ipb_deleted );
CREATE TRIGGER image_wmcsActorOnInsert AFTER INSERT ON image
FOR EACH ROW CALL wmcsActorOnInsert( NEW.img_actor, 0 );
CREATE TRIGGER image_wmcsActorOnUpdate AFTER UPDATE ON image
FOR EACH ROW CALL wmcsActorOnUpdate( OLD.img_actor, 0, NEW.img_actor, 0 );
CREATE TRIGGER image_wmcsActorOnDelete AFTER DELETE ON image
FOR EACH ROW CALL wmcsActorOnDelete( OLD.img_actor, 0 );
CREATE TRIGGER oldimage_wmcsActorOnInsert AFTER INSERT ON oldimage
FOR EACH ROW CALL wmcsActorOnInsert( NEW.oi_actor, NEW.oi_deleted&4 );
CREATE TRIGGER oldimage_wmcsActorOnUpdate AFTER UPDATE ON oldimage
FOR EACH ROW CALL wmcsActorOnUpdate( OLD.oi_actor, OLD.oi_deleted&4, NEW.oi_actor, NEW.oi_deleted&4 );
CREATE TRIGGER oldimage_wmcsActorOnDelete AFTER DELETE ON oldimage
FOR EACH ROW CALL wmcsActorOnDelete( OLD.oi_actor, OLD.oi_deleted&4 );
CREATE TRIGGER filearchive_wmcsActorOnInsert AFTER INSERT ON filearchive
FOR EACH ROW CALL wmcsActorOnInsert( NEW.fa_actor, NEW.fa_deleted&4 );
CREATE TRIGGER filearchive_wmcsActorOnUpdate AFTER UPDATE ON filearchive
FOR EACH ROW CALL wmcsActorOnUpdate( OLD.fa_actor, OLD.fa_deleted&4, NEW.fa_actor, NEW.fa_deleted&4 );
CREATE TRIGGER filearchive_wmcsActorOnDelete AFTER DELETE ON filearchive
FOR EACH ROW CALL wmcsActorOnDelete( OLD.fa_actor, OLD.fa_deleted&4 );
CREATE TRIGGER recentchanges_wmcsActorOnInsert AFTER INSERT ON recentchanges
FOR EACH ROW CALL wmcsActorOnInsert( NEW.rc_actor, NEW.rc_deleted&4 );
CREATE TRIGGER recentchanges_wmcsActorOnUpdate AFTER UPDATE ON recentchanges
FOR EACH ROW CALL wmcsActorOnUpdate( OLD.rc_actor, OLD.rc_deleted&4, NEW.rc_actor, NEW.rc_deleted&4 );
CREATE TRIGGER recentchanges_wmcsActorOnDelete AFTER DELETE ON recentchanges
FOR EACH ROW CALL wmcsActorOnDelete( OLD.rc_actor, OLD.rc_deleted&4 );
CREATE TRIGGER logging_wmcsActorOnInsert AFTER INSERT ON logging
FOR EACH ROW CALL wmcsActorOnInsert( NEW.log_actor, NOT ( NEW.log_deleted&4 = 0 AND NEW.log_type IN ($LOG_TYPE_LIST$) ) );
CREATE TRIGGER logging_wmcsActorOnUpdate AFTER UPDATE ON logging
FOR EACH ROW CALL wmcsActorOnUpdate( OLD.log_actor, NOT ( OLD.log_deleted&4 = 0 AND OLD.log_type IN ($LOG_TYPE_LIST$) ), NEW.log_actor, NOT ( NEW.log_deleted&4 = 0 AND NEW.log_type IN ($LOG_TYPE_LIST$) ) );
CREATE TRIGGER logging_wmcsActorOnDelete AFTER DELETE ON logging
FOR EACH ROW CALL wmcsActorOnDelete( OLD.log_actor, NOT ( OLD.log_deleted&4 = 0 AND OLD.log_type IN ($LOG_TYPE_LIST$) ) );
CREATE TRIGGER revision_actor_temp_wmcsActorOnInsert AFTER INSERT ON revision_actor_temp
FOR EACH ROW CALL wmcsActorOnInsert( NEW.revactor_actor, (SELECT rev_deleted&4 FROM revision WHERE rev_id=NEW.revactor_rev) );
CREATE TRIGGER revision_actor_temp_wmcsActorOnUpdate AFTER UPDATE ON revision_actor_temp
FOR EACH ROW CALL wmcsActorOnUpdate( OLD.revactor_actor, (SELECT rev_deleted&4 FROM revision WHERE rev_id=OLD.revactor_rev), NEW.revactor_actor, (SELECT rev_deleted&4 FROM revision WHERE rev_id=NEW.revactor_rev) );
CREATE TRIGGER revision_actor_temp_wmcsActorOnDelete AFTER DELETE ON revision_actor_temp
FOR EACH ROW CALL wmcsActorOnDelete( OLD.revactor_actor, (SELECT rev_deleted&4 FROM revision WHERE rev_id=OLD.revactor_rev) );
CREATE TRIGGER revision_wmcsActorOnInsert AFTER INSERT ON revision
FOR EACH ROW CALL wmcsActorOnInsert( (SELECT revactor_actor FROM revision_actor_temp WHERE revactor_rev=NEW.rev_id), NEW.rev_deleted&4 );
CREATE TRIGGER revision_wmcsActorOnUpdate AFTER UPDATE ON revision
FOR EACH ROW CALL wmcsActorOnUpdate( (SELECT revactor_actor FROM revision_actor_temp WHERE revactor_rev=OLD.rev_id), OLD.rev_deleted&4, (SELECT revactor_actor FROM revision_actor_temp WHERE revactor_rev=NEW.rev_id), NEW.rev_deleted&4 );
CREATE TRIGGER revision_wmcsActorOnDelete AFTER DELETE ON revision
FOR EACH ROW CALL wmcsActorOnDelete( (SELECT revactor_actor FROM revision_actor_temp WHERE revactor_rev=OLD.rev_id), OLD.rev_deleted&4 );

Event Timeline

Anomie created this paste.Feb 6 2019, 8:12 PM
Anomie edited the content of this paste. (Show Details)
Anomie edited the content of this paste. (Show Details)Feb 6 2019, 8:15 PM