Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

Undefined array key "dirname" #72

Open
christophknoth opened this issue Dec 2, 2021 · 2 comments
Open

Undefined array key "dirname" #72

christophknoth opened this issue Dec 2, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@christophknoth
Copy link

christophknoth commented Dec 2, 2021

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 bnomei self-assigned this Jan 27, 2022
@bnomei bnomei added the bug Something isn't working label Jan 27, 2022
@bnomei
Copy link
Owner

bnomei commented Jan 27, 2022

@christophknoth thanks for reporting the issue.

if you can still replicate the issue could you dump the $objectid on error?

$pathinfo = pathinfo($objectid);

      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
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants