datagrid icon indicating copy to clipboard operation
datagrid copied to clipboard

NetteDatabaseDataSource.php - Unhandled date creation in filters

Open janmottl opened this issue 7 years ago • 0 comments

NetteDatabaseDataSource.php - there is unhandled date creation in filters. It crasches when \DateTime::createFromFormat returns false. It's necessary to check if $date_from and $date_to is false.

` public function applyFilterDateRange(Filter\FilterDateRange $filter) { $conditions = $filter->getCondition();

	$value_from = $conditions[$filter->getColumn()]['from'];
	$value_to   = $conditions[$filter->getColumn()]['to'];

	if ($value_from) {
		$date_from = \DateTime::createFromFormat($filter->getPhpFormat(), $value_from);
		if ($date_from !== false) {
            $date_from->setTime(0, 0, 0);
            $this->applyWhere("DATE({$filter->getColumn()})", $date_from->format('Y-m-d'), '>=');
        }
	}

	if ($value_to) {
		$date_to = \DateTime::createFromFormat($filter->getPhpFormat(), $value_to);
        if ($date_to !== false) {
            $date_to->setTime(23, 59, 59);
            $this->applyWhere("DATE({$filter->getColumn()})", $date_to->format('Y-m-d'), '<=');
        }
	}
}

`

janmottl avatar Oct 18 '18 06:10 janmottl