Doctrine: "1/1ReflectionException: Property Power\SelfBundle\Entity\Check::$part1 does not exists" - symfony

I am working with symfony. I have an entity Check. It has a relation field part.
The definition is something like:
/** #ORM\OneToMany(targetEntity="Power\SelfBundle\Entity\Friends", mappedBy="check")*/
protected $part1;
In the inverse relation (at Friendsentity) the declaration is like:
/** #ORM\ManyToOne(targetEntity="Power\SelfBundle\Entity\Check", inversedBy="part1") */
public $check;
Now for removing ambiguity I have deleted the field and replaced it by part. I have updated the schema and cleared the cache and logs.
Later I am inserting into the friends entity (table infact) and it gives an error while event calling the entity:
1/1ReflectionException: Property Power\SelfBundle\Entity\Check::$part1 does not exists
But $part1 is deleted long ago. The cache is cleared and the log is cleared too. I have searched the whole project but nowhere even the text part1 is found.
I am out of my wit!!
Can anyone please help me!!
Thanks.

The problem is fixed after lots of researching.
The problem was in doctrine metadata cache.
In my config.yml file metadata_cache_driver was set to use APC. So clearing the doctrine app/cache was not helpful.
After lots of searching - I have done
php -r "apc_clear_cache(); apc_clear_cache('user'); apc_clear_cache('opcode');"
and BINGO it worked!!
So in my config_dev.yml I have overridden the setting to set the metadata_cache_driver to array.

Related

Nelmio/Alice 2.x Symfony 3 , Loading Related Fixtures in Different Bundles

If there's already answer to my question then sorry and please point me in the right direction because I can't find anything.
Let's say I have two Bundles. Each bundle has fixures.yml file and loader file.
Loaders and fixtures are working fine when they are not depending on each other.
However when I am referencing fixtureA from fixtureB I get duplicated record in database.
E.g:
user_{1..10}:
email (unique): '<firstName()>+<randomNumber()>#gmail.com'
plainPassword: 'secret'
story_{1..10}:
user: "#user_<current()>"
title: '<word>'
When they are in separated files - duplicated row. When they are in the same file everything is ok.
Why it's being loaded twice?
I even tried this:
$objects = Fixtures::load(__DIR__ . '/fixtures.yml', $manager, ['persist_once'=>true]);
No luck.
Evey time I am trying to use user object in story fixtures alice tries to save it into db again.
Best Regards,
Robert
I did a little research and talked to people - it looks like it's a possible bug. You can learn more here:
Nelmio/Alice 2.x Duplicated Row
Also I would like to share my work around:
I wanted to keep things separated and clean. Instead of keeping all fixtures in one file in one bundle you can move it to App/DataFixtures/ORM directory. However Symfony will not look for fixtures in this directory. You can:
add path to the fixtures in console command:
doctrine:fixtures:load --fixtures=/var/www/story/app/DataFixtures/ORM
create alias for above solution
override DoctrineFixturesBundle - how to do this
I hope this will help if you have similar issue.

Drupal 8: Mismatched entity and/or field definitions

While trying to understand why my view is not displaying, I noticed the following error in the log:
I do not think it is possible to delete the URL alias from Taxonomy terms. At least I cannot find how to do this.
I have, however gone through ALL of my taxonomy terms and removed the value for this field.
I have also done the following with Pathauto:
Also, I have checked the report located at admin/reports/fields and can confirm that there are no entities that use a field called URL alias.
I have gone through each content item and ensured that they have the following setting (anyone know how to do this in bulk?). But still the error remains.
Anyone know then how I can fix this strange error?
Im not entirely sure what this command does, but it fixed the error:
drush updb --entity-updates
Since https://www.drupal.org/node/2554097, the magic in Drupal core that took care of updating entity definitions is gone. drush updb --entiy-updates is an alternative to this but it is not a silver bullet. Instead, it is safer to write database updates.
Taking the screenshot at the top as an example, here is a database update that would delete those two field definitions:
/**
* Fix taxonomy and node field definitions.
*
*/
function mymodule_update_8101() {
$manager = \Drupal::entityDefinitionUpdateManager();
if ($field = $manager->getFieldStorageDefinition('alias', 'node')) {
$manager->uninstallFieldStorageDefinition($field);
}
if ($field = $manager->getFieldStorageDefinition('alias', 'term')) {
$manager->uninstallFieldStorageDefinition($field);
}
}
Have a look at the rest of the available methods at https://www.drupal.org/node/2554097 in order to write database updates for each scenario.
use the entity_update module or the devel_entity_updates module

Typo3 Extbase Repository->findAll() returns empty

I just can't findAll() make return anything even though I am able to access a specific record by findByUid().
I have taken note (and tried to workaround / set up) of the typoscript solution and the record storage page bug without any success.
I am using a dummy extension code made by the extension builder in TYPO3 (current version) for your convenience. I have tested with data manually added through the TYPO3 config ui.
Any help would be much appreciated.
All the best and thanks in advance
Mario
For 99.9 % you didn't set your storagePid properly, it has to be the PID of the page where your records are stored. Effect: findAll() uses this PID to filter the records, while findByUid(uid) ignores PID (it searches by UID wherever record is stored.
Go to the main page > Templates and make sure that you included TypoScript from your new ext, then go to constant editor and set proper PID of page with your records. Clear whole cache at the end!
Also you can debug your SQL statement like in this answer, most probably at the end of statement you'll see something like AND your_table_name.pid IN (0) which definitely means that you didn't set storagePid or you didn't clear the cache.

Symfony2s doctrine:generate:entities doesn't generate repo classes

I go with Symfony2 docs. It's said that adding
/**
* #ORM\Entity(repositoryClass="Acme\StoreBundle\Entity\ProductRepository")
*/
in my entity file and running php app/console doctrine:generate:entities Acme should create the ProductRepository file. It doesn't. I can't clarimy this more, it's just doesnt create that file, just recreates those entity files that were there before.
I found the answer here:
http://brentertainment.com/other/docs/book/doctrine/orm.html
If you have already generated your entity class before adding the repositoryClass mapping, you have to create the class on your own. Fortunately, it’s pretty easy. Simply create the class in the Repository directory of your bundle and be sure it extends Doctrine\ORM\EntityRepository. Once you’ve created the class, you can add any method to query your entities.
Simple, we have to do it by hand because we have already run this once
If you are using orm.yml files to generate your entities, you can define the repositoryClass, and then generate the entities again:
Acme\StoreBundle\Entity\Product:
type: entity
table: product
...
repositoryClass: Acme\StoreBundle\Entity\ProductRepository
...
And then run:
php app/console doctrine:generate:entities AcmeStoreBundle
You can try to specify a particular bundle:
php app/console doctrine:generate:entities AcmeStoreBundle
Note that i have the full bundles name.
This would help even if you run doctrine:generate:entities before.
Super easy solution to this:
Generate an entity if you haven't already:
php app/console doctrine:generate:entity --entity="AppBundle:EntityName" --fields="id:string(255) content:text(100)"
Now modify these comment lines to your previously generated Entity:
* #ORM\Table(name="TABLENAME")
* #ORM\Entity(repositoryClass="AppBundle\Entity\EntityNameRepository")
Now, just run:
php app/console doctrine:generate:entities AppBundle:EntityNameRepository
Now you have an entity and repository. :)
To get rid of this problem and generate repo classes, you can temporary modify the end of the following file :
symfony\vendor\doctrine\doctrine-bundle\Doctrine\Bundle\DoctrineBundle\Command\generateEntitiesDoctrineCommand.php
if ($m->customRepositoryClassName
&& false !== strpos($m->customRepositoryClassName, $metadata->getNamespace())) {
$repoGenerator->writeEntityRepositoryClass(
$m->customRepositoryClassName, $metadata->getPath());
}
with the following code :
if (true) {
$output->writeln(
sprintf(' > AND Repository <comment>%s</comment>', $m->name . "Repository")
);
$repoGenerator->writeEntityRepositoryClass(
$m->name . "Repository", $metadata->getPath());
}
Some explanations : in this code,
the if condition is simplified with 'if (true)' (and could finally be completely suppressed if you want)
$m->customRepositoryClassName is replaced by $m->name."Repository"
I added some output to be well informed (in the terminal window) when the repo files are generated.
If you don't use the 'if(true)' condition, and want to check things by yourself, you can also add a facultative else case with an output to get well informed in the future :
else {
$output->writeln(sprintf(' > NO repository generated for this class'));
}
After the modifications, you can re-run the command as usual :
php app/console doctrine:generate:entities AcmeStoreBundle
This is a temporary code, because the problem is not very clear for me until now, the only things I see is that it seems to come from $m->customRepositoryClassName which returns an empty string.
So, to find another and definitive solution, a way could be to check the method customRepositoryClassName of the metadata object...
based in Astucieux's answer:
if (true) {
$fullRepositoryClassName = $name . "\\Repository\\" . $basename . "Repository";
$output->writeln(
sprintf(' > AND Repository <comment>%s</comment>', $fullRepositoryClassName)
);
$repoGenerator->writeEntityRepositoryClass(
$fullRepositoryClassName, $metadata->getPath());
}

Symfony 2.1 - FPNTagBundle with annotated Tag entity

I have installed FPNTagBundle via composer. I have successfully added tags to my articles, but when I add DoctrineExtensions' TagRepository as the repositoryClass with
/**
* #ORM\Entity(repositoryClass="DoctrineExtensions\Taggable\Entity\TagRepository")
* #ORM\Table
*/
class Tag extends FPN\TagBundle\Entity\Tag
and try to use TagRepository's method getResourceIdsForTag('post', 'tagname'), it fails. I've checked the repository class with
$tagRepo = $this->getDoctrine()->getRepository('GergelyPolonkaiFrontBundle:Tag');
echo get_class($tagRepo);
and it's not TagRepository, but Doctrine\ORM\Entity\Repository. I don't have any other error message regarding the repositoryClass thing, even if I specify an invalid classname.
Have I found a bug, or do I miss something somewhere?
It seems I was hitting a bug. After merging some pull requests by Fabien Pennequin 16 days ago, it now seems working as expected.

Resources