Exemple #1
0
function postCreate($topic_id, $author_id, $message, $flags)
{
    global $database_cfg;
    $errors = array();
    if (!userExistsById($author_id)) {
        $errors[] = "User marked as author (" . $author_id . ") not found";
    }
    if (!topicExistsById($topic_id)) {
        $errors[] = "Topic marked as parent not found";
    }
    if (postExists($topic_id, $message)) {
        $errors[] = "This post already exists in this topic";
    }
    if (count($errors) > 0) {
        return $errors;
    }
    databaseQuery("insert into " . $database_cfg["prefix"] . "posts (topic_id, author_id, message, flags, created) values ('" . intval($topic_id) . "', '" . intval($author_id) . "', '" . stringEncode($message) . "', '" . $flags . "', '" . stringEncode(date("H:i, d.m.Y")) . "')");
    databaseQuery("update " . $database_cfg["prefix"] . "topics set edited='" . stringEncode(date("H:i, d.m.Y")) . "' where id='" . intval($topic_id) . "'", "Can't update topic");
}
$storage->storeAccessToken('GitHub', $token);
$stmt = $dbConnection->query('SELECT id, feed_id, repository FROM feeds_repositories ORDER BY id ASC');
$repositories = [];
$feeds = $stmt->fetchAll();
foreach ($feeds as $repository) {
    $repositories[] = $repository['repository'];
}
$repositories = array_unique($repositories);
$result = [];
foreach ($repositories as $repository) {
    $result[$repository] = json_decode($github->request('repos/' . $repository . '/releases'), true);
}
foreach ($feeds as $feed) {
    $timestamp = new \DateTime();
    foreach ($result[$feed['repository']] as $release) {
        if (postExists($dbConnection, $feed['feed_id'], $release['id'])) {
            continue;
        }
        $postId = addPost($dbConnection, $feed['id'], $release);
        logAddition($dbConnection, $feed['feed_id'], $postId, $timestamp);
    }
}
function postExists(\PDO $dbConnection, $feedId, $releaseId)
{
    $query = 'SELECT count(posts.id)';
    $query .= ' FROM posts';
    $query .= ' JOIN feeds_repositories ON feeds_repositories.id = posts.feed_repository_id';
    $query .= ' WHERE feeds_repositories.feed_id = :feedID';
    $query .= ' AND release_id = :releaseID';
    $stmt = $dbConnection->prepare($query);
    $stmt->execute(['feedID' => $feedId, 'releaseID' => $releaseId]);