<?php

define(
'BASE_PATH',
realpath(__DIR__.'/../..')
);

require_once BASE_PATH.'/config/autoload.php';
require_once BASE_PATH.'/config/bootstrap.php';

$db=\App\Core\Database::getInstance();

echo "EXECUTION ACTIONS\n";

$db->exec(
"TRUNCATE TABLE execution_actions"
);

$rows=
$db->query("
SELECT
oaa.*,
aro.action_type
FROM orchestration_action_approvals oaa
LEFT JOIN autonomous_review_orchestration aro
ON aro.id=oaa.orchestration_id
WHERE oaa.approval_status='approved'
")->fetchAll(PDO::FETCH_ASSOC);

foreach($rows as $r){

    $db->prepare("
    INSERT INTO execution_actions
    (
        approval_id,
        conference_id,
        action_type
    )
    VALUES
    (
        ?,?,?
    )
    ")->execute([
        $r['id'],
        $r['conference_id'],
        $r['action_type']
    ]);

}

echo "DONE\n";
