Skip to content

Commit

Permalink
wip...
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost authored and exploide committed Jul 21, 2020
1 parent 23188fa commit c63cb54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
31 changes: 14 additions & 17 deletions classes/OSMPhotoNoteDao.class.php
Expand Up @@ -4,10 +4,12 @@
class OSMPhotoNoteDao
{
private $mysqli;
private $max_tmp_lifetime;

public function __construct($mysqli)
public function __construct($mysqli, $max_tmp_lifetime)
{
$this->mysqli = $mysqli;
$this->max_tmp_lifetime = $max_tmp_lifetime;
$this->createTable();
}

Expand All @@ -23,17 +25,21 @@ private function createTable()
);
}

public function newPhoto($file_ext)
public function newPhoto(string $file_ext): int
{
$stmt = $this->mysqli->prepare(
'INSERT INTO photos(file_ext, creation_time)
VALUES (?, NOW())'
);
$stmt = $this->mysqli->prepare('INSERT INTO photos(file_ext, creation_time) VALUES (?, NOW())');
$stmt->bind_param('s', $file_ext);
$stmt->execute();
return $this->mysqli->insert_id;
}

public function activatePhoto(int $photo_id, int $note_id)
{
$stmt = $this->mysqli->prepare("UPDATE photos SET note_id = ? WHERE file_id = ?");
$stmt->bind_param('ii', $note_id, $photo_id);
$stmt->execute();
}

public function deletePhoto(int $file_id)
{
$stmt = $this->mysqli->prepare('DELETE FROM photos WHERE file_id=?');
Expand All @@ -48,8 +54,7 @@ public function getOldInactivePhotos(): array
WHERE note_id IS NULL
AND creation_time < ADDDATE(NOW(), INTERVAL -? HOUR)'
);
$max_age = Config::MAX_TMP_LIFETIME_HOURS;
$stmt->bind_param('i', $max_age);
$stmt->bind_param('i', $max_tmp_lifetime);
$stmt->execute();
$result = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
return $result;
Expand Down Expand Up @@ -92,13 +97,5 @@ public function getInactivePhotos(array $photo_ids): array
return $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
}

public function activatePhoto(int $photo_id, int $note_id)
{
$stmt = $this->mysqli->prepare(
"UPDATE photos SET note_id = ?
WHERE file_id = ?"
);
$stmt->bind_param('ii', $note_id, $photo_id);
$stmt->execute();
}

}
10 changes: 0 additions & 10 deletions migrate_db.php

This file was deleted.

0 comments on commit c63cb54

Please sign in to comment.