Skip to content

Commit

Permalink
fix: sqlite queries need a leading zero
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricerenck committed Apr 7, 2022
1 parent 72d382d commit 50240a0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion utils/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function trackMention(string $target, string $source, string $type, strin
public function getSummaryByMonth(int $year, int $month)
{
try {
$month = parseInt($month);
$month = $month < 10 ? '0' . $month : $month;

$result = $this->db->query('SELECT COUNT(id) as summary, * FROM webmentions WHERE mention_date LIKE "' . $year . '-' . $month . '-%" GROUP BY mention_type;');
$summary = [
'summary' => 0,
Expand Down Expand Up @@ -111,6 +114,9 @@ public function getDetailsByMonth(int $timestamp)
public function getTargets(int $year, int $month)
{
try {
$month = parseInt($month);
$month = $month < 10 ? '0' . $month : $month;

$result = $this->db->query('SELECT mention_target, mention_type, COUNT(mention_type) as mentions FROM webmentions WHERE mention_date LIKE "' . $year . '-' . $month . '-%" GROUP BY mention_target, mention_type;');
$targets = [];

Expand Down Expand Up @@ -149,6 +155,9 @@ public function getTargets(int $year, int $month)
public function getSources(int $year, int $month)
{
try {
$month = parseInt($month);
$month = $month < 10 ? '0' . $month : $month;

$result = $this->db->query('SELECT mention_source, mention_type, mention_image, COUNT(mention_type) as mentions FROM webmentions WHERE mention_date LIKE "' . $year . '-' . $month . '-%" GROUP BY mention_source, mention_type;');
$sources = [];

Expand Down Expand Up @@ -194,8 +203,11 @@ public function getStatSummary()
}

$timestamp = time();
$year = date('Y', $timestamp);
$month = date('m', $timestamp);

$stats = new WebmentionStats();
$summary = $stats->getSummaryByMonth($timestamp);
$summary = $stats->getSummaryByMonth($year, $month);

return $summary;
}
Expand Down

0 comments on commit 50240a0

Please sign in to comment.