2016-01-08 21:00:02 +00:00
|
|
|
<?php
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
class VisitsSync extends Vn\Lib\Method {
|
|
|
|
function run($db) {
|
2019-05-09 10:02:23 +00:00
|
|
|
$result = $db->query(
|
|
|
|
"SELECT id, agent
|
|
|
|
FROM visitAgent
|
|
|
|
WHERE version = '0.0'
|
|
|
|
OR platform = 'unknown'
|
|
|
|
OR cookies IS NULL
|
|
|
|
ORDER BY id DESC LIMIT 1"
|
|
|
|
);
|
2016-07-22 20:00:27 +00:00
|
|
|
|
2019-05-09 10:02:23 +00:00
|
|
|
$stmt = $db->prepare(
|
|
|
|
"UPDATE visitAgent
|
|
|
|
SET platform = ?,
|
|
|
|
browser = ?,
|
|
|
|
version = ?,
|
|
|
|
javascript = ?,
|
|
|
|
cookies = ?
|
|
|
|
WHERE id = ?"
|
|
|
|
);
|
2016-01-08 21:00:02 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if ($result && $stmt) {
|
|
|
|
set_time_limit(0);
|
2016-01-08 21:00:02 +00:00
|
|
|
|
|
|
|
$stmt->bind_param('sssiii'
|
|
|
|
,$platform
|
|
|
|
,$browser
|
|
|
|
,$version
|
|
|
|
,$javascript
|
|
|
|
,$cookies
|
|
|
|
,$id
|
|
|
|
);
|
|
|
|
|
|
|
|
// Update the visit info using browscap
|
2016-08-25 10:47:09 +00:00
|
|
|
|
|
|
|
$count = 0;
|
2016-01-08 21:00:02 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
while ($row = $result->fetch_assoc()) {
|
|
|
|
$info = get_browser($row['agent']);
|
2019-05-09 10:02:23 +00:00
|
|
|
if (!$info) continue;
|
|
|
|
|
2016-01-08 21:00:02 +00:00
|
|
|
$platform = $info->platform;
|
|
|
|
$browser = $info->browser;
|
|
|
|
$version = $info->version;
|
2019-05-09 10:02:23 +00:00
|
|
|
$javascript = !property_exists($info, 'javascript') || $info->javascript;
|
|
|
|
$cookies = !property_exists($info, 'cookies') || $info->cookies;
|
2016-01-08 21:00:02 +00:00
|
|
|
$id = $row['id'];
|
2018-05-23 10:14:20 +00:00
|
|
|
$stmt->execute();
|
2016-08-25 10:47:09 +00:00
|
|
|
|
|
|
|
$count++;
|
2016-01-08 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 10:02:23 +00:00
|
|
|
echo "$count records updated.\n";
|
2016-01-08 21:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($stmt)
|
2018-05-23 10:14:20 +00:00
|
|
|
$stmt->close();
|
2016-01-08 21:00:02 +00:00
|
|
|
if ($result)
|
2018-05-23 10:14:20 +00:00
|
|
|
$result->free();
|
2016-01-08 21:00:02 +00:00
|
|
|
}
|
|
|
|
}
|