diff --git a/utils/Migrations.php b/utils/Migrations.php index 45829e8..e92b4ad 100644 --- a/utils/Migrations.php +++ b/utils/Migrations.php @@ -15,7 +15,16 @@ public function migrate() $pluginPath = str_replace('utils', '', __DIR__); $migrationPath = $pluginPath . '/migrations/'; + if(!file_exists(option('mauricerenck.indieConnector.sqlitePath', '.sqlite/'))) { + mkdir(option('mauricerenck.indieConnector.sqlitePath', '.sqlite/')); + } + $db = $this->connect(); + + if ($db === null || $db === false) { + return false; + } + $versionResult = $db->query('SELECT version FROM migrations ORDER BY version DESC LIMIT 1'); if (!Dir::exists($migrationPath)) { diff --git a/utils/WebmentionStats.php b/utils/WebmentionStats.php index 2cde00a..b7945a1 100644 --- a/utils/WebmentionStats.php +++ b/utils/WebmentionStats.php @@ -51,7 +51,7 @@ public function updateOutbox(string $pageUuid, string $target) public function getSummaryByMonth(int $year, int $month) { try { - $month = (integer)$month; + $month = (int)$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;'); @@ -114,7 +114,7 @@ public function getDetailsByMonth(int $timestamp) public function getTargets(int $year, int $month) { try { - $month = (integer)$month; + $month = (int)$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;'); @@ -159,7 +159,7 @@ public function getTargets(int $year, int $month) public function getSources(int $year, int $month) { try { - $month = (integer)$month; + $month = (int)$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;'); @@ -198,7 +198,7 @@ public function getSources(int $year, int $month) public function getSentMentions(int $year, int $month) { try { - $month = (integer)$month; + $month = (int)$month; $month = $month < 10 ? '0' . $month : $month; $result = $this->db->query('SELECT page_uuid, target FROM webmention_outbox WHERE sent_date LIKE "' . $year . '-' . $month . '-%";'); @@ -207,13 +207,13 @@ public function getSentMentions(int $year, int $month) foreach ($result->data as $webmention) { $page = page('page://' . $webmention->page_uuid); - if(is_null($page)) { + if (is_null($page)) { $targets[] = [ - 'target' => $webmention->target, - 'title' => $webmention->page_uuid, - 'pageUrl' => '#', - 'panelUrl' => '#', - ]; + 'target' => $webmention->target, + 'title' => $webmention->page_uuid, + 'pageUrl' => '#', + 'panelUrl' => '#', + ]; continue; } @@ -223,7 +223,6 @@ public function getSentMentions(int $year, int $month) 'pageUrl' => $page->url(), 'panelUrl' => $page->panel()->url(), ]; - } return $targets; @@ -291,7 +290,6 @@ private function connect() return true; } catch (Exception $e) { - echo 'Could not connect to Database: ', $e->getMessage(), "\n"; return false; } }