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,70 @@
<?php
/**
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.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 OCA\Text\Db;
use OCP\AppFramework\Db\Entity;
/**
* @method getId(): int
* @method getCurrentVersion(): int
* @method setCurrentVersion(int $version): void
* @method getLastSavedVersion(): int
* @method setLastSavedVersion(int $version): void
* @method getInitialVersion(): int
* @method setInitialVersion(int $version): void
* @method getLastSavedVersionTime(): int
* @method setLastSavedVersionTime(int $time): void
* @method getLastSavedVersionEtag(): string
* @method setLastSavedVersionEtag(string $etag): void
* @method getBaseVersionEtag(): string
* @method setBaseVersionEtag(string $etag): void
*/
class Document extends Entity implements \JsonSerializable {
public $id = null;
// TODO: Remove obsolete field `currentVersion`
protected int $currentVersion = 0;
protected int $lastSavedVersion = 0;
protected int $initialVersion = 0;
protected int $lastSavedVersionTime = 0;
protected string $lastSavedVersionEtag = '';
protected string $baseVersionEtag = '';
public function __construct() {
$this->addType('id', 'integer');
$this->addType('currentVersion', 'integer');
$this->addType('lastSavedVersion', 'integer');
$this->addType('lastSavedVersionTime', 'integer');
$this->addType('initialVersion', 'integer');
}
public function jsonSerialize(): array {
return [
'id' => $this->id,
'lastSavedVersion' => $this->lastSavedVersion,
'lastSavedVersionTime' => $this->lastSavedVersionTime,
'baseVersionEtag' => $this->baseVersionEtag,
'initialVersion' => $this->initialVersion
];
}
}
@@ -0,0 +1,66 @@
<?php
/**
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.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 OCA\Text\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
/** @extends QBMapper<Document> */
class DocumentMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'text_documents', Document::class);
}
/**
* @param $documentId
* @return Document
* @throws DoesNotExistException
*/
public function find(int $documentId): Document {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$result = $qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('id', $qb->createNamedParameter($documentId)))
->executeQuery();
$data = $result->fetch();
$result->closeCursor();
if ($data === false) {
throw new DoesNotExistException('Document doesn\'t exist');
}
return Document::fromRow($data);
}
public function findAll(): array {
$qb = $this->db->getQueryBuilder();
$result = $qb->select('*')
->from($this->getTableName())
->executeQuery();
return $this->findEntities($qb);
}
}
+84
View File
@@ -0,0 +1,84 @@
<?php
/**
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.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 OCA\Text\Db;
use JsonSerializable;
use OCA\Text\Exception\InvalidSessionException;
use OCP\AppFramework\Db\Entity;
/**
* @method void setUserId(?string $userId)
* @method string getToken()
* @method void setToken(string $token)
* @method string getColor()
* @method void setColor(string $color)
* @method string|null getGuestName()
* @method void setGuestName(string $guestName)
* @method string|null getAwarenessMessage()
* @method void setLastAwarenessMessage(string $message)
* @method int getLastContact()
* @method void setLastContact(int $getTime)
* @method int getDocumentId()
* @method void setDocumentId(int $documentId)
*/
class Session extends Entity implements JsonSerializable {
public $id;
protected ?string $userId = null;
protected string $token = '';
protected string $color = '';
protected ?string $guestName = null;
protected ?string $lastAwarenessMessage = '';
protected int $lastContact = 0;
protected int $documentId = 0;
public function __construct() {
$this->addType('id', 'integer');
$this->addType('documentId', 'integer');
$this->addType('lastContact', 'integer');
}
public function isGuest(): bool {
return $this->userId === null;
}
public function getUserId(): string {
if ($this->userId === null) {
throw new InvalidSessionException('No user id found');
}
return $this->userId;
}
public function jsonSerialize(): array {
return [
'id' => $this->id,
'userId' => $this->userId,
'token' => $this->token,
'color' => $this->color,
'lastAwarenessMessage' => $this->lastAwarenessMessage,
'lastContact' => $this->lastContact,
'guestName' => $this->guestName,
'documentId' => $this->documentId,
];
}
}
@@ -0,0 +1,174 @@
<?php
/**
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.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 OCA\Text\Db;
use OCA\Text\Service\SessionService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
/** @extends QBMapper<Session> */
class SessionMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'text_sessions', Session::class);
}
/**
* @return array
*/
public function findAllDocuments(): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName());
return $this->findEntities($qb);
}
/**
* @param $documentId
* @param $sessionId
* @param $token
* @return Session
* @throws DoesNotExistException
*/
public function find(int $documentId, int $sessionId, string $token): Session {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$result = $qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)))
->andWhere($qb->expr()->eq('id', $qb->createNamedParameter($sessionId)))
->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
->executeQuery();
$data = $result->fetch();
$result->closeCursor();
if ($data === false) {
throw new DoesNotExistException('Session is invalid');
}
return Session::fromRow($data);
}
/**
* @return Session[]
*
* @psalm-return array<Session>
*/
public function findAll(int $documentId): array {
$qb = $this->db->getQueryBuilder();
$qb->select('id', 'color', 'document_id', 'last_awareness_message', 'last_contact', 'user_id', 'guest_name')
->from($this->getTableName())
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)));
return $this->findEntities($qb);
}
/**
* @return Session[]
*
* @psalm-return array<Session>
*/
public function findAllActive(int $documentId): array {
$qb = $this->db->getQueryBuilder();
$qb->select('id', 'color', 'document_id', 'last_awareness_message', 'last_contact', 'user_id', 'guest_name')
->from($this->getTableName())
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)))
->andWhere($qb->expr()->gt('last_contact', $qb->createNamedParameter(time() - SessionService::SESSION_VALID_TIME)));
return $this->findEntities($qb);
}
/**
* @return Session[]
*
* @psalm-return array<Session>
*/
public function findAllInactive(): array {
$qb = $this->db->getQueryBuilder();
$qb->select('id', 'color', 'document_id', 'last_awareness_message', 'last_contact', 'user_id', 'guest_name')
->from($this->getTableName())
->where($qb->expr()->lt('last_contact', $qb->createNamedParameter(time() - SessionService::SESSION_VALID_TIME)));
return $this->findEntities($qb);
}
public function deleteInactiveWithoutSteps(?int $documentId = null): int {
$lastContact = time() - SessionService::SESSION_VALID_TIME;
$inactiveSessionBuilder = $this->db->getQueryBuilder();
$inactiveSessionBuilder->select('s.id')
->from('text_sessions', 's')
->leftJoin('s', 'text_steps', 'st', $inactiveSessionBuilder->expr()->eq('st.session_id', 's.id'))
->where($inactiveSessionBuilder->expr()->lt('last_contact', $inactiveSessionBuilder->createNamedParameter($lastContact)))
->andWhere($inactiveSessionBuilder->expr()->isNull('st.id'));
if ($documentId !== null) {
$inactiveSessionBuilder->andWhere($inactiveSessionBuilder->expr()->eq('s.document_id', $inactiveSessionBuilder->createNamedParameter($documentId)));
}
$result = $inactiveSessionBuilder->executeQuery();
$documentIds = array_map(function ($row) {
return (int)$row['id'];
}, $result->fetchAll());
$result->closeCursor();
$chunks = array_chunk($documentIds, 500);
$deleteBuilder = $this->db->getQueryBuilder();
$deleteBuilder->delete($this->getTableName())
->where($deleteBuilder->expr()->in('id', $deleteBuilder->createParameter('ids'), IQueryBuilder::PARAM_INT_ARRAY));
$deletedCount = 0;
foreach ($chunks as $ids) {
$deleteBuilder->setParameter('ids', $ids, IQueryBuilder::PARAM_INT_ARRAY);
$deletedCount += $deleteBuilder->executeStatement();
}
return $deletedCount;
}
public function deleteByDocumentId(int $documentId): int {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->getTableName())
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)));
return $qb->executeStatement();
}
public function isUserInDocument(int $documentId, string $userId): bool {
$qb = $this->db->getQueryBuilder();
$result = $qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)))
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)))
->setMaxResults(1)
->executeQuery();
$data = $result->fetch();
$result->closeCursor();
if ($data === false) {
return false;
}
return true;
}
}
+76
View File
@@ -0,0 +1,76 @@
<?php
/**
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.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 OCA\Text\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
/**
* @method getData(): string
* @method setData(string $data): void
* @method getVersion(): int
* @method setVersion(int $version): void
* @method getSessionId(): int
* @method setSessionId(int $sessionId): void
* @method getDocumentId(): int
* @method setDocumentId(int $documentId): void
*/
class Step extends Entity implements JsonSerializable {
/*
* Transition: We now use the auto-incrementing id as the version.
* To ensure that new steps always have a larger version than those that
* used the version field, use the largest possible 32-bit integer value.
*/
public const VERSION_STORED_IN_ID = 2147483647;
public $id = null;
protected string $data = '';
protected int $version = 0;
protected int $sessionId = 0;
protected int $documentId = 0;
public function __construct() {
$this->addType('id', 'integer');
$this->addType('version', 'integer');
$this->addType('documentId', 'integer');
$this->addType('sessionId', 'integer');
}
public function jsonSerialize(): array {
$jsonData = \json_decode($this->data, false);
if (\json_last_error() !== JSON_ERROR_NONE) {
throw new \InvalidArgumentException('Failed to parse step data');
}
$version = $this->getVersion() === self::VERSION_STORED_IN_ID
? $this->getId()
: $this->getVersion();
return [
'id' => $this->getId(),
'data' => $jsonData,
'version' => $version,
'sessionId' => $this->getSessionId()
];
}
}
@@ -0,0 +1,96 @@
<?php
/**
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.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 OCA\Text\Db;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
/** @extends QBMapper<Step> */
class StepMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'text_steps', Step::class);
}
/**
* @return Step[]
*/
public function find(int $documentId, int $fromVersion): array {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)))
->andWhere($qb->expr()->gt('version', $qb->createNamedParameter($fromVersion)))
->andWhere($qb->expr()->gt('id', $qb->createNamedParameter($fromVersion)));
$qb
->setMaxResults(1000)
->orderBy('id');
return $this->findEntities($qb);
}
public function getLatestVersion(int $documentId): ?int {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$result = $qb->select('id')
->from($this->getTableName())
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)))
->setMaxResults(1)
->orderBy('id', 'DESC')
->executeQuery();
$data = $result->fetch();
if ($data === false) {
return null;
}
return $data['id'];
}
public function deleteAll(int $documentId): void {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->getTableName())
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)))
->executeStatement();
}
// not in use right now
public function deleteBeforeVersion(int $documentId, int $version): int {
$qb = $this->db->getQueryBuilder();
return $qb->delete($this->getTableName())
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)))
->andWhere($qb->expr()->lte('id', $qb->createNamedParameter($version)))
->executeStatement();
}
public function deleteAfterVersion(int $documentId, int $version): int {
$qb = $this->db->getQueryBuilder();
return $qb->delete($this->getTableName())
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)))
->andWhere($qb->expr()->gt('version', $qb->createNamedParameter($version)))
->andWhere($qb->expr()->gt('id', $qb->createNamedParameter($version)))
->executeStatement();
}
}