Skip to content

Commit

Permalink
Database fixes on catalogus and publication
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzondervan committed Aug 8, 2024
1 parent 92e9659 commit 6d3aab5
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 7 deletions.
12 changes: 10 additions & 2 deletions lib/Db/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Catalog extends Entity implements JsonSerializable

protected bool $listed = false;
protected ?string $organisation = null;
protected array $metadata = [];
protected ?array $metadata = null;

public function __construct() {
$this->addType(fieldName: 'title', type: 'string');
Expand All @@ -42,11 +42,17 @@ public function getJsonFields(): array

public function hydrate(array $object): self
{


if(isset($object['metadata']) === false) {
$object['metadata'] = [];
}

$jsonFields = $this->getJsonFields();

foreach($object as $key => $value) {
if (in_array($key, $jsonFields) === true && $value === []) {
$value = null;
$value = [];
}

$method = 'set'.ucfirst($key);
Expand All @@ -71,6 +77,8 @@ public function jsonSerialize(): array
'image' => $this->image,
'search' => $this->search,
'listed' => $this->listed,
'metadata' => $this->metadata,
'organisation'=> $this->organisation,

];

Expand Down
9 changes: 7 additions & 2 deletions lib/Db/Publication.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public function hydrate(array $object): self
$this->setData(null);
$this->setModified(new DateTime());


if(isset($object['published']) === false) {
$object['published'] = null;
}

foreach($object as $key => $value) {
if (in_array($key, $jsonFields) === true && $value === []) {
$value = [];
Expand Down Expand Up @@ -114,8 +119,8 @@ public function jsonSerialize(): array
'portal' => $this->portal,
'catalogi' => $this->catalogi,
'metaData' => $this->metaData,
'published' => $this->published->format('c'),
'modified' => $this->modified->format('c'),
'published' => $this->published?->format('c'),
'modified' => $this->modified?->format('c'),
'featured' => $this->featured !== null ? (bool) $this->featured : null,
'organization' => $this->organization,
'data' => $this->data,
Expand Down
6 changes: 3 additions & 3 deletions lib/Migration/Version6Date20240723125106.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
]
);
$table->addColumn(name: 'organization', typeName: TYPES::JSON, options: [
'default' => [],
'default' => 'a:0:{}',
'notnull' => false,
]);
$table->addColumn(name: 'data', typeName: TYPES::JSON, options: [
'default' => [],
'default' => 'a:0:{}',
'notnull' => false,
]);
$table->addColumn(name: 'attachments', typeName: TYPES::JSON, options: [
'default' => [],
'default' => 'a:0:{}',
'notnull' => false,
]);
$table->addColumn(name: 'attachment_count', typeName: TYPES::INTEGER);
Expand Down
77 changes: 77 additions & 0 deletions lib/Migration/Version6Date20240808085441.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

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

namespace OCA\OpenCatalogi\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 Version6Date20240808085441 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();

if($schema->hasTable(tableName: 'catalogi') === true) {
$table = $schema->getTable(tableName: 'catalogi');

if($table->hasColumn(name: 'organization') === false) {
$table->addColumn(
name: 'organization',
typeName: Types::STRING,
options: [
'notNull' => false,
'default' => null
]);
}
if($table->hasColumn(name: 'metadata') === false) {
$table->addColumn(
name: 'metadata',
typeName: Types::JSON,
options: [
'notNull' => false,
'default' => 'a:0:{}'
]);
}

}

return $schema;
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}
63 changes: 63 additions & 0 deletions lib/Migration/Version6Date20240808092738.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

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

namespace OCA\OpenCatalogi\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 Version6Date20240808092738 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();

if($schema->hasTable(tableName: 'publications') === true) {
$table = $schema->getTable(tableName: 'publications');

if($table->hasColumn(name: 'published') === true) {
$column = $table->getColumn(name: 'published');
$column->setDefault(default: null);
}

}

return $schema;
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}
62 changes: 62 additions & 0 deletions lib/Migration/Version6Date20240808093230.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

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

namespace OCA\OpenCatalogi\Migration;

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

/**
* FIXME Auto-generated migration step: Please modify to your needs!
*/
class Version6Date20240808093230 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();

if($schema->hasTable(tableName: 'publications') === true) {
$table = $schema->getTable(tableName: 'publications');

if($table->hasColumn(name: 'published') === true) {
$column = $table->getColumn(name: 'published');
$column->setNotnull(notnull: false);
}

}

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 6d3aab5

Please sign in to comment.