Compare commits
4 Commits
revamp-pro
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
16c9b610ce
|
|||
|
65118b6abe
|
|||
|
75226f8314
|
|||
|
1a4676d85d
|
@@ -29,7 +29,7 @@ You should now be able to access the site at [http://localhost:1080](http://loca
|
|||||||
|
|
||||||
Sometimes it is useful to completely reset the state of the project, deleting the data, redownloading dependencies, etc. You can do this by running `./scripts/reset.sh`. Be careful, as this will delete all data in the database!
|
Sometimes it is useful to completely reset the state of the project, deleting the data, redownloading dependencies, etc. You can do this by running `./scripts/reset.sh`. Be careful, as this will delete all data in the database!
|
||||||
|
|
||||||
> [!WARN]
|
> [!WARNING]
|
||||||
> Even when resetting the project with the reset script, there are some situation where you need to clear your cookies or your browser cache to get a clean state.
|
> Even when resetting the project with the reset script, there are some situation where you need to clear your cookies or your browser cache to get a clean state.
|
||||||
> How to do this varies between browsers, so please refer to your browser's documentation for instructions.
|
> How to do this varies between browsers, so please refer to your browser's documentation for instructions.
|
||||||
|
|
||||||
|
|||||||
6
flake.lock
generated
6
flake.lock
generated
@@ -2,11 +2,11 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1767026758,
|
"lastModified": 1767364772,
|
||||||
"narHash": "sha256-7fsac/f7nh/VaKJ/qm3I338+wAJa/3J57cOGpXi0Sbg=",
|
"narHash": "sha256-fFUnEYMla8b7UKjijLnMe+oVFOz6HjijGGNS1l7dYaQ=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "346dd96ad74dc4457a9db9de4f4f57dab2e5731d",
|
"rev": "16c7794d0a28b5a37904d55bcca36003b9109aaa",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
overlays.default = final: prev: {
|
overlays.default = final: prev: {
|
||||||
inherit (self.packages.${final.system}) pvv-nettsiden;
|
inherit (self.packages.${final.stdenv.hostPlatform.system}) pvv-nettsiden;
|
||||||
formats = prev.formats // {
|
formats = prev.formats // {
|
||||||
php = import ./nix/php-generator.nix { pkgs = prev; lib = prev.lib; };
|
php = import ./nix/php-generator.nix { pkgs = prev; lib = prev.lib; };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ namespace pvv\side;
|
|||||||
class Door {
|
class Door {
|
||||||
private $pdo;
|
private $pdo;
|
||||||
|
|
||||||
|
const DAYS_OF_DOOR_HISTORY = 7;
|
||||||
|
|
||||||
public function __construct(\PDO $pdo) {
|
public function __construct(\PDO $pdo) {
|
||||||
$this->pdo = $pdo;
|
$this->pdo = $pdo;
|
||||||
}
|
}
|
||||||
@@ -67,7 +69,7 @@ class Door {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function removeOld(): void {
|
private function removeOld(): void {
|
||||||
$firstValidTime = time() - 60 * 60 * 24 * 7; // One week before now
|
$firstValidTime = time() - 60 * 60 * 24 * self::DAYS_OF_DOOR_HISTORY;
|
||||||
$query = 'DELETE FROM door WHERE time < :firstValid';
|
$query = 'DELETE FROM door WHERE time < :firstValid';
|
||||||
$statement = $this->pdo->prepare($query);
|
$statement = $this->pdo->prepare($query);
|
||||||
$statement->bindParam(':firstValid', $firstValidTime, \PDO::PARAM_STR);
|
$statement->bindParam(':firstValid', $firstValidTime, \PDO::PARAM_STR);
|
||||||
@@ -77,7 +79,7 @@ class Door {
|
|||||||
public function createEvent(\DateTimeImmutable $time, bool $open): void {
|
public function createEvent(\DateTimeImmutable $time, bool $open): void {
|
||||||
$query = 'INSERT INTO door(time, open) VALUES (:time, :open)';
|
$query = 'INSERT INTO door(time, open) VALUES (:time, :open)';
|
||||||
$statement = $this->pdo->prepare($query);
|
$statement = $this->pdo->prepare($query);
|
||||||
$statement->bindParam(':time', $time, \PDO::PARAM_STR);
|
$statement->bindParam(':time', $time->getTimestamp(), \PDO::PARAM_INT);
|
||||||
$statement->bindParam(':open', $open, \PDO::PARAM_BOOL);
|
$statement->bindParam(':open', $open, \PDO::PARAM_BOOL);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,9 @@ function handleSetState(): void {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$door->createEvent((int) $event->time, $event->isDoorOpen ? 1 : 0);
|
$time = (new \DateTimeImmutable())->setTimestamp((int) $event->time);
|
||||||
|
|
||||||
|
$door->createEvent($time, $event->isDoorOpen);
|
||||||
echo '{"status": "OK"}';
|
echo '{"status": "OK"}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user