Skip to content

Commit

Permalink
Merge branch 'development' into feature/DIMOC-204/fileService
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoLouwerse committed Aug 8, 2024
2 parents c285871 + 2a71806 commit 7ae9271
Show file tree
Hide file tree
Showing 25 changed files with 552 additions and 183 deletions.
20 changes: 17 additions & 3 deletions lib/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,28 @@ public function index(SearchService $searchService): JSONResponse

$fieldsToSearch = ['title', 'description', 'summary'];

if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
if($this->config->hasKey($this->appName, 'elasticLocation') === false
|| $this->config->getValueString($this->appName, 'elasticLocation') === ''
) {
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);

$limit = null;
$offset = null;

if(isset($filters['_limit']) === true) {
$limit = $filters['_limit'];
}

if(isset($filters['_page']) === true) {
$offset = ($limit * ($filters['_page'] - 1));
}

$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->publicationMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);


return new JSONResponse(['results' => $this->publicationMapper->findAll(limit: $limit, offset: $offset, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}

//@TODO: find a better way to get query params. This fixes it for now.
Expand Down
26 changes: 19 additions & 7 deletions lib/Db/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
class Catalog extends Entity implements JsonSerializable
{

protected ?string $title = null;
protected ?string $summary = null;
protected ?string $description = null;
protected ?string $image = null;
protected ?string $search = null;
protected ?string $title = null;
protected ?string $summary = null;
protected ?string $description = null;
protected ?string $image = null;
protected ?string $search = null;

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

public function __construct() {
$this->addType(fieldName: 'title', type: 'string');
Expand All @@ -24,6 +26,8 @@ public function __construct() {
$this->addType(fieldName: 'image', type: 'string');
$this->addType(fieldName: 'search', type: 'string');
$this->addType(fieldName: 'listed', type: 'boolean');
$this->addType(fieldName: 'organisation', type: 'string');
$this->addType(fieldName: 'metadata', type: 'json');

}

Expand All @@ -38,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 @@ -67,6 +77,8 @@ public function jsonSerialize(): array
'image' => $this->image,
'search' => $this->search,
'listed' => $this->listed,
'metadata' => $this->metadata,
'organisation'=> $this->organisation,

];

Expand Down
10 changes: 8 additions & 2 deletions lib/Db/Publication.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public function hydrate(array $object): self
$this->setAttachments(null);
$this->setOrganization(null);
$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 === []) {
Expand Down Expand Up @@ -114,8 +120,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 {
}
}
Loading

0 comments on commit 7ae9271

Please sign in to comment.