<commit_before>-- User
delimiter //
DROP TRIGGER IF EXISTS `userAfterInsert`//
CREATE TRIGGER `userAfterInsert` AFTER INSERT ON `user`
FOR EACH ROW
BEGIN
    -- ROLE PLAYER
    INSERT INTO user_group (userId, groupId) VALUE (NEW.id, 2);
    -- Player
    INSERT INTO vgr_player (id, pseudo, normandie_user_id, slug) values (NEW.id, NEW.username, NEW.id, NEW.slug);
END //
delimiter ;

delimiter //
DROP TRIGGER IF EXISTS `userAfterUpdate`//
CREATE TRIGGER `userAfterUpdate` AFTER UPDATE ON `user`
FOR EACH ROW
BEGIN
    -- Player
    UPDATE vgr_player
    SET
        pseudo = NEW.username,
        avatar = NEW.avatar
    WHERE normandie_user_id = NEW.id;
END //
delimiter ;


-- PlayerChart
delimiter //
DROP TRIGGER IF EXISTS `vgrPlayerChartAfterInsert`//
CREATE TRIGGER `vgrPlayerChartAfterInsert` AFTER INSERT ON `vgr_player_chart`
FOR EACH ROW
BEGIN
    UPDATE vgr_chart
	  SET nbPost = (SELECT COUNT(idPlayer) FROM vgr_player_chart WHERE idChart = NEW.idChart AND idStatus != 7),
		statusPlayer = 'MAJ',
		statusTeam = 'MAJ'
	WHERE id = NEW.idChart;
	UPDATE vgr_player
	SET nbChart = (SELECT COUNT(idChart) FROM vgr_player_chart WHERE idPlayer = NEW.idPlayer)
	WHERE id = NEW.idPlayer;
END //
delimiter ;


delimiter //
DROP TRIGGER IF EXISTS `vgrChartPlayerAfterUpdate`//
CREATE TRIGGER vgrChartPlayerAfterUpdate AFTER UPDATE ON vgr_player_chart
FOR EACH ROW
BEGIN
	DECLARE done INT DEFAULT FALSE;
	DECLARE chartlib_id_src INT;
	DECLARE chartlib_id_dest INT;
	DECLARE cur1 CURSOR FOR SELECT idLibChart FROM vgr_chartlib WHERE idChart = OLD.idChart ORDER BY idLibChart ASC;
	DECLARE cur2 CURSOR FOR SELECT idLibChart FROM vgr_chartlib WHERE idChart = NEW.idChart ORDER BY idLibChart ASC;

	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

	IF OLD.lastUpdate != NEW.lastUpdate THEN
		UPDATE vgr_chart
	    SET statusPlayer = 'MAJ',
	        statusTeam = 'MAJ'
	    WHERE id = OLD.idChart;
	END IF;
	IF (OLD.idStatus != NEW.idStatus AND (NEW.idStatus != 2 OR NEW.idStatus != 5)) THEN
		UPDATE vgr_chart
	    SET statusPlayer = 'MAJ'
	    WHERE id = OLD.idChart;
	END IF;
	IF (OLD.idStatus != NEW.idStatus AND (OLD.idStatus = 7 OR NEW.idStatus = 7) ) THEN
		UPDATE vgr_chart
		SET nbPost = (SELECT COUNT(idPlayer) FROM vgr_player_chart WHERE idChart = OLD.idChart AND idStatus != 7)
		WHERE id = OLD.idChart;
	END IF;

	-- MOVE SCORE
	IF OLD.idChart != NEW.idChart THEN

		open cur1;
		open cur2;

		read_loop: LOOP
			FETCH cur1 INTO chartlib_id_src;
			IF done THEN
				LEAVE read_loop;
			END IF;
			FETCH cur2 INTO chartlib_id_dest;

			UPDATE vgr_player_chartlib SET idLibChart = chartlib_id_dest WHERE idLibChart = chartlib_id_src AND idPlayerChart = NEW.id;<commit_msg>Chart to MAJ if change platform<commit_after>-- User
delimiter //
DROP TRIGGER IF EXISTS `userAfterInsert`//
CREATE TRIGGER `userAfterInsert` AFTER INSERT ON `user`
FOR EACH ROW
BEGIN
    -- ROLE PLAYER
    INSERT INTO user_group (userId, groupId) VALUE (NEW.id, 2);
    -- Player
    INSERT INTO vgr_player (id, pseudo, normandie_user_id, slug) values (NEW.id, NEW.username, NEW.id, NEW.slug);
END //
delimiter ;

delimiter //
DROP TRIGGER IF EXISTS `userAfterUpdate`//
CREATE TRIGGER `userAfterUpdate` AFTER UPDATE ON `user`
FOR EACH ROW
BEGIN
    -- Player
    UPDATE vgr_player
    SET
        pseudo = NEW.username,
        avatar = NEW.avatar
    WHERE normandie_user_id = NEW.id;
END //
delimiter ;


-- PlayerChart
delimiter //
DROP TRIGGER IF EXISTS `vgrPlayerChartAfterInsert`//
CREATE TRIGGER `vgrPlayerChartAfterInsert` AFTER INSERT ON `vgr_player_chart`
FOR EACH ROW
BEGIN
    UPDATE vgr_chart
	  SET nbPost = (SELECT COUNT(idPlayer) FROM vgr_player_chart WHERE idChart = NEW.idChart AND idStatus != 7),
		statusPlayer = 'MAJ',
		statusTeam = 'MAJ'
	WHERE id = NEW.idChart;
	UPDATE vgr_player
	SET nbChart = (SELECT COUNT(idChart) FROM vgr_player_chart WHERE idPlayer = NEW.idPlayer)
	WHERE id = NEW.idPlayer;
END //
delimiter ;


delimiter //
DROP TRIGGER IF EXISTS `vgrChartPlayerAfterUpdate`//
CREATE TRIGGER vgrChartPlayerAfterUpdate AFTER UPDATE ON vgr_player_chart
FOR EACH ROW
BEGIN
	DECLARE done INT DEFAULT FALSE;
	DECLARE chartlib_id_src INT;
	DECLARE chartlib_id_dest INT;
	DECLARE cur1 CURSOR FOR SELECT idLibChart FROM vgr_chartlib WHERE idChart = OLD.idChart ORDER BY idLibChart ASC;
	DECLARE cur2 CURSOR FOR SELECT idLibChart FROM vgr_chartlib WHERE idChart = NEW.idChart ORDER BY idLibChart ASC;

	DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

	IF ((OLD.lastUpdate != NEW.lastUpdate) OR (OLD.idPlatform != NEW.idPlatform)) THEN
		UPDATE vgr_chart
	    SET statusPlayer = 'MAJ',
	        statusTeam = 'MAJ'
	    WHERE id = OLD.idChart;
	END IF;
	IF (OLD.idStatus != NEW.idStatus AND (NEW.idStatus != 2 OR NEW.idStatus != 5)) THEN
		UPDATE vgr_chart
	    SET statusPlayer = 'MAJ'
	    WHERE id = OLD.idChart;
	END IF;
	IF (OLD.idStatus != NEW.idStatus AND (OLD.idStatus = 7 OR NEW.idStatus = 7) ) THEN
		UPDATE vgr_chart
		SET nbPost = (SELECT COUNT(idPlayer) FROM vgr_player_chart WHERE idChart = OLD.idChart AND idStatus != 7)
		WHERE id = OLD.idChart;
	END IF;

	-- MOVE SCORE
	IF OLD.idChart != NEW.idChart THEN

		open cur1;
		open cur2;

		read_loop: LOOP
			FETCH cur1 INTO chartlib_id_src;
			IF done THEN
				LEAVE read_loop;
			END IF;
			FETCH cur2 INTO chartlib_id_dest;

			UPDATE vgr_player_chartlib SET idLibChart = chartlib_id_dest WHERE idLibChart = chartlib_id_src AND idPlayerChart = NEW.id;
{'fraction_non_alphanumeric': 0.07873436350257543, 'fraction_numerical': 0.004782928623988227, 'mean_word_length': 3.7526223776223775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1060277', 'n_tokens_mistral': 2074, 'n_tokens_neox': 1862, 'n_words': 605}