zteeed / dokuwiki-discord-notifier

Notify page events via Discord
https://www.dokuwiki.org/plugin:discordnotifier
7 stars 6 forks source link

E_WARNING: Trying to access array offset on value of type null #28

Open Miro-Collas opened 1 year ago

Miro-Collas commented 1 year ago

PHP8.1 Release 2023-04-04a "Jack Jackrum"

2023-09-01 22:49:10E_WARNING: Trying to access array offset on value of type null/home/fswiki/public_html/lib/plugins/discordnotifier/helper.php(37)
    #0 /home/fswiki/public_html/lib/plugins/discordnotifier/helper.php(37): dokuwiki\ErrorHandler::errorHandler(2, 'Trying to acces...', '/home/fswiki/pu...', 37)
    #1 /home/fswiki/public_html/lib/plugins/discordnotifier/action.php(31): helper_plugin_discordnotifier->valid_namespace()
    #2 /home/fswiki/public_html/inc/Extension/EventHandler.php(80): action_plugin_discordnotifier->_handle(Object(dokuwiki\Extension\Event), NULL)
    #3 /home/fswiki/public_html/inc/Extension/Event.php(96): dokuwiki\Extension\EventHandler->process_event(Object(dokuwiki\Extension\Event), 'AFTER')
    #4 /home/fswiki/public_html/inc/File/PageFile.php(194): dokuwiki\Extension\Event->advise_after()
    #5 /home/fswiki/public_html/inc/common.php(1289): dokuwiki\File\PageFile->saveWikiText('', '\xE2\x86\xB7 Page name c...', false)
    #6 /home/fswiki/public_html/lib/plugins/move/helper/op.php(204): saveWikiText('support:test', '', '\xE2\x86\xB7 Page name c...')
    #7 /home/fswiki/public_html/lib/plugins/move/action/rename.php(117): helper_plugin_move_op->movePage('support:test', 'support:test2')
    #8 /home/fswiki/public_html/inc/Extension/EventHandler.php(80): action_plugin_move_rename->handle_ajax(Object(dokuwiki\Extension\Event), NULL)
    #9 /home/fswiki/public_html/inc/Extension/Event.php(74): dokuwiki\Extension\EventHandler->process_event(Object(dokuwiki\Extension\Event), 'BEFORE')
    #10 /home/fswiki/public_html/inc/Ajax.php(27): dokuwiki\Extension\Event->advise_before()
    #11 /home/fswiki/public_html/lib/exe/ajax.php(22): dokuwiki\Ajax->__construct('plugin_move_ren...')
    #12 {main}

the code in question is:

            foreach ( $validNamespacesArr as $namespace ) {
                if ( strpos( $namespace, $INFO['namespace'] ) === 0 ) {
                    return true;
                }
            }

specifically this line:

if ( strpos( $namespace, $INFO['namespace'] ) === 0 )

I am clearly not understanding the logic, I guess. I tried the following change:

            foreach ( $validNamespacesArr as $namespace ) {
                if(isset($namespace) && isset($INFO['namespace']) ) {
                    if ( strpos( $namespace, $INFO['namespace'] ) === 0 ) {
                        return true;
                    }
                }
            }

No errors, but then the page edit is not reported at all.

Note: this happens when the page is being renamed via the move plugin. So there is some kind of conflict. Using that same plugin also causes the name of the person doing the move not to be filled. One of the changes in PR #27 corrects for that, filling in (Unknown). Without that change, the name reported is simply blank/empty.

Miro-Collas commented 1 year ago

So, with my almost non-existent understanding of Dokuwiki development, it seems that the move plugin is informing other plugins of what it is doing by raising an event and passing the affected pages in that event: https://github.com/michitux/dokuwiki-plugin-move/blob/master/helper/op.php#L164

However, this plugin totally ignores that data and instead expects to find the information in the $INFO global, which only contains some of the required information (why $INFO isn't filled in completely, I have no idea): https://github.com/zteeed/dokuwiki-discord-notifier/blob/master/action.php#L31 and the valid_namespace function at https://github.com/zteeed/dokuwiki-discord-notifier/blob/master/helper.php#L31

Having said all of that, it seems that move sends a custom event, 'PLUGIN_MOVE_PAGE_RENAME', which this plugin would not know about; it is hooking into 'COMMON_WIKIPAGE_SAVE'.

I have no idea how to even begin to try to resolve this. So I won't. A warning is being generated yet the plugin works as it should - by "miracle", I guess. ;-) The only question is, how much longer will it contine to work before Dokuwiki changes and/or PHP changes break it.

Miro-Collas commented 1 year ago

I dug a bit... the issue raised here has been solved by this plugin: https://github.com/glensc/dokuwiki-plugin-slacknotifier which specifically handles the events raised by move.

See also https://www.dokuwiki.org/plugin:move#for_plugin_authors

@zteeed might wish to fork the slack plugin and make the changes needed to make it work with discord, perhaps. [runs way]