Skip to content

Commit adac7ec

Browse files
committed
MAGETWO-58479: [Github]Magento 2.1.0: db fields with mysql default value CURRENT_TIMESTAMP cannot be updated through the EntityManager #5385
1 parent c4071ee commit adac7ec

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

dev/tests/integration/testsuite/Magento/Cms/Model/PageTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Cms\Model;
77

8+
use Magento\Cms\Api\PageRepositoryInterface;
9+
810
/**
911
* @magentoAppArea adminhtml
1012
*/
@@ -53,10 +55,10 @@ public function testUpdateTime()
5355
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
5456
/** @var \Magento\Cms\Model\Page $page */
5557
$page = $objectManager->create(\Magento\Cms\Model\Page::class);
56-
$page->setData(['data' => ['title' => 'Test title', 'stores' => [1]], 'expectedIdentifier' => 'test-title']);
58+
$page->setData(['title' => 'Test', 'stores' => [1]]);
5759
$page->setUpdateTime($updateTime);
5860
$page->save();
59-
$page = $page->load($page->getId());
61+
$page = $objectManager->get(PageRepositoryInterface::class)->getById($page->getId());
6062
$this->assertEquals($updateTime, $page->getUpdateTime());
6163
}
6264

lib/internal/Magento/Framework/EntityManager/Db/CreateRow.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ protected function prepareData(EntityMetadataInterface $metadata, AdapterInterfa
5050
{
5151
$output = [];
5252
foreach ($connection->describeTable($metadata->getEntityTable()) as $column) {
53-
54-
if ($column['DEFAULT'] == 'CURRENT_TIMESTAMP') {
53+
$columnName = strtolower($column['COLUMN_NAME']);
54+
if ($this->canNotSetTimeStamp($columnName, $column, $data)) {
5555
continue;
5656
}
57-
if (isset($data[strtolower($column['COLUMN_NAME'])])) {
57+
58+
if (isset($data[$columnName])) {
5859
$output[strtolower($column['COLUMN_NAME'])] = $data[strtolower($column['COLUMN_NAME'])];
5960
} elseif ($column['DEFAULT'] === null) {
6061
$output[strtolower($column['COLUMN_NAME'])] = null;
@@ -66,6 +67,18 @@ protected function prepareData(EntityMetadataInterface $metadata, AdapterInterfa
6667
return $output;
6768
}
6869

70+
/**
71+
* @param string $columnName
72+
* @param string $column
73+
* @param array $data
74+
* @return bool
75+
*/
76+
private function canNotSetTimeStamp($columnName, $column, array $data)
77+
{
78+
return $column['DEFAULT'] == 'CURRENT_TIMESTAMP' && !isset($data[$columnName])
79+
&& empty($column['NULLABLE']);
80+
}
81+
6982
/**
7083
* @param string $entityType
7184
* @param array $data

lib/internal/Magento/Framework/EntityManager/Db/UpdateRow.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ protected function prepareData(EntityMetadataInterface $metadata, AdapterInterfa
6868
return $output;
6969
}
7070

71+
/**
72+
* @param string $columnName
73+
* @param string $column
74+
* @param array $data
75+
* @return bool
76+
*/
77+
private function canNotSetTimeStamp($columnName, $column, array $data)
78+
{
79+
return $column['DEFAULT'] == 'CURRENT_TIMESTAMP' && !isset($data[$columnName])
80+
&& empty($column['NULLABLE']);
81+
}
82+
7183
/**
7284
* @param string $entityType
7385
* @param array $data
@@ -84,16 +96,4 @@ public function execute($entityType, $data)
8496
);
8597
return $data;
8698
}
87-
88-
/**
89-
* @param string $columnName
90-
* @param string $column
91-
* @param array $data
92-
* @return bool
93-
*/
94-
protected function canNotSetTimeStamp($columnName, $column, array $data)
95-
{
96-
return $column['DEFAULT'] == 'CURRENT_TIMESTAMP' && !isset($data[$columnName])
97-
&& empty($column['NULLABLE']);
98-
}
9999
}

0 commit comments

Comments
 (0)