Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/Db/ObjectEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@
class ObjectEntity extends Entity implements JsonSerializable
{
protected ?string $uuid = null;
protected ?string $uri = null;
protected ?string $version = null;
protected ?string $register = null;
protected ?string $schema = null;
protected ?array $object = [];
protected ?array $files = []; // array of file ids that are related to this object
protected ?array $relations = []; // array of object ids that this object is related to
protected ?string $textRepresentation = null;
protected ?DateTime $updated = null;
protected ?DateTime $created = null;

public function __construct() {
$this->addType(fieldName:'uuid', type: 'string');
$this->addType(fieldName:'uuid', type: 'string');
$this->addType(fieldName:'uri', type: 'string');
$this->addType(fieldName:'version', type: 'string');
$this->addType(fieldName:'register', type: 'string');
$this->addType(fieldName:'schema', type: 'string');
$this->addType(fieldName:'object', type: 'json');
$this->addType(fieldName:'files', type: 'json');
$this->addType(fieldName:'relations', type: 'json');
$this->addType(fieldName:'textRepresentation', type: 'text');
$this->addType(fieldName:'updated', type: 'datetime');
$this->addType(fieldName:'created', type: 'datetime');
Expand Down Expand Up @@ -72,10 +78,13 @@ public function getObjectArray(): array
return [
'id' => $this->id,
'uuid' => $this->uuid,
'uri' => $this->uri,
'version' => $this->version,
'register' => $this->register,
'schema' => $this->schema,
'object' => $this->object,
'files' => $this->files,
'relations' => $this->relations,
'textRepresentation' => $this->textRepresentation,
'updated' => isset($this->updated) ? $this->updated->format('c') : null,
'created' => isset($this->created) ? $this->created->format('c') : null
Expand Down
78 changes: 78 additions & 0 deletions lib/Migration/Version1Date20241128221000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\OpenRegister\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* FIXME Auto-generated migration step: Please modify to your needs!
*/
class Version1Date20241128221000 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

// Update the openregister_objects table
$table = $schema->getTable('openregister_objects');
if ($table->hasColumn('uri') === false) {
$table->addColumn(
name: 'uri',
typeName: Types::STRING,
options: [
'notnull' => true,
'length' => 255
]
)->setDefault('');
}
if ($table->hasColumn('files') === false) {
$table->addColumn(
name: 'files',
typeName: Types::JSON,
options: ['notnull' => false]
)->setDefault('{}');
}
if ($table->hasColumn('relations') === false) {
$table->addColumn(
name: 'relations',
typeName: Types::JSON,
options: ['notnull' => false]
)->setDefault('{}');;
}

return $schema;
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}
Loading