diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2019-05-31 01:28:29 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2019-05-31 01:28:29 -0100 |
commit | a8e1ddc27918f8d87b2ad296314cdae4a036d669 (patch) | |
tree | a8507fc964627fc615136bd19fe01006639c8531 | |
parent | 12111ac7e09ac919f64e92d43f254c2177130e17 (diff) |
in case creation is empty
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | lib/Migration/Version0002Date20190506000001.php | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/Migration/Version0002Date20190506000001.php b/lib/Migration/Version0002Date20190506000001.php index a115997c..59aa6a5e 100644 --- a/lib/Migration/Version0002Date20190506000001.php +++ b/lib/Migration/Version0002Date20190506000001.php @@ -32,9 +32,12 @@ namespace OCA\Social\Migration; use Closure; +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 +1175,6 @@ class Version0002Date20190506000001 extends SimpleMigrationStep { $cursor = $qb->execute(); while ($data = $cursor->fetch()) { $this->insertInto($dest, $fields, $data); - } $cursor->closeCursor(); @@ -1183,6 +1185,8 @@ 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(); @@ -1196,9 +1200,16 @@ class Version0002Date20190506000001 extends SimpleMigrationStep { $value = hash('sha512', $this->get('id', $data, '')); } - $insert->setValue( - $field, $insert->createNamedParameter($value) - ); + if ($field === 'creation' && $value === '') { + $insert->setValue( + 'creation', + $insert->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE) + ); + } else { + $insert->setValue( + $field, $insert->createNamedParameter($value) + ); + } } $insert->execute(); |