Visitor Count fix
This commit is contained in:
parent
8747812a56
commit
e046ea7ed9
@ -14,9 +14,38 @@ namespace Api\Visitors {
|
|||||||
use Api\VisitorsAPI;
|
use Api\VisitorsAPI;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Driver\SQL\Condition\Compare;
|
use Driver\SQL\Condition\Compare;
|
||||||
|
use Driver\SQL\Expression\Add;
|
||||||
use Driver\SQL\Query\Select;
|
use Driver\SQL\Query\Select;
|
||||||
|
use Driver\SQL\Strategy\UpdateStrategy;
|
||||||
use Objects\User;
|
use Objects\User;
|
||||||
|
|
||||||
|
class ProcessVisit extends VisitorsAPI {
|
||||||
|
public function __construct(User $user, bool $externalCall = false) {
|
||||||
|
parent::__construct($user, $externalCall, array(
|
||||||
|
"cookie" => new StringType("cookie")
|
||||||
|
));
|
||||||
|
$this->isPublic = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute($values = array()) {
|
||||||
|
if (!parent::execute($values)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = $this->user->getSQL();
|
||||||
|
$cookie = $this->getParam("cookie");
|
||||||
|
$day = (new DateTime())->format("Ymd");
|
||||||
|
$sql->insert("Visitor", array("cookie", "day"))
|
||||||
|
->addRow($cookie, $day)
|
||||||
|
->onDuplicateKeyStrategy(new UpdateStrategy(
|
||||||
|
array("day", "cookie"),
|
||||||
|
array("count" => new Add("Visitor.count", 1))))
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
return $this->success;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Stats extends VisitorsAPI {
|
class Stats extends VisitorsAPI {
|
||||||
public function __construct(User $user, bool $externalCall = false) {
|
public function __construct(User $user, bool $externalCall = false) {
|
||||||
parent::__construct($user, $externalCall, array(
|
parent::__construct($user, $externalCall, array(
|
||||||
|
@ -254,20 +254,13 @@ class User extends ApiObject {
|
|||||||
|
|
||||||
public function processVisit() {
|
public function processVisit() {
|
||||||
if ($this->sql && $this->sql->isConnected() && isset($_COOKIE["PHPSESSID"]) && !empty($_COOKIE["PHPSESSID"])) {
|
if ($this->sql && $this->sql->isConnected() && isset($_COOKIE["PHPSESSID"]) && !empty($_COOKIE["PHPSESSID"])) {
|
||||||
|
|
||||||
if ($this->isBot()) {
|
if ($this->isBot()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cookie = $_COOKIE["PHPSESSID"];
|
$cookie = $_COOKIE["PHPSESSID"];
|
||||||
$day = (new DateTime())->format("Ymd");
|
$req = new \Api\Visitors\ProcessVisit($this);
|
||||||
|
$req->execute(array("cookie" => $cookie));
|
||||||
$this->sql->insert("Visitor", array("cookie", "day"))
|
|
||||||
->addRow($cookie, $day)
|
|
||||||
->onDuplicateKeyStrategy(new UpdateStrategy(
|
|
||||||
array("month", "cookie"),
|
|
||||||
array("count" => new Add("Visitor.count", 1))))
|
|
||||||
->execute();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user