<?php namespace Eae\Command;

use EventDate;
use Illuminate\Support\Facades\DB;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Throwable;

class SyncEventDatesCommand extends BaseCommand {

	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $name = 'cronologias:sync-event-dates';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'Sync event dates';

	/**
	 * Create a new command instance.
	 *
	 * @return void
	 */
	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 */
	public function fire()
	{
        DB::beginTransaction();
        try {

            $eventDates = EventDate::all();

            foreach ($eventDates as $eventDateItem) {
                syncEventDate($eventDateItem);
                $eventDateItem->save();
            }

            DB::commit();
        } catch (Throwable $e) {
            DB::rollBack();
            throw($e);
        }
	}

}
