2022-08-20 02:53:21 +00:00
|
|
|
<?php
|
2022-10-19 17:10:36 +00:00
|
|
|
|
2022-08-20 02:53:21 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\Memories\Db;
|
|
|
|
|
2022-10-27 16:19:25 +00:00
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
2022-08-20 02:53:21 +00:00
|
|
|
use OCP\IDBConnection;
|
2023-03-23 23:58:49 +00:00
|
|
|
use OCP\IRequest;
|
2022-08-20 02:53:21 +00:00
|
|
|
|
2022-10-19 17:10:36 +00:00
|
|
|
class TimelineQuery
|
|
|
|
{
|
2022-09-11 02:05:04 +00:00
|
|
|
use TimelineQueryDays;
|
2022-09-13 07:55:32 +00:00
|
|
|
use TimelineQueryFilters;
|
2022-11-07 04:48:10 +00:00
|
|
|
use TimelineQueryFolders;
|
2022-11-22 11:31:31 +00:00
|
|
|
use TimelineQueryLivePhoto;
|
2023-02-08 21:53:38 +00:00
|
|
|
use TimelineQueryMap;
|
2023-08-21 06:07:07 +00:00
|
|
|
use TimelineQueryNativeX;
|
2023-03-10 17:30:56 +00:00
|
|
|
use TimelineQuerySingleItem;
|
2022-09-11 02:05:04 +00:00
|
|
|
|
2023-03-10 17:30:56 +00:00
|
|
|
public const TIMELINE_SELECT = [
|
2023-08-21 06:07:07 +00:00
|
|
|
'm.datetaken', 'm.dayid',
|
|
|
|
'm.w', 'm.h', 'm.liveid',
|
|
|
|
'm.isvideo', 'm.video_duration',
|
|
|
|
'f.etag', 'f.name AS basename',
|
|
|
|
'mimetypes.mimetype',
|
2023-03-10 17:30:56 +00:00
|
|
|
];
|
|
|
|
|
2022-09-09 07:31:42 +00:00
|
|
|
protected IDBConnection $connection;
|
2023-03-23 23:58:49 +00:00
|
|
|
protected IRequest $request;
|
2023-10-13 22:10:59 +00:00
|
|
|
protected ?TimelineRoot $_root = null; // cache
|
2023-04-16 22:46:26 +00:00
|
|
|
protected bool $_rootEmptyAllowed = false;
|
2022-08-20 02:53:21 +00:00
|
|
|
|
2023-03-23 23:58:49 +00:00
|
|
|
public function __construct(IDBConnection $connection, IRequest $request)
|
2022-10-19 17:10:36 +00:00
|
|
|
{
|
2022-09-09 07:31:42 +00:00
|
|
|
$this->connection = $connection;
|
2023-03-23 23:58:49 +00:00
|
|
|
$this->request = $request;
|
2022-09-09 07:31:42 +00:00
|
|
|
}
|
2022-09-25 13:21:40 +00:00
|
|
|
|
2023-04-16 22:46:26 +00:00
|
|
|
public function allowEmptyRoot(bool $value = true)
|
|
|
|
{
|
|
|
|
$this->_rootEmptyAllowed = $value;
|
|
|
|
}
|
|
|
|
|
2023-03-23 23:58:49 +00:00
|
|
|
public function getBuilder()
|
|
|
|
{
|
|
|
|
return $this->connection->getQueryBuilder();
|
|
|
|
}
|
|
|
|
|
2022-10-27 19:54:51 +00:00
|
|
|
public static function debugQuery(IQueryBuilder &$query, string $sql = '')
|
2022-10-27 16:19:25 +00:00
|
|
|
{
|
|
|
|
// Print the query and exit
|
|
|
|
$sql = empty($sql) ? $query->getSQL() : $sql;
|
|
|
|
$sql = str_replace('*PREFIX*', 'oc_', $sql);
|
2022-10-27 19:58:47 +00:00
|
|
|
$sql = self::replaceQueryParams($query, $sql);
|
2022-10-27 19:54:51 +00:00
|
|
|
echo "{$sql}";
|
|
|
|
|
2023-04-20 21:12:42 +00:00
|
|
|
exit; // only for debugging, so this is okay
|
2022-10-27 19:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function replaceQueryParams(IQueryBuilder &$query, string $sql)
|
|
|
|
{
|
|
|
|
$params = $query->getParameters();
|
2023-10-13 23:59:14 +00:00
|
|
|
$platform = $query->getConnection()->getDatabasePlatform();
|
2022-10-27 16:19:25 +00:00
|
|
|
foreach ($params as $key => $value) {
|
2023-02-05 20:39:46 +00:00
|
|
|
if (\is_array($value)) {
|
2023-10-13 23:59:14 +00:00
|
|
|
$value = implode(',', array_map(static fn ($v) => $platform->quoteStringLiteral($v), $value));
|
2023-02-05 20:39:46 +00:00
|
|
|
} elseif (\is_bool($value)) {
|
2023-10-13 23:59:14 +00:00
|
|
|
$value = $platform->quoteStringLiteral($value ? '1' : '0');
|
2023-02-05 20:39:46 +00:00
|
|
|
} elseif (null === $value) {
|
2023-10-13 23:59:14 +00:00
|
|
|
$value = $platform->quoteStringLiteral('NULL');
|
2023-02-05 20:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$sql = str_replace(':'.$key, $value, $sql);
|
2022-10-27 16:19:25 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 19:54:51 +00:00
|
|
|
return $sql;
|
2022-10-27 16:19:25 +00:00
|
|
|
}
|
2022-10-19 17:10:36 +00:00
|
|
|
}
|