Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Page plugin stucked when login is out

plugins

Solved by Junillon View solution

Started by Junillon 1 year ago · 6 replies · 79 views
1 year ago

Hi, I made a server plugin to transfer pages from one server to another with rsync or sftp.
It's working pretty good but I still have a last problem for a good integration in admin.

  • I go to the page transfer (not the plugin conf, the real page transfer)
  • For some reason I leave the page open a long time (mostly because I make change to files in another terminal)
  • I come back and try the transfer action but login has run out of time
    -And that's the purpose : instead of coming back to the login page, it comes back to nothing but a white window (but with the debug at bottom)
    and that's all... no login box.
    What do I miss ?
1 year ago

Not sure what the real page transfer is, but you can have different session timeout for your plugin. For example Admin plugin has a separate session timeout option from the main timeout

1 year ago

the "real page" is the one with the transfer logic, not the plugin configuration.
Capture d’écran 2025-01-22 à 21.20.47|448x433

Even if it's another session timeout, in all other peaces of the admin interface, if you reach the session timeout, you go back to the login. In my case, this is only an empty window.
Capture d’écran 2025-01-22 à 21.18.50|690x343

1 year ago

Blank page usually means some errors. Did you try turning on error output? Not sure, but maybe in PHP config?

1 year ago Solution

I don't get any error (nor the grav log or php log) but probably I don't understand exactly how it goes in admin part when you are not login.
In my case it seems that all plugins are loaded and initialised (not sure but...) before the global system check about the login.
Therefore in my plugin as I have

JS
public function onPluginsInitialized(): void
    {
        if ($this->isAdmin()) {
                $this->enable([
                'onAdminMenu' => ['onAdminMenu', 0],
                'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
                'onPagesInitialized' => ['onPagesInitialized', 0],
                'onAdminTaskExecute' => ['onAdminTaskExecute', 0],
                ]);
        }
    }

it directly goes to onPagesInitializer and perform the code. Of course it fails because of a redirection to a page unreachable as the unlog blocks it.

PHP
if ($uri->path() === '/admin/pagetransfer') {
                        $page = new \Grav\Common\Page\Page();
                        $page->init(new \SplFileInfo(__DIR__ . '/pages/admin/pagetransfer.md'));
                        $page->template('pagetransfer');  // Use template Twig `pageTransfer.html.twig`
                        $this->grav['page'] = $page;
                }

So I don't know if it's the right thing to do, but changing to this finally made the job:

PHP
public function onPluginsInitialized(): void
    {
        if ($this->grav['user']->authenticated && $this->isAdmin()) {

You confirm this is the right thing to do ? 🤔

1 year ago

@Francois:
You confirm this is the right thing to do ?

I honestly don't know. Would require to do some researching, which unfortunately I don't have time for currently

1 year ago

don't worry. It's anyway nice from you to answer all the time 😉

I'll keep my answer as the solution for others who may need a way to do it in case of same problem. 😇

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 74 6 hours ago
General · by pamtbaau, 11 hours ago
1 47 11 hours ago
General · by Andy Miller, 23 hours ago
0 43 23 hours ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 39 5 days ago