kirby3-autoid icon indicating copy to clipboard operation
kirby3-autoid copied to clipboard

Undefined array key "dirname"

Open christophknoth opened this issue 2 years ago • 2 comments

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. :)

christophknoth avatar Dec 02 '21 15:12 christophknoth

@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;
          }
        }

bnomei avatar Jan 27 '22 11:01 bnomei

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.

christophknoth avatar Jan 27 '22 17:01 christophknoth