1. Go to this page and download the library: Download basecom/akeneo-cron-ui library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Basecom\Bundle\CronUiBundle\CronAction\Cronjob;
class CurlCronjob implements Cronjob
{
public function getCronExpression(): string
{
return '*/5 * * * *'; // Every five minutes
}
public function execute(): bool
{
$ch = curl_init('https://example.com');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_TIMEOUT,10);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpcode === 200; // Return true, if the status code is 200
}
public function getLabel(): string
{
return 'curl example.com';
}
}
use Basecom\Bundle\CronUiBundle\CronAction\CommandCronjob;
class SchemaUpdateCronjob extends CommandCronjob
{
public function getCommand(): string
{
// This is the command which should be executed.
// If you would run it manually: ./bin/console {command_name}
return 'doctrine:schema:update';
}
public function getCommandParams(): array
{
// You don't need to override this method if you don't have specific parameters
return [
'--force',
'--env' => 'prod'
];
}
public function getCronExpression(): string
{
// You can use simple aliases like '@hourly', '@daily' and so on..
return '@hourly';
}
}
use Basecom\Bundle\CronUiBundle\CronAction\JobCronjob;
class ExportProductsCronjob extends JobCronjob
{
public function getJobName(): string
{
// This is the code / name of the akeneo job which should be executed.
return 'csv_product_export';
}
public function getJobParams(): array
{
// This method must not be overriden if you don't need to override parameters.
return [
'filePath' => '/home/akeneo/my-daily-export/example.csv'
];
}
public function getCronExpression(): string
{
// The interface has some predefined constants for expression which are often used.
return static::DAILY;
}
}