/** * Adds a syncronization attempt tag into the item data array. * * @param Array $item_data * See scan_dados_item_data(). * * @param Bool $action * Which action has been performed. CREATE/UPDATE or FAIL. * * @param String $service * The service name. */ private function set_sync_attempt_tag(&$item_data, $action, $service = 'produto') { $prime_id_field = $this->config['servicos'][$service]['prime_id_field']; switch ($action) { case nx::SYNC_TAG_ACTION_CREATE: $prime_id_field_value = $item_data[$prime_id_field]; $msg = "Item {$prime_id_field}={$prime_id_field_value} foi CRIADO com sucesso no servico {$service}."; tools::print_green($msg); break; case nx::SYNC_TAG_ACTION_UPDATE: $prime_id_field_value = $item_data[$prime_id_field]; $msg = "Item {$prime_id_field}={$prime_id_field_value} foi ATUALIZADO com sucesso no servico {$service}."; tools::print_green($msg); break; case nx::SYNC_TAG_ACTION_ITEM_DATA_EMPTY: $msg = "O arquivo dados estava vazio."; tools::print_yellow($msg); break; case nx::SYNC_TAG_ACTION_FAIL: $msg = "A sincronizacao falhou."; tools::print_yellow($msg); break; default: $msg = "O valor do parametro \$action eh invalido. Entre em contado com a NortaoX."; $this->log($msg); throw new \InvalidArgumentException(tools::print_red($msg)); } $attempts = 1; if (isset($item_data['-sincronizacao-']['tentativas'])) { $attempts += $item_data['-sincronizacao-']['tentativas']; } $date_time = $this->container['date_time']; $date_time = $date_time->format("Y-m-d H:i:s"); $item_data['-sincronizacao-'] = array('tentativas' => $attempts, 'hora_ultima_tentativa' => $date_time, 'ultima_msg' => $msg); }
/** * Performs validation on passed arguments. * * @param Integer $command_arguments_qty_expected * Number of arguments expected after the expected parameters. */ private function check_command_arguments($command_arguments_qty_expected = 1) { $command_type = $this->command_type; $command_parameters = $this->command_parameters; $command_arguments_qty_sent = $this->command_arguments_qty_sent; if ($command_arguments_qty_expected !== $command_arguments_qty_sent) { throw new Exception(tools::print_yellow("'{$command_type} {$command_parameters}' requer {$command_arguments_qty_expected} argumento(s). Foi(ram) enviado(s) {$command_arguments_qty_sent}.")); } }