WARNING: Change migrations to fit NC names

Okay, promise this is the last time
pull/37/head
Varun Patil 2022-08-20 21:28:41 +00:00
parent b02185ed9e
commit 829487cac7
9 changed files with 59 additions and 82392 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -153,10 +153,10 @@ class ApiController extends Controller {
// Map sub to JSON array // Map sub to JSON array
$subdirArray = [ $subdirArray = [
"day_id" => -0.1, "dayid" => -0.1,
"detail" => array_map(function ($node) { "detail" => array_map(function ($node) {
return [ return [
"file_id" => $node->getId(), "fileid" => $node->getId(),
"name" => $node->getName(), "name" => $node->getName(),
"is_folder" => 1, "is_folder" => 1,
"path" => $node->getPath(), "path" => $node->getPath(),

View File

@ -20,7 +20,7 @@ class TimelineQuery {
*/ */
private function processDays(&$days) { private function processDays(&$days) {
foreach($days as &$row) { foreach($days as &$row) {
$row["day_id"] = intval($row["day_id"]); $row["dayid"] = intval($row["dayid"]);
$row["count"] = intval($row["count"]); $row["count"] = intval($row["count"]);
} }
return $days; return $days;
@ -35,14 +35,14 @@ class TimelineQuery {
IConfig &$config, IConfig &$config,
string &$user, string &$user,
): array { ): array {
$sql = 'SELECT day_id, COUNT(file_id) AS count $sql = 'SELECT `*PREFIX*memories`.`dayid`, COUNT(`*PREFIX*memories`.`fileid`) AS count
FROM `*PREFIX*memories` FROM `*PREFIX*memories`
INNER JOIN `*PREFIX*filecache` INNER JOIN `*PREFIX*filecache`
ON `*PREFIX*filecache`.`fileid` = `*PREFIX*memories`.`file_id` ON `*PREFIX*filecache`.`fileid` = `*PREFIX*memories`.`fileid`
AND `*PREFIX*filecache`.`path` LIKE ? AND `*PREFIX*filecache`.`path` LIKE ?
WHERE user_id=? WHERE uid=?
GROUP BY day_id GROUP BY `*PREFIX*memories`.`dayid`
ORDER BY day_id DESC'; ORDER BY `*PREFIX*memories`.`dayid` DESC';
$path = "files" . Exif::getPhotosPath($config, $user) . "%"; $path = "files" . Exif::getPhotosPath($config, $user) . "%";
$rows = $this->connection->executeQuery($sql, [$path, $user], [ $rows = $this->connection->executeQuery($sql, [$path, $user], [
@ -56,13 +56,13 @@ class TimelineQuery {
* @param int $folderId * @param int $folderId
*/ */
public function getDaysFolder(int &$folderId) { public function getDaysFolder(int &$folderId) {
$sql = 'SELECT day_id, COUNT(file_id) AS count $sql = 'SELECT `*PREFIX*memories`.`dayid`, COUNT(`*PREFIX*memories`.`fileid`) AS count
FROM `*PREFIX*memories` FROM `*PREFIX*memories`
INNER JOIN `*PREFIX*filecache` INNER JOIN `*PREFIX*filecache`
ON `*PREFIX*filecache`.`fileid` = `*PREFIX*memories`.`file_id` ON `*PREFIX*filecache`.`fileid` = `*PREFIX*memories`.`fileid`
AND (`*PREFIX*filecache`.`parent`=? OR `*PREFIX*filecache`.`fileid`=?) AND (`*PREFIX*filecache`.`parent`=? OR `*PREFIX*filecache`.`fileid`=?)
GROUP BY day_id GROUP BY dayid
ORDER BY day_id DESC'; ORDER BY dayid DESC';
$rows = $this->connection->executeQuery($sql, [$folderId, $folderId], [ $rows = $this->connection->executeQuery($sql, [$folderId, $folderId], [
\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT,
])->fetchAll(); ])->fetchAll();
@ -75,10 +75,10 @@ class TimelineQuery {
*/ */
private function processDay(&$day) { private function processDay(&$day) {
foreach($day as &$row) { foreach($day as &$row) {
$row["file_id"] = intval($row["file_id"]); $row["fileid"] = intval($row["fileid"]);
$row["is_video"] = intval($row["is_video"]); $row["isvideo"] = intval($row["isvideo"]);
if (!$row["is_video"]) { if (!$row["isvideo"]) {
unset($row["is_video"]); unset($row["isvideo"]);
} }
} }
return $day; return $day;
@ -95,13 +95,13 @@ class TimelineQuery {
string &$user, string &$user,
int &$dayId, int &$dayId,
): array { ): array {
$sql = 'SELECT file_id, *PREFIX*filecache.etag, is_video $sql = 'SELECT `*PREFIX*memories`.`fileid`, *PREFIX*filecache.etag, `*PREFIX*memories`.`isvideo`
FROM *PREFIX*memories FROM *PREFIX*memories
INNER JOIN *PREFIX*filecache INNER JOIN *PREFIX*filecache
ON *PREFIX*filecache.fileid = *PREFIX*memories.file_id ON `*PREFIX*filecache`.`fileid` = `*PREFIX*memories`.`fileid`
AND `*PREFIX*filecache`.`path` LIKE ? AND `*PREFIX*filecache`.`path` LIKE ?
WHERE user_id = ? AND day_id = ? WHERE `*PREFIX*memories`.`uid` = ? AND `*PREFIX*memories`.`dayid` = ?
ORDER BY date_taken DESC'; ORDER BY `*PREFIX*memories`.`datetaken` DESC';
$path = "files" . Exif::getPhotosPath($config, $user) . "%"; $path = "files" . Exif::getPhotosPath($config, $user) . "%";
$rows = $this->connection->executeQuery($sql, [$path, $user, $dayId], [ $rows = $this->connection->executeQuery($sql, [$path, $user, $dayId], [
@ -119,12 +119,12 @@ class TimelineQuery {
int &$folderId, int &$folderId,
int &$dayId, int &$dayId,
): array { ): array {
$sql = 'SELECT file_id, *PREFIX*filecache.etag, is_video $sql = 'SELECT `*PREFIX*memories`.`fileid`, `*PREFIX*filecache`.`etag`, `*PREFIX*memories`.`isvideo`
FROM `*PREFIX*memories` FROM `*PREFIX*memories`
INNER JOIN `*PREFIX*filecache` INNER JOIN `*PREFIX*filecache`
ON `*PREFIX*filecache`.`fileid` = `*PREFIX*memories`.`file_id` ON `*PREFIX*filecache`.`fileid` = `*PREFIX*memories`.`fileid`
AND (`*PREFIX*filecache`.`parent`=? OR `*PREFIX*filecache`.`fileid`=?) AND (`*PREFIX*filecache`.`parent`=? OR `*PREFIX*filecache`.`fileid`=?)
WHERE `*PREFIX*memories`.`day_id`=?'; WHERE `*PREFIX*memories`.`dayid`=?';
$rows = $this->connection->executeQuery($sql, [$folderId, $folderId, $dayId], [ $rows = $this->connection->executeQuery($sql, [$folderId, $folderId, $dayId], [
\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT,
])->fetchAll(); ])->fetchAll();

View File

@ -28,8 +28,8 @@ class TimelineWrite {
// Check if we want to process this file // Check if we want to process this file
$mime = $file->getMimeType(); $mime = $file->getMimeType();
$is_image = in_array($mime, Application::IMAGE_MIMES); $is_image = in_array($mime, Application::IMAGE_MIMES);
$is_video = in_array($mime, Application::VIDEO_MIMES); $isvideo = in_array($mime, Application::VIDEO_MIMES);
if (!$is_image && !$is_video) { if (!$is_image && !$isvideo) {
return; return;
} }
@ -41,7 +41,7 @@ class TimelineWrite {
// Check if need to update // Check if need to update
$sql = 'SELECT `mtime` $sql = 'SELECT `mtime`
FROM *PREFIX*memories FROM *PREFIX*memories
WHERE file_id = ? AND user_id = ?'; WHERE `fileid` = ? AND `uid` = ?';
$prevRow = $this->connection->executeQuery($sql, [ $prevRow = $this->connection->executeQuery($sql, [
$fileId, $user, $fileId, $user,
], [ ], [
@ -65,10 +65,10 @@ class TimelineWrite {
if ($prevRow) { if ($prevRow) {
// Update existing row // Update existing row
$sql = 'UPDATE *PREFIX*memories $sql = 'UPDATE *PREFIX*memories
SET day_id = ?, date_taken = ?, is_video = ?, mtime = ? SET `dayid` = ?, `datetaken` = ?, `isvideo` = ?, `mtime` = ?
WHERE user_id = ? AND file_id = ?'; WHERE `uid` = ? AND `fileid` = ?';
$this->connection->executeStatement($sql, [ $this->connection->executeStatement($sql, [
$dayId, $dateTaken, $is_video, $mtime, $dayId, $dateTaken, $isvideo, $mtime,
$user, $fileId, $user, $fileId,
], [ ], [
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_BOOL, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_BOOL, \PDO::PARAM_INT,
@ -77,10 +77,10 @@ class TimelineWrite {
} else { } else {
// Create new row // Create new row
$sql = 'INSERT $sql = 'INSERT
INTO *PREFIX*memories (day_id, date_taken, is_video, mtime, user_id, file_id) INTO *PREFIX*memories (`dayid`, `datetaken`, `isvideo`, `mtime`, `uid`, `fileid`)
VALUES (?, ?, ?, ?, ?, ?)'; VALUES (?, ?, ?, ?, ?, ?)';
$this->connection->executeStatement($sql, [ $this->connection->executeStatement($sql, [
$dayId, $dateTaken, $is_video, $mtime, $dayId, $dateTaken, $isvideo, $mtime,
$user, $fileId, $user, $fileId,
], [ ], [
\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_BOOL, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_BOOL, \PDO::PARAM_INT,
@ -96,7 +96,7 @@ class TimelineWrite {
public function deleteFile(File &$file) { public function deleteFile(File &$file) {
$sql = 'DELETE $sql = 'DELETE
FROM *PREFIX*memories FROM *PREFIX*memories
WHERE file_id = ?'; WHERE `fileid` = ?';
$this->connection->executeStatement($sql, [$file->getId()], [\PDO::PARAM_INT]); $this->connection->executeStatement($sql, [$file->getId()], [\PDO::PARAM_INT]);
} }
} }

View File

@ -50,21 +50,21 @@ class Version000000Date20220812163631 extends SimpleMigrationStep {
'autoincrement' => true, 'autoincrement' => true,
'notnull' => true, 'notnull' => true,
]); ]);
$table->addColumn('user_id', 'string', [ $table->addColumn('uid', 'string', [
'notnull' => true, 'notnull' => true,
'length' => 200, 'length' => 200,
]); ]);
$table->addColumn('date_taken', Types::DATETIME, [ $table->addColumn('datetaken', Types::DATETIME, [
'notnull' => false, 'notnull' => false,
]); ]);
$table->addColumn('file_id', Types::BIGINT, [ $table->addColumn('fileid', Types::BIGINT, [
'notnull' => true, 'notnull' => true,
'length' => 20, 'length' => 20,
]); ]);
$table->addColumn('day_id', Types::INTEGER, [ $table->addColumn('dayid', Types::INTEGER, [
'notnull' => true, 'notnull' => true,
]); ]);
$table->addColumn('is_video', Types::BOOLEAN, [ $table->addColumn('isvideo', Types::BOOLEAN, [
'notnull' => false, 'notnull' => false,
'default' => false 'default' => false
]); ]);
@ -73,9 +73,9 @@ class Version000000Date20220812163631 extends SimpleMigrationStep {
]); ]);
$table->setPrimaryKey(['id']); $table->setPrimaryKey(['id']);
$table->addIndex(['user_id'], 'memories_user_id_index'); $table->addIndex(['uid'], 'memories_uid_index');
$table->addIndex(['user_id', 'day_id'], 'memories_ud_index'); $table->addIndex(['uid', 'dayid'], 'memories_ud_index');
$table->addUniqueIndex(['user_id', 'file_id'], 'memories_day_uf_ui'); $table->addUniqueIndex(['uid', 'fileid'], 'memories_day_uf_ui');
} }
if ($schema->hasTable('filecache')) { if ($schema->hasTable('filecache')) {

View File

@ -3,7 +3,7 @@
hasPreview: previewFileInfos.length > 0, hasPreview: previewFileInfos.length > 0,
onePreview: previewFileInfos.length === 1, onePreview: previewFileInfos.length === 1,
}" }"
@click="openFolder(data.file_id)" @click="openFolder(data.fileid)"
v-bind:style="{ v-bind:style="{
width: rowHeight + 'px', width: rowHeight + 'px',
height: rowHeight + 'px', height: rowHeight + 'px',

View File

@ -1,10 +1,10 @@
<template> <template>
<div> <div>
<div v-if="data.is_video" class="icon-video-white"></div> <div v-if="data.isvideo" class="icon-video-white"></div>
<img <img
@click="openFile()" @click="openFile()"
:src="data.ph ? undefined : getPreviewUrl(data.file_id, data.etag)" :src="data.ph ? undefined : getPreviewUrl(data.fileid, data.etag)"
:key="data.file_id" :key="data.fileid"
@load = "data.l = Math.random()" @load = "data.l = Math.random()"
@error="(e) => e.target.src='/apps/memories/img/error.svg'" @error="(e) => e.target.src='/apps/memories/img/error.svg'"
v-bind:style="{ v-bind:style="{
@ -48,7 +48,7 @@ export default {
// Check if already loaded fileInfos or load // Check if already loaded fileInfos or load
let fileInfos = this.day.fileInfos; let fileInfos = this.day.fileInfos;
if (!fileInfos) { if (!fileInfos) {
const ids = this.day.detail.map(p => p.file_id); const ids = this.day.detail.map(p => p.fileid);
try { try {
this.loading = true; this.loading = true;
fileInfos = await dav.getFiles(ids); fileInfos = await dav.getFiles(ids);
@ -73,7 +73,7 @@ export default {
} }
// Get this photo in the fileInfos // Get this photo in the fileInfos
const photo = fileInfos.find(d => Number(d.fileid) === Number(this.data.file_id)); const photo = fileInfos.find(d => Number(d.fileid) === Number(this.data.fileid));
if (!photo) { if (!photo) {
alert('Cannot find this photo anymore!'); alert('Cannot find this photo anymore!');
return; return;

View File

@ -344,7 +344,7 @@ export default {
} }
// Make date string // Make date string
const dateTaken = new Date(Number(day.day_id)*86400*1000); const dateTaken = new Date(Number(day.dayid)*86400*1000);
let dateStr = dateTaken.toLocaleDateString("en-US", { dateStyle: 'full', timeZone: 'UTC' }); let dateStr = dateTaken.toLocaleDateString("en-US", { dateStyle: 'full', timeZone: 'UTC' });
if (dateTaken.getUTCFullYear() === new Date().getUTCFullYear()) { if (dateTaken.getUTCFullYear() === new Date().getUTCFullYear()) {
// hack: remove last 6 characters of date string // hack: remove last 6 characters of date string
@ -354,7 +354,7 @@ export default {
// Create tick if month changed // Create tick if month changed
const dtYear = dateTaken.getUTCFullYear(); const dtYear = dateTaken.getUTCFullYear();
const dtMonth = dateTaken.getUTCMonth() const dtMonth = dateTaken.getUTCMonth()
if (Number.isInteger(day.day_id) && (dtMonth !== prevMonth || dtYear !== prevYear)) { if (Number.isInteger(day.dayid) && (dtMonth !== prevMonth || dtYear !== prevYear)) {
// Format dateTaken as MM YYYY // Format dateTaken as MM YYYY
const dateTimeFormat = new Intl.DateTimeFormat('en-US', { month: 'short' }); const dateTimeFormat = new Intl.DateTimeFormat('en-US', { month: 'short' });
const monthName = dateTimeFormat.formatToParts(dateTaken)[0].value; const monthName = dateTimeFormat.formatToParts(dateTaken)[0].value;
@ -373,7 +373,7 @@ export default {
prevYear = dtYear; prevYear = dtYear;
// Special headers // Special headers
if (day.day_id === -0.1) { if (day.dayid === -0.1) {
dateStr = "Folders"; dateStr = "Folders";
} }
@ -384,10 +384,10 @@ export default {
size: 40, size: 40,
head: true, head: true,
loadedImages: false, loadedImages: false,
dayId: day.day_id, dayId: day.dayid,
day: day, day: day,
}; };
this.heads[day.day_id] = head; this.heads[day.dayid] = head;
this.list.push(head); this.list.push(head);
currTopStatic += head.size; currTopStatic += head.size;
@ -403,7 +403,7 @@ export default {
for (let j = 0; j < rowCount; j++) { for (let j = 0; j < rowCount; j++) {
row.photos.push({ row.photos.push({
ph: true, // placeholder ph: true, // placeholder
file_id: `${day.day_id}-${i}-${j}`, fileid: `${day.dayid}-${i}-${j}`,
}); });
} }
@ -415,7 +415,7 @@ export default {
// Check preloads // Check preloads
for (const day of data) { for (const day of data) {
if (day.count && day.detail) { if (day.count && day.detail) {
this.processDay(day.day_id, day.detail); this.processDay(day.dayid, day.detail);
} }
} }
@ -443,7 +443,7 @@ export default {
const data = res.data; const data = res.data;
if (this.state !== startState) return; if (this.state !== startState) return;
this.days.find(d => d.day_id === dayId).detail = data; this.days.find(d => d.dayid === dayId).detail = data;
this.processDay(dayId, data); this.processDay(dayId, data);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -501,7 +501,7 @@ export default {
id: ++this.numRows, id: ++this.numRows,
photos: [], photos: [],
size: this.rowHeight, size: this.rowHeight,
dayId: day.day_id, dayId: day.dayid,
day: day, day: day,
}; };
}, },