The application needs to query an external api every 60 seconds to check if it has new orders. If have new orders, it must create a new record in the orders database.
For this I must create a routine to run using cron from linux.
Where should I put the php file of this routine and how do I access the database of this routine via Entity of cakephp? Is there a sample?
your API doesn’t respond after 60 seconds/at all?
responds with such a huge data-set that you can’t process it in 60 seconds.
You don’t want to re-fetch data from the API if you haven’t processed the “old” request.
Regarding “accessing the database”: In CakePHP you should never directly access the database. Otherwise why would you use a MVC framework with an ORM?
What you need is the LocatorAwareTrait explained in Query Builder - 4.x
With that you can get a table instance which behaves the same like you have in your generated controllers from bin/cake bake.
So like
public function execute(Arguments $args, ConsoleIo $io)
{
$tableInstance = $this->getTableLocator()->get('Categories');
$query = $tableInstance->find();
}
is the same as in your controller doing
public funtion index()
{
$query = $this->Categories->find();
}
With that table instance you can basically do all CRUD operations which are already present in your controller.
Which one would you recommend? or does one plugin has some advantages over the other? I’ve read both documentations but since I’ve never implemented something like this, I don’t know which one should I use.
My goal is to read mysql data from several tables, apply some formulas and create records in another table.