Drop uid column
parent
f5eeb1ae9d
commit
373c398941
|
@ -212,10 +212,10 @@ class Index extends Command {
|
||||||
|
|
||||||
$uid = $user->getUID();
|
$uid = $user->getUID();
|
||||||
$userFolder = $this->rootFolder->getUserFolder($uid);
|
$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 {
|
try {
|
||||||
$folderPath = $folder->getPath();
|
$folderPath = $folder->getPath();
|
||||||
|
|
||||||
|
@ -231,9 +231,9 @@ class Index extends Command {
|
||||||
|
|
||||||
foreach ($nodes as &$node) {
|
foreach ($nodes as &$node) {
|
||||||
if ($node instanceof Folder) {
|
if ($node instanceof Folder) {
|
||||||
$this->parseFolder($node, $refresh, $uid);
|
$this->parseFolder($node, $refresh);
|
||||||
} elseif ($node instanceof File) {
|
} elseif ($node instanceof File) {
|
||||||
$this->parseFile($node, $refresh, $uid);
|
$this->parseFile($node, $refresh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (StorageNotAvailableException $e) {
|
} catch (StorageNotAvailableException $e) {
|
||||||
|
@ -244,8 +244,8 @@ class Index extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseFile(File &$file, bool &$refresh, string $uid): void {
|
private function parseFile(File &$file, bool &$refresh): void {
|
||||||
$res = $this->timelineWrite->processFile($file, $refresh, $uid);
|
$res = $this->timelineWrite->processFile($file, $refresh);
|
||||||
if ($res === 2) {
|
if ($res === 2) {
|
||||||
$this->nProcessed++;
|
$this->nProcessed++;
|
||||||
} else if ($res === 1) {
|
} else if ($res === 1) {
|
||||||
|
|
|
@ -38,8 +38,7 @@ class TimelineWrite {
|
||||||
*/
|
*/
|
||||||
public function processFile(
|
public function processFile(
|
||||||
File &$file,
|
File &$file,
|
||||||
bool $force=false,
|
bool $force=false
|
||||||
string $fallbackUid=null
|
|
||||||
): int {
|
): int {
|
||||||
// There is no easy way to UPSERT in a standard SQL way, so just
|
// 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,
|
// do multiple calls. The worst that can happen is more updates,
|
||||||
|
@ -57,24 +56,11 @@ class TimelineWrite {
|
||||||
$mtime = $file->getMtime();
|
$mtime = $file->getMtime();
|
||||||
$fileId = $file->getId();
|
$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
|
// Check if need to update
|
||||||
$query = $this->connection->getQueryBuilder();
|
$query = $this->connection->getQueryBuilder();
|
||||||
$query->select('fileid', 'mtime')
|
$query->select('fileid', 'mtime')
|
||||||
->from('memories')
|
->from('memories')
|
||||||
->where(
|
->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
|
||||||
$query->expr()->andX(
|
|
||||||
$query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)),
|
|
||||||
$query->expr()->eq('uid', $query->createNamedParameter($uid, IQueryBuilder::PARAM_STR)),
|
|
||||||
));
|
|
||||||
$prevRow = $query->executeQuery()->fetch();
|
$prevRow = $query->executeQuery()->fetch();
|
||||||
if ($prevRow && !$force && intval($prevRow['mtime']) === $mtime) {
|
if ($prevRow && !$force && intval($prevRow['mtime']) === $mtime) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -98,11 +84,7 @@ class TimelineWrite {
|
||||||
->set('datetaken', $query->createNamedParameter($dateTaken, IQueryBuilder::PARAM_STR))
|
->set('datetaken', $query->createNamedParameter($dateTaken, IQueryBuilder::PARAM_STR))
|
||||||
->set('mtime', $query->createNamedParameter($mtime, IQueryBuilder::PARAM_INT))
|
->set('mtime', $query->createNamedParameter($mtime, IQueryBuilder::PARAM_INT))
|
||||||
->set('isvideo', $query->createNamedParameter($isvideo, IQueryBuilder::PARAM_INT))
|
->set('isvideo', $query->createNamedParameter($isvideo, IQueryBuilder::PARAM_INT))
|
||||||
->where(
|
->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
|
||||||
$query->expr()->andX(
|
|
||||||
$query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)),
|
|
||||||
$query->expr()->eq('uid', $query->createNamedParameter($uid, IQueryBuilder::PARAM_STR)),
|
|
||||||
));
|
|
||||||
$query->executeStatement();
|
$query->executeStatement();
|
||||||
} else {
|
} else {
|
||||||
// Try to create new row
|
// Try to create new row
|
||||||
|
@ -110,7 +92,6 @@ class TimelineWrite {
|
||||||
$query->insert('memories')
|
$query->insert('memories')
|
||||||
->values([
|
->values([
|
||||||
'fileid' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT),
|
'fileid' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT),
|
||||||
'uid' => $query->createNamedParameter($uid, IQueryBuilder::PARAM_STR),
|
|
||||||
'dayid' => $query->createNamedParameter($dayId, IQueryBuilder::PARAM_INT),
|
'dayid' => $query->createNamedParameter($dayId, IQueryBuilder::PARAM_INT),
|
||||||
'datetaken' => $query->createNamedParameter($dateTaken, IQueryBuilder::PARAM_STR),
|
'datetaken' => $query->createNamedParameter($dateTaken, IQueryBuilder::PARAM_STR),
|
||||||
'mtime' => $query->createNamedParameter($mtime, IQueryBuilder::PARAM_INT),
|
'mtime' => $query->createNamedParameter($mtime, IQueryBuilder::PARAM_INT),
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2022 Your name <your@email.com>
|
||||||
|
*
|
||||||
|
* @author Your name <your@email.com>
|
||||||
|
*
|
||||||
|
* @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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue