@@ -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 DateTime $date |
|
| 64 | - * @param string $text |
|
| 65 | - * |
|
| 66 | - * @return array|false |
|
| 67 | - */ |
|
| 68 | - public function getTwitterByFields(DateTime $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 DateTime $date |
|
| 64 | + * @param string $text |
|
| 65 | + * |
|
| 66 | + * @return array|false |
|
| 67 | + */ |
|
| 68 | + public function getTwitterByFields(DateTime $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, DateTime $datetime, array $metadata) |
|
| 104 | - { |
|
| 105 | - $query = " |
|
| 103 | + public function insertTweet($tweetId, DateTime $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 | } |
@@ -17,14 +17,14 @@ discard block |
||
| 17 | 17 | * @return boolean |
| 18 | 18 | */ |
| 19 | 19 | $buildFeed = function (Feed $feed, $folder, $name = 'rss') { |
| 20 | - $tempFeed = __DIR__ . "/../../public/{$folder}/{$name}-new.xml"; |
|
| 21 | - $finalFeed = __DIR__ . "/../../public/{$folder}/{$name}.xml"; |
|
| 20 | + $tempFeed = __DIR__ . "/../../public/{$folder}/{$name}-new.xml"; |
|
| 21 | + $finalFeed = __DIR__ . "/../../public/{$folder}/{$name}.xml"; |
|
| 22 | 22 | |
| 23 | - $feedHandle = fopen($tempFeed, 'w'); |
|
| 24 | - fwrite($feedHandle, $feed->render()); |
|
| 25 | - fclose($feedHandle); |
|
| 23 | + $feedHandle = fopen($tempFeed, 'w'); |
|
| 24 | + fwrite($feedHandle, $feed->render()); |
|
| 25 | + fclose($feedHandle); |
|
| 26 | 26 | |
| 27 | - rename($tempFeed, $finalFeed); |
|
| 27 | + rename($tempFeed, $finalFeed); |
|
| 28 | 28 | }; |
| 29 | 29 | |
| 30 | 30 | |
@@ -43,34 +43,34 @@ discard block |
||
| 43 | 43 | $activeBlogPosts = $blogPostRepository->getActivePosts(); |
| 44 | 44 | |
| 45 | 45 | foreach ($activeBlogPosts as $blogPost) { |
| 46 | - $blogPostItem = new Item(); |
|
| 47 | - |
|
| 48 | - $blogPostItem->title($blogPost['title']); |
|
| 49 | - |
|
| 50 | - $url = "http://blog.jacobemerick.com/{$blogPost['category']}/{$blogPost['path']}/"; |
|
| 51 | - $blogPostItem->url($url); |
|
| 52 | - $blogPostItem->guid($url, true); |
|
| 53 | - |
|
| 54 | - $description = $blogPost['body']; |
|
| 55 | - $description = strip_tags($description); |
|
| 56 | - $description = strtok($description, "\n"); |
|
| 57 | - if (strlen($description) > 250) { |
|
| 58 | - $description = wordwrap($description, 250); |
|
| 59 | - $description = strtok($description, "\n"); |
|
| 60 | - if (substr($description, -1) != '.') { |
|
| 61 | - $description .= '…'; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - $description = html_entity_decode($description); |
|
| 65 | - $blogPostItem->description($description); |
|
| 66 | - |
|
| 67 | - $categoryUrl = "http://blog.jacobemerick.com/{$blogPost['category']}/"; |
|
| 68 | - $blogPostItem->category($blogPost['category'], $categoryUrl); |
|
| 69 | - |
|
| 70 | - $pubDate = new DateTime($blogPost['date']); |
|
| 71 | - $blogPostItem->pubDate($pubDate->getTimestamp()); |
|
| 72 | - |
|
| 73 | - $blogPostItem->appendTo($blogPostChannel); |
|
| 46 | + $blogPostItem = new Item(); |
|
| 47 | + |
|
| 48 | + $blogPostItem->title($blogPost['title']); |
|
| 49 | + |
|
| 50 | + $url = "http://blog.jacobemerick.com/{$blogPost['category']}/{$blogPost['path']}/"; |
|
| 51 | + $blogPostItem->url($url); |
|
| 52 | + $blogPostItem->guid($url, true); |
|
| 53 | + |
|
| 54 | + $description = $blogPost['body']; |
|
| 55 | + $description = strip_tags($description); |
|
| 56 | + $description = strtok($description, "\n"); |
|
| 57 | + if (strlen($description) > 250) { |
|
| 58 | + $description = wordwrap($description, 250); |
|
| 59 | + $description = strtok($description, "\n"); |
|
| 60 | + if (substr($description, -1) != '.') { |
|
| 61 | + $description .= '…'; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + $description = html_entity_decode($description); |
|
| 65 | + $blogPostItem->description($description); |
|
| 66 | + |
|
| 67 | + $categoryUrl = "http://blog.jacobemerick.com/{$blogPost['category']}/"; |
|
| 68 | + $blogPostItem->category($blogPost['category'], $categoryUrl); |
|
| 69 | + |
|
| 70 | + $pubDate = new DateTime($blogPost['date']); |
|
| 71 | + $blogPostItem->pubDate($pubDate->getTimestamp()); |
|
| 72 | + |
|
| 73 | + $blogPostItem->appendTo($blogPostChannel); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $buildFeed($blogPostFeed, 'blog'); |
@@ -88,33 +88,33 @@ discard block |
||
| 88 | 88 | $activeBlogComments = $commentRepository->getActiveCommentsBySite('blog'); |
| 89 | 89 | |
| 90 | 90 | foreach ($activeBlogComments as $blogComment) { |
| 91 | - $blogCommentItem = new Item(); |
|
| 92 | - |
|
| 93 | - $blogCommentItem->title("Comment on '{$blogComment['title']}' from {$blogComment['name']}"); |
|
| 94 | - |
|
| 95 | - $url = "http://blog.jacobemerick.com/{$blogComment['category']}/{$blogComment['path']}/"; |
|
| 96 | - $url .= "#comment-{$blogComment['id']}"; |
|
| 97 | - $blogCommentItem->url($url); |
|
| 98 | - $blogCommentItem->guid($url, true); |
|
| 99 | - |
|
| 100 | - $description = $blogComment['body']; |
|
| 101 | - $description = strip_tags($description); |
|
| 102 | - $description = strtok($description, "\n"); |
|
| 103 | - if (strlen($description) > 250) { |
|
| 104 | - $description = wordwrap($description, 250); |
|
| 105 | - $description = strtok($description, "\n"); |
|
| 106 | - if (substr($description, -1) != '.') { |
|
| 107 | - $description .= '…'; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - $description = html_entity_decode($description); |
|
| 111 | - $description = trim($description); |
|
| 112 | - $blogCommentItem->description($description); |
|
| 113 | - |
|
| 114 | - $pubDate = new DateTime($blogComment['date']); |
|
| 115 | - $blogCommentItem->pubDate($pubDate->getTimestamp()); |
|
| 116 | - |
|
| 117 | - $blogCommentItem->appendTo($blogCommentChannel); |
|
| 91 | + $blogCommentItem = new Item(); |
|
| 92 | + |
|
| 93 | + $blogCommentItem->title("Comment on '{$blogComment['title']}' from {$blogComment['name']}"); |
|
| 94 | + |
|
| 95 | + $url = "http://blog.jacobemerick.com/{$blogComment['category']}/{$blogComment['path']}/"; |
|
| 96 | + $url .= "#comment-{$blogComment['id']}"; |
|
| 97 | + $blogCommentItem->url($url); |
|
| 98 | + $blogCommentItem->guid($url, true); |
|
| 99 | + |
|
| 100 | + $description = $blogComment['body']; |
|
| 101 | + $description = strip_tags($description); |
|
| 102 | + $description = strtok($description, "\n"); |
|
| 103 | + if (strlen($description) > 250) { |
|
| 104 | + $description = wordwrap($description, 250); |
|
| 105 | + $description = strtok($description, "\n"); |
|
| 106 | + if (substr($description, -1) != '.') { |
|
| 107 | + $description .= '…'; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + $description = html_entity_decode($description); |
|
| 111 | + $description = trim($description); |
|
| 112 | + $blogCommentItem->description($description); |
|
| 113 | + |
|
| 114 | + $pubDate = new DateTime($blogComment['date']); |
|
| 115 | + $blogCommentItem->pubDate($pubDate->getTimestamp()); |
|
| 116 | + |
|
| 117 | + $blogCommentItem->appendTo($blogCommentChannel); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | $buildFeed($blogCommentFeed, 'blog', 'rss-comments'); |