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

PDOException on serialize/cache a NodeWrapper #31

Open
vocjunior opened this issue Sep 1, 2014 · 0 comments
Open

PDOException on serialize/cache a NodeWrapper #31

vocjunior opened this issue Sep 1, 2014 · 0 comments

Comments

@vocjunior
Copy link

I got the exception: PDOException: You cannot serialize or unserialize PDO instances when I tried to save a \DoctrineExtensions\NestedSet\NodeWrapper object in Doctrine Cache. To fix this bug I made the following changes in NodeWrapper class. Please, consider add this changes in next release.

    /**
     * To avoid PDO exception, the property 'manager' cannot be serialized
     * If you need the manager after unserialize the object, you MUST call the attachManager() method in the current wrapper
     * @return array
     */
    function __sleep() {
        return [
            'node',
            'parent',
            'ancestors',
            'descendants',
            'children',
            'level',
            'outlineNumbers',
        ];
    }

    /**
     * Attach a {@see \DoctrineExtensions\NestedSet\Manager} to the current wrapper
     * This method is useful after wakeup a serialized object
     * @param Manager $manager
     */
    public function attachManager(Manager $manager) {
        if (empty($this->manager)) {
            $this->manager = $manager;
        }
    }
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