Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flex Users storage problem #167

Open
Sogl opened this issue Sep 16, 2022 · 1 comment
Open

Flex Users storage problem #167

Sogl opened this issue Sep 16, 2022 · 1 comment

Comments

@Sogl
Copy link

Sogl commented Sep 16, 2022

I want to store users in accounts\username folder.

In my config\system.yaml:

accounts:
  type: flex
  storage: folder
  avatar: gravatar

I copied system/blueprints/flex/user-accounts.yaml to user/blueprints/flex/user-accounts.yaml. Data configuration part:

  # Data Configuration
  data:
    object: 'Grav\Common\Flex\Types\Users\UserObject'
    collection: 'Grav\Common\Flex\Types\Users\UserCollection'
    index: 'Grav\Common\Flex\Types\Users\UserIndex'
    storage:
      class: 'Grav\Common\Flex\Types\Users\Storage\UserFolderStorage'
      options:
        formatter:
          class: 'Grav\Framework\File\Formatter\YamlFormatter'
        folder: 'account://'
        pattern: '{FOLDER}/{KEY}{EXT}'
        indexed: true
        key: username
        case_sensitive: false 

All should be fine but users are saved to hashed folders:

image

As you can see with Xdebug, pattern and storage_key are wrong (not from our storage configuration):

image

Ok. I can extend UserObject to my custom to override save() func:

<?php

declare(strict_types=1);

namespace Grav\Plugin\SoglFlex\Flex\Types\Users;

use Grav\Common\Grav;
use Grav\Common\Flex\Types\Users\UserObject as DefaultUserObject;

class UserObject extends DefaultUserObject
{
    /**
     * {@inheritdoc}
     * @see FlexObjectInterface::save()
     */
    public function save()
    {
        if (!$this->exists()) {
            $this->setStorageKey($this->getProperty('username'));
        }
        parent::save();
    }
}

Much better but still triple nesting:
image

BUT when I try to override class: 'Grav\Plugin\SoglFlex\Flex\Types\Users\UserFolderStorage' it just not fire.

It looks as if the entire storage section is not being read, but the default values are being used.

@mahagr How to fix?

@Sogl
Copy link
Author

Sogl commented Sep 17, 2022

After hours of debugging I found that if I write in config\system.yaml:

accounts:
  type: flex
  storage: SOMETHING
  avatar: gravatar

My custom class works fine and also all other storage options from user-accounts.yaml.

However, each time of Configuration saving (in Admin panel) storage: SOMETHING will be overwritten. Need to add +1 value for custom or something else:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant