@@ -8,100 +8,100 @@ |
||
8 | 8 | class MysqlChangelogRepository implements ChangelogRepositoryInterface |
9 | 9 | { |
10 | 10 | |
11 | - /** @var ConnectionLocator */ |
|
12 | - protected $connections; |
|
11 | + /** @var ConnectionLocator */ |
|
12 | + protected $connections; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @param ConnectonLocator $connections |
|
16 | - */ |
|
17 | - public function __construct(ConnectionLocator $connections) |
|
18 | - { |
|
19 | - $this->connections = $connections; |
|
20 | - } |
|
14 | + /** |
|
15 | + * @param ConnectonLocator $connections |
|
16 | + */ |
|
17 | + public function __construct(ConnectionLocator $connections) |
|
18 | + { |
|
19 | + $this->connections = $connections; |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param integer $limit |
|
24 | - * @param integer $offset |
|
25 | - * |
|
26 | - * @return array|false |
|
27 | - */ |
|
28 | - public function getChanges($limit = null, $offset = 0) |
|
29 | - { |
|
30 | - $query = " |
|
22 | + /** |
|
23 | + * @param integer $limit |
|
24 | + * @param integer $offset |
|
25 | + * |
|
26 | + * @return array|false |
|
27 | + */ |
|
28 | + public function getChanges($limit = null, $offset = 0) |
|
29 | + { |
|
30 | + $query = " |
|
31 | 31 | SELECT `message`, `message_short`, `datetime`, `commit_link` |
32 | 32 | FROM `jpemeric_stream`.`changelog` |
33 | 33 | ORDER BY `datetime` DESC"; |
34 | - if (!is_null($limit)) { |
|
35 | - $query .= " |
|
34 | + if (!is_null($limit)) { |
|
35 | + $query .= " |
|
36 | 36 | LIMIT {$offset}, {$limit}"; |
37 | - } |
|
37 | + } |
|
38 | 38 | |
39 | - return $this |
|
40 | - ->connections |
|
41 | - ->getRead() |
|
42 | - ->fetchAll($query); |
|
43 | - } |
|
39 | + return $this |
|
40 | + ->connections |
|
41 | + ->getRead() |
|
42 | + ->fetchAll($query); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $hash |
|
47 | - * |
|
48 | - * @return array|false |
|
49 | - */ |
|
50 | - public function getChangeByHash($hash) |
|
51 | - { |
|
52 | - $query = " |
|
45 | + /** |
|
46 | + * @param string $hash |
|
47 | + * |
|
48 | + * @return array|false |
|
49 | + */ |
|
50 | + public function getChangeByHash($hash) |
|
51 | + { |
|
52 | + $query = " |
|
53 | 53 | SELECT * |
54 | 54 | FROM `jpemeric_stream`.`changelog` |
55 | 55 | WHERE `hash` = :hash |
56 | 56 | LIMIT 1"; |
57 | 57 | |
58 | - $bindings = [ |
|
59 | - 'hash' => $hash, |
|
60 | - ]; |
|
58 | + $bindings = [ |
|
59 | + 'hash' => $hash, |
|
60 | + ]; |
|
61 | 61 | |
62 | - return $this |
|
63 | - ->connections |
|
64 | - ->getRead() |
|
65 | - ->fetchOne($query, $bindings); |
|
66 | - } |
|
62 | + return $this |
|
63 | + ->connections |
|
64 | + ->getRead() |
|
65 | + ->fetchOne($query, $bindings); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param string $hash |
|
70 | - * @param string $message |
|
71 | - * @param DateTime $datetime |
|
72 | - * @param string $author |
|
73 | - * @param string $commit_link |
|
74 | - * |
|
75 | - * @return |
|
76 | - */ |
|
77 | - public function insertChange($hash, $message, DateTime $datetime, $author, $commit_link) |
|
78 | - { |
|
79 | - $message_short = $message; |
|
80 | - $message_short = strtok($message_short, "\n"); |
|
81 | - if (strlen($message_short) > 72) { |
|
82 | - $message_short = wordwrap($message_short, 65); |
|
83 | - $message_short = strtok($message_short, "\n"); |
|
84 | - $message_short .= '...'; |
|
85 | - } |
|
68 | + /** |
|
69 | + * @param string $hash |
|
70 | + * @param string $message |
|
71 | + * @param DateTime $datetime |
|
72 | + * @param string $author |
|
73 | + * @param string $commit_link |
|
74 | + * |
|
75 | + * @return |
|
76 | + */ |
|
77 | + public function insertChange($hash, $message, DateTime $datetime, $author, $commit_link) |
|
78 | + { |
|
79 | + $message_short = $message; |
|
80 | + $message_short = strtok($message_short, "\n"); |
|
81 | + if (strlen($message_short) > 72) { |
|
82 | + $message_short = wordwrap($message_short, 65); |
|
83 | + $message_short = strtok($message_short, "\n"); |
|
84 | + $message_short .= '...'; |
|
85 | + } |
|
86 | 86 | |
87 | - $query = " |
|
87 | + $query = " |
|
88 | 88 | INSERT INTO `jpemeric_stream`.`changelog` |
89 | 89 | (`hash`, `message`, `message_short`, `datetime`, `author`, `commit_link`) |
90 | 90 | VALUES |
91 | 91 | (:hash, :message, :message_short, :datetime, :author, :commit_link)"; |
92 | 92 | |
93 | - $bindings = [ |
|
94 | - 'hash' => $hash, |
|
95 | - 'message' => $message, |
|
96 | - 'message_short' => $message_short, |
|
97 | - 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
98 | - 'author' => $author, |
|
99 | - 'commit_link' => $commit_link |
|
100 | - ]; |
|
93 | + $bindings = [ |
|
94 | + 'hash' => $hash, |
|
95 | + 'message' => $message, |
|
96 | + 'message_short' => $message_short, |
|
97 | + 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
98 | + 'author' => $author, |
|
99 | + 'commit_link' => $commit_link |
|
100 | + ]; |
|
101 | 101 | |
102 | - return $this |
|
103 | - ->connections |
|
104 | - ->getWrite() |
|
105 | - ->perform($query, $bindings); |
|
106 | - } |
|
102 | + return $this |
|
103 | + ->connections |
|
104 | + ->getWrite() |
|
105 | + ->perform($query, $bindings); |
|
106 | + } |
|
107 | 107 | } |
@@ -8,89 +8,89 @@ |
||
8 | 8 | class MysqlGithubRepository implements GithubRepositoryInterface |
9 | 9 | { |
10 | 10 | |
11 | - /** @var ConnectionLocator */ |
|
12 | - protected $connections; |
|
11 | + /** @var ConnectionLocator */ |
|
12 | + protected $connections; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @param ConnectonLocator $connections |
|
16 | - */ |
|
17 | - public function __construct(ConnectionLocator $connections) |
|
18 | - { |
|
19 | - $this->connections = $connections; |
|
20 | - } |
|
14 | + /** |
|
15 | + * @param ConnectonLocator $connections |
|
16 | + */ |
|
17 | + public function __construct(ConnectionLocator $connections) |
|
18 | + { |
|
19 | + $this->connections = $connections; |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param integer $limit |
|
24 | - * @param integer $offset |
|
25 | - * |
|
26 | - * @return array|false |
|
27 | - */ |
|
28 | - public function getEvents($limit = null, $offset = 0) |
|
29 | - { |
|
30 | - $query = " |
|
22 | + /** |
|
23 | + * @param integer $limit |
|
24 | + * @param integer $offset |
|
25 | + * |
|
26 | + * @return array|false |
|
27 | + */ |
|
28 | + public function getEvents($limit = null, $offset = 0) |
|
29 | + { |
|
30 | + $query = " |
|
31 | 31 | SELECT `id`, `event_id`, `datetime` |
32 | 32 | FROM `jpemeric_stream`.`github` |
33 | 33 | ORDER BY `datetime` DESC"; |
34 | - if (!is_null($limit)) { |
|
35 | - $query .= " |
|
34 | + if (!is_null($limit)) { |
|
35 | + $query .= " |
|
36 | 36 | LIMIT {$offset}, {$limit}"; |
37 | - } |
|
37 | + } |
|
38 | 38 | |
39 | - return $this |
|
40 | - ->connections |
|
41 | - ->getRead() |
|
42 | - ->fetchAll($query); |
|
43 | - } |
|
39 | + return $this |
|
40 | + ->connections |
|
41 | + ->getRead() |
|
42 | + ->fetchAll($query); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param integer $eventId |
|
47 | - * |
|
48 | - * @return array|false |
|
49 | - */ |
|
50 | - public function getEventByEventId($eventId) |
|
51 | - { |
|
52 | - $query = " |
|
45 | + /** |
|
46 | + * @param integer $eventId |
|
47 | + * |
|
48 | + * @return array|false |
|
49 | + */ |
|
50 | + public function getEventByEventId($eventId) |
|
51 | + { |
|
52 | + $query = " |
|
53 | 53 | SELECT * |
54 | 54 | FROM `jpemeric_stream`.`github` |
55 | 55 | WHERE `event_id` = :event_id |
56 | 56 | LIMIT 1"; |
57 | 57 | |
58 | - $bindings = [ |
|
59 | - 'event_id' => $eventId, |
|
60 | - ]; |
|
58 | + $bindings = [ |
|
59 | + 'event_id' => $eventId, |
|
60 | + ]; |
|
61 | 61 | |
62 | - return $this |
|
63 | - ->connections |
|
64 | - ->getRead() |
|
65 | - ->fetchOne($query, $bindings); |
|
66 | - } |
|
62 | + return $this |
|
63 | + ->connections |
|
64 | + ->getRead() |
|
65 | + ->fetchOne($query, $bindings); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param integer $eventId |
|
70 | - * @param string $eventType |
|
71 | - * @param DateTime $datetime |
|
72 | - * @param array $metadata |
|
73 | - * |
|
74 | - * @return |
|
75 | - */ |
|
76 | - public function insertEvent($eventId, $eventType, DateTime $datetime, array $metadata) |
|
77 | - { |
|
78 | - $query = " |
|
68 | + /** |
|
69 | + * @param integer $eventId |
|
70 | + * @param string $eventType |
|
71 | + * @param DateTime $datetime |
|
72 | + * @param array $metadata |
|
73 | + * |
|
74 | + * @return |
|
75 | + */ |
|
76 | + public function insertEvent($eventId, $eventType, DateTime $datetime, array $metadata) |
|
77 | + { |
|
78 | + $query = " |
|
79 | 79 | INSERT INTO `jpemeric_stream`.`github` |
80 | 80 | (`event_id`, `type`, `datetime`, `metadata`) |
81 | 81 | VALUES |
82 | 82 | (:event_id, :event_type, :datetime, :metadata)"; |
83 | 83 | |
84 | - $bindings = [ |
|
85 | - 'event_id' => $eventId, |
|
86 | - 'event_type' => $eventType, |
|
87 | - 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
88 | - 'metadata' => json_encode($metadata), |
|
89 | - ]; |
|
84 | + $bindings = [ |
|
85 | + 'event_id' => $eventId, |
|
86 | + 'event_type' => $eventType, |
|
87 | + 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
88 | + 'metadata' => json_encode($metadata), |
|
89 | + ]; |
|
90 | 90 | |
91 | - return $this |
|
92 | - ->connections |
|
93 | - ->getWrite() |
|
94 | - ->perform($query, $bindings); |
|
95 | - } |
|
91 | + return $this |
|
92 | + ->connections |
|
93 | + ->getWrite() |
|
94 | + ->perform($query, $bindings); |
|
95 | + } |
|
96 | 96 | } |
@@ -6,36 +6,36 @@ |
||
6 | 6 | use Jacobemerick\Web\Domain\Stream\Twitter\MysqlTwitterRepository as TwitterRepository; |
7 | 7 | |
8 | 8 | $client = new TwitterOAuth( |
9 | - $config->twitter->consumer_key, |
|
10 | - $config->twitter->consumer_secret, |
|
11 | - $config->twitter->access_token, |
|
12 | - $config->twitter->access_token_secret |
|
9 | + $config->twitter->consumer_key, |
|
10 | + $config->twitter->consumer_secret, |
|
11 | + $config->twitter->access_token, |
|
12 | + $config->twitter->access_token_secret |
|
13 | 13 | ); |
14 | 14 | $client->setDecodeJsonAsArray(true); |
15 | 15 | |
16 | 16 | $twitterRepository = new TwitterRepository($container['db_connection_locator']); |
17 | 17 | |
18 | 18 | $recentTweets = $client->get('statuses/user_timeline', [ |
19 | - 'screen_name' => 'jpemeric', |
|
20 | - 'count' => 50, |
|
21 | - 'trim_user' => true, |
|
19 | + 'screen_name' => 'jpemeric', |
|
20 | + 'count' => 50, |
|
21 | + 'trim_user' => true, |
|
22 | 22 | ]); |
23 | 23 | |
24 | 24 | foreach ($recentTweets as $tweet) { |
25 | - $uniqueTweetCheck = $twitterRepository->getTwitterByTweetId($tweet['id_str']); |
|
26 | - if ($uniqueTweetCheck !== false) { |
|
27 | - $currentTweetHash = md5($uniqueTweetCheck['metadata']); |
|
28 | - $newTweetHash = md5(json_encode($tweet)); |
|
29 | - if ($uniqueTweetCheck['metadata'] != json_encode($tweet)) { |
|
30 | - $twitterRepository->updateTweetMetadata($tweet['id_str'], $tweet); |
|
31 | - } |
|
32 | - continue; |
|
33 | - } |
|
34 | - |
|
35 | - $twitterRepository->insertTweet( |
|
36 | - $tweet['id_str'], |
|
37 | - (new DateTime($tweet['created_at']))->setTimezone($container['default_timezone']), |
|
38 | - $tweet |
|
39 | - ); |
|
25 | + $uniqueTweetCheck = $twitterRepository->getTwitterByTweetId($tweet['id_str']); |
|
26 | + if ($uniqueTweetCheck !== false) { |
|
27 | + $currentTweetHash = md5($uniqueTweetCheck['metadata']); |
|
28 | + $newTweetHash = md5(json_encode($tweet)); |
|
29 | + if ($uniqueTweetCheck['metadata'] != json_encode($tweet)) { |
|
30 | + $twitterRepository->updateTweetMetadata($tweet['id_str'], $tweet); |
|
31 | + } |
|
32 | + continue; |
|
33 | + } |
|
34 | + |
|
35 | + $twitterRepository->insertTweet( |
|
36 | + $tweet['id_str'], |
|
37 | + (new DateTime($tweet['created_at']))->setTimezone($container['default_timezone']), |
|
38 | + $tweet |
|
39 | + ); |
|
40 | 40 | } |
41 | 41 |
@@ -8,133 +8,133 @@ |
||
8 | 8 | class MysqlTwitterRepository implements TwitterRepositoryInterface |
9 | 9 | { |
10 | 10 | |
11 | - /** @var ConnectionLocator */ |
|
12 | - protected $connections; |
|
13 | - |
|
14 | - /** |
|
15 | - * @param ConnectonLocator $connections |
|
16 | - */ |
|
17 | - public function __construct(ConnectionLocator $connections) |
|
18 | - { |
|
19 | - $this->connections = $connections; |
|
20 | - } |
|
21 | - |
|
22 | - /** |
|
23 | - * @param integer $id |
|
24 | - * |
|
25 | - * @return array|false |
|
26 | - */ |
|
27 | - public function getTwitterById($id) |
|
28 | - { |
|
29 | - $query = " |
|
11 | + /** @var ConnectionLocator */ |
|
12 | + protected $connections; |
|
13 | + |
|
14 | + /** |
|
15 | + * @param ConnectonLocator $connections |
|
16 | + */ |
|
17 | + public function __construct(ConnectionLocator $connections) |
|
18 | + { |
|
19 | + $this->connections = $connections; |
|
20 | + } |
|
21 | + |
|
22 | + /** |
|
23 | + * @param integer $id |
|
24 | + * |
|
25 | + * @return array|false |
|
26 | + */ |
|
27 | + public function getTwitterById($id) |
|
28 | + { |
|
29 | + $query = " |
|
30 | 30 | SELECT * |
31 | 31 | FROM `jpemeric_stream`.`twitter` |
32 | 32 | WHERE `id` = :id |
33 | 33 | LIMIT 1"; |
34 | - $bindings = [ |
|
35 | - 'id' => $id, |
|
36 | - ]; |
|
37 | - |
|
38 | - return $this |
|
39 | - ->connections |
|
40 | - ->getRead() |
|
41 | - ->fetchOne($query, $bindings); |
|
42 | - } |
|
43 | - |
|
44 | - public function getTwitterByTweetId($tweetId) |
|
45 | - { |
|
46 | - $query = " |
|
34 | + $bindings = [ |
|
35 | + 'id' => $id, |
|
36 | + ]; |
|
37 | + |
|
38 | + return $this |
|
39 | + ->connections |
|
40 | + ->getRead() |
|
41 | + ->fetchOne($query, $bindings); |
|
42 | + } |
|
43 | + |
|
44 | + public function getTwitterByTweetId($tweetId) |
|
45 | + { |
|
46 | + $query = " |
|
47 | 47 | SELECT `id`, `tweet_id`, `datetime`, `metadata` |
48 | 48 | FROM `jpemeric_stream`.`twitter2` |
49 | 49 | WHERE `tweet_id` = :tweet_id |
50 | 50 | LIMIT 1"; |
51 | 51 | |
52 | - $bindings = [ |
|
53 | - 'tweet_id' => $tweetId, |
|
54 | - ]; |
|
55 | - |
|
56 | - return $this |
|
57 | - ->connections |
|
58 | - ->getRead() |
|
59 | - ->fetchOne($query, $bindings); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @param DateTimeInterface $date |
|
64 | - * @param string $text |
|
65 | - * |
|
66 | - * @return array|false |
|
67 | - */ |
|
68 | - public function getTwitterByFields(DateTimeInterface $date, $text) |
|
69 | - { |
|
70 | - $query = " |
|
52 | + $bindings = [ |
|
53 | + 'tweet_id' => $tweetId, |
|
54 | + ]; |
|
55 | + |
|
56 | + return $this |
|
57 | + ->connections |
|
58 | + ->getRead() |
|
59 | + ->fetchOne($query, $bindings); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @param DateTimeInterface $date |
|
64 | + * @param string $text |
|
65 | + * |
|
66 | + * @return array|false |
|
67 | + */ |
|
68 | + public function getTwitterByFields(DateTimeInterface $date, $text) |
|
69 | + { |
|
70 | + $query = " |
|
71 | 71 | SELECT * |
72 | 72 | FROM `jpemeric_stream`.`twitter` |
73 | 73 | WHERE `date` = :date AND `text` = :text |
74 | 74 | LIMIT 1"; |
75 | - $bindings = [ |
|
76 | - 'date' => $date->format('Y-m-d H:i:s'), |
|
77 | - 'text' => $text, |
|
78 | - ]; |
|
79 | - |
|
80 | - return $this |
|
81 | - ->connections |
|
82 | - ->getRead() |
|
83 | - ->fetchOne($query, $bindings); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @return array|false |
|
88 | - */ |
|
89 | - public function getUnmappedTwitters() |
|
90 | - { |
|
91 | - $query = " |
|
75 | + $bindings = [ |
|
76 | + 'date' => $date->format('Y-m-d H:i:s'), |
|
77 | + 'text' => $text, |
|
78 | + ]; |
|
79 | + |
|
80 | + return $this |
|
81 | + ->connections |
|
82 | + ->getRead() |
|
83 | + ->fetchOne($query, $bindings); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @return array|false |
|
88 | + */ |
|
89 | + public function getUnmappedTwitters() |
|
90 | + { |
|
91 | + $query = " |
|
92 | 92 | SELECT `id`, `date` |
93 | 93 | FROM `jpemeric_stream`.`twitter` |
94 | 94 | LEFT JOIN `jpemeric_stream`.`post` |
95 | 95 | ON `post`.`type_id` = `twitter`.`id` AND `post`.`id` IS NULL"; |
96 | 96 | |
97 | - return $this |
|
98 | - ->connections |
|
99 | - ->getRead() |
|
100 | - ->fetchAll($query); |
|
101 | - } |
|
97 | + return $this |
|
98 | + ->connections |
|
99 | + ->getRead() |
|
100 | + ->fetchAll($query); |
|
101 | + } |
|
102 | 102 | |
103 | - public function insertTweet($tweetId, DateTimeInterface $datetime, array $metadata) |
|
104 | - { |
|
105 | - $query = " |
|
103 | + public function insertTweet($tweetId, DateTimeInterface $datetime, array $metadata) |
|
104 | + { |
|
105 | + $query = " |
|
106 | 106 | INSERT INTO `jpemeric_stream`.`twitter2` |
107 | 107 | (`tweet_id`, `datetime`, `metadata`) |
108 | 108 | VALUES |
109 | 109 | (:tweet_id, :datetime, :metadata)"; |
110 | 110 | |
111 | - $bindings = [ |
|
112 | - 'tweet_id' => $tweetId, |
|
113 | - 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
114 | - 'metadata' => json_encode($metadata), |
|
115 | - ]; |
|
116 | - |
|
117 | - return $this |
|
118 | - ->connections |
|
119 | - ->getWrite() |
|
120 | - ->perform($query, $bindings); |
|
121 | - } |
|
122 | - |
|
123 | - public function updateTweetMetadata($tweetId, array $metadata) |
|
124 | - { |
|
125 | - $query = " |
|
111 | + $bindings = [ |
|
112 | + 'tweet_id' => $tweetId, |
|
113 | + 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
114 | + 'metadata' => json_encode($metadata), |
|
115 | + ]; |
|
116 | + |
|
117 | + return $this |
|
118 | + ->connections |
|
119 | + ->getWrite() |
|
120 | + ->perform($query, $bindings); |
|
121 | + } |
|
122 | + |
|
123 | + public function updateTweetMetadata($tweetId, array $metadata) |
|
124 | + { |
|
125 | + $query = " |
|
126 | 126 | UPDATE `jpemeric_stream`.`twitter2` |
127 | 127 | SET `metadata` = :metadata |
128 | 128 | WHERE `tweet_id` = :tweet_id"; |
129 | 129 | |
130 | - $bindings = [ |
|
131 | - 'metadata' => json_encode($metadata), |
|
132 | - 'tweet_id' => $tweetId, |
|
133 | - ]; |
|
130 | + $bindings = [ |
|
131 | + 'metadata' => json_encode($metadata), |
|
132 | + 'tweet_id' => $tweetId, |
|
133 | + ]; |
|
134 | 134 | |
135 | - return $this |
|
136 | - ->connections |
|
137 | - ->getWrite() |
|
138 | - ->perform($query, $bindings); |
|
139 | - } |
|
135 | + return $this |
|
136 | + ->connections |
|
137 | + ->getWrite() |
|
138 | + ->perform($query, $bindings); |
|
139 | + } |
|
140 | 140 | } |