bnomei / kirby3-autoid

Automatic unique ID for Pages, Files and Structures including performant helpers to retrieve them. Bonus: Tiny-URL.
https://forum.getkirby.com/t/kirby3-autoid-plugin/23572
MIT License
80 stars 8 forks source link

Undefined array key "dirname" #72

Open christophknoth opened 2 years ago

christophknoth commented 2 years ago

Hi Bnomei, I am trying out autoid on a server with php8.0.12 and I get the following error

Whoops\Exception\ErrorException thrown with message "Undefined array key "dirname""

Stacktrace:
#29 Whoops\Exception\ErrorException in /var/.../site/plugins/kirby3-autoid-master/classes/AutoIDDatabase.php:245
#28 Whoops\Run:handleError in /var/.../site/plugins/kirby3-autoid-master/classes/AutoIDDatabase.php:245
#27 Bnomei\AutoIDDatabase:pageFilenameFromPath in /var/.../site/plugins/kirby3-autoid-master/classes/AutoIDDatabase.php:89
#26 Bnomei\AutoIDDatabase:findByID in /var/.../site/plugins/kirby3-autoid-master/classes/AutoID.php:131
#25 Bnomei\AutoID:find in /var/.../site/plugins/kirby3-autoid-master/index.php:19
#24 autoid in /var/.../site/plugins/kirby3-autoid-master/index.php:121
#23 Kirby\Filesystem\F:{closure} in /var/.../kirby/src/Cms/Field.php:78
#22 Kirby\Cms\Field:__call in /var/.../site/snippets/single-action-overview-with-full-content.php:217
#21 include in /var/.../kirby/src/Filesystem/F.php:410
#20 Kirby\Filesystem\F:loadIsolated in /var/.../kirby/src/Filesystem/F.php:387
#19 Kirby\Filesystem\F:load in /var/.../kirby/src/Toolkit/Tpl.php:36
#18 Kirby\Toolkit\Tpl:load in /var/.../kirby/config/components.php:300
#17 Kirby\Cms\Core:{closure} in /var/.../kirby/src/Cms/App.php:1433
#16 Kirby\Cms\App:snippet in /var/.../kirby/config/helpers.php:717
#15 snippet in /var/.../site/snippets/everything.php:5
#14 include in /var/.../kirby/src/Filesystem/F.php:410
#13 Kirby\Filesystem\F:loadIsolated in /var/.../kirby/src/Filesystem/F.php:387
#12 Kirby\Filesystem\F:load in /var/.../kirby/src/Toolkit/Tpl.php:36
#11 Kirby\Toolkit\Tpl:load in /var/.../kirby/config/components.php:300
#10 Kirby\Cms\Core:{closure} in /var/.../kirby/src/Cms/App.php:1433
#9 Kirby\Cms\App:snippet in /var/.../kirby/config/helpers.php:717
#8 snippet in /var/.../site/templates/home.php:3
#7 include in /var/.../kirby/src/Filesystem/F.php:410
#6 Kirby\Filesystem\F:loadIsolated in /var/.../kirby/src/Filesystem/F.php:387
#5 Kirby\Filesystem\F:load in /var/.../kirby/src/Toolkit/Tpl.php:36
#4 Kirby\Toolkit\Tpl:load in /var/.../kirby/src/Cms/Template.php:167
#3 Kirby\Cms\Template:render in /var/.../kirby/src/Cms/Page.php:1061
#2 Kirby\Cms\Page:render in /var/.../kirby/src/Cms/App.php:704
#1 Kirby\Cms\App:io in /var/.../kirby/src/Cms/App.php:1077
#0 Kirby\Cms\App:render in /var/.../index.php:5

I know you are on parental leave and it is not urgent but I just wanted to let you know. :)

bnomei commented 2 years ago

@christophknoth thanks for reporting the issue.

if you can still replicate the issue could you dump the $objectid on error? https://github.com/bnomei/kirby3-autoid/blob/76372d3b8d6bab5f4c7188944f48e54f9eb33b51/classes/AutoIDDatabase.php#L244

      if (pathinfo($objectid, PATHINFO_EXTENSION)) {
            $pathinfo = pathinfo($objectid);
            $page = $pathinfo['dirname'];
            $filename = $pathinfo['basename'];
        } else {
           try{
               $pathinfo = pathinfo($objectid);
               $page = $pathinfo['dirname'] === '.' ? $pathinfo['basename'] : $pathinfo['dirname'] . '/' . $pathinfo['basename'];
               $structure = strpos($page, '#') !== false ? explode('#', $page)[1] : '';
           } catch(\Exception $ex) {
                var_dump($objectid);
                echo $ex->getMessage();
                die;
          }
        }
christophknoth commented 2 years ago

Thank you for getting back to me. I tried what you said and realized that this dump is probably not very helpful:

string(0) ""
--
  | Undefined array key "dirname"

So I looked into my code and put an if ($node->linkfield()->toPage()) { before I use $node->linkfield->fromAutoID() and that did the trick. It seems with PHP7.4 autoid did not stumble over an empty field.