'training_new_member', 'name' => 'Szkolenie nowego członka', 'subject_scope' => 'person', 'version' => 1, 'is_latest' => 1, 'is_active' => 1, 'sort_order' => 40, 'start_node_id' => 'tracker', 'definition_json' => '{ "start_node_id": "tracker", "nodes": { "tracker": { "id": "tracker", "name": "Tracker szkoleń", "ui_hints": { "title": "Szkolenia dla młodego członka", "status": "in_progress", "reason": "Oczekiwanie na ukończenie wszystkich szkoleń", "next_step": "Zaktualizuj status", "form_schema": [ { "name": "w1", "label": "W1", "type": "checkbox" }, { "name": "w2", "label": "W2", "type": "checkbox" }, { "name": "w3", "label": "W3", "type": "checkbox" }, { "name": "w4", "label": "W4", "type": "checkbox" }, { "name": "w5", "label": "W5", "type": "checkbox" }, { "name": "w6", "label": "W6", "type": "checkbox" }, { "name": "msp", "label": "MSP", "type": "checkbox" }, { "name": "ltt", "label": "LTT", "type": "checkbox" } ] } }, "completed": { "id": "completed", "name": "Zakończony", "ui_hints": { "title": "Wszystkie szkolenia ukończone", "status": "positive", "reason": "Wszystkie szkolenia zostały ukończone", "next_step": "Zaktualizuj status", "form_schema": [ { "name": "w1", "label": "W1", "type": "checkbox" }, { "name": "w2", "label": "W2", "type": "checkbox" }, { "name": "w3", "label": "W3", "type": "checkbox" }, { "name": "w4", "label": "W4", "type": "checkbox" }, { "name": "w5", "label": "W5", "type": "checkbox" }, { "name": "w6", "label": "W6", "type": "checkbox" }, { "name": "msp", "label": "MSP", "type": "checkbox" }, { "name": "ltt", "label": "LTT", "type": "checkbox" } ] } } }, "transitions": [ { "id": "update_tracker", "name": "Zapisz zmiany", "from": "tracker", "to": "tracker", "actions": [ { "type": "set_data", "params": { "keys": [ "w1", "w2", "w3", "w4", "w5", "w6", "msp", "ltt" ] } } ] }, { "id": "auto_complete", "name": "Automatyczne zakończenie", "from": "tracker", "to": "completed", "condition": { "type": "all_true", "fields": [ "w1", "w2", "w3", "w4", "w5", "w6", "msp", "ltt" ] } }, { "id": "update_completed", "name": "Zapisz zmiany", "from": "completed", "to": "tracker", "actions": [ { "type": "set_data", "params": { "keys": [ "w1", "w2", "w3", "w4", "w5", "w6", "msp", "ltt" ] } } ] } ]' ], [ 'code' => 'customer_journey', 'name' => 'Członkostwo', 'subject_scope' => 'person', 'version' => 1, 'is_latest' => 1, 'is_active' => 1, 'sort_order' => 50, 'start_node_id' => 'survey_3m', 'definition_json' => '{ "start_node_id": "survey_3m", "initial_data": { "cycle_year": 1 }, "nodes": { "survey_3m": { "name": "Ankieta 3 miesiąca", "type": "user_task", "ui_hints": { "title": "Ankieta 3 miesiąca", "status": "in_progress", "reason": "Oczekuje na ankietę po 3 miesiącach", "next_step": "Wypełnij ankietę", "form_schema": [ { "name": "survey_3m_done_at", "type": "date", "label": "Data wykonania", "required": true, "default": "now" }, { "name": "note", "type": "text", "label": "Notatka" } ] } }, "survey_7m": { "name": "Ankieta 7 miesiąca", "type": "user_task", "ui_hints": { "title": "Ankieta 7 miesiąca", "status": "in_progress", "reason": "Oczekuje na ankietę po 7 miesiącach", "next_step": "Wypełnij ankietę", "form_schema": [ { "name": "survey_7m_done_at", "type": "date", "label": "Data wykonania", "required": true, "default": "now" }, { "name": "note", "type": "text", "label": "Notatka" } ] } }, "payment": { "name": "Wpłata", "type": "user_task", "ui_hints": { "title": "Wpłata", "status": "in_progress", "reason": "Oczekuje na wpłatę", "next_step": "Zaksięguj wpłatę", "form_schema": [ { "name": "payment_done_at", "type": "date", "label": "Data wpłaty", "required": true, "default": "now" }, { "name": "note", "type": "text", "label": "Notatka" } ] } }, "committee": { "name": "Komitet", "type": "user_task", "ui_hints": { "title": "Komitet", "status": "in_progress", "reason": "Decyzja komitetu", "next_step": "Wprowadź decyzję", "form_schema": [ { "name": "committee_decision", "type": "select", "label": "Decyzja", "options": [ { "value": "approved", "label": "Zatwierdzony" }, { "value": "rejected", "label": "Odrzucony" }, { "value": "pending", "label": "Oczekujący" } ], "required": true }, { "name": "note", "type": "text", "label": "Notatka" } ] } }, "renewal": { "name": "Przedłużenie członkostwa", "type": "user_task", "ui_hints": { "title": "Przedłużenie członkostwa", "status": "in_progress", "reason": "Oczekuje na przedłużenie", "next_step": "Przedłuż na kolejny rok", "form_schema": [ { "name": "renewal_done_at", "type": "date", "label": "Data przedłużenia", "required": true, "default": "now" }, { "name": "note", "type": "text", "label": "Notatka" } ] } } }, "transitions": [ { "id": "finish_survey_3m", "name": "Zakończ ankietę (3m)", "from": "survey_3m", "to": "survey_7m", "actions": [ { "type": "set_data", "params": { "keys": [ "survey_3m_done_at", "note" ] } } ] }, { "id": "finish_survey_7m", "name": "Zakończ ankietę (7m)", "from": "survey_7m", "to": "payment", "actions": [ { "type": "set_data", "params": { "keys": [ "survey_7m_done_at", "note" ] } } ] }, { "id": "finish_payment", "name": "Potwierdź wpłatę", "from": "payment", "to": "committee", "actions": [ { "type": "set_data", "params": { "keys": [ "payment_done_at", "note" ] } } ] }, { "id": "finish_committee", "name": "Wprowadź decyzję komitetu", "from": "committee", "to": "renewal", "actions": [ { "type": "set_data", "params": { "keys": [ "committee_decision", "note" ] } } ] }, { "id": "finish_renewal", "name": "Zamknij cykl i rozpocznij kolejny rok", "from": "renewal", "to": "survey_3m", "actions": [ { "type": "set_data", "params": { "keys": [ "renewal_done_at", "note" ] } }, { "type": "increment_data", "params": { "key": "cycle_year", "by": 1 } }, { "type": "reset_data", "params": { "keys": [ "survey_3m_done_at", "survey_7m_done_at", "payment_done_at", "committee_decision", "renewal_done_at" ] } } ] } ]' ] ]; try { $checkStmt = $pdo->prepare("SELECT COUNT(*) FROM process_definitions WHERE code = :code"); $insertStmt = $pdo->prepare("INSERT INTO process_definitions (code, name, subject_scope, version, is_latest, is_active, sort_order, start_node_id, definition_json) VALUES (:code, :name, :subject_scope, :version, :is_latest, :is_active, :sort_order, :start_node_id, :definition_json)"); foreach ($processes as $p) { $checkStmt->execute(['code' => $p['code']]); $exists = $checkStmt->fetchColumn() > 0; if (!$exists) { $insertStmt->execute([ 'code' => $p['code'], 'name' => $p['name'], 'subject_scope' => $p['subject_scope'], 'version' => $p['version'], 'is_latest' => $p['is_latest'], 'is_active' => $p['is_active'], 'sort_order' => $p['sort_order'], 'start_node_id' => $p['start_node_id'], 'definition_json' => $p['definition_json'] ]); } } echo "Migration 040 successful: Missing process definitions inserted.\n"; } catch (PDOException $e) { die("Migration 040 failed: " . $e->getMessage() . "\n"); } } // For manual execution if needed if (basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])) { migrate_040(db()); }