Skip to content

Commit

Permalink
Fixes after CR vol 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbieniek committed Dec 21, 2018
1 parent c401934 commit 3cc691f
Showing 1 changed file with 16 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
class UpdateTimestampsToUTCCommand extends ContainerAwareCommand
{
const DEFAULT_ITERATION_COUNT = 100;
const EZDATE_ONLY_MODE = 'date';
const EZDATETIME_ONLY_MODE = 'datetime';
const ALL_MODE = 'all';
const MODES = [
'date' => ['ezdate'],
'datetime' => ['ezdatetime'],
'all' => ['ezdate', 'ezdatetime'],
];

/**
* @var int
Expand Down Expand Up @@ -159,6 +161,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->dryRun = $input->getOption('dry-run');
$this->mode = $input->getOption('mode');

if (!isset(self::MODES[$this->mode])) {
$output->writeln(
sprintf('Selected mode is not supported, please use one of: %s', implode(', ', array_keys(self::MODES)))
);

return;
}

$from = $input->getOption('from');
$to = $input->getOption('to');

Expand All @@ -168,11 +178,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($to && !$this->validateDateTimeString($to, $output)) {
return;
}

if ($from) {
$this->from = $this->dateStringToTimestamp($from);
}

if ($to) {
$this->to = $this->dateStringToTimestamp($to);
}
Expand All @@ -187,19 +195,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$timezone = $input->getArgument('timezone');
$this->timezone = $this->validateTimezone($timezone, $output);

$modeTxt = 'Converting timestamps for both ezdate and ezdatetime fields.';

switch ($this->mode) {
case 'date':
$modeTxt = 'Converting timestamps for ezdate fields.';
break;
case 'datetime':
$modeTxt = 'Converting timestamps for ezdatetime fields.';
break;
}

$output->writeln([
$modeTxt,
sprintf('Converting timestamps for fields: %s', implode(', ', self::MODES[$this->mode])),
'Calculating number of Field values to update...',
]);
$count = $this->countTimestampBasedFields();
Expand Down Expand Up @@ -313,7 +310,7 @@ protected function getTimestampBasedFields($offset, $limit)
->where(
$query->expr()->in(
'a.data_type_string',
$query->createNamedParameter($this->getFields(), Connection::PARAM_STR_ARRAY)
$query->createNamedParameter(self::MODES[$this->mode], Connection::PARAM_STR_ARRAY)
)
)
->andWhere('a.data_int is not null')
Expand Down Expand Up @@ -353,7 +350,7 @@ protected function countTimestampBasedFields()
->where(
$query->expr()->in(
'a.data_type_string',
$query->createNamedParameter($this->getFields(), Connection::PARAM_STR_ARRAY)
$query->createNamedParameter(self::MODES[$this->mode], Connection::PARAM_STR_ARRAY)
)
)
->andWhere('a.data_int is not null')
Expand Down Expand Up @@ -498,23 +495,6 @@ private function getPhpPath()
return $this->phpPath;
}

/**
* @return string[]
*/
private function getFields()
{
$fields = [];

if ($this->mode == 'date' || $this->mode == 'all') {
$fields[] = 'ezdate';
}
if ($this->mode == 'datetime' || $this->mode == 'all') {
$fields[] = 'ezdatetime';
}

return $fields;
}

/**
* @param $dateString string
* @throws \Exception
Expand Down

0 comments on commit 3cc691f

Please sign in to comment.