-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log fetches to external websites in DB
- Loading branch information
1 parent
7fff637
commit 54c23f2
Showing
10 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace flusio\migrations; | ||
|
||
class Migration202104290001CreateFetchLogs | ||
{ | ||
public function migrate() | ||
{ | ||
$database = \Minz\Database::get(); | ||
|
||
$database->exec(<<<'SQL' | ||
CREATE TABLE fetch_logs ( | ||
id SERIAL PRIMARY KEY, | ||
created_at TIMESTAMPTZ NOT NULL, | ||
url TEXT NOT NULL, | ||
host TEXT NOT NULL | ||
); | ||
SQL); | ||
|
||
return true; | ||
} | ||
|
||
public function rollback() | ||
{ | ||
$database = \Minz\Database::get(); | ||
|
||
$database->exec(<<<'SQL' | ||
DROP TABLE fetch_logs; | ||
SQL); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace flusio\models; | ||
|
||
/** | ||
* @author Marien Fressinaud <[email protected]> | ||
* @license http://www.gnu.org/licenses/agpl-3.0.en.html AGPL | ||
*/ | ||
class FetchLog extends \Minz\Model | ||
{ | ||
use DaoConnector; | ||
|
||
public const PROPERTIES = [ | ||
'id' => [ | ||
'type' => 'integer', | ||
], | ||
|
||
'created_at' => [ | ||
'type' => 'datetime', | ||
], | ||
|
||
'url' => [ | ||
'type' => 'string', | ||
'required' => true, | ||
], | ||
|
||
'host' => [ | ||
'type' => 'string', | ||
'required' => true, | ||
], | ||
]; | ||
|
||
/** | ||
* Create a log in DB for the given URL. | ||
* | ||
* @param string $url | ||
*/ | ||
public static function log($url) | ||
{ | ||
$host = \flusio\utils\Belt::host($url); | ||
$fetch_log = new self([ | ||
'url' => $url, | ||
'host' => $host, | ||
]); | ||
$fetch_log->save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace flusio\models\dao; | ||
|
||
/** | ||
* @author Marien Fressinaud <[email protected]> | ||
* @license http://www.gnu.org/licenses/agpl-3.0.en.html AGPL | ||
*/ | ||
class FetchLog extends \Minz\DatabaseModel | ||
{ | ||
/** | ||
* @throws \Minz\Errors\DatabaseError | ||
*/ | ||
public function __construct() | ||
{ | ||
$properties = array_keys(\flusio\models\FetchLog::PROPERTIES); | ||
parent::__construct('fetch_logs', 'id', $properties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters