diff --git a/lib/Command/Index.php b/lib/Command/Index.php index 96e05cb0..1c87ef68 100644 --- a/lib/Command/Index.php +++ b/lib/Command/Index.php @@ -212,10 +212,10 @@ class Index extends Command { $uid = $user->getUID(); $userFolder = $this->rootFolder->getUserFolder($uid); - $this->parseFolder($userFolder, $refresh, $uid); + $this->parseFolder($userFolder, $refresh); } - private function parseFolder(Folder &$folder, bool &$refresh, string $uid): void { + private function parseFolder(Folder &$folder, bool &$refresh): void { try { $folderPath = $folder->getPath(); @@ -231,9 +231,9 @@ class Index extends Command { foreach ($nodes as &$node) { if ($node instanceof Folder) { - $this->parseFolder($node, $refresh, $uid); + $this->parseFolder($node, $refresh); } elseif ($node instanceof File) { - $this->parseFile($node, $refresh, $uid); + $this->parseFile($node, $refresh); } } } catch (StorageNotAvailableException $e) { @@ -244,8 +244,8 @@ class Index extends Command { } } - private function parseFile(File &$file, bool &$refresh, string $uid): void { - $res = $this->timelineWrite->processFile($file, $refresh, $uid); + private function parseFile(File &$file, bool &$refresh): void { + $res = $this->timelineWrite->processFile($file, $refresh); if ($res === 2) { $this->nProcessed++; } else if ($res === 1) { diff --git a/lib/Db/TimelineWrite.php b/lib/Db/TimelineWrite.php index 3baaa083..bc60c957 100644 --- a/lib/Db/TimelineWrite.php +++ b/lib/Db/TimelineWrite.php @@ -38,8 +38,7 @@ class TimelineWrite { */ public function processFile( File &$file, - bool $force=false, - string $fallbackUid=null + bool $force=false ): int { // There is no easy way to UPSERT in a standard SQL way, so just // do multiple calls. The worst that can happen is more updates, @@ -57,24 +56,11 @@ class TimelineWrite { $mtime = $file->getMtime(); $fileId = $file->getId(); - $uid = $file->getOwner()->getUID(); - if (empty($uid)) { - // Most likely this is an extrnal mount (that may be shared between users) - $uid = $fallbackUid; - } - if (empty($uid)) { - return 0; - } - // Check if need to update $query = $this->connection->getQueryBuilder(); $query->select('fileid', 'mtime') ->from('memories') - ->where( - $query->expr()->andX( - $query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)), - $query->expr()->eq('uid', $query->createNamedParameter($uid, IQueryBuilder::PARAM_STR)), - )); + ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); $prevRow = $query->executeQuery()->fetch(); if ($prevRow && !$force && intval($prevRow['mtime']) === $mtime) { return 1; @@ -98,11 +84,7 @@ class TimelineWrite { ->set('datetaken', $query->createNamedParameter($dateTaken, IQueryBuilder::PARAM_STR)) ->set('mtime', $query->createNamedParameter($mtime, IQueryBuilder::PARAM_INT)) ->set('isvideo', $query->createNamedParameter($isvideo, IQueryBuilder::PARAM_INT)) - ->where( - $query->expr()->andX( - $query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)), - $query->expr()->eq('uid', $query->createNamedParameter($uid, IQueryBuilder::PARAM_STR)), - )); + ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); $query->executeStatement(); } else { // Try to create new row @@ -110,7 +92,6 @@ class TimelineWrite { $query->insert('memories') ->values([ 'fileid' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT), - 'uid' => $query->createNamedParameter($uid, IQueryBuilder::PARAM_STR), 'dayid' => $query->createNamedParameter($dayId, IQueryBuilder::PARAM_INT), 'datetaken' => $query->createNamedParameter($dateTaken, IQueryBuilder::PARAM_STR), 'mtime' => $query->createNamedParameter($mtime, IQueryBuilder::PARAM_INT), diff --git a/lib/Migration/Version200000Date20220924015634.php b/lib/Migration/Version200000Date20220924015634.php new file mode 100644 index 00000000..edc6a37c --- /dev/null +++ b/lib/Migration/Version200000Date20220924015634.php @@ -0,0 +1,99 @@ + + * + * @author Your name + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Memories\Migration; + +use Closure; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; +use OCP\IDBConnection; + +/** + * Auto-generated migration step: Please modify to your needs! + */ +class Version200000Date20220924015634 extends SimpleMigrationStep { + + /** @var IDBConnection */ + private $dbc; + + public function __construct(IDBConnection $dbc) { + $this->dbc = $dbc; + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + */ + public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + if ($schema->hasTable('memories')) { + $table = $schema->getTable('memories'); + if ($table->hasColumn('uid')) { + $sql = $this->dbc->getDatabasePlatform()->getTruncateTableSQL('`*PREFIX*memories`', false); + $this->dbc->executeStatement($sql); + } + } + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + if (!$schema->hasTable('memories')) { + throw new \Exception('Memories table does not exist'); + } + + $table = $schema->getTable('memories'); + if ($table->hasIndex('memories_uid_index')) { + $table->dropIndex('memories_uid_index'); + $table->dropIndex('memories_ud_index'); + $table->dropIndex('memories_day_uf_ui'); + $table->dropColumn('uid'); + + $table->addIndex(['dayid'], 'memories_dayid_index'); + $table->addUniqueIndex(['fileid'], 'memories_fileid_index'); + } + + return $schema; + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + */ + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { + } +}