1
0
mirror of synced 2024-11-25 06:26:04 +03:00
tiu-client/run.php

39 lines
972 B
PHP
Raw Normal View History

2015-09-07 18:09:12 +03:00
<?php
2016-04-28 13:29:42 +03:00
$startTime = date('Y-m-d H:i:s');
2015-09-07 18:09:12 +03:00
require(__DIR__ . "/classes/ApiHelper.php");
require(__DIR__ . "/config/config.php");
if (! file_exists(__DIR__ . "/logs")) {
2015-09-07 18:09:12 +03:00
mkdir(__DIR__ . "/logs");
}
2015-11-05 16:43:03 +03:00
if (file_exists(__DIR__ . "/logs/cookie.txt")) {
2015-09-07 18:09:12 +03:00
unlink(__DIR__ . "/logs/cookie.txt");
}
2015-09-07 18:09:12 +03:00
$lockFile = __DIR__ . "/run.lock";
2015-11-05 16:43:03 +03:00
2015-09-07 18:09:12 +03:00
if (file_exists($lockFile)) {
if ((int)file_get_contents($lockFile) > time()) {
echo "script is busy";
exit();
}
}
2015-11-05 16:43:03 +03:00
2016-04-28 13:29:42 +03:00
file_put_contents($lockFile, strtotime('+5 minutes'));
2015-09-07 18:09:12 +03:00
2015-11-05 16:43:03 +03:00
if (file_exists(__DIR__ . "/logs/sync.log")) {
2016-05-30 12:52:04 +03:00
$lastSyncTime = file_get_contents(__DIR__ . "/logs/sync.log");
$lastSyncTime = new DateTime($lastSyncTime);
$lastSyncTime->sub(new DateInterval('PT1M'));
$config['date_from'] = $lastSyncTime->format('Y-m-d H:i:s');
2015-11-05 16:43:03 +03:00
}
2016-05-30 12:52:04 +03:00
$apiHelper = new ApiHelper($config);
2015-09-07 18:09:12 +03:00
if ($apiHelper->processXMLOrders()) {
2015-11-05 16:43:03 +03:00
unlink($lockFile);
2016-04-28 13:29:42 +03:00
file_put_contents(__DIR__ . "/logs/sync.log", $startTime);
2016-05-30 12:52:04 +03:00
}