Skip to content

Commit

Permalink
Merge pull request #29 from dreamfactorysoftware/develop
Browse files Browse the repository at this point in the history
Merge Develop
  • Loading branch information
Anas authored Oct 23, 2023
2 parents 8c1d051 + 2dbc35a commit aeef859
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/Enums/BinaryDataTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace DreamFactory\Core\MongoDb\Enums;

/**
* Binary data types for MongoDB
* https://www.mongodb.com/docs/manual/reference/bson-types/#binary-data
*/
class BinaryDataTypes
{
const GENERIC = 0;
const FUNCTION_DATA = 1;
const BINARY_OLD = 2;
const UUID_OLD = 3;
const UUID = 4;
const MD5 = 5;
const ENCRYPTED_BSON_VALUE = 6;
const COMPRESSED_TIME_SERIES_DATA = 7;
const CUSTOM_DATA = 128;
}
7 changes: 4 additions & 3 deletions src/Resources/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use DreamFactory\Core\Exceptions\InternalServerErrorException;
use DreamFactory\Core\Exceptions\NotFoundException;
use DreamFactory\Core\Exceptions\RestException;
use DreamFactory\Core\MongoDb\Enums\BinaryDataTypes;
use DreamFactory\Core\MongoDb\Services\MongoDb;
use DreamFactory\Core\Database\Resources\BaseNoSqlDbTableResource;
use DreamFactory\Core\Utility\DataFormatter;
Expand Down Expand Up @@ -679,7 +680,7 @@ protected static function fromMongoObjects($record)
}
$data = $data->toDateTime();
$data = ['$date' => $data->format($cfgFormat)];
} elseif ($data instanceof Binary) {
} elseif ($data instanceof Binary && $data->getType() === BinaryDataTypes::GENERIC) {
$data = $data->getData();
}
}
Expand All @@ -702,7 +703,7 @@ protected static function toMongoObjects($record)
if (is_string($data) && (static::DEFAULT_ID_FIELD == $key)) {
$record[$key] = static::idToMongoId($data);
} elseif (is_array($data)) {
if (1 === count($data)) {
// if (1 === count($data)) {
// using typed definition, i.e. {"$date" : "2014-08-02T08:40:12.569Z" }
if (array_key_exists('$date', $data)) {
$temp = $data['$date'];
Expand All @@ -721,7 +722,7 @@ protected static function toMongoObjects($record)
} else {
$record[$key] = static::toMongoObjects($data);
}
}
// }
}
}
}
Expand Down

0 comments on commit aeef859

Please sign in to comment.