@@ -11,44 +11,44 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | $lastBlogActivity = $activityRepository->getActivityLastUpdateByType('blog'); |
| 13 | 13 | if ($lastBlogActivity === false) { |
| 14 | - $lastBlogActivityDateTime = new DateTime('2008-05-03'); |
|
| 14 | + $lastBlogActivityDateTime = new DateTime('2008-05-03'); |
|
| 15 | 15 | } else { |
| 16 | - $lastBlogActivityDateTime = new DateTime($lastBlogActivity['updated_at']); |
|
| 17 | - $lastBlogActivityDateTime->modify('-5 days'); |
|
| 16 | + $lastBlogActivityDateTime = new DateTime($lastBlogActivity['updated_at']); |
|
| 17 | + $lastBlogActivityDateTime->modify('-5 days'); |
|
| 18 | 18 | } |
| 19 | 19 | $newBlogActivity = $blogRepository->getBlogsUpdatedSince($lastBlogActivityDateTime); |
| 20 | 20 | foreach ($newBlogActivity as $blog) { |
| 21 | - $uniqueBlogCheck = $activityRepository->getActivityByTypeId('blog', $blog['id']); |
|
| 22 | - if ($uniqueBlogCheck !== false) { |
|
| 23 | - continue; |
|
| 24 | - } |
|
| 21 | + $uniqueBlogCheck = $activityRepository->getActivityByTypeId('blog', $blog['id']); |
|
| 22 | + if ($uniqueBlogCheck !== false) { |
|
| 23 | + continue; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - $blogData = json_decode($blog['metadata'], true); |
|
| 27 | - $message = sprintf( |
|
| 28 | - 'Blogged about %s: <a href="%s" title="Jacob Emerick\'s Blog | %s">%s</a>.', |
|
| 29 | - str_replace('-', ' ', $blogData['category']), |
|
| 30 | - $blogData['link'], |
|
| 31 | - $blogData['title'], |
|
| 32 | - $blogData['title'] |
|
| 33 | - ); |
|
| 34 | - $messageLong = sprintf( |
|
| 35 | - "<h4><a href=\"%s\" title=\"Jacob Emerick's Blog | %s\">%s</a></h4>\n" . |
|
| 36 | - "<p>%s [<a href=\"%s\">read more</a></a>]</p>", |
|
| 37 | - $blogData['link'], |
|
| 38 | - $blogData['title'], |
|
| 39 | - $blogData['title'], |
|
| 40 | - htmlentities($blogData['description']), |
|
| 41 | - $blogData['link'] |
|
| 42 | - ); |
|
| 26 | + $blogData = json_decode($blog['metadata'], true); |
|
| 27 | + $message = sprintf( |
|
| 28 | + 'Blogged about %s: <a href="%s" title="Jacob Emerick\'s Blog | %s">%s</a>.', |
|
| 29 | + str_replace('-', ' ', $blogData['category']), |
|
| 30 | + $blogData['link'], |
|
| 31 | + $blogData['title'], |
|
| 32 | + $blogData['title'] |
|
| 33 | + ); |
|
| 34 | + $messageLong = sprintf( |
|
| 35 | + "<h4><a href=\"%s\" title=\"Jacob Emerick's Blog | %s\">%s</a></h4>\n" . |
|
| 36 | + "<p>%s [<a href=\"%s\">read more</a></a>]</p>", |
|
| 37 | + $blogData['link'], |
|
| 38 | + $blogData['title'], |
|
| 39 | + $blogData['title'], |
|
| 40 | + htmlentities($blogData['description']), |
|
| 41 | + $blogData['link'] |
|
| 42 | + ); |
|
| 43 | 43 | |
| 44 | - $activityRepository->insertActivity( |
|
| 45 | - $message, |
|
| 46 | - $messageLong, |
|
| 47 | - (new DateTime($blog['datetime'])), |
|
| 48 | - [], |
|
| 49 | - 'blog', |
|
| 50 | - $blog['id'] |
|
| 51 | - ); |
|
| 44 | + $activityRepository->insertActivity( |
|
| 45 | + $message, |
|
| 46 | + $messageLong, |
|
| 47 | + (new DateTime($blog['datetime'])), |
|
| 48 | + [], |
|
| 49 | + 'blog', |
|
| 50 | + $blog['id'] |
|
| 51 | + ); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | use Jacobemerick\Web\Domain\Stream\BlogComment\MysqlBlogCommentRepository as BlogCommentRepository; |
@@ -56,28 +56,28 @@ discard block |
||
| 56 | 56 | $blogCommentActivity = $blogCommentRepository->getBlogComments(); |
| 57 | 57 | $blogCommentHolder = []; |
| 58 | 58 | foreach ($blogCommentActivity as $blogComment) { |
| 59 | - $blogPermalink = $blogComment['permalink']; |
|
| 60 | - $blogPermalink = explode('#', $blogPermalink); |
|
| 61 | - $blogPermalink = current($blogPermalink); |
|
| 59 | + $blogPermalink = $blogComment['permalink']; |
|
| 60 | + $blogPermalink = explode('#', $blogPermalink); |
|
| 61 | + $blogPermalink = current($blogPermalink); |
|
| 62 | 62 | |
| 63 | - $blog = $blogRepository->getBlogByPermalink($blogPermalink); |
|
| 64 | - if (!array_key_exists($blog['id'], $blogCommentHolder)) { |
|
| 65 | - $blogCommentHolder[$blog['id']] = 1; |
|
| 66 | - } else { |
|
| 67 | - $blogCommentHolder[$blog['id']]++; |
|
| 68 | - } |
|
| 63 | + $blog = $blogRepository->getBlogByPermalink($blogPermalink); |
|
| 64 | + if (!array_key_exists($blog['id'], $blogCommentHolder)) { |
|
| 65 | + $blogCommentHolder[$blog['id']] = 1; |
|
| 66 | + } else { |
|
| 67 | + $blogCommentHolder[$blog['id']]++; |
|
| 68 | + } |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | foreach ($blogCommentHolder as $blogId => $commentCount) { |
| 72 | - $blogActivity = $activityRepository->getActivityByTypeId('blog', $blogId); |
|
| 73 | - $blogActivityMetadata = json_decode($blogActivity['metadata']); |
|
| 74 | - if ( |
|
| 75 | - !isset($blogActivityMetadata['comments']) || |
|
| 76 | - $blogActivityMetadata['comments'] != $commentCount |
|
| 77 | - ) { |
|
| 78 | - $activityRepository->updateActivityMetadata( |
|
| 79 | - $blogActivity['id'], |
|
| 80 | - ['comments' => $commentCount] |
|
| 81 | - ); |
|
| 82 | - } |
|
| 72 | + $blogActivity = $activityRepository->getActivityByTypeId('blog', $blogId); |
|
| 73 | + $blogActivityMetadata = json_decode($blogActivity['metadata']); |
|
| 74 | + if ( |
|
| 75 | + !isset($blogActivityMetadata['comments']) || |
|
| 76 | + $blogActivityMetadata['comments'] != $commentCount |
|
| 77 | + ) { |
|
| 78 | + $activityRepository->updateActivityMetadata( |
|
| 79 | + $blogActivity['id'], |
|
| 80 | + ['comments' => $commentCount] |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -4,9 +4,9 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface ActivityRepositoryInterface |
| 6 | 6 | { |
| 7 | - public function getActivityById($id); |
|
| 8 | - public function getActivities($limit = null, $offset = 0); |
|
| 9 | - public function getActivitiesCount(); |
|
| 10 | - public function getActivitiesByType($type, $limit = null, $offset = 0); |
|
| 11 | - public function getActivitiesByTypeCount($type); |
|
| 7 | + public function getActivityById($id); |
|
| 8 | + public function getActivities($limit = null, $offset = 0); |
|
| 9 | + public function getActivitiesCount(); |
|
| 10 | + public function getActivitiesByType($type, $limit = null, $offset = 0); |
|
| 11 | + public function getActivitiesByTypeCount($type); |
|
| 12 | 12 | } |
@@ -8,192 +8,192 @@ |
||
| 8 | 8 | class MysqlActivityRepository implements ActivityRepositoryInterface |
| 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 getActivityById($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 getActivityById($id) |
|
| 28 | + { |
|
| 29 | + $query = " |
|
| 30 | 30 | SELECT * |
| 31 | 31 | FROM `jpemeric_stream`.`activity` |
| 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 getActivityByTypeId($type, $typeId) |
|
| 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 getActivityByTypeId($type, $typeId) |
|
| 45 | + { |
|
| 46 | + $query = " |
|
| 47 | 47 | SELECT * |
| 48 | 48 | FROM `jpemeric_stream`.`activity` |
| 49 | 49 | WHERE `type` = :type && `type_id` = :type_id |
| 50 | 50 | LIMIT 1"; |
| 51 | - $bindings = [ |
|
| 52 | - 'type' => $type, |
|
| 53 | - 'type_id' => $typeId, |
|
| 54 | - ]; |
|
| 55 | - |
|
| 56 | - return $this |
|
| 57 | - ->connections |
|
| 58 | - ->getRead() |
|
| 59 | - ->fetchOne($query, $bindings); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - public function getActivityLastUpdateByType($type) |
|
| 63 | - { |
|
| 64 | - $query = " |
|
| 51 | + $bindings = [ |
|
| 52 | + 'type' => $type, |
|
| 53 | + 'type_id' => $typeId, |
|
| 54 | + ]; |
|
| 55 | + |
|
| 56 | + return $this |
|
| 57 | + ->connections |
|
| 58 | + ->getRead() |
|
| 59 | + ->fetchOne($query, $bindings); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + public function getActivityLastUpdateByType($type) |
|
| 63 | + { |
|
| 64 | + $query = " |
|
| 65 | 65 | SELECT * |
| 66 | 66 | FROM `jpemeric_stream`.`activity` |
| 67 | 67 | WHERE `type` = :type |
| 68 | 68 | ORDER BY `updated_at` DESC |
| 69 | 69 | LIMIT 1"; |
| 70 | 70 | |
| 71 | - $bindings = [ |
|
| 72 | - 'type' => $type, |
|
| 73 | - ]; |
|
| 74 | - |
|
| 75 | - return $this |
|
| 76 | - ->connections |
|
| 77 | - ->getRead() |
|
| 78 | - ->fetchOne($query, $bindings); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param integer $limit |
|
| 83 | - * @param integer $offset |
|
| 84 | - * |
|
| 85 | - * @return array|false |
|
| 86 | - */ |
|
| 87 | - public function getActivities($limit = null, $offset = 0) |
|
| 88 | - { |
|
| 89 | - $query = " |
|
| 71 | + $bindings = [ |
|
| 72 | + 'type' => $type, |
|
| 73 | + ]; |
|
| 74 | + |
|
| 75 | + return $this |
|
| 76 | + ->connections |
|
| 77 | + ->getRead() |
|
| 78 | + ->fetchOne($query, $bindings); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param integer $limit |
|
| 83 | + * @param integer $offset |
|
| 84 | + * |
|
| 85 | + * @return array|false |
|
| 86 | + */ |
|
| 87 | + public function getActivities($limit = null, $offset = 0) |
|
| 88 | + { |
|
| 89 | + $query = " |
|
| 90 | 90 | SELECT * |
| 91 | 91 | FROM `jpemeric_stream`.`activity` |
| 92 | 92 | ORDER BY `datetime` DESC"; |
| 93 | - if (!is_null($limit)) { |
|
| 94 | - $query .= " |
|
| 93 | + if (!is_null($limit)) { |
|
| 94 | + $query .= " |
|
| 95 | 95 | LIMIT {$offset}, {$limit}"; |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - return $this |
|
| 99 | - ->connections |
|
| 100 | - ->getRead() |
|
| 101 | - ->fetchAll($query); |
|
| 102 | - } |
|
| 98 | + return $this |
|
| 99 | + ->connections |
|
| 100 | + ->getRead() |
|
| 101 | + ->fetchAll($query); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - public function getActivitiesCount() |
|
| 105 | - { |
|
| 106 | - $query = " |
|
| 104 | + public function getActivitiesCount() |
|
| 105 | + { |
|
| 106 | + $query = " |
|
| 107 | 107 | SELECT COUNT(1) AS `count` |
| 108 | 108 | FROM `jpemeric_stream`.`activity`"; |
| 109 | 109 | |
| 110 | - return $this |
|
| 111 | - ->connections |
|
| 112 | - ->getRead() |
|
| 113 | - ->fetchValue($query); |
|
| 114 | - } |
|
| 110 | + return $this |
|
| 111 | + ->connections |
|
| 112 | + ->getRead() |
|
| 113 | + ->fetchValue($query); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - public function getActivitiesByType($type, $limit = null, $offset = 0) |
|
| 117 | - { |
|
| 118 | - $query = " |
|
| 116 | + public function getActivitiesByType($type, $limit = null, $offset = 0) |
|
| 117 | + { |
|
| 118 | + $query = " |
|
| 119 | 119 | SELECT * |
| 120 | 120 | FROM `jpemeric_stream`.`activity` |
| 121 | 121 | WHERE `type` = :type |
| 122 | 122 | ORDER BY `datetime` DESC"; |
| 123 | - if (!is_null($limit)) { |
|
| 124 | - $query .= " |
|
| 123 | + if (!is_null($limit)) { |
|
| 124 | + $query .= " |
|
| 125 | 125 | LIMIT {$offset}, {$limit}"; |
| 126 | - } |
|
| 127 | - $bindings = [ |
|
| 128 | - 'type' => $type, |
|
| 129 | - ]; |
|
| 130 | - |
|
| 131 | - return $this |
|
| 132 | - ->connections |
|
| 133 | - ->getRead() |
|
| 134 | - ->fetchAll($query, $bindings); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - public function getActivitiesByTypeCount($type) |
|
| 138 | - { |
|
| 139 | - $query = " |
|
| 126 | + } |
|
| 127 | + $bindings = [ |
|
| 128 | + 'type' => $type, |
|
| 129 | + ]; |
|
| 130 | + |
|
| 131 | + return $this |
|
| 132 | + ->connections |
|
| 133 | + ->getRead() |
|
| 134 | + ->fetchAll($query, $bindings); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + public function getActivitiesByTypeCount($type) |
|
| 138 | + { |
|
| 139 | + $query = " |
|
| 140 | 140 | SELECT COUNT(1) AS `count` |
| 141 | 141 | FROM `jpemeric_stream`.`activity` |
| 142 | 142 | WHERE `type` = :type"; |
| 143 | - $bindings = [ |
|
| 144 | - 'type' => $type, |
|
| 145 | - ]; |
|
| 146 | - |
|
| 147 | - return $this |
|
| 148 | - ->connections |
|
| 149 | - ->getRead() |
|
| 150 | - ->fetchValue($query, $bindings); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - public function insertActivity( |
|
| 154 | - $message, |
|
| 155 | - $messageLong, |
|
| 156 | - DateTime $datetime, |
|
| 157 | - array $metadata, |
|
| 158 | - $type, |
|
| 159 | - $typeId |
|
| 160 | - ) { |
|
| 161 | - $query = " |
|
| 143 | + $bindings = [ |
|
| 144 | + 'type' => $type, |
|
| 145 | + ]; |
|
| 146 | + |
|
| 147 | + return $this |
|
| 148 | + ->connections |
|
| 149 | + ->getRead() |
|
| 150 | + ->fetchValue($query, $bindings); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + public function insertActivity( |
|
| 154 | + $message, |
|
| 155 | + $messageLong, |
|
| 156 | + DateTime $datetime, |
|
| 157 | + array $metadata, |
|
| 158 | + $type, |
|
| 159 | + $typeId |
|
| 160 | + ) { |
|
| 161 | + $query = " |
|
| 162 | 162 | INSERT INTO `jpemeric_stream`.`activity` |
| 163 | 163 | (`message`, `message_long`, `datetime`, `metadata`, `type`, `type_id`) |
| 164 | 164 | VALUES |
| 165 | 165 | (:message, :message_long, :datetime, :metadata, :type, :type_id)"; |
| 166 | 166 | |
| 167 | - $bindings = [ |
|
| 168 | - 'message' => $message, |
|
| 169 | - 'message_long' => $messageLong, |
|
| 170 | - 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
| 171 | - 'metadata' => json_encode($metadata), |
|
| 172 | - 'type' => $type, |
|
| 173 | - 'type_id' => $typeId, |
|
| 174 | - ]; |
|
| 175 | - |
|
| 176 | - return $this |
|
| 177 | - ->connections |
|
| 178 | - ->getWrite() |
|
| 179 | - ->perform($query, $bindings); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - public function updateActivityMetadata($activityId, array $metadata) |
|
| 183 | - { |
|
| 184 | - $query = " |
|
| 167 | + $bindings = [ |
|
| 168 | + 'message' => $message, |
|
| 169 | + 'message_long' => $messageLong, |
|
| 170 | + 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
| 171 | + 'metadata' => json_encode($metadata), |
|
| 172 | + 'type' => $type, |
|
| 173 | + 'type_id' => $typeId, |
|
| 174 | + ]; |
|
| 175 | + |
|
| 176 | + return $this |
|
| 177 | + ->connections |
|
| 178 | + ->getWrite() |
|
| 179 | + ->perform($query, $bindings); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + public function updateActivityMetadata($activityId, array $metadata) |
|
| 183 | + { |
|
| 184 | + $query = " |
|
| 185 | 185 | UPDATE `jpemeric_stream`.`activity` |
| 186 | 186 | SET `metadata` = :metadata |
| 187 | 187 | WHERE `id` = :id"; |
| 188 | 188 | |
| 189 | - $bindings = [ |
|
| 190 | - 'metadata' => json_encode($metadata), |
|
| 191 | - 'id' => $activityId, |
|
| 192 | - ]; |
|
| 189 | + $bindings = [ |
|
| 190 | + 'metadata' => json_encode($metadata), |
|
| 191 | + 'id' => $activityId, |
|
| 192 | + ]; |
|
| 193 | 193 | |
| 194 | - return $this |
|
| 195 | - ->connections |
|
| 196 | - ->getWrite() |
|
| 197 | - ->perform($query, $bindings); |
|
| 198 | - } |
|
| 194 | + return $this |
|
| 195 | + ->connections |
|
| 196 | + ->getWrite() |
|
| 197 | + ->perform($query, $bindings); |
|
| 198 | + } |
|
| 199 | 199 | } |
@@ -8,129 +8,129 @@ |
||
| 8 | 8 | class MysqlBlogRepository implements BlogRepositoryInterface |
| 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 getBlogById($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 getBlogById($id) |
|
| 28 | + { |
|
| 29 | + $query = " |
|
| 30 | 30 | SELECT * |
| 31 | 31 | FROM `jpemeric_stream`.`blog` |
| 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 getBlogByPermalink($permalink) |
|
| 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 getBlogByPermalink($permalink) |
|
| 45 | + { |
|
| 46 | + $query = " |
|
| 47 | 47 | SELECT * |
| 48 | 48 | FROM `jpemeric_stream`.`blog2` |
| 49 | 49 | WHERE `permalink` = :permalink |
| 50 | 50 | LIMIT 1"; |
| 51 | - $bindings = [ |
|
| 52 | - 'permalink' => $permalink, |
|
| 53 | - ]; |
|
| 54 | - |
|
| 55 | - return $this |
|
| 56 | - ->connections |
|
| 57 | - ->getRead() |
|
| 58 | - ->fetchOne($query, $bindings); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param string $title |
|
| 63 | - * |
|
| 64 | - * @return array|false |
|
| 65 | - */ |
|
| 66 | - public function getBlogByTitle($title) |
|
| 67 | - { |
|
| 68 | - $query = " |
|
| 51 | + $bindings = [ |
|
| 52 | + 'permalink' => $permalink, |
|
| 53 | + ]; |
|
| 54 | + |
|
| 55 | + return $this |
|
| 56 | + ->connections |
|
| 57 | + ->getRead() |
|
| 58 | + ->fetchOne($query, $bindings); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param string $title |
|
| 63 | + * |
|
| 64 | + * @return array|false |
|
| 65 | + */ |
|
| 66 | + public function getBlogByTitle($title) |
|
| 67 | + { |
|
| 68 | + $query = " |
|
| 69 | 69 | SELECT * |
| 70 | 70 | FROM `jpemeric_stream`.`blog` |
| 71 | 71 | WHERE `title` = :title |
| 72 | 72 | LIMIT 1"; |
| 73 | - $bindings = [ |
|
| 74 | - 'title' => $title, |
|
| 75 | - ]; |
|
| 76 | - |
|
| 77 | - return $this |
|
| 78 | - ->connections |
|
| 79 | - ->getRead() |
|
| 80 | - ->fetchOne($query, $bindings); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function getBlogs($limit = null, $offset = 0) |
|
| 84 | - { |
|
| 85 | - $query = " |
|
| 73 | + $bindings = [ |
|
| 74 | + 'title' => $title, |
|
| 75 | + ]; |
|
| 76 | + |
|
| 77 | + return $this |
|
| 78 | + ->connections |
|
| 79 | + ->getRead() |
|
| 80 | + ->fetchOne($query, $bindings); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function getBlogs($limit = null, $offset = 0) |
|
| 84 | + { |
|
| 85 | + $query = " |
|
| 86 | 86 | SELECT `id`, `permalink`, `datetime` |
| 87 | 87 | FROM `jpemeric_stream`.`blog2` |
| 88 | 88 | ORDER BY `datetime` DESC"; |
| 89 | - if (!is_null($limit)) { |
|
| 90 | - $query .= " |
|
| 89 | + if (!is_null($limit)) { |
|
| 90 | + $query .= " |
|
| 91 | 91 | LIMIT {$limit}, {$offset}"; |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return $this |
|
| 95 | - ->connections |
|
| 96 | - ->getRead() |
|
| 97 | - ->fetchAll($query); |
|
| 98 | - } |
|
| 94 | + return $this |
|
| 95 | + ->connections |
|
| 96 | + ->getRead() |
|
| 97 | + ->fetchAll($query); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - public function getBlogsUpdatedSince(DateTime $datetime) |
|
| 101 | - { |
|
| 102 | - $query = " |
|
| 100 | + public function getBlogsUpdatedSince(DateTime $datetime) |
|
| 101 | + { |
|
| 102 | + $query = " |
|
| 103 | 103 | SELECT * |
| 104 | 104 | FROM `jpemeric_stream`.`blog2` |
| 105 | 105 | WHERE `updated_at` >= :last_update"; |
| 106 | 106 | |
| 107 | - $bindings = [ |
|
| 108 | - 'last_update' => $datetime->format('Y-m-d H:i:s'), |
|
| 109 | - ]; |
|
| 107 | + $bindings = [ |
|
| 108 | + 'last_update' => $datetime->format('Y-m-d H:i:s'), |
|
| 109 | + ]; |
|
| 110 | 110 | |
| 111 | - return $this |
|
| 112 | - ->connections |
|
| 113 | - ->getRead() |
|
| 114 | - ->fetchAll($query, $bindings); |
|
| 115 | - } |
|
| 111 | + return $this |
|
| 112 | + ->connections |
|
| 113 | + ->getRead() |
|
| 114 | + ->fetchAll($query, $bindings); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - public function insertBlog($permalink, DateTime $datetime, array $metadata) |
|
| 118 | - { |
|
| 119 | - $query = " |
|
| 117 | + public function insertBlog($permalink, DateTime $datetime, array $metadata) |
|
| 118 | + { |
|
| 119 | + $query = " |
|
| 120 | 120 | INSERT INTO `jpemeric_stream`.`blog2` |
| 121 | 121 | (`permalink`, `datetime`, `metadata`) |
| 122 | 122 | VALUES |
| 123 | 123 | (:permalink, :datetime, :metadata)"; |
| 124 | 124 | |
| 125 | - $bindings = [ |
|
| 126 | - 'permalink' => $permalink, |
|
| 127 | - 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
| 128 | - 'metadata' => json_encode($metadata), |
|
| 129 | - ]; |
|
| 130 | - |
|
| 131 | - return $this |
|
| 132 | - ->connections |
|
| 133 | - ->getWrite() |
|
| 134 | - ->perform($query, $bindings); |
|
| 135 | - } |
|
| 125 | + $bindings = [ |
|
| 126 | + 'permalink' => $permalink, |
|
| 127 | + 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
| 128 | + 'metadata' => json_encode($metadata), |
|
| 129 | + ]; |
|
| 130 | + |
|
| 131 | + return $this |
|
| 132 | + ->connections |
|
| 133 | + ->getWrite() |
|
| 134 | + ->perform($query, $bindings); |
|
| 135 | + } |
|
| 136 | 136 | } |