diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2019-05-31 02:03:40 -0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-31 02:03:40 -0100 |
commit | aeaf2786c6eafcb36274f75a4f49825c28eae060 (patch) | |
tree | ffb4e74f4014337d1cf3396f987c8ea799bb5619 | |
parent | cf1560b2454b1d3b9df3d16268ffc9db902295c0 (diff) | |
parent | b13ade6938701ae7a8c38be9984651991a953109 (diff) |
Merge pull request #553 from nextcloud/bugfix/552/creation-can-be-empty
in case creation is empty
-rw-r--r-- | lib/Migration/Version0002Date20190506000001.php | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/lib/Migration/Version0002Date20190506000001.php b/lib/Migration/Version0002Date20190506000001.php index a115997c..bf32139f 100644 --- a/lib/Migration/Version0002Date20190506000001.php +++ b/lib/Migration/Version0002Date20190506000001.php @@ -32,9 +32,13 @@ namespace OCA\Social\Migration; use Closure; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; +use DateTime; use Doctrine\DBAL\Types\Type; +use Exception; use OCA\Social\Db\CoreRequestBuilder; use OCP\DB\ISchemaWrapper; +use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; @@ -1172,7 +1176,6 @@ class Version0002Date20190506000001 extends SimpleMigrationStep { $cursor = $qb->execute(); while ($data = $cursor->fetch()) { $this->insertInto($dest, $fields, $data); - } $cursor->closeCursor(); @@ -1183,11 +1186,20 @@ class Version0002Date20190506000001 extends SimpleMigrationStep { * @param string $table * @param array $fields * @param array $data + * + * @throws Exception */ private function insertInto(string $table, array $fields, array $data) { $insert = $this->connection->getQueryBuilder(); $insert->insert($table); + $datetimeFields = [ + 'creation', + 'last', + 'caching', + 'published_time' + ]; + foreach ($fields as $field) { $value = $this->get($field, $data, ''); if ($field === 'id_prim' @@ -1195,13 +1207,23 @@ class Version0002Date20190506000001 extends SimpleMigrationStep { && $this->get('id', $data, '') !== '') { $value = hash('sha512', $this->get('id', $data, '')); } - - $insert->setValue( - $field, $insert->createNamedParameter($value) - ); + + if (in_array($field, $datetimeFields) && $value === '') { + $insert->setValue( + $field, + $insert->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE) + ); + } else { + $insert->setValue( + $field, $insert->createNamedParameter($value) + ); + } + } + + try { + $insert->execute(); + } catch (UniqueConstraintViolationException $e) { } - - $insert->execute(); } |