70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\Memories\Db;
|
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
use OCP\Files\File;
|
|
use OCP\IDBConnection;
|
|
|
|
trait TimelineWriteOrphans
|
|
{
|
|
protected IDBConnection $connection;
|
|
|
|
/**
|
|
* Set the mtime of all files in the table to -1.
|
|
*/
|
|
public function resetAllMtime()
|
|
{
|
|
$query = $this->connection->getQueryBuilder();
|
|
$query->update('memories')
|
|
->set('mtime', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT))
|
|
;
|
|
$query->executeStatement();
|
|
}
|
|
|
|
/**
|
|
* Mark a file as not orphaned.
|
|
*/
|
|
public function unorphan(File &$file)
|
|
{
|
|
$query = $this->connection->getQueryBuilder();
|
|
$query->update('memories')
|
|
->set('orphan', $query->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))
|
|
->where($query->expr()->eq('fileid', $query->createNamedParameter($file->getId(), IQueryBuilder::PARAM_INT)))
|
|
;
|
|
$query->executeStatement();
|
|
}
|
|
|
|
/**
|
|
* Mark all files in the table as orphaned.
|
|
*
|
|
* @return int Number of rows affected
|
|
*/
|
|
public function orphanAll(): int
|
|
{
|
|
$query = $this->connection->getQueryBuilder();
|
|
$query->update('memories')
|
|
->set('orphan', $query->createNamedParameter(true, IQueryBuilder::PARAM_BOOL))
|
|
;
|
|
|
|
return $query->executeStatement();
|
|
}
|
|
|
|
/**
|
|
* Remove all entries that are orphans.
|
|
*
|
|
* @return int Number of rows affected
|
|
*/
|
|
public function removeOrphans(): int
|
|
{
|
|
$query = $this->connection->getQueryBuilder();
|
|
$query->delete('memories')
|
|
->where($query->expr()->eq('orphan', $query->createNamedParameter(true, IQueryBuilder::PARAM_BOOL)))
|
|
;
|
|
|
|
return $query->executeStatement();
|
|
}
|
|
}
|