cakephp callback before every database operation - cakephp

Recently my records started to disappear from my application's database so I want to log every database operation cakephp makes. Where should I put the logging commands?
P.S.: This is not the first time cakephp do this to me. Did anybody face this problem?

You have a function beforeSave() in model.
public function beforeSave(){
// code for logging
}
You can put it in AppModel.php. It's called before saving to DB.
Edit:
Well, I have found something and I hope it will help you:
http://bakery.cakephp.org/articles/rainchen/2009/03/09/how-to-debug-as-in-rails

You'll have to make your own DatabaseLoggerClass. Or
this article will help you achieve the same what you needed.
This documentation page might also help you to save log for each database operation.

Related

Entity Not Updated in Database

I was trying to update entries in the package using EntityManager but its entity is not getting updated for some reason.
I was using entityManager.merge(entity) to update.
Any suggestions on how to fix or debug?
Would have been nice to put the code here, did You try using #Transactional on the method?
also check this link which is similar to your question.

I am not able to add data in the vespa

I am not able to add data to the database even though the database is up.
I have checked it using
vespa-get-cluster-state
The error message that I got is in the image below.
Please let me know what to do to resolve this issue.
You need to ensure that all your nodes agree on the current time, by running NTP.
You'll probably be better off deploying on https://cloud.vespa.ai so you don't need to deal with this yourself.

How to move logs from DB to files in Magento EE?

I need to change log saving place from DB to files. I found only one way - rewrite Mage_Log module resource models and modify save() function for every resource model, but, as I understand right, it's not very good way. Please, tell me, how can I save logs into files, but not into DB (eg: visitor logs)?
You'll need to override app/code/core/Mage/Log/Model/Resource/Vistor.php.
In there, you'll find several places where it's writing this information into the DB which makes your site that much slower.
To answer your question, you'll need to change the following method(s):
_saveUrlInfo($visitor)
_saveVisitorUrl($visitor)
_saveCustomerInfo($visitor)
_saveQuoteInfo($visitor)
For those of you who may have landed on this page looking for information on how to disable the logs all together, you can find instructions here:
http://www.axertion.com/tutorials/2012/12/how-to-disable-magento-logging-to-the-database/

Generate Wordpress posts

Is there any way to generate posts/pages for Wordpress? I have a seperate database with information I would like to use. For example, I would like to create the posts with the ID from my own database as link in Wordpress.
I think this is the way: http://codex.wordpress.org/Function_Reference/wp_insert_post although I have no idea where to put this. functions.php or post.php? And is it possible to call it on intervals? Maybe through a cronjob.
If anyone can point me in the right direction/confirm that I am on the right path that would be very helpfull.
Thanks!
Yes, wp_insert_post is the correct function, but the code should be in your own Plugin.
And then set up a WP Cron Job with wp_schedule_event

How to do extended logging to database with CakePHP?

Need to log into a database table (logs) all major actions which took place in my app. The actions, for example, would be login/logout, view, add, update, etc. So, every time somebody logs in or, say, views a particular record - that would be logged in the database table.
I would like to call that method from all controllers in as simple way as possible - something like logIt($action, $object, $note) - as this would be dotted around the place, in every controller. It should also be reasonably efficient.
Do you have any suggestions? What would be the best way to do something like that?
Thanks guys. Regards from a CakePHP newbie.
You can use $this->log($data,'log_file'); anywhere in cake (model, view, controller). The data will be logged to tmp/logs/log_file.log
If it needs to go into DB, you'll need to setup a log method in app_controller, load the model yourself. And call that log in any controller you need.
Personally I think Anh Phams answer is a lot more "cake" and scalable, but if you need that list to be updated in real time then you'll have to put it into the DB I guess.
The best way to do this otherwise would be a custom component of some sort, which you could attach to your controllers as you see fit. Of course you could always create a simple method in your AppController, which loads a 'log' model and saves a record when you call it.

Resources