Commit 34b1a332 authored by cividesk's avatar cividesk

Corrects Github collector

parent f5d8656f
...@@ -554,11 +554,11 @@ DROP TABLE IF EXISTS `github_user`; ...@@ -554,11 +554,11 @@ DROP TABLE IF EXISTS `github_user`;
CREATE TABLE IF NOT EXISTS `github_user` ( CREATE TABLE IF NOT EXISTS `github_user` (
`id` int(11) NOT NULL, `id` int(11) NOT NULL,
`login` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `login` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`company` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `company` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`email` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`location` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `location` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`avatar_url` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `avatar_url` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`first_commit` DATETIME DEFAULT NULL, `first_commit` DATETIME DEFAULT NULL,
PRIMARY KEY (`login`) PRIMARY KEY (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
......
...@@ -32,7 +32,6 @@ $users = array(); ...@@ -32,7 +32,6 @@ $users = array();
foreach($repos as $repo) { foreach($repos as $repo) {
echo "Repository $repo ..."; echo "Repository $repo ...";
$new_commits = 0; $new_commits = 0;
$stm_c->bindParam(':repository', $repo);
// Get last commit date in database // Get last commit date in database
$result = $dbh->query("SELECT MAX(author_date) FROM github_commit WHERE repository='$repo';")->fetch(); $result = $dbh->query("SELECT MAX(author_date) FROM github_commit WHERE repository='$repo';")->fetch();
...@@ -45,22 +44,21 @@ foreach($repos as $repo) { ...@@ -45,22 +44,21 @@ foreach($repos as $repo) {
// Loop over each commit (paged) // Loop over each commit (paged)
while (sizeof($commits)) { while (sizeof($commits)) {
foreach($commits as $commit) { foreach($commits as $commit) {
/* @var $commit GitHubCommit */ $params = array(
':repository' => $repo,
// Write commit to database ':hash' => $commit->getSha(),
$hash = $commit->getSha(); ':author_login' => ($commit->getAuthor() ? $commit->getAuthor()->getLogin() : ''),
$stm_c->bindParam(':hash', $hash); ':author_date' => str_replace(array('T','Z'), ' ', $commit->getCommit()->getAuthor()->getDate()),
$author_login = ($commit->getAuthor() ? $commit->getAuthor()->getLogin() : ''); ':committer_login' => ($commit->getCommitter() ? $commit->getCommitter()->getLogin() : ''),
$stm_c->bindParam(':author_login', $author_login); ':committer_date' => str_replace(array('T','Z'), ' ', $commit->getCommit()->getCommitter()->getDate()),
$author_date = $commit->getCommit()->getAuthor()->getDate(); ':message' => substr($commit->getCommit()->getMessage(), 0, 1000),
$stm_c->bindParam(':author_date', $author_date); );
$committer_login = ($commit->getCommitter() ? $commit->getCommitter()->getLogin() : ''); if ($stm_c->execute($params)) {
$stm_c->bindParam(':committer_login', $committer_login); $new_commits++;
$committer_date = $commit->getCommit()->getCommitter()->getDate(); } else {
$stm_c->bindParam(':committer_date', $committer_date); $errorInfo = $stm_c->errorInfo();
$message = $commit->getCommit()->getMessage(); echo $errorInfo[2] . PHP_EOL;
$stm_c->bindParam(':message', $message); }
if ($stm_c->execute()) $new_commits++;
} }
$commits = $client->getNextPage(); $commits = $client->getNextPage();
} }
...@@ -81,15 +79,21 @@ foreach ($dbh->query($query) as $row) { ...@@ -81,15 +79,21 @@ foreach ($dbh->query($query) as $row) {
} }
/* @var $user GitHubFullUser */ /* @var $user GitHubFullUser */
if ($user) { if ($user) {
$stm_u->bindParam(':id', $user->getId()); $params = array(
$stm_u->bindParam(':login', $user->getLogin()); ':id' => $user->getId(),
$stm_u->bindParam(':name', $user->getName()); ':login' => $user->getLogin(),
$stm_u->bindParam(':company', $user->getCompany()); ':name' => $user->getName(),
$stm_u->bindParam(':email', $user->getEmail()); ':company' => $user->getCompany(),
$stm_u->bindParam(':location', $user->getLocation()); ':email' => $user->getEmail(),
$stm_u->bindParam(':avatar_url', $user->getAvatarUrl()); ':location' => $user->getLocation(),
$stm_u->execute(); ':avatar_url' => $user->getAvatarUrl(),
$updated ++; );
if ($stm_u->execute($params)) {
$updated ++;;
} else {
$errorInfo = $stm_u->errorInfo();
echo $errorInfo[2] . PHP_EOL;
}
} else { } else {
echo "Unknown user - login: " . $row[0] . "\n"; echo "Unknown user - login: " . $row[0] . "\n";
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment