Context : I have been asked today to add a new feature on a quite old project (something like Symfony 2.0). It consisted in adding a new attribute to an entity and add the corresponding field to the edition form. Child play : I have edited the code and it works well in dev environment (set directly in app.php)
Problem : When the environment set in app.php is prod, the entity is not persisted when the form is submitted, nor retrieved when the form is loaded.
Investigations : What I have checked so far in prod env :
The submitted form is correct
The controller manages to map the form and to hydrate the entity correctly
I have deleted the cache multiple times both manually and from command line
I have checked the SQL query after the form has been submitted, the query does not update my new field as expected
Supposition : The problem seems to apppear when the entity is flushed, it is like the new field was completely ignored.
Assumption : After having exposed my problem to more experienced symfony developers, the only suggestion was that there may be a PHP cache (not the symfony one) somewhere parasitizing my prodenv. This assumption is being tested (I could not restart apache myself) and I will be able to test it maybe tomorrow in the best scenario.
Still, I feel like the PHP cache assumption has 10% chance to be the good one. I can not share with you the whole project code, but I am asking you if you could post every idea you might have regarding this issue.
UPDATE : I have restarted Apache2. Problem is still persisting. It seems like Doctrine builds its cache on a former version of the project (It does not see any changes in the annotations for example) even though app/cache/ is empty. Any idea ?
I have deleted the cache multiple times both manually and from command
line
Can you clarify? Symfony's cache is not the same as doctrine's. Depending on your configuration doctrine could be using something like apc, reddis or something else to cache its own queries and result data. If you haven't yet, try to perform these commands:
app/console doctrine:cache:clear-metadata
app/console doctrine:cache:clear-query
app/console doctrine:cache:clear-result
If you're still out of luck, I'm more than 10% sure that an apache restart will do the trick.
If this worked, you should check your prods config yml and see if you find something like:
metadata_cache_driver : something
result_cache_driver : something
query_cache_driver : something
Full answer was to execute :
app/console doctrine:cache:clear-metadata --env=prod
The caching was caused by a memcache configuration only present in production environment.
Related
I have problem, after insert or update in my screen i see message:
Warning:
rename(C:\Users\Name\Desktop\BaseApp\var\cache\dev/doctrine/orm/Proxies__CG__AppBundleEntityCategory.php.57483ae07bdb29.50220410,C:\Users\Name\Desktop\BaseApp\var\cache\dev/doctrine/orm/Proxies__CG__AppBundleEntityCategory.php):
All time after update i see this message, after reload page all is right,
i use my app on windows, dev mode, symfony3,
Regards!
The problem is that the Doctrine's proxy class generation code doesn't handle concurrent requests very well. It works on Unix-like systems, but not on Windows, where you can't just rename over a file that is open.
See configuration of the doctrine bundle. You'll most like have auto_generate_proxy_classes set to "%kernel.debug%" (this is the default setting in symfony standard edition).
Try changing auto_generate_proxy_classes to false. You'll now have to manually clear the cache if you change your entities, but that error should be gone.
I have a website in Symfony linked to a a MySQL database. The website is having some troubles, so I have to update the information in the database. The thing is, when I update on the database, it stays updated there but on the website it doesn't show any changes.
For example, a user is registered. I go to the database to change the email so I can register another account with the same email. The database is updated with the new email, but on the website it says that the old email is still in use.
I know that I am updating the right database, because when I register a new client on the website, it appears on the database. Any ideas on to why this might be happening?
Like Angel Iliikov mentions in the comments, it's very likely a caching issue. The following suggestions assumes you have access to the command line - which a typical Symfony user should. If you don't already have it, most hosting providers allow you to get SSH access.
Clear the following caches:
1. Symfony's cache
Symfony will store a lot of data in the cache files to prevent it from having to process requests from scratch. When Symfony apps go wonky, a very common fix is to clear this cache and retry. The standard way to clear this cache is with a console command run at your project's root directory:
$ app/console cache:clear
If you run into issues, David Soussan answer provides more information on this one.
2. Doctrine's cache
According to commenters on another question (formatted by me):
The doctrine cache is often stored in apc rather than in the file
system so removing the cache files would not help. The general app/console cache:clear is only for the symfony (app) cache. I don't think it clears the doctrine cache(s).
-caponica
Alternative PHP Cache (APC) is an optional component enabled in php.ini. It's possible Doctrine is caching information there as well if it happens to be enabled.
The accepted answer on the previously mentioned question provides an answer for clearing Doctrine's cache:
$ app/console doctrine:cache:clear-metadata
$ app/console doctrine:cache:clear-query
$ app/console doctrine:cache:clear-result
-amitchhajer
3. Your browser's cache
This is very unlikely to be causing any issues. But if you are doing something to send caching headers over HTTP - it's possible that the application would have properly updated the data, but your browser is displaying an old page.
Each browser has a different way of clearing cache. Google provides support for how to do it Chrome. and Mozilla provides support for how do it in Firefox.
If clearing the cache doesn't solve your problem, it's likely a problem with your application or workflow and will need debugging. A few things you can try:
Make sure you really updated the correct database. Confirm this
on two separate DB clients.
Create your own Symfony
command
where the only thing you do is query the database. If it returns the correct result, you should check that other components are using the same query. If not, check your config/parameters to ensure you're using the right database.
If your Symfony application is not showing the updated database record that is because it is using the cache which still contains the old data. This is often a problem with Symfony, refreshing the page just reloads from the cache. Try clearing the cache first. Now, very often cache:clear does not work from the command line, I've had it happen all the time and never really understood why. The answer is to just delete all the cache files, as per Fabien Potencier's tip: http://fabien.potencier.org/a-symfony-tip-clear-the-cache-without-the-command-line.html. That works and is my go-to solution for when eg; composer update did not clear the cache afterwards. In fact I got into the habit of just deleting the cache files on my dev machine before doing composer install or update.
Adam,
Use these commands to clear your cache:
# dev environment
$ app/console cache:clear
# production environment
$ app/console cache:clear --env=prod
I had problems using the mysql database supplied by my host server at first but then I installed the latest mysql database version available in softaculus inside my host server and then I was able to access mysql inside softaculus or directly by the url (www.mypage.com/mysql). Finally it works perfectly. You can try to do something similar.
I have two servers (on locally and one production). They have the same settings. The only thing I update when I want my new code to go to production is the src folder. So this folder is exactly the same when I push a release.
On my local server the new column in my entity/table works, and can be created, updated, etc. But on my production environment, this new column isn't noticed or even selected by doctrine.
The new column is in my database (both production and local), is in my entity.php file, in my entity.orm.yml file.
I did the app/console cache:clear option. Both dev and prod and on both servers.
What am I doing wrong?
Finally found the solution.
Because I didn't use metadata cache on the local server, but I did on my production server, it saved my mapping information. That's why doctrine didn't knew I had new columns. The solution was to clear the metadata cache using:
php bin/console doctrine:cache:clear-metadata
After that I run php bin/console doctrine:schema:update --dump-sql and I got the new columns.
I need to install and configure an existing Laravel 4 project.
I tried to do, but when I ran composer update or composer install a lot of issues appear.
I have the database too (with data) so I ran the migration but doesn't work because the console show me an issue about the "table doesn't exist".
Can anyone tell me the complete process to configure the App?.
I mean, what its first, second and so and so because maybe in some step I made a mistake
To install and configure an existing project, you'd typically
Check out its source code
Run composer install
Run php artisan migrate
Check the README for specific instructions on installing 3rd party assets, or any additional steps you'd need to take
If the above creates errors, its either because of something in your environment (installing over an old project?) or some problem with the way the Laravel developer created their project.
To install and configure an existing project, you'd typically check those things first :
You should goto app/config/database.php check file and verify username and password.
After check in Project Folder vendor folder and composer.json file exist then remove it (that remove old configuration now we going to fresh configuration).
Then after back to command prompt and fire command composer update and that download some dependent file download.
Now Run php artisan serve
that tricks work for me last time when I migrate another host.
Carlos, when using an existing DB you'll need to check the migrations table to see which migrations have run successfully. Typically when taking over a laravel project setting up a new db and running the migrations against it is a good idea because you never know what hacks were made to the database outside the migration system. One small change can throw the entire system into a useless state because it's looking for a table or column that doesn't exist or has been modified. If you run the migrations against a bare db you can also figure out which tables were manually created (which could very well be your issue) outside the system and add them in as necessary. Cobbling things together after a previous developer is tedious, hopefully there is decent documentation.
Note that if you are using Git with .gitignore, don't forget to copy .env variables in new location too.
I'm still experiencing issues with the console commands in Doctrine 2.
During first set up of my project I could run the console commands to update the db from my annotated models without a problem e.g.
doctrine orm:schema-tool:update --force
Since then I've been diligently working away on the project and now need to run this again. However, now when the above runs nothing happens. No error message, no report on success - the command just completes silently.
I'm presuming that I've done something that's broken this but I've no way of knowing without some kind of error report so I'm stumped.
How can I work out what the problem is????
As long as you don't have any data fixtures in your DB you could try dropping it and recreating it again.
doctrine orm:schema-tool:drop --force --full-database
doctrine orm:schema-tool:create
Personally I manage the updates with the Doctrine migrations tool. I had some issues getting :update to work as expected when I was first trying it out.
Ok so I've got this working. Rather foolishly I'd added a class to the models directory that should have been elsewhere and removing this seems to permit the schema-tool to work. It would be nice if the tool gave some feedback though rather than just 'completing' silently, but ultimately just a daft oversight on my part.