joomla / joomla-cms

Home of the Joomla! Content Management System
https://www.joomla.org
GNU General Public License v2.0
4.77k stars 3.65k forks source link

When using the Joomla 4 API to Create an Article it fails (500) as soon as an Editor Plugin is installed #37975

Closed DonPedro34 closed 2 years ago

DonPedro34 commented 2 years ago

Steps to reproduce the issue

Use Postman to create an Article /content/articles

With no Admin Plugin installed/enabled this Works Fine. You can use the boxplus Plugin or others to reproduce.

With Demo body: { "alias": "my-article-3", "articletext": "My text", "catid": 126, "language": "*", "metadesc": "", "metakey": "", "title": "Here's an article" }

Expected result

{ "links": { "self": "http://xxxxxxxxxxx/api/index.php/v1/content/articles" }, "data": { "type": "articles", "id": "123", "attributes": { "typeAlias": "com_content.article", "id": 123, "asset_id": 466, "title": "Here's an article", "alias": "my-article-3", "state": 0, "created": "2022-06-03 20:59:53", "created_by": 816, "created_by_alias": "", "modified": "2022-06-03 20:59:53", "modified_by": 816, "publish_up": null, "publish_down": null, "images": [], "urls": [], "version": 1, "metakey": "", "metadesc": "", "access": 1, "hits": 0, "metadata": [], "featured": 0, "language": "*", "note": "", "tags": [], "featured_up": null, "featured_down": null, "text": "My text ", "show-infobox": { "true": "True" }, "date": "", "inaturalist-link": "", "show-maps": { "false": "False" }, "location": "", "copyright": "xxxxxxxxx", "camera": { "": null }, "lens": { "": null }, "latitude": "", "english": "", "longitude": "", "german": "", "danish": "" }, "relationships": { "category": { "data": { "type": "categories", "id": "126" } }, "created_by": { "data": { "type": "users", "id": "816" } }, "modified_by": { "data": { "type": "users", "id": "816" } } } } }

Actual result

{ "errors": { "code": 500, "title": "Internal server error" } }

System information (as much as possible)

Joomla 4.1.4

Additional comments

The Article is actually added but CMSPlugin.php fails with this error:

2022-06-03T20:42:25+00:00 CRITICAL 91.141.77.73 error Uncaught Throwable of type ArgumentCountError thrown with message "Too few arguments to function plgContentembed_google_map::onContentPrepare(), 3 passed in [ROOT]/libraries/src/Plugin/CMSPlugin.php on line 285 and exactly 4 expected". Stack trace: #0 [ROOT]/libraries/src/Plugin/CMSPlugin.php(285): plgContentembed_google_map->onContentPrepare('com_content.art...', Object(Joomla\CMS\Object\CMSObject), NULL)

1 [ROOT]/libraries/vendor/joomla/event/src/Dispatcher.php(486): Joomla\CMS\Plugin\CMSPlugin->Joomla\CMS\Plugin{closure}(Object(Joomla\Event\Event))

2 [ROOT]/libraries/src/Application/EventAware.php(111): Joomla\Event\Dispatcher->dispatch('onContentPrepar...', Object(Joomla\Event\Event))

3 [ROOT]/api/components/com_content/src/View/Articles/JsonapiView.php(196): Joomla\CMS\Application\WebApplication->triggerEvent('onContentPrepar...', Array)

4 [ROOT]/libraries/src/MVC/View/JsonApiView.php(222): Joomla\Component\Content\Api\View\Articles\JsonapiView->prepareItem(Object(Joomla\CMS\Object\CMSObject))

5 [ROOT]/api/components/com_content/src/View/Articles/JsonapiView.php(178): Joomla\CMS\MVC\View\JsonApiView->displayItem()

6 [ROOT]/libraries/src/MVC/Controller/ApiController.php(187): Joomla\Component\Content\Api\View\Articles\JsonapiView->displayItem()

7 [ROOT]/libraries/src/MVC/Controller/ApiController.php(344): Joomla\CMS\MVC\Controller\ApiController->displayItem(1327)

8 [ROOT]/libraries/src/MVC/Controller/BaseController.php(735): Joomla\CMS\MVC\Controller\ApiController->add()

9 [ROOT]/libraries/src/Dispatcher/ApiDispatcher.php(59): Joomla\CMS\MVC\Controller\BaseController->execute('add')

10 [ROOT]/libraries/src/Component/ComponentHelper.php(389): Joomla\CMS\Dispatcher\ApiDispatcher->dispatch()

11 [ROOT]/libraries/src/Application/ApiApplication.php(423): Joomla\CMS\Component\ComponentHelper::renderComponent('com_content')

12 [ROOT]/libraries/src/Application/ApiApplication.php(110): Joomla\CMS\Application\ApiApplication->dispatch()

13 [ROOT]/libraries/src/Application/CMSApplication.php(278): Joomla\CMS\Application\ApiApplication->doExecute()

14 [ROOT]/api/includes/app.php(54): Joomla\CMS\Application\CMSApplication->execute()

15 [ROOT]/api/index.php(31): require_once('/www/htdocs/w00...')

16 {main}

DonPedro34 commented 2 years ago

POST http://xxxxxxxxx/api/index.php/v1/content/articles 500 372 ms POST /api/index.php/v1/content/articles HTTP/1.1 Content-Type: application/json X-Joomla-Token: c2hhMjU2OjgxNjoyODYwNzk5NWFiZjhhZjJjNzVhMmU1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx User-Agent: PostmanRuntime/7.29.0 Accept: / Postman-Token: b52f1e9b-ac8c-4993-a625-d479b73f9558 Host: import.insects.at Accept-Encoding: gzip, deflate, br Connection: keep-alive Content-Length: 181

{ "alias": "my-article-5", "articletext": "My text", "catid": 126, "language": "*", "metadesc": "", "metakey": "", "title": "Here's an article" }

HTTP/1.1 500 Internal Server Error Date: Fri, 03 Jun 2022 21:13:34 GMT Server: Apache x-frame-options: SAMEORIGIN referrer-policy: strict-origin-when-cross-origin cross-origin-opener-policy: same-origin X-Powered-By: JoomlaAPI/1.0 Expires: Wed, 17 Aug 2005 00:00:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache X-Content-Type-Options: nosniff Upgrade: h2,h2c Connection: Upgrade, close Last-Modified: Fri, 03 Jun 2022 21:13:34 GMT Vary: User-Agent Transfer-Encoding: chunked Content-Type: application/vnd.api+json; charset=utf-8

{"errors":{"code":500,"title":"Internal server error"}}


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/37975.

alikon commented 2 years ago

from your stack trace Too few arguments to function plgContentembed_google_map::onContentPrepare(), 3 passed in [ROOT]/libraries/src/Plugin/CMSPlugin.php on line 285 and exactly 4 expected". Stack trace: #0 [ROOT]/libraries/src/Plugin/CMSPlugin.php(285): plgContentembed_google_map->onContentPrepare('com_content.art...',

there is an error in that content plugin embed_google_map

Quy commented 2 years ago

Closing as not a core issue.

michalriha commented 2 years ago

Hi, I apologize for commenting on an already closed issue, but I can reproduce this problem with other plugins (e.g. ignite gallery). The problem seems to be here https://github.com/joomla/joomla-cms/blob/a84ef004541e63ea1952fb9c1ba024265ca2894e/api/components/com_content/src/View/Articles/JsonapiView.php#L191

Acording to plugin events documentation at https://docs.joomla.org/Plugin/Events/Content#onContentPrepare , event handlers should be invoked with 4 arguments, but JsonapiView triggers the event with only 3 arguments (the $page argument is missing).

I think either the documentation should be made clear that the $page argument is optional, or the JsonapiView should pass the 4th argument.

aftertaf commented 2 years ago

Same apology - but I have the same issue. IF this is related to a plugin that is not sending 4 arguments, it can be causing all API calls to fail (which is my situation : 500 internal error on GETs of any kind...) ?