From d2e6689407b3e5e1e0438ebc09521c5af5912127 Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Wed, 11 May 2022 14:25:34 +0530 Subject: [PATCH] More defensive checks for date_epoch data type. --- .../CustomOrderTable/MetaToCustomTableMigrator.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce/src/Database/Migrations/CustomOrderTable/MetaToCustomTableMigrator.php b/plugins/woocommerce/src/Database/Migrations/CustomOrderTable/MetaToCustomTableMigrator.php index 1f1a93603d9..4269240769a 100644 --- a/plugins/woocommerce/src/Database/Migrations/CustomOrderTable/MetaToCustomTableMigrator.php +++ b/plugins/woocommerce/src/Database/Migrations/CustomOrderTable/MetaToCustomTableMigrator.php @@ -751,7 +751,14 @@ WHERE $where_clause $row[ $destination_alias ] = wc_string_to_bool( $row[ $destination_alias ] ); } if ( 'date_epoch' === $schema['type'] ) { - $row[ $alias ] = ( new \DateTime( "@{$row[ $alias ]}" ) )->format( 'Y-m-d H:i:s' ); + if ( '' === $row[ $alias ] || null === $row[ $alias ] ) { + $row[ $alias ] = null; + } else { + $row[ $alias ] = ( new \DateTime( "@{$row[ $alias ]}" ) )->format( 'Y-m-d H:i:s' ); + } + if ( '0000-00-00 00:00:00' === $row[ $destination_alias ] ) { + $row[ $destination_alias ] = null; + } } if ( is_null( $row[ $alias ] ) ) { $row[ $alias ] = $this->get_type_defaults( $schema['type'] );