distantnative / search-for-kirby

Kirby 3 plugin for adding a search index (sqlite or Algolia).
43 stars 3 forks source link

Saving file via Panel throws Exception (Call to a member function has() on array) #44

Closed tobiasfabian closed 3 years ago

tobiasfabian commented 3 years ago

Describe the bug

When I’m saving a file (e.g. pdf, jpg, etc.) via the panel I got the following error.

// POST /api/pages/downloads/files/lorem-ipsum.pdf
{
    "status": "error",
    "message": "Call to a member function has() on array",
    "code": 500,
    "exception": "Error",
    "key": null,
    "file": "hasRules.php",
    "line": 43,
    "details": [],
    "route": "(.*)/files/([a-zA-Z0-9\\.\\-_%= \\+\\@\\(\\)]+)"
}

I think it’s this file:

https://github.com/distantnative/search-for-kirby/blob/main/src/models/Index/hasRules.php#L43

Steps to reproduce

  1. Open Panel
  2. Open a file (e.g. jpg, pdf, etc)
  3. Edit a field of the file
  4. Save the file
  5. Got this exception Bildschirmfoto 2021-01-26 um 19 18 33

Expected behavior

Error message shouldn’t appear ;-)

Additional context

The data is saved correctly to the file’s content file (e.g. /content/downloads/lorem-ipsum.pdf.txt) – nothing bad happens – but the user experience isn’t good since the user gets an error message and the orange “status” bar at the bottom of the Panel (Revert | Save) does not disappear although the content is saved.

I have set the entries.files (see below) option to false. When I remove this option, I can save files without an error message.

I also tested with user fields. When I try to update a user and the entries.users option is set to false I get the error message. When I remove the option the error doesn’t occur.

Specifications

tobiasfabian commented 3 years ago

I think this solves the problem.

https://github.com/tobiasfabian/search-for-kirby/commit/8f38e43a3e701c8b99202f429c505257f0960703

I’ll try and test it to make sure it has no negative side effects.