tq: mark hidden files
Signed-off-by: Varun Patil <radialapps@gmail.com>pull/807/merge
parent
58760b1c53
commit
5820c53857
|
@ -10,23 +10,15 @@ trait TimelineQueryCTE
|
||||||
* CTE to get all files recursively in the given top folders
|
* CTE to get all files recursively in the given top folders
|
||||||
* :topFolderIds - The top folders to get files from.
|
* :topFolderIds - The top folders to get files from.
|
||||||
*
|
*
|
||||||
* @param bool $noHidden Whether to filter out files in hidden folders
|
* @param bool $hidden Whether to include files in hidden folders
|
||||||
* If the top folder is hidden, the files in it will still be returned
|
* If the top folder is hidden, the files in it will still be returned
|
||||||
|
* Hidden files are marked as such in the "hidden" field
|
||||||
*/
|
*/
|
||||||
protected static function CTE_FOLDERS_ALL(bool $noHidden): string
|
protected static function CTE_FOLDERS_ALL(bool $hidden): string
|
||||||
{
|
{
|
||||||
// Whether to filter out the archive folder
|
|
||||||
$CLS_HIDDEN_JOIN = $noHidden ? "f.name NOT LIKE '.%'" : '1 = 1';
|
|
||||||
|
|
||||||
// Filter out folder MIME types
|
// Filter out folder MIME types
|
||||||
$FOLDER_MIME_QUERY = "SELECT MAX(id) FROM *PREFIX*mimetypes WHERE mimetype = 'httpd/unix-directory'";
|
$FOLDER_MIME_QUERY = "SELECT MAX(id) FROM *PREFIX*mimetypes WHERE mimetype = 'httpd/unix-directory'";
|
||||||
|
|
||||||
// Select filecache as f
|
|
||||||
$BASE_QUERY = 'SELECT f.fileid, f.name FROM *PREFIX*filecache f';
|
|
||||||
|
|
||||||
// From top folders
|
|
||||||
$CLS_TOP_FOLDER = 'f.fileid IN (:topFolderIds)';
|
|
||||||
|
|
||||||
// Select 1 if there is a .nomedia file in the folder
|
// Select 1 if there is a .nomedia file in the folder
|
||||||
$SEL_NOMEDIA = "SELECT 1 FROM *PREFIX*filecache f2
|
$SEL_NOMEDIA = "SELECT 1 FROM *PREFIX*filecache f2
|
||||||
WHERE (f2.parent = f.fileid)
|
WHERE (f2.parent = f.fileid)
|
||||||
|
@ -35,22 +27,29 @@ trait TimelineQueryCTE
|
||||||
// Check no nomedia file exists in the folder
|
// Check no nomedia file exists in the folder
|
||||||
$CLS_NOMEDIA = "NOT EXISTS ({$SEL_NOMEDIA})";
|
$CLS_NOMEDIA = "NOT EXISTS ({$SEL_NOMEDIA})";
|
||||||
|
|
||||||
|
// Whether to filter out hidden folders
|
||||||
|
$CLS_HIDDEN_JOIN = $hidden ? '1 = 1' : "f.name NOT LIKE '.%'";
|
||||||
|
|
||||||
return
|
return
|
||||||
"*PREFIX*cte_folders_all(fileid, name) AS (
|
"*PREFIX*cte_folders_all(fileid, name, hidden) AS (
|
||||||
{$BASE_QUERY}
|
SELECT f.fileid, f.name,
|
||||||
|
(0) AS hidden
|
||||||
|
FROM *PREFIX*filecache f
|
||||||
WHERE (
|
WHERE (
|
||||||
{$CLS_TOP_FOLDER} AND
|
f.fileid IN (:topFolderIds) AND
|
||||||
{$CLS_NOMEDIA}
|
{$CLS_NOMEDIA}
|
||||||
)
|
)
|
||||||
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
|
||||||
{$BASE_QUERY}
|
SELECT f.fileid, f.name,
|
||||||
|
(CASE WHEN c.hidden = 1 OR f.name LIKE '.%' THEN 1 ELSE 0 END) AS hidden
|
||||||
|
FROM *PREFIX*filecache f
|
||||||
INNER JOIN *PREFIX*cte_folders_all c
|
INNER JOIN *PREFIX*cte_folders_all c
|
||||||
ON (
|
ON (
|
||||||
f.parent = c.fileid AND
|
f.parent = c.fileid AND
|
||||||
f.mimetype = ({$FOLDER_MIME_QUERY}) AND
|
f.mimetype = ({$FOLDER_MIME_QUERY}) AND
|
||||||
{$CLS_HIDDEN_JOIN}
|
({$CLS_HIDDEN_JOIN})
|
||||||
)
|
)
|
||||||
WHERE (
|
WHERE (
|
||||||
{$CLS_NOMEDIA}
|
{$CLS_NOMEDIA}
|
||||||
|
@ -58,19 +57,25 @@ trait TimelineQueryCTE
|
||||||
)";
|
)";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** CTE to get all folders recursively in the given top folders excluding archive */
|
/**
|
||||||
protected static function CTE_FOLDERS(): string
|
* CTE to get all folders recursively in the given top folders.
|
||||||
|
*
|
||||||
|
* @param bool $hidden Whether to include files in hidden folders
|
||||||
|
*/
|
||||||
|
protected static function CTE_FOLDERS(bool $hidden): string
|
||||||
{
|
{
|
||||||
$cte = '*PREFIX*cte_folders AS (
|
$CLS_HIDDEN = $hidden ? 'MIN(hidden)' : '0';
|
||||||
|
|
||||||
|
$cte = "*PREFIX*cte_folders AS (
|
||||||
SELECT
|
SELECT
|
||||||
fileid
|
fileid, ({$CLS_HIDDEN}) AS hidden
|
||||||
FROM
|
FROM
|
||||||
*PREFIX*cte_folders_all
|
*PREFIX*cte_folders_all
|
||||||
GROUP BY
|
GROUP BY
|
||||||
fileid
|
fileid
|
||||||
)';
|
)";
|
||||||
|
|
||||||
return self::bundleCTEs([self::CTE_FOLDERS_ALL(true), $cte]);
|
return self::bundleCTEs([self::CTE_FOLDERS_ALL($hidden), $cte]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** CTE to get all archive folders recursively in the given top folders */
|
/** CTE to get all archive folders recursively in the given top folders */
|
||||||
|
@ -94,7 +99,7 @@ trait TimelineQueryCTE
|
||||||
ON (f.parent = c.fileid)
|
ON (f.parent = c.fileid)
|
||||||
)";
|
)";
|
||||||
|
|
||||||
return self::bundleCTEs([self::CTE_FOLDERS_ALL(false), $cte]);
|
return self::bundleCTEs([self::CTE_FOLDERS_ALL(true), $cte]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function bundleCTEs(array $ctes): string
|
protected static function bundleCTEs(array $ctes): string
|
||||||
|
|
|
@ -126,7 +126,7 @@ trait TimelineQueryDays
|
||||||
// Get SQL
|
// Get SQL
|
||||||
$CTE_SQL = \array_key_exists('cteFoldersArchive', $params) && $params['cteFoldersArchive']
|
$CTE_SQL = \array_key_exists('cteFoldersArchive', $params) && $params['cteFoldersArchive']
|
||||||
? self::CTE_FOLDERS_ARCHIVE()
|
? self::CTE_FOLDERS_ARCHIVE()
|
||||||
: self::CTE_FOLDERS();
|
: self::CTE_FOLDERS(false);
|
||||||
|
|
||||||
// Add WITH clause if needed
|
// Add WITH clause if needed
|
||||||
if (false !== strpos($sql, 'cte_folders')) {
|
if (false !== strpos($sql, 'cte_folders')) {
|
||||||
|
|
Loading…
Reference in New Issue