I have now run out of ideas and Google is not helping either. I believe the issue is rather simple to solve, but currently I am not seeing why it happens. Everything works fine on my testing environment with dev mode.
But doesn't work on production where the dev mode is off and proxy files need to be generated manually.
The first time I generated proxy files on the production environment, everything worked fine. Now I needed to improve some of the entities and when I use the "doctrine orm:generate-proxies" command again, then all the proxy files get generated and when I look at the new entity proxy files, then I can see that the new column are mapped.
But when I try to save or load new object, then nothing gets saved or load to the new columns. It is as if doctrine 2 doesn't understand, that there are new proxy files that it should use. Instead, it keeps on using some other hidden old proxy files, cached away in some dark end.
Any idea why doctrine 2 doesn't use the newly generated proxy files?
For extra clarity, this the the Doctrine Initialisation code.
$paths = array(__DIR__ . '/../ORM/Definition/Doctrine2/Entity');
$isDevMode = false;
$autoGenerateProxyClasses = AbstractProxyFactory::AUTOGENERATE_NEVER;
if ($this->serverDevelopment()) {
$isDevMode = true;
$autoGenerateProxyClasses = AbstractProxyFactory::AUTOGENERATE_ALWAYS;
}
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => 'REMOVE',
'password' => 'REMOVE',
'dbname' => 'REMOVE',
'host' => 'REMOVE'
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$config->setProxyDir(__DIR__ . '/../ORM/Definition/Doctrine2/Entity/Proxy');
$config->setProxyNamespace('Database\ORM\Definition\Doctrine2\Entity\Proxy');
$config->setAutoGenerateProxyClasses($autoGenerateProxyClasses);
$this->entityManager = EntityManager::create($dbParams, $config);
Any help would be appreciated,
Hendrik
I am using following code to generate proxies:
$em = Zend_Registry::get('em');
$proxyFactory = $em->getProxyFactory();
$metadatas = $em->getMetadataFactory()->getAllMetadata();
$proxyFactory->generateProxyClasses($metadatas, APPLICATION_PATH . '/models/Proxies');
I have Proxies folder inside models folder.
Try generating proxies using this code.
Found out the issue. But I'm not sure, if it was the permissions or the user. But I changed the folder from 775 to 777 and also the user. Now it works :)
Related
I've looked all around for a way to join multiple databases using doctrine 2, but all i've found until now are work arounds but i couldn't understood how to modify my config file to do so
//my config.php file
$isDevMode = true;
$path = array(ROOTPATH."/src");
$config = Setup::createAnnotationMetadataConfiguration($path, $isDevMode);
// database configuration parameters
$conn = array(
'driver' => 'pdo_mysql',
'user' => 'root',
'password' => '',
'dbname' => 'test',
);
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
On this topic here, the accepted answer said that i have to create multiple entity managers,which it's logic , but when i got here, on the PHP tab(i'm using PHP as annotations), i was lost.Couldn't figure out how to change my already existing config file.
Then i found a documentation about joining databases, here , but that looks very different from what i have , probably because is an older version and i don't know if this still work, but i haven't tested that because i don't use yaml,and there's nowhere an explanation on how to do that without using a framework or yaml,xml annotations.
ok, my first SO question, be nice.
I am having problems finding the answer to this question. yes ive tried
the options for the transfer constructor don't mention any ACL options.
my searches on google come up either blank or for version 2.x
this is my code
$options[] = [
'DEBUG' => true,
];
// Where the files will be transferred to
$dest = 's3://newbucket/'.$UUID;
// Create a transfer object.
$manager = new \Aws\S3\Transfer($s3, $path, $dest, $options );
// Perform the transfer synchronously.
$manager->transfer();
$promise = $manager->promise();
$promise->then(function () {
echo 'Done!';
});
everything uploads ok but the files are not public-read
where/how do i set Public-read on the files uploaded in VERSION 3.2
You can add a 'before' closure to the array of options you're passing to the transfer manager that could handle assigning permissions. Try replacing your manager instantiation code with this:
$manager = new \Aws\S3\Transfer($s3, $path, $dest, [
'before' => function (\Aws\CommandInterface $command) {
if (in_array($command->getName(), ['PutObject', 'CreateMultipartUpload'])) {
$command['ACL'] = 'public-read';
}
},
]);
One way you can do it is set the permissions on the Bucket in the console. under permissions of the bucket you want to set. click 'edit bucket policy'
The other peice of info you will need is how to create the JSON file that you paste in. http://awspolicygen.s3.amazonaws.com/policygen.html if you get an error from AWS's tool just reformat it based on what you see in http://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html
I hope that helps others
In my project I use code below to add to assetic some named assets and one of them use lessphp filter.
public function prepend(ContainerBuilder $container)
{
$configs = $container->getExtensionConfig($this->getAlias());
$config = $this->processConfiguration(new Configuration(), $configs);
$this->configureAsseticBundle($container, $config);
}
protected function configureAsseticBundle(ContainerBuilder $container, array $config)
{
foreach (array_keys($container->getExtensions()) as $name) {
switch ($name) {
case 'assetic':
$container->prependExtensionConfig(
$name,
array(
'assets' => array(
'some_less' => array(
'inputs' => array(
'#SomeBundle/Resources/public/less/some.less'
),
'filters' => array('lessphp'),
),
)
)
);
break;
}
}
}
When I dump assets using assetic:dump everything is working fine in production enviroment but in dev enviroment lessphp filter for this named asset works only after few page refresh and after some time it doesn't work anymore and I need to remove all cache. After remove cache it work fine again... for few minutes...
I also noticed that it stop working when I edit any bundle extension class (DependencyInjection/[BundleName]Extension.php).
Does anyone have any idea what i did wrong?
I suspect this is because of the issue reported here. There's a bug in the Assetic code that will incorrectly "clear" out the filters for an asset during rendering, so they are never applied.
You should be able to reliably reproduce it by clearing the cache with php app/console cache:clear. But you should then be able to "fix" it by completely removing the dev cache files and reloading the page.
The PR I referenced is not get committed (it's waiting for a test), but it's a couple lines of a code you can manually add just to confirm it's the fix you're looking for.
I've got a dubious issue. I have a set of existing annotated Doctrine entities which have been successfully used in a Symfony2/Doctrine2 project. However, I'm currently isolating some core functionality of this project into it's own web framework independent library and I can't seem to get the entities to function properly.
At the moment my major concern is the fact that the Doctrine CLI utility is giving me mixed results.
When I do the following:
bin/doctrine orm:validate-schema
I get the following output:
[Mapping] OK - The mapping files are correct.
[Database] OK - The database schema is in sync with the mapping files.
But when I do:
bin/doctrine orm:info
I get this:
[Exception]
You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors.
I have gone over my configuration a gazillion times now. I've even removed all my entities and left a most basic User entity in there giving me the same scenario.
What could possible be the source of these mixed results?
It turns out that the standard Doctrine config set up [1] doesn't work with my code base, or any code base I have tested with, maybe the docs are outdated. After ploughing through the Interwebs for hours, this is the configuration that finally made it work for me:
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\Annotations\AnnotationReader;
$paths = array( realpath(__DIR__."/../src/My/Entity") );
$isDevMode = TRUE;
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => 'myuser',
'password' => 's3cr3t',
'dbname' => 'mydb',
);
$cache = new \Doctrine\Common\Cache\ArrayCache();
$reader = new AnnotationReader();
$driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, $paths);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$config->setMetadataCacheImpl( $cache );
$config->setQueryCacheImpl( $cache );
$config->setMetadataDriverImpl( $driver );
$entityManager = EntityManager::create($dbParams, $config);
//-- This I had to add to support the Mysql enum type.
$platform = $entityManager->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
[1] http://docs.doctrine-project.org/en/latest/tutorials/getting-started.html
The accepted answer is ok but the same thing could be achieved in less verbose manner:
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
$paths = array( realpath(__DIR__."/../src/My/Entity") );
$isDevMode = TRUE;
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => 'myuser',
'password' => 's3cr3t',
'dbname' => 'mydb',
);
$config = Setup::createAnnotationMetadataConfiguration(
$paths, $isDevMode, null, null, false
);
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
$entityManager = EntityManager::create($dbParams, $config);
//-- This I had to add to support the Mysql enum type.
$platform = $entityManager->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
All here is about usage of simple annotation driver or not (last parameter of the Setup::createAnnotationMetadataConfiguration function. By default, a simple annotation driver is used which doesn't recognise the #ORM\Entity annotation.
I have PHP entity in Ressources/config/doctrine/Foo.orm.php
but I use annotation.
Too different way for orm = [Exception]
You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors.
Just delete the bad entity file
For me it happened that I imported the vendor directory from a different system and it wasn't working properly.
A simple composer install or php composer.phar install fixed it.
Hi, everyone!
I'm building a PHP site and I decided to go with Doctrine as DBAL and ORM. I'm a bit rusty on my PHP skills, so please help me understand one thing.
The way to configure Doctrine, as specified in their docs is to execute code like this:
if ($applicationMode == "development") {
$cache = new \Doctrine\Common\Cache\ArrayCache;
} else {
$cache = new \Doctrine\Common\Cache\ApcCache;
}
$config = new Configuration;
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver('/path/to/lib/MyProject/Entities');
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setProxyDir('/path/to/myproject/lib/MyProject/Proxies');
$config->setProxyNamespace('MyProject\Proxies');
if ($applicationMode == "development") {
$config->setAutoGenerateProxyClasses(true);
} else {
$config->setAutoGenerateProxyClasses(false);
}
$connectionOptions = array(
'driver' => 'pdo_sqlite',
'path' => 'database.sqlite'
);
What I'm puzzled about is how should you execute this code. Is it something you put in a config.php file and include in each of your pages, basically executing this each time a page is processed? Or am I supposed to do this configuration once?
On a related note - please help me understand how setting cache to ArrayCache instead of APC cache helps me during development?
Thanks!
doctrine is a pretty hard choice if your PHP skills are rusty... Anyway...
You can create the connection and eventmanger once in a bootstrap file. Then you can pass the eventmanager instance to your class constructors or make it availably through a static registry (dirty dirty dirty) or ...
This is a good starting point (for orm 2.0):
http://www.doctrine-project.org/docs/orm/2.0/en/tutorials/getting-started-xml-edition.html
The only reason for using ArrayCache in dev mode I can think of is, that you do not have to configure APC at that point and can focus on your coding. In production mode APC gives you the extra boost and is highly recommended.
Regards
Flo