<?php

require_once './bootstrapMigration.php';

$instanceManager = \Zeedhi\Framework\DependencyInjection\InstanceManager::getInstance();
/** @var \Teknisa\Libs\Service\Migration $migrationService */
$migrationService = $instanceManager->getService('migrationService');

/**
 * $argv[0] => Current file name: "saveLastMigration.php"
 * $argv[1] => Object name of VERSAOOBJETO table. In CP, is Repository URL
 * $argv[2] => File name to update last applied migration
 * $argv[3] => File name of the last applied migration
 * $argv[4] => Organization ID
 * $argv[5] => Operator code
 * $argv[6] => Pendent files
 */

if($argv[3] == 'null') {
    $argv[3] = null;
}

if(!isset($argv[6])) {
    $argv[6] = '[]';
}

$scriptOutput = $migrationService->saveLastSuccessMigration($argv[1], $argv[2], $argv[3], $argv[4], $argv[5], $argv[6]);
echo json_encode($scriptOutput);