b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / vendor / mailcampaigns / magento2connector / Cron /
Filename/home/dev2.destoffenstraat.com/vendor/mailcampaigns/magento2connector/Cron/PostCron.php
Size1.97 kb
Permissionrw-r--r--
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified03-Jun-2020 10:16
Last accessed23-Aug-2025 03:56
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

namespace MailCampaigns\Connector\Cron;

class PostCron {

protected $helper;
protected $resource;
protected $connection;
protected $tn__mc_api_pages;
protected $tn__mc_api_queue;
protected $mcapi;

public function __construct(
\MailCampaigns\Connector\Helper\Data $dataHelper,
\Magento\Framework\App\ResourceConnection $Resource,
\MailCampaigns\Connector\Helper\MailCampaigns_API $mcapi
) {
$this->resource = $Resource;
$this->helper = $dataHelper;
$this->mcapi = $mcapi;
}

public function execute()
{
//database connection
$this->connection = $this->resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);

//tables
$this->tn__mc_api_pages = $this->resource->getTableName('mc_api_pages');
$this->tn__mc_api_queue = $this->resource->getTableName('mc_api_queue');

// Report queue size
$sql = "SELECT COUNT(*) AS queue_size FROM `".$this->tn__mc_api_queue."`";
$rows = $this->connection->fetchAll($sql);
foreach ($rows as $row)
{
$this->mcapi->Call("report_magento_queue_status", array("queue_size" => (int)$row["queue_size"], "datetime" => time()));
}

// Process one page per each cron
$sql = "SELECT * FROM `".$this->tn__mc_api_queue."` WHERE error = 0 ORDER BY id ASC LIMIT 2000";
$rows = $this->connection->fetchAll($sql);
$starttime = time();

// Loop through queue list
foreach ($rows as $row)
{
// Send it to MailCampaigns API
if ($this->mcapi->PostCall($row["stream_data"]))
{
// Delete queued call
$sql = "DELETE FROM `".$this->tn__mc_api_queue."` WHERE id = '".$row["id"]."'";
$this->connection->query($sql);
}
else
{
// Update queued call
$sql = "UPDATE `".$this->tn__mc_api_queue."` SET error = 1 WHERE id = '".$row["id"]."'";
$this->connection->query($sql);
}

// Detect timeout
if ((time() - $starttime) > 55)
{
return;
}
}

return $this;
}
}