Skip to content

Commit

Permalink
Merge branch 'feature/saterday-night-fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvdlinde committed Oct 19, 2024
2 parents 036a2bc + 59a819c commit 0ff4218
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Db/ObjectEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ObjectEntity extends Entity implements JsonSerializable
protected ?string $uuid = null;
protected ?string $register = null;
protected ?string $schema = null;
protected ?string $version = null;
protected ?array $object = [];
protected ?DateTime $updated = null;
protected ?DateTime $created = null;
Expand All @@ -19,6 +20,7 @@ public function __construct() {
$this->addType(fieldName:'uuid', type: 'string');
$this->addType(fieldName:'register', type: 'string');
$this->addType(fieldName:'schema', type: 'string');
$this->addType(fieldName: 'version', type: 'string');
$this->addType(fieldName:'object', type: 'json');
$this->addType(fieldName:'updated', type: 'datetime');
$this->addType(fieldName:'created', type: 'datetime');
Expand Down Expand Up @@ -63,6 +65,7 @@ public function jsonSerialize(): array
// return [
// 'id' => $this->id,
// 'uuid' => $this->uuid,
// 'version' => $this->version,
// 'register' => $this->register,
// 'schema' => $this->schema,
// 'object' => $this->object,
Expand Down
6 changes: 6 additions & 0 deletions lib/Db/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

class Register extends Entity implements JsonSerializable
{
protected ?string $uuid = null;
protected ?string $title = null;
protected ?string $version = null;
protected ?string $description = null;
protected ?array $schemas = [];
protected ?string $source = null;
Expand All @@ -17,7 +19,9 @@ class Register extends Entity implements JsonSerializable
protected ?DateTime $created = null;

public function __construct() {
$this->addType(fieldName: 'uuid', type: 'string');
$this->addType(fieldName: 'title', type: 'string');
$this->addType(fieldName: 'version', type: 'string');
$this->addType(fieldName: 'description', type: 'string');
$this->addType(fieldName: 'schemas', type: 'json');
$this->addType(fieldName: 'source', type: 'string');
Expand Down Expand Up @@ -64,7 +68,9 @@ public function jsonSerialize(): array
{
return [
'id' => $this->id,
'uuid' => $this->uuid,
'title' => $this->title,
'version' => $this->version,
'description' => $this->description,
'schemas' => $this->schemas,
'source' => $this->source,
Expand Down
7 changes: 7 additions & 0 deletions lib/Db/RegisterMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use Symfony\Component\Uid\Uuid;

class RegisterMapper extends QBMapper
{
Expand Down Expand Up @@ -61,6 +62,12 @@ public function createFromArray(array $object): Register
{
$register = new Register();
$register->hydrate(object: $object);

// Set uuid if not provided
if ($register->getUuid() === null) {
$register->setUuid(Uuid::v4());
}

return $this->insert(entity: $register);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Db/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class Schema extends Entity implements JsonSerializable
{
protected ?string $uuid = null;
protected ?string $title = null;
protected ?string $version = null;
protected ?string $description = null;
Expand All @@ -20,6 +21,7 @@ class Schema extends Entity implements JsonSerializable
protected ?DateTime $created = null;

public function __construct() {
$this->addType(fieldName: 'uuid', type: 'string');
$this->addType(fieldName: 'title', type: 'string');
$this->addType(fieldName: 'version', type: 'string');
$this->addType(fieldName: 'description', type: 'string');
Expand Down Expand Up @@ -93,6 +95,7 @@ public function jsonSerialize(): array

$array = [
'id' => $this->id,
'uuid' => $this->uuid,
'title' => $this->title,
'version' => $this->version,
'description' => $this->description,
Expand Down
7 changes: 7 additions & 0 deletions lib/Db/SchemaMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use Symfony\Component\Uid\Uuid;

class SchemaMapper extends QBMapper
{
Expand Down Expand Up @@ -70,6 +71,12 @@ public function createFromArray(array $object): Schema
{
$schema = new Schema();
$schema->hydrate(object: $object);

// Set uuid if not provided
if ($schema->getUuid() === null) {
$schema->setUuid(Uuid::v4());
}

return $this->insert(entity: $schema);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/Db/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

class Source extends Entity implements JsonSerializable
{
protected ?string $uuid = null;
protected ?string $title = null;
protected ?string $version = null;
protected ?string $description = null;
protected ?string $databaseUrl = null;
protected ?string $type = null;
protected ?DateTime $updated = null;
protected ?DateTime $created = null;

public function __construct() {
$this->addType(fieldName: 'uuid', type: 'string');
$this->addType(fieldName: 'title', type: 'string');
$this->addType(fieldName: 'version', type: 'string');
$this->addType(fieldName: 'description', type: 'string');
$this->addType(fieldName: 'databaseUrl', type: 'string');
$this->addType(fieldName: 'type', type: 'string');
Expand Down Expand Up @@ -60,7 +64,9 @@ public function jsonSerialize(): array
{
return [
'id' => $this->id,
'uuid' => $this->uuid,
'title' => $this->title,
'version' => $this->version,
'description' => $this->description,
'databaseUrl' => $this->databaseUrl,
'type' => $this->type,
Expand Down
6 changes: 6 additions & 0 deletions lib/Db/SourceMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use Symfony\Component\Uid\Uuid;

class SourceMapper extends QBMapper
{
Expand Down Expand Up @@ -61,6 +62,11 @@ public function createFromArray(array $object): Source
{
$source = new Source();
$source->hydrate(object: $object);

// Set uuid if not provided
if ($source->getUuid() === null) {
$source->setUuid(Uuid::v4());
}
return $this->insert(entity: $source);
}

Expand Down
81 changes: 81 additions & 0 deletions lib/Migration/Version1Date20241019205009.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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;

class Version1Date20241019205009 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_sources table
$table = $schema->getTable('openregister_sources');
if (!$table->hasColumn('uuid')) {
$table->addColumn(name: 'uuid', typeName: Types::STRING, options: ['notnull' => true, 'length' => 255]);
$table->addIndex(['uuid'], 'openregister_sources_uuid_index');
}
if (!$table->hasColumn('version')) {
$table->addColumn(name: 'version', typeName: Types::STRING, options: ['notnull' => true, 'length' => 255, 'default' => '0.0.1']);
}

// Update the openregister_schemas table
$table = $schema->getTable('openregister_schemas');
if (!$table->hasColumn('uuid')) {
$table->addColumn(name: 'uuid', typeName: Types::STRING, options: ['notnull' => true, 'length' => 255]);
$table->addIndex(['uuid'], 'openregister_schemas_uuid_index');
}

// Update the openregister_registers table
$table = $schema->getTable('openregister_registers');
if (!$table->hasColumn('uuid')) {
$table->addColumn(name: 'uuid', typeName: Types::STRING, options: ['notnull' => true, 'length' => 255]);
$table->addIndex(['uuid'], 'openregister_registers_uuid_index');
}
if (!$table->hasColumn('version')) {
$table->addColumn(name: 'version', typeName: Types::STRING, options: ['notnull' => true, 'length' => 255, 'default' => '0.0.1']);
}

// Update the openregister_objects table
$table = $schema->getTable('openregister_objects');
if (!$table->hasColumn('version')) {
$table->addColumn(name: 'version', typeName: Types::STRING, options: ['notnull' => true, 'length' => 255, 'default' => '0.0.1']);
}

return $schema;
}

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

0 comments on commit 0ff4218

Please sign in to comment.