From a229b73118884438c2bea07e733697587800759a Mon Sep 17 00:00:00 2001 From: Schneider Roland Date: Wed, 28 Sep 2022 22:16:22 +0200 Subject: [PATCH] add version condition to trigger --- .../m220928_165551_update_trigger.php | 217 ++++++++++++++++++ docker/fitness/docker-compose.yml | 2 + 2 files changed, 219 insertions(+) create mode 100644 console/migrations/m220928_165551_update_trigger.php diff --git a/console/migrations/m220928_165551_update_trigger.php b/console/migrations/m220928_165551_update_trigger.php new file mode 100644 index 0000000..13be830 --- /dev/null +++ b/console/migrations/m220928_165551_update_trigger.php @@ -0,0 +1,217 @@ += CURDATE() + and id_ticket_current = New.id_ticket_current + and (direction = 7 or direction = 3); + INSERT INTO devlog (msg) values (concat('count all', @p_count_all)); + + + IF @p_count_all = 1 + THEN + + select usage_count, max_usage_count + into @p_usage_count ,@p_max_usage_count + from ticket + where id_ticket = NEW.id_ticket_current; + + + update ticket set usage_count = usage_count + 1 where id_ticket = NEW.id_ticket_current; + + + INSERT INTO log (type, message, app, id_ticket, id_door_log, created_at, updated_at) + values (30, concat('Bérlet használat (elotte: ', @p_usage_count, ' > utana: ', @p_usage_count + 1, + ' max: ', @p_max_usage_count, ')'), ' trigger_inc_ticket', New.id_ticket_current, + New.id_door_log, now(), now()); + else + + select min(created_at) + + INTERVAL (3 * FLOOR(((HOUR(TIMEDIFF(min(created_at), now())) / 3)))) hour as last_date + into @p_from + from door_log + where created_at > CURDATE() + and id_customer is not null + and id_ticket_current = NEW.id_ticket_current + and (direction = 7 or direction = 3); + + + select count(*) + into @p_count_all_2 + from door_log + where created_at >= @p_from + and id_ticket_current = New.id_ticket_current + and (direction = 7 or direction = 3); + + INSERT INTO devlog (msg) + values (CONCAT('Belépések száma az aktuális 3 órás intervalumban: ', @p_count_all_2)); + + + IF @p_count_all_2 = 1 + THEN + INSERT INTO devlog (msg) + values ('Az aktuális intervallumban ez az első belépés, usage_count növelése'); + + select usage_count, max_usage_count + into @p_usage_count ,@p_max_usage_count + from ticket + where id_ticket = NEW.id_ticket_current; + + update ticket set usage_count = usage_count + 1 where id_ticket = New.id_ticket_current; + + INSERT INTO log (type, message, app, id_ticket, id_door_log, created_at, updated_at) + values (40, concat('Bérlet használat/egy nap tobbszori (elotte: ', @p_usage_count, ' > utana: ', + @p_usage_count + 1, ' max: ', @p_max_usage_count, ')'), + ' trigger_inc_ticket', New.id_ticket_current, New.id_door_log, now(), now()); + END IF; + END IF; + End IF; + + + IF NEW.direction = 5 or New.direction = 1 + then + INSERT INTO devlog (msg) values ('Kilépés van folyamatban, kilépések számának beállítása'); + update ticket set count_move_out = usage_count where id_ticket = NEW.id_ticket_current; + END IF; + + INSERT INTO devlog (msg) values ('Kártya validáció módosítása'); + + UPDATE card as c1 + left JOIN (select ticket.id_card as id_card, max(ticket.id_ticket) as id_ticket + from ticket + where ticket.start <= CURDATE() + and ticket.end >= curdate() + and ticket.status = 10 + and ticket.count_move_out < ticket.max_usage_count + and ticket.id_card = New.id_card + group by id_card + order by id_card desc) as t + on t.id_card = c1.id_card + SET c1.validity = case + when t.id_card is null then (c1.validity | 1 << 0) + else (c1.validity & ~(1 << 0)) end + , c1.flag = case + when t.id_card is null then (c1.flag | 1 << 0) + else (c1.flag & ~(1 << 0)) end + , c1.id_ticket_current = case when t.id_ticket is null then null else t.id_ticket end + WHERE c1.type <> 50 + and c1.id_card = New.id_card; + + + IF NEW.direction = 5 or New.direction = 1 + then + + + select max(ticket.id_ticket) + into @p_mo_ticket_id + from ticket + where ticket.start <= CURDATE() + and ticket.end >= curdate() + and ticket.status = 10 + and ticket.count_move_out < ticket.max_usage_count + and ticket.id_card = New.id_card + group by id_card + order by id_card desc; + + + set @p_allow_enter = true; + + + update card + set flag_out = (flag_out | 1 << 1), + flag = case when @p_allow_enter then (flag & ~(1 << 1)) else (flag | 1 << 1) end + WHERE type <> 50 + and id_card = New.id_card; + + END IF; + + + IF (NEW.direction = 7 or New.direction = 3) and NEW.id_ticket_current is not null + THEN + + update card + set flag_out = (flag_out & ~(1 << 1)), + flag = (flag | 1 << 1) + WHERE type <> 50 + and id_card = New.id_card; + END IF; + + END IF; + END IF; +END + "; + $this->execute($sql); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + echo "m220928_165551_update_trigger cannot be reverted.\n"; + + return true; + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m220928_165551_update_trigger cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/docker/fitness/docker-compose.yml b/docker/fitness/docker-compose.yml index 9c9e98f..337b4e2 100644 --- a/docker/fitness/docker-compose.yml +++ b/docker/fitness/docker-compose.yml @@ -33,6 +33,8 @@ services: MYSQL_DATABASE: cutler_prod2 MYSQL_USER: cutler_prod MYSQL_PASSWORD: cutler_prod + ports: + - "42003:3306" cutlermail: image: reachfive/fake-smtp-server