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

Missing find() method in ApiUser #184

Open
marc-farre opened this issue Dec 4, 2024 · 7 comments
Open

Missing find() method in ApiUser #184

marc-farre opened this issue Dec 4, 2024 · 7 comments
Assignees

Comments

@marc-farre
Copy link
Contributor

I could not tell what creates this error in the log (see below), but since we have a ApiUser::findOne() method (see here), perhaps we could add a find() method?
I'm not sure...

Error: Call to undefined method humhub\modules\rest\models\ApiUser::find() in /var/www/protected/humhub/modules/content/components/ContentContainerController.php:166
Stack trace:
#0 /var/www/protected/humhub/modules/content/components/ContentContainerController.php(74): humhub\modules\content\components\ContentContainerController->getContentContainerByGuid('d87c21e5-0ef4-4...')
#1 /var/www/protected/vendor/yiisoft/yii2/base/BaseObject.php(109): humhub\modules\content\components\ContentContainerController->init()
#2 /var/www/protected/vendor/yiisoft/yii2/base/Controller.php(95): yii\base\BaseObject->__construct(Array)
#3 [internal function]: yii\base\Controller->__construct('user', Object(humhub\modules\ecommerce\Module), Array)
#4 /var/www/protected/vendor/yiisoft/yii2/di/Container.php(411): ReflectionClass->newInstanceArgs(Array)
#5 /var/www/protected/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('humhub\\modules\\...', Array, Array)
#6 /var/www/protected/vendor/yiisoft/yii2/BaseYii.php(345): yii\di\Container->get('humhub\\modules\\...', Array)
#7 /var/www/protected/vendor/yiisoft/yii2/base/Module.php(666): yii\BaseYii::createObject('humhub\\modules\\...', Array)
#8 /var/www/protected/vendor/yiisoft/yii2/base/Module.php(620): yii\base\Module->createControllerByID('user')
#9 /var/www/protected/vendor/yiisoft/yii2/base/Module.php(612): yii\base\Module->createController('subscriptions')
#10 /var/www/protected/vendor/yiisoft/yii2/base/Module.php(546): yii\base\Module->createController('user/subscripti...')
#11 /var/www/protected/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('ecommerce/user/...', Array)
#12 /var/www/protected/vendor/yiisoft/yii2/base/Application.php(384): yii\web\Application->handleRequest(Object(humhub\components\Request))
#13 /var/www/index.php(33): yii\base\Application->run()
#14 {main}
@gevorgmansuryan
Copy link
Contributor

gevorgmansuryan commented Dec 7, 2024

@marc-farre \humhub\modules\rest\models\ApiUser is not AR model, it's model for validation (yii\base\Model), and should not have find and findOne methods, and should not be used as AR model in ecommerce module. So findOne should be removed. @luke- what you think?

@marc-farre
Copy link
Contributor Author

@gevorgmansuryan Thanks.
It's strange that the ecommerce comes up in the error, because there is no API in this module.
So I really don't know if there is a relation with the module and the issue.
I know that the API on this instance is used to create new users, in a basic way.
If needed, I'll ask the client for the API request code and try to reproduce to understand what's going on.

@gevorgmansuryan
Copy link
Contributor

@marc-farre yep, let's ask for request

@marc-farre
Copy link
Contributor Author

Let's close this issue for now, I will reopen it if I think there is a real problem ApiUser.
Thanks @gevorgmansuryan for your review.

@marc-farre
Copy link
Contributor Author

marc-farre commented Dec 18, 2024

Reopening the issue, because now I understand what happens.

When creating a new user using the Rest API POST api/v1/user request:
the class humhub\modules\rest\models\ApiUser is added to the contentcontainer table
instead of the humhub\modules\user\models\User one.

The bug then occurs here: https://github.com/humhub/humhub/blob/e91a8ac1269a9b71f4f4d5bf602608dcb3ab1520/protected/humhub/modules/content/components/ContentContainerController.php#L164-L166

When fixing this issue, I think we should create a migration to repair the table, such as:

UPDATE `contentcontainer` 
SET `class` = 'humhub\\modules\\user\\models\\User'
WHERE `class` = 'humhub\\modules\\rest\\models\\ApiUser'

@marc-farre marc-farre reopened this Dec 18, 2024
@gevorgmansuryan
Copy link
Contributor

@marc-farre I've tried to create user with rest, and class in contentcontainer was saved correctly. I think fixing database data with migration only will solve the issue

@marc-farre
Copy link
Contributor Author

Thanks for trying. When I find time, I'll try to investigate more and test on my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants