I have a custom Data Source, let’s call it SQSDatasource. It’s working fine, generally, for find(), save(), and even delete().
class SQSDatasource extends DataSource {
public function delete(Model $Model, $conditions = null) {
// Deliberate break point to ensure that this function is being called
print_r($conditions);
exit();
// I have my proper delete logic here, which works fine usually
}
}
A Model, say Job that uses the SQSDatasource. There is no extraordinary logic in Job.
I am encountering a strange anomaly, however.
class TestShell extends AppShell {
public $uses = array('Job');
public function main() {
// This works fine.
$job = $this->Job->find('first');
// The break point never gets called
$this->Job->delete('TEST!');
// This gets called
$this->out('This gets called.');
}
}
However, if I remove $this->Job->find() before calling $this->Job->delete(), it works perfectly fine. delete() would get called.
Anyone has any clue on this anomaly?
I’ve managed to find out where the problem lies. My datasource code is actually complete with full implementation of
read(),create(), etc. And all the standard CakePHP CRUD functions work fine with my datasource.The problem I had is mainly due to these reasons:
delete()in CakePHP actually does afind('count')internally before allowing the delete, which I was not expectingThe behavior of amazon-sqs. When a message is in-flight, it is temporarily invisible.
Also, for amazon-sqs, you cannot delete a message without first querying it (as delete is done not via message ID, but via message handler). And once you start querying it, it becomes temporarily invisible, which results to CakePHP thinking that the delete is invalid.