Auto delete query is executed in CakePHP - cakephp

I'm facing issue in Query that was written through normal CakePHP version 2.3.4
The problem occurs rarely [not frequently] - only few row gets auto deleted.
There is neither any cron nor any action in Controller-file to execute "Delete" command/query.
But why this auto-deletion is happening is miserable for me till now.
The Table structure is as provided below:
CREATE TABLE IF NOT EXISTS `bulk_orders` (
`id` int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY (`id`),
UNIQUE KEY `order_no` (`order_no`)
) EN
GINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=16270 ;
CREATE TABLE IF NOT EXISTS `bulk_order_lines` (
`id` int(10) NOT NULL auto_increment,
`order_id` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=34711 ;
Auto delete query is executed like below :
Delete from bulk_orders where ID=1234;
Can anybody please help me to find the solution on this?

Your question is very vague.
I assume you have baked your CRUD controller actions and templates via bake?
Usually this is the developers fault then - failure by design.
The HTTP specs are pretty clear about what protocol type to use for modifying the DB: POST
Additionally, it should also be secured via auth or some additional measure to avoid abusing.
But using POST here instead of GET prevents BOTs and people with little knowledge of deleting your content - by accident or purpose.
$this->Form->postLink()
is what you should be using.
And the action itself should contain
$this->request->allowMethod('post');
etc.
Please confirm that this is what you got in your code already.

Related

How do I count unique page view count to my web page using Cakephp 3.0?

I'm trying to implement total unique page view count to my webpage, Any one knows that how to do that just give me an idea to implement using CakePHP 3.0
create table for page view
ex:
CREATE TABLE `pageview` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`page` text NOT NULL,
`userip` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
then store visitor ip address into your table using
// gets the user IP Address
$userip=$_SERVER['REMOTE_ADDR'];
You can do it by checking both COOKIE and IP
There is a Plugins written by CakeManager which give those facility with proper functionality
https://github.com/cakemanager/cakephp-analyzer

How to use separate table for passwords for Auth in CakePHP?

I have a database with the following tables:
CREATE TABLE `visitors` (
`name` varchar(64) not null,
`id` int(10) unsigned not null auto_increment,
# ...more fields here
PRIMARY KEY (`id`),
UNIQUE KEY (`name`)
);
CREATE TABLE `credentials` (
`id` int(10) unsigned not null auto_increment,
`visitor_id` int(10) unsigned,
`type` enum('password','openid','google','facebook') not null,
`token` char(40) not null,
`modified` datetime,
`hint` varchar(64),
PRIMARY KEY (`id`),
KEY `visitor` (`visitor_id`),
KEY `token` (`token`)
);
After thinking about this for a awhile, I've decided that this is "right" for e.g. normalization and allowing visitors to have multiple login credentials, including multiple passwords.
However, I'd like to use Cake's ACL features, and AuthComponent assumes that hashed passwords are stored in the same table as user (visitor) information. What's the best way to work around this? Do I have to use Auth->login(), or is there a better way?
If you're using CakePHP 2.x this can be archived pretty simple by creating a new authentication handler. Looking at the existing Form handler will also help you. You should be able to extend it or copy the code into a new handler and modify it to match your needs.
Read the authentication chapter in the book. It has a section just about creating a custom handler but to get an understanding of how the whole thing works I really suggest you to read the whole page.

Wordpress dbDelta not functioning

I'm currently writing a plugin for a customer, and while it's usually working good, I found that dbDelta does not allow me to create the table I need on plugin activation.
I'm running the below code to bind the activation function:
register_activation_hook(__FILE__, 'adminInstallation');
And this is the function itself:
function adminInstallation(){
global $wpdb;
$objectEquipment = 'wp_object_equipment';
$equipmentSQL = "CREATE TABLE ".$objectEquipment." (
id mediumint(9) NOT NULL AUTO_INCREMENT,
name tinytext NOT NULL
);";
require_once(ABSPATH.'wp-admin/includes/upgrade.php');
$equipment = dbDelta($equipmentSQL);
}
Once this has been run, I am checking the database, but no tables have been added. Trying to dump the error will only result in Wordpress telling me there was unexpected output, but it wont let me see the actual message that the server returns. This issue has been bugging me for some hours, and I cant continue until it's solved. Does anyone here have any idea why it might do this?
As far as I can tell, all the code is valid, and this is the third plugin I've written. I even tried using the code from my previous ones, but that did not work either.
EDIT: I tried running the function after the plugin activation and dump the dbDelta response. It reports that the table has been created, but still, there's nothing new in the database. Any ideas?
Thanks in advance! //
Jonathan
From http://codex.wordpress.org/Creating_Tables_with_Plugins:
You have to put each field on its own line in your SQL statement.
You have to have two spaces between the words PRIMARY KEY and the definition of your primary key.
You must use the key word KEY rather than its synonym INDEX and you must include at least one KEY.
You shoud echo $wpdb->last_error; after dbDelta call so you get the mysql error.
You can try this function:
$table_name = "ratings";
$table_columns = "id INT(6) UNSIGNED AUTO_INCREMENT,
rate tinyint(1) NOT NULL,
ticket_id bigint(20) NOT NULL,
response_id bigint(20) NOT NULL,
created_at TIMESTAMP";
$table_keys = "PRIMARY KEY (id),
KEY ratings_rate (rate),
UNIQUE KEY ratings_response_id (response_id)";
create_table($table_name, $table_columns, $table_keys);
I search and dbDelta is running $wpdb->query($sqlQuery); for custom queries.
For those whose dbDelta is not working use
dbDelta($sql_query_to_create_table);
Thanks!
Have a nice code
I do know that dbDelta is very particular about the formatting. I believe the issue is that you are not using backticks (`) around database parts. Try the following.
On a side note, wouldn't hurt to designate a primary key.
$equipmentSQL = "CREATE TABLE `".$objectEquipment."` (
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
`name` tinytext NOT NULL,
PRIMARY KEY (`id`)
);";

Cake Bake error

i am trying to use cakes baking console and when i use cake bake model all
i am getting the following error
Attendance Table Structure
CREATE TABLE IF NOT EXISTS `mydb`.`attendences` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`dateTime` DATETIME NULL ,
PRIMARY KEY (`id`) )
ENGINE = InnoDB;
Rather than baking it all at once, do it table-by-table and model-controller-view separately. That way you'll be able to pin down the error.
Have you created any fixtures correctly? See http://book.cakephp.org/view/360/Creating-fixtures and check the syntax is correct, particularly in the array definitions.

How do I use the TranslateBehavior in CakePHP?

There is no documentation on cakephp.org and I am unable to find one on google. Please link me some documentation or supply one!
The translate behavior is another of CakePHP's very useful but poorly documented features. I've implemented it a couple of times with reasonable success in multi-lingual websites along the following lines.
Firstly, the translate behavior will only internationalize the database content of your site. If you've any more static content, you'll want to look at Cake's __('string') wrapper function and gettext (there's some useful information about this here)
Assuming there's Contents that we want to translate with the following db table:
CREATE TABLE `contents` (
`id` int(11) unsigned NOT NULL auto_increment,
`title` varchar(255) default NULL,
`body` text,
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
The content.php model then has:
var $actsAs = array('Translate' => array('title' => 'titleTranslation',
'body' => 'bodyTranslation'
));
in its definition. You then need to add the i18n table to the database thusly:
CREATE TABLE `i18n` (
`id` int(10) NOT NULL auto_increment,
`locale` varchar(6) NOT NULL,
`model` varchar(255) NOT NULL,
`foreign_key` int(10) NOT NULL,
`field` varchar(255) NOT NULL,
`content` mediumtext,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Then when you're saving the data to the database in your controller, set the locale to the language you want (this example would be for Polish):
$this->Content->locale = 'pol';
$result = $this->Content->save($this->data);
This will create entries in the i18n table for the title and body fields for the pol locale. Finds will find based on the current locale set in the user's browser, returning an array like:
[Content]
[id]
[titleTranslation]
[bodyTranslation]
We use the excellent p28n component to implement a language switching solution that works pretty well with the gettext and translate behaviours.
It's not a perfect system - as it creates HABTM relationships on the fly, it can cause some issues with other relationships you may have created manually, but if you're careful, it can work well.
For anyone searching the same thing, cakephp updated their documentation. For Translate Behavior go here..

Resources