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

Cannot access protected property Omeka\Entity\ResourceTemplateProperty::$isRequired #955

Closed
jajm opened this issue Jun 22, 2017 · 4 comments · Fixed by #959
Closed

Cannot access protected property Omeka\Entity\ResourceTemplateProperty::$isRequired #955

jajm opened this issue Jun 22, 2017 · 4 comments · Fixed by #959
Milestone

Comments

@jajm
Copy link
Contributor

jajm commented Jun 22, 2017

Hi,

I ran into a weird bug lately and I'm not sure how to fix it.

The error message is

PHP Fatal error:  Cannot access protected property Omeka\Entity\ResourceTemplateProperty::$isRequired in /home/omekas/omeka-s/vendor/doctrine/collections/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php on line 90
PHP Stack trace:
PHP   1. {main}() /home/omekas/omeka-s/test.php:0
PHP   2. Omeka\Api\Manager->create() /home/omekas/omeka-s/test.php:41
PHP   3. Omeka\Api\Manager->execute() /home/omekas/omeka-s/application/src/Api/Manager.php:78
PHP   4. Omeka\Api\Adapter\AbstractEntityAdapter->create() /home/omekas/omeka-s/application/src/Api/Manager.php:224
PHP   5. Omeka\Api\Adapter\AbstractEntityAdapter->hydrateEntity() /home/omekas/omeka-s/application/src/Api/Adapter/AbstractEntityAdapter.php:267
PHP   6. Omeka\Api\Adapter\AbstractResourceEntityAdapter->validateEntity() /home/omekas/omeka-s/application/src/Api/Adapter/AbstractEntityAdapter.php:563
PHP   7. Doctrine\ORM\PersistentCollection->matching() /home/omekas/omeka-s/application/src/Api/Adapter/AbstractResourceEntityAdapter.php:150
PHP   8. Doctrine\Common\Collections\ArrayCollection->matching() /home/omekas/omeka-s/vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php:652
PHP   9. array_filter() /home/omekas/omeka-s/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php:387
PHP  10. Doctrine\Common\Collections\Expr\ClosureExpressionVisitor->Doctrine\Common\Collections\Expr\{closure}() /home/omekas/omeka-s/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php:387
PHP  11. Doctrine\Common\Collections\Expr\ClosureExpressionVisitor::getObjectFieldValue() /home/omekas/omeka-s/vendor/doctrine/collections/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php:133

This happens sometimes when using CSVImport, but I think it's not related to this module. I've been able to reproduce the problem with this script:

<?php

$email = 'CHANGEME';
$password = 'CHANGEME';

require __DIR__ . '/bootstrap.php';

$application = Omeka\Mvc\Application::init(require __DIR__ . '/application/config/application.config.php');

$serviceLocator = $application->getServiceManager();
$auth = $serviceLocator->get('Omeka\AuthenticationService');
$api = $serviceLocator->get('Omeka\ApiManager');

$adapter = $auth->getAdapter();
$adapter->setIdentity($email);
$adapter->setCredential($password);
$auth->authenticate();

$itemData = [
    'o:resource_template' => [
        'o:id' => 1,
    ],
    'dcterms:title' => [
        [
            'property_id' => 1,
            'type' => 'literal',
            '@value' => 'test',
        ]
    ],
];

// This works
$response = $api->create('items', $itemData);
$item = $response->getContent();

// This still works
$api->create('items', $itemData);

// But this fails (Cannot access protected property Omeka\Entity\ResourceTemplateProperty::$isRequired)
$item->value('dcterms:title');
$api->create('items', $itemData);

It seems that if the entities are already loaded, Doctrine doesn't query the database but instead filter directly from the loaded collection.
Of course, changing Omeka\Entity\ResourceTemplateProperty::$isRequired visibility to public fixes the problem, but I don't know if it's the best solution.

@zerocrates
Copy link
Member

You're correct that Doctrine tries to access the already-loaded property when it does lookups for stuff that's been loaded from the database already.

What version of S are you using? If you're using a Git checkout, have you run gulp deps lately to get the current dependencies? Doctrine had an upstream change that should have addressed this, and that should have been pulled in as part of beta4.

@jajm
Copy link
Contributor Author

jajm commented Jun 23, 2017

I'm using the develop branch (v1.0.0-beta4-33-gef28c843). I just ran gulp deps but nothing changed.
I also disabled all modules, but the problem is still there.

@jajm
Copy link
Contributor Author

jajm commented Jun 23, 2017

I've added a test to be run with Travis, and it fails with the same error: https://travis-ci.org/biblibre/omeka-s/builds/246099385

@jajm
Copy link
Contributor Author

jajm commented Jun 23, 2017

And I just discovered that if I change the getter method isRequired() to getIsRequired(), Doctrine seems to use the getter and the error is gone.

jajm added a commit to biblibre/omeka-s that referenced this issue Jun 23, 2017
isRequired() is not usable by Doctrine which sometimes may fail with the
following error:

PHP Fatal error:  Cannot access protected property
Omeka\Entity\ResourceTemplateProperty::$isRequired

Keep isRequired() for convenience and backward compatibility for
modules that might use it

(fix omeka#955)
@zerocrates zerocrates modified the milestone: July 10 2017 Jun 26, 2017
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

Successfully merging a pull request may close this issue.

2 participants