migrate therinaldos.com data
Build & Deploy to DigitalOcean Space / build (push) Failing after 2m38s

This commit is contained in:
2024-05-05 15:50:45 -04:00
commit ef1ff240d4
23182 changed files with 3801898 additions and 0 deletions
@@ -0,0 +1,117 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @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 OC\TextToImage\Db;
use DateTime;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\TextToImage\Task as OCPTask;
/**
* @method setLastUpdated(DateTime $lastUpdated)
* @method DateTime getLastUpdated()
* @method setInput(string $type)
* @method string getInput()
* @method setResultPath(string $resultPath)
* @method string getResultPath()
* @method setStatus(int $type)
* @method int getStatus()
* @method setUserId(?string $userId)
* @method string|null getUserId()
* @method setAppId(string $type)
* @method string getAppId()
* @method setIdentifier(string $identifier)
* @method string|null getIdentifier()
* @method setNumberOfImages(int $numberOfImages)
* @method int getNumberOfImages()
* @method setCompletionExpectedAt(DateTime $at)
* @method DateTime getCompletionExpectedAt()
*/
class Task extends Entity {
protected $lastUpdated;
protected $type;
protected $input;
protected $status;
protected $userId;
protected $appId;
protected $identifier;
protected $numberOfImages;
protected $completionExpectedAt;
/**
* @var string[]
*/
public static array $columns = ['id', 'last_updated', 'input', 'status', 'user_id', 'app_id', 'identifier', 'number_of_images', 'completion_expected_at'];
/**
* @var string[]
*/
public static array $fields = ['id', 'lastUpdated', 'input', 'status', 'userId', 'appId', 'identifier', 'numberOfImages', 'completionExpectedAt'];
public function __construct() {
// add types in constructor
$this->addType('id', 'integer');
$this->addType('lastUpdated', 'datetime');
$this->addType('input', 'string');
$this->addType('status', 'integer');
$this->addType('userId', 'string');
$this->addType('appId', 'string');
$this->addType('identifier', 'string');
$this->addType('numberOfImages', 'integer');
$this->addType('completionExpectedAt', 'datetime');
}
public function toRow(): array {
return array_combine(self::$columns, array_map(function ($field) {
return $this->{'get'.ucfirst($field)}();
}, self::$fields));
}
public static function fromPublicTask(OCPTask $task): Task {
/** @var Task $dbTask */
$dbTask = Task::fromParams([
'id' => $task->getId(),
'lastUpdated' => \OCP\Server::get(ITimeFactory::class)->getDateTime(),
'status' => $task->getStatus(),
'numberOfImages' => $task->getNumberOfImages(),
'input' => $task->getInput(),
'userId' => $task->getUserId(),
'appId' => $task->getAppId(),
'identifier' => $task->getIdentifier(),
'completionExpectedAt' => $task->getCompletionExpectedAt(),
]);
return $dbTask;
}
public function toPublicTask(): OCPTask {
$task = new OCPTask($this->getInput(), $this->getAppId(), $this->getNumberOfImages(), $this->getuserId(), $this->getIdentifier());
$task->setId($this->getId());
$task->setStatus($this->getStatus());
$task->setCompletionExpectedAt($this->getCompletionExpectedAt());
return $task;
}
}
@@ -0,0 +1,127 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @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 OC\TextToImage\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
/**
* @extends QBMapper<Task>
*/
class TaskMapper extends QBMapper {
public function __construct(
IDBConnection $db,
private ITimeFactory $timeFactory,
) {
parent::__construct($db, 'text2image_tasks', Task::class);
}
/**
* @param int $id
* @return Task
* @throws Exception
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
public function find(int $id): Task {
$qb = $this->db->getQueryBuilder();
$qb->select(Task::$columns)
->from($this->tableName)
->where($qb->expr()->eq('id', $qb->createPositionalParameter($id)));
return $this->findEntity($qb);
}
/**
* @param int $id
* @param string|null $userId
* @return Task
* @throws DoesNotExistException
* @throws Exception
* @throws MultipleObjectsReturnedException
*/
public function findByIdAndUser(int $id, ?string $userId): Task {
$qb = $this->db->getQueryBuilder();
$qb->select(Task::$columns)
->from($this->tableName)
->where($qb->expr()->eq('id', $qb->createPositionalParameter($id)));
if ($userId === null) {
$qb->andWhere($qb->expr()->isNull('user_id'));
} else {
$qb->andWhere($qb->expr()->eq('user_id', $qb->createPositionalParameter($userId)));
}
return $this->findEntity($qb);
}
/**
* @param string $userId
* @param string $appId
* @param string|null $identifier
* @return array
* @throws Exception
*/
public function findUserTasksByApp(?string $userId, string $appId, ?string $identifier = null): array {
$qb = $this->db->getQueryBuilder();
$qb->select(Task::$columns)
->from($this->tableName)
->where($qb->expr()->eq('user_id', $qb->createPositionalParameter($userId)))
->andWhere($qb->expr()->eq('app_id', $qb->createPositionalParameter($appId)));
if ($identifier !== null) {
$qb->andWhere($qb->expr()->eq('identifier', $qb->createPositionalParameter($identifier)));
}
return $this->findEntities($qb);
}
/**
* @param int $timeout
* @return Task[] the deleted tasks
* @throws Exception
*/
public function deleteOlderThan(int $timeout): array {
$datetime = $this->timeFactory->getDateTime();
$datetime->sub(new \DateInterval('PT'.$timeout.'S'));
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where($qb->expr()->lt('last_updated', $qb->createPositionalParameter($datetime, IQueryBuilder::PARAM_DATE)));
$deletedTasks = $this->findEntities($qb);
$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)
->where($qb->expr()->lt('last_updated', $qb->createPositionalParameter($datetime, IQueryBuilder::PARAM_DATE)));
$qb->executeStatement();
return $deletedTasks;
}
public function update(Entity $entity): Entity {
$entity->setLastUpdated($this->timeFactory->getDateTime());
return parent::update($entity);
}
}