Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Introduce ModuleInfoInterface and fix fatal error on Marketplace keyword search #6771

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ HumHub Changelog

1.16.0 (Unreleased)
-------------------
- Fix #6771: Fatal error on Marketplace keyword search (and Introduce `ModuleInfoInterface` #6771)
- Fix #6754: Regression due to return type (#6550)
- Enh #6550: Improve module migrations
- Fix #6237: Migration errors during module activation are ignored
Expand Down
38 changes: 25 additions & 13 deletions protected/humhub/components/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace humhub\components;

use humhub\interfaces\ModuleInfoInterface;
use humhub\models\Setting;
use humhub\modules\activity\components\BaseActivity;
use humhub\modules\admin\jobs\DisableModuleJob;
Expand All @@ -34,7 +35,7 @@
* @property SettingsManager $settings
* @author luke
*/
class Module extends \yii\base\Module
class Module extends \yii\base\Module implements ModuleInfoInterface
{
/**
* @var array|null the loaded module.json info file
Expand Down Expand Up @@ -62,9 +63,26 @@ public function init()
}

/**
* Returns the module's name provided by module.json file
*
* @return string Name
* @inheritDoc
* @since 1.16
*/
public function getId()
{
if (!empty($this->id)) {
return $this->id;
}

$info = $this->getModuleInfo();

if ($info['id']) {
return $info['id'];
}

throw new InvalidConfigException(static::class . '::$id property must be set.');
}

/**
* @inheritDoc
*/
public function getName()
{
Expand All @@ -78,9 +96,7 @@ public function getName()
}

/**
* Returns the module's description provided by module.json file
*
* @return string Description
* @inheritDoc
*/
public function getDescription()
{
Expand All @@ -94,9 +110,7 @@ public function getDescription()
}

/**
* Returns the module's version number provided by module.json file
*
* @return string Version Number
* @inheritDoc
*/
public function getVersion()
{
Expand Down Expand Up @@ -127,9 +141,7 @@ public function getImage()
}

/**
* Returns module's keywords provided by module.json file
*
* @return array List of keywords
* @inheritDoc
*/
public function getKeywords(): array
{
Expand Down
4 changes: 3 additions & 1 deletion protected/humhub/components/ModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
use humhub\components\bootstrap\ModuleAutoLoader;
use humhub\components\console\Application as ConsoleApplication;
use humhub\exceptions\InvalidArgumentTypeException;
use humhub\interfaces\ModuleInfoInterface;
use humhub\models\ModuleEnabled;
use humhub\modules\admin\events\ModulesEvent;
use humhub\modules\marketplace\models\Module as OnlineModuleModel;
use humhub\modules\marketplace\Module as ModuleMarketplace;
use Throwable;
use Yii;
Expand Down Expand Up @@ -418,7 +420,7 @@ public function filterModulesByKeyword(?array $modules, $keyword = null): array
}

foreach ($modules as $id => $module) {
/* @var Module $module */
/* @var ModuleInfoInterface|Module|OnlineModuleModel $module */
$searchFields = [$id];
if ($searchField = $module->getName()) {
$searchFields[] = $searchField;
Expand Down
50 changes: 50 additions & 0 deletions protected/humhub/interfaces/ModuleInfoInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* @link https://www.humhub.org/
* @copyright Copyright (c) 2023 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace humhub\interfaces;

/**
* @since 1.16
*/
interface ModuleInfoInterface
{
/**
* Returns the ID that uniquely identifies this module among other modules which have the same [[module|parent]].
*
* @return string ID (Return type SHOULD be enforced)
*/
public function getId();

/**
* Returns the module's name provided by module.json file
*
* @return string Name (Return type SHOULD be enforced)
*/
public function getName();

/**
* Returns the module's description provided by module.json file
*
* @return string Description (Return type SHOULD be enforced)
*/
public function getDescription();

/**
* Returns the module's version number provided by module.json file
*
* @return string Version Number (Return type SHOULD be enforced)
*/
public function getVersion();

/**
* Returns the module's keywords provided by module.json file
*
* @return array List of keywords
*/
public function getKeywords(): array;
}
40 changes: 39 additions & 1 deletion protected/humhub/modules/marketplace/models/Module.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2021 HumHub GmbH & Co. KG
Expand All @@ -7,6 +8,7 @@

namespace humhub\modules\marketplace\models;

use humhub\interfaces\ModuleInfoInterface;
use humhub\modules\marketplace\Module as MarketplaceModule;
use humhub\modules\marketplace\services\FilterService;
use humhub\widgets\Link;
Expand All @@ -26,7 +28,7 @@
*
* @since 1.11
*/
class Module extends Model
class Module extends Model implements ModuleInfoInterface
{
/**
* @var string
Expand Down Expand Up @@ -140,6 +142,42 @@ public function __construct($config = [])
parent::__construct($config);
}

/**
* @inheritDoc
* @since 1.16
*/
public function getId(): string
{
return $this->id;
}

/**
* @inheritDoc
* @since 1.16
*/
public function getName(): string
{
return $this->name;
}

/**
* @inheritDoc
* @since 1.16
*/
public function getDescription(): string
{
return '';
}

/**
* @inheritDoc
* @since 1.16
*/
public function getKeywords(): array
{
return [];
}

public function getIsNonFree(): bool
{
return (!empty($this->price_eur) || !empty($this->price_request_quote));
Expand Down