Completed
Push — master ( 989695...7cfad9 )
by Jacob
07:09
created
src/Domain/Stream/DailyMile/MysqlDailyMileRepository.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -8,106 +8,106 @@
 block discarded – undo
8 8
 class MysqlDailyMileRepository implements DailyMileRepositoryInterface
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 $limit
24
-     * @param integer $offset
25
-     *
26
-     * @return array|false
27
-     */
28
-    public function getEntries($limit = null, $offset = 0)
29
-    {
30
-        $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 $limit
24
+	 * @param integer $offset
25
+	 *
26
+	 * @return array|false
27
+	 */
28
+	public function getEntries($limit = null, $offset = 0)
29
+	{
30
+		$query = "
31 31
             SELECT `id`, `entry_id`, `datetime`
32 32
             FROM `jpemeric_stream`.`dailymile`
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
-        }
38
-
39
-        return $this
40
-            ->connections
41
-            ->getRead()
42
-            ->fetchAll($query);
43
-    }
44
-
45
-    /**
46
-     * @param integer $entryId
47
-     *
48
-     * @return array|false
49
-     */
50
-    public function getEntryByEntryId($entryId)
51
-    {
52
-        $query = "
37
+		}
38
+
39
+		return $this
40
+			->connections
41
+			->getRead()
42
+			->fetchAll($query);
43
+	}
44
+
45
+	/**
46
+	 * @param integer $entryId
47
+	 *
48
+	 * @return array|false
49
+	 */
50
+	public function getEntryByEntryId($entryId)
51
+	{
52
+		$query = "
53 53
             SELECT *
54 54
             FROM `jpemeric_stream`.`dailymile`
55 55
             WHERE `entry_id` = :entry_id
56 56
             LIMIT 1";
57 57
 
58
-        $bindings = [
59
-            'entry_id' => $entryId,
60
-        ];
58
+		$bindings = [
59
+			'entry_id' => $entryId,
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
-    public function getDailyMilesUpdatedSince(DateTime $datetime)
69
-    {
70
-        $query = "
68
+	public function getDailyMilesUpdatedSince(DateTime $datetime)
69
+	{
70
+		$query = "
71 71
             SELECT *
72 72
             FROM `jpemeric_stream`.`dailymile`
73 73
             WHERE `updated_at` >= :last_update";
74 74
 
75
-        $bindings = [
76
-            'last_update' => $datetime->format('Y-m-d H:i:s'),
77
-        ];
78
-
79
-        return $this
80
-            ->connections
81
-            ->getRead()
82
-            ->fetchAll($query, $bindings);
83
-    }
84
-
85
-    /**
86
-     * @param integer  $entryId
87
-     * @param string   $entryType
88
-     * @param DateTime $datetime
89
-     * @param array    $metadata
90
-     *
91
-     * @return
92
-     */
93
-    public function insertEntry($entryId, $entryType, DateTime $datetime, array $metadata)
94
-    {
95
-        $query = "
75
+		$bindings = [
76
+			'last_update' => $datetime->format('Y-m-d H:i:s'),
77
+		];
78
+
79
+		return $this
80
+			->connections
81
+			->getRead()
82
+			->fetchAll($query, $bindings);
83
+	}
84
+
85
+	/**
86
+	 * @param integer  $entryId
87
+	 * @param string   $entryType
88
+	 * @param DateTime $datetime
89
+	 * @param array    $metadata
90
+	 *
91
+	 * @return
92
+	 */
93
+	public function insertEntry($entryId, $entryType, DateTime $datetime, array $metadata)
94
+	{
95
+		$query = "
96 96
             INSERT INTO `jpemeric_stream`.`dailymile`
97 97
                 (`entry_id`, `type`, `datetime`, `metadata`)
98 98
             VALUES
99 99
                 (:entry_id, :entry_type, :datetime, :metadata)";
100 100
 
101
-        $bindings = [
102
-            'entry_id' => $entryId,
103
-            'entry_type' => $entryType,
104
-            'datetime' => $datetime->format('Y-m-d H:i:s'),
105
-            'metadata' => json_encode($metadata),
106
-        ];
107
-
108
-        return $this
109
-            ->connections
110
-            ->getWrite()
111
-            ->perform($query, $bindings);
112
-    }
101
+		$bindings = [
102
+			'entry_id' => $entryId,
103
+			'entry_type' => $entryType,
104
+			'datetime' => $datetime->format('Y-m-d H:i:s'),
105
+			'metadata' => json_encode($metadata),
106
+		];
107
+
108
+		return $this
109
+			->connections
110
+			->getWrite()
111
+			->perform($query, $bindings);
112
+	}
113 113
 }
Please login to merge, or discard this patch.
src/Domain/Stream/Goodread/MysqlGoodreadRepository.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -8,93 +8,93 @@
 block discarded – undo
8 8
 class MysqlGoodreadRepository implements GoodreadRepositoryInterface
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 $limit
24
-     * @param integer $offset
25
-     *
26
-     * @return array|false
27
-     */
28
-    public function getReviews($limit = null, $offset = 0)
29
-    {
30
-        $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 $limit
24
+	 * @param integer $offset
25
+	 *
26
+	 * @return array|false
27
+	 */
28
+	public function getReviews($limit = null, $offset = 0)
29
+	{
30
+		$query = "
31 31
             SELECT `id`, `permalink`, `datetime`
32 32
             FROM `jpemeric_stream`.`goodread`
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
-    public function getReviewByPermalink($permalink)
46
-    {
47
-        $query = "
45
+	public function getReviewByPermalink($permalink)
46
+	{
47
+		$query = "
48 48
             SELECT *
49 49
             FROM `jpemeric_stream`.`goodread`
50 50
             WHERE `permalink` = :permalink
51 51
             LIMIT 1";
52 52
 
53
-        $bindings = [
54
-            'permalink' => $permalink,
55
-        ];
53
+		$bindings = [
54
+			'permalink' => $permalink,
55
+		];
56 56
 
57
-        return $this
58
-            ->connections
59
-            ->getRead()
60
-            ->fetchOne($query, $bindings);
61
-    }
57
+		return $this
58
+			->connections
59
+			->getRead()
60
+			->fetchOne($query, $bindings);
61
+	}
62 62
 
63
-    public function getGoodreadsUpdatedSince(DateTime $datetime)
64
-    {
65
-        $query = "
63
+	public function getGoodreadsUpdatedSince(DateTime $datetime)
64
+	{
65
+		$query = "
66 66
             SELECT *
67 67
             FROM `jpemeric_stream`.`goodread`
68 68
             WHERE `updated_at` >= :last_update";
69 69
 
70
-        $bindings = [
71
-            'last_update' => $datetime->format('Y-m-d H:i:s'),
72
-        ];
70
+		$bindings = [
71
+			'last_update' => $datetime->format('Y-m-d H:i:s'),
72
+		];
73 73
 
74
-        return $this
75
-            ->connections
76
-            ->getRead()
77
-            ->fetchAll($query, $bindings);
78
-    }
74
+		return $this
75
+			->connections
76
+			->getRead()
77
+			->fetchAll($query, $bindings);
78
+	}
79 79
 
80
-    public function insertReview($permalink, $bookId, DateTime $datetime, array $metadata)
81
-    {
82
-        $query = "
80
+	public function insertReview($permalink, $bookId, DateTime $datetime, array $metadata)
81
+	{
82
+		$query = "
83 83
             INSERT INTO `jpemeric_stream`.`goodread`
84 84
                 (`permalink`, `book_id`, `datetime`, `metadata`)
85 85
             VALUES
86 86
                 (:permalink, :book_id, :datetime, :metadata)";
87 87
 
88
-        $bindings = [
89
-            'permalink' => $permalink,
90
-            'book_id' => $bookId,
91
-            'datetime' => $datetime->format('Y-m-d H:i:s'),
92
-            'metadata' => json_encode($metadata),
93
-        ];
94
-
95
-        return $this
96
-            ->connections
97
-            ->getWrite()
98
-            ->perform($query, $bindings);
99
-    }
88
+		$bindings = [
89
+			'permalink' => $permalink,
90
+			'book_id' => $bookId,
91
+			'datetime' => $datetime->format('Y-m-d H:i:s'),
92
+			'metadata' => json_encode($metadata),
93
+		];
94
+
95
+		return $this
96
+			->connections
97
+			->getWrite()
98
+			->perform($query, $bindings);
99
+	}
100 100
 }
Please login to merge, or discard this patch.
script/cron/build-activity-stream.php 1 patch
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -11,44 +11,44 @@  discard block
 block discarded – undo
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
-    }
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
-    );
43
-
44
-    $activityRepository->insertActivity(
45
-        $message,
46
-        $messageLong,
47
-        (new DateTime($blog['datetime'])),
48
-        [],
49
-        'blog',
50
-        $blog['id']
51
-    );
21
+	$uniqueBlogCheck = $activityRepository->getActivityByTypeId('blog', $blog['id']);
22
+	if ($uniqueBlogCheck !== false) {
23
+		continue;
24
+	}
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
+	);
43
+
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,30 +56,30 @@  discard block
 block discarded – undo
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);
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
-    }
59
+	$blogPermalink = $blogComment['permalink'];
60
+	$blogPermalink = explode('#', $blogPermalink);
61
+	$blogPermalink = current($blogPermalink);
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
+	}
69 69
 }
70 70
 
71 71
 foreach ($blogCommentHolder as $blogId => $commentCount) {
72
-    $blogActivity = $activityRepository->getActivityByTypeId('blog', $blogId);
73
-    $blogActivityMetadata = json_decode($blogActivity['metadata'], true);
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'], true);
74
+	if (
75
+		!isset($blogActivityMetadata['comments']) ||
76
+		$blogActivityMetadata['comments'] != $commentCount
77
+	) {
78
+		$activityRepository->updateActivityMetadata(
79
+			$blogActivity['id'],
80
+			['comments' => $commentCount]
81
+		);
82
+	}
83 83
 }
84 84
 
85 85
 // distance
@@ -88,67 +88,67 @@  discard block
 block discarded – undo
88 88
 
89 89
 $lastDailyMileActivity = $activityRepository->getActivityLastUpdateByType('distance');
90 90
 if ($lastDailyMileActivity === false) {
91
-    $lastDailyMileActivityDateTime = new DateTime('2008-05-03');
91
+	$lastDailyMileActivityDateTime = new DateTime('2008-05-03');
92 92
 } else {
93
-    $lastDailyMileActivityDateTime = new DateTime($lastDailyMileActivity['updated_at']);
94
-    $lastDailyMileActivityDateTime->modify('-5 days');
93
+	$lastDailyMileActivityDateTime = new DateTime($lastDailyMileActivity['updated_at']);
94
+	$lastDailyMileActivityDateTime->modify('-5 days');
95 95
 }
96 96
 $newDailyMileActivity = $dailyMileRepository->getDailyMilesUpdatedSince($lastDailyMileActivityDateTime);
97 97
 foreach ($newDailyMileActivity as $dailyMile) {
98
-    $uniqueDailyMileCheck = $activityRepository->getActivityByTypeId('distance', $dailyMile['id']);
99
-    if ($uniqueDailyMileCheck !== false) {
100
-        continue;
101
-    }
102
-
103
-    $dailyMileData = json_decode($dailyMile['metadata'], true);
104
-    if ($dailyMile['type'] == 'Hiking') {
105
-        $message = sprintf(
106
-            '%s %.2f %s and felt %s.',
107
-            'Hiked',
108
-            $dailyMileData['workout']['distance']['value'],
109
-            $dailyMileData['workout']['distance']['units'],
110
-            $dailyMileData['workout']['felt']
111
-        );
112
-        $messageLong = "<p>{$message}</p>";
113
-        if (isset($dailyMileData['workout']['title'])) {
114
-            $messageLong .= "\n<p>I was hiking up around the {$dailyMileData['workout']['title']} area.</p>";
115
-        }
116
-    } else if ($dailyMile['type'] == 'Running') {
117
-        $message = sprintf(
118
-            '%s %.2f %s and felt %s.',
119
-            'Ran',
120
-            $dailyMileData['workout']['distance']['value'],
121
-            $dailyMileData['workout']['distance']['units'],
122
-            $dailyMileData['workout']['felt']
123
-        );
124
-        $messageLong = "<p>{$message}</p>";
125
-        if (isset($dailyMileData['message'])) {
126
-            $messageLong .= "\n<p>Afterwards, I was all like '{$dailyMileData['message']}'.</p>";
127
-        }
128
-    } else if ($dailyMile['type'] == 'Walking') {
129
-        $message = sprintf(
130
-            '%s %.2f %s and felt %s.',
131
-            'Walked',
132
-            $dailyMileData['workout']['distance']['value'],
133
-            $dailyMileData['workout']['distance']['units'],
134
-            $dailyMileData['workout']['felt']
135
-        );
136
-        $messageLong = "<p>{$message}</p>";
137
-        if (isset($dailyMileData['message'])) {
138
-            $messageLong .= "\n<p>{$dailyMileData['message']}</p>";
139
-        }
140
-    } else {
141
-        continue;
142
-    }
143
-
144
-    $activityRepository->insertActivity(
145
-        $message,
146
-        $messageLong,
147
-        (new DateTime($dailyMile['datetime'])),
148
-        [],
149
-        'distance',
150
-        $dailyMile['id']
151
-    );
98
+	$uniqueDailyMileCheck = $activityRepository->getActivityByTypeId('distance', $dailyMile['id']);
99
+	if ($uniqueDailyMileCheck !== false) {
100
+		continue;
101
+	}
102
+
103
+	$dailyMileData = json_decode($dailyMile['metadata'], true);
104
+	if ($dailyMile['type'] == 'Hiking') {
105
+		$message = sprintf(
106
+			'%s %.2f %s and felt %s.',
107
+			'Hiked',
108
+			$dailyMileData['workout']['distance']['value'],
109
+			$dailyMileData['workout']['distance']['units'],
110
+			$dailyMileData['workout']['felt']
111
+		);
112
+		$messageLong = "<p>{$message}</p>";
113
+		if (isset($dailyMileData['workout']['title'])) {
114
+			$messageLong .= "\n<p>I was hiking up around the {$dailyMileData['workout']['title']} area.</p>";
115
+		}
116
+	} else if ($dailyMile['type'] == 'Running') {
117
+		$message = sprintf(
118
+			'%s %.2f %s and felt %s.',
119
+			'Ran',
120
+			$dailyMileData['workout']['distance']['value'],
121
+			$dailyMileData['workout']['distance']['units'],
122
+			$dailyMileData['workout']['felt']
123
+		);
124
+		$messageLong = "<p>{$message}</p>";
125
+		if (isset($dailyMileData['message'])) {
126
+			$messageLong .= "\n<p>Afterwards, I was all like '{$dailyMileData['message']}'.</p>";
127
+		}
128
+	} else if ($dailyMile['type'] == 'Walking') {
129
+		$message = sprintf(
130
+			'%s %.2f %s and felt %s.',
131
+			'Walked',
132
+			$dailyMileData['workout']['distance']['value'],
133
+			$dailyMileData['workout']['distance']['units'],
134
+			$dailyMileData['workout']['felt']
135
+		);
136
+		$messageLong = "<p>{$message}</p>";
137
+		if (isset($dailyMileData['message'])) {
138
+			$messageLong .= "\n<p>{$dailyMileData['message']}</p>";
139
+		}
140
+	} else {
141
+		continue;
142
+	}
143
+
144
+	$activityRepository->insertActivity(
145
+		$message,
146
+		$messageLong,
147
+		(new DateTime($dailyMile['datetime'])),
148
+		[],
149
+		'distance',
150
+		$dailyMile['id']
151
+	);
152 152
 }
153 153
 
154 154
 // books
@@ -157,46 +157,46 @@  discard block
 block discarded – undo
157 157
 
158 158
 $lastGoodreadActivity = $activityRepository->getActivityLastUpdateByType('book');
159 159
 if ($lastGoodreadActivity === false) {
160
-    $lastGoodreadActivityDateTime = new DateTime('2010-08-28');
160
+	$lastGoodreadActivityDateTime = new DateTime('2010-08-28');
161 161
 } else {
162
-    $lastGoodreadActivityDateTime = new DateTime($lastGoodreadActivity['updated_at']);
163
-    $lastGoodreadActivityDateTime->modify('-5 days');
162
+	$lastGoodreadActivityDateTime = new DateTime($lastGoodreadActivity['updated_at']);
163
+	$lastGoodreadActivityDateTime->modify('-5 days');
164 164
 }
165 165
 $newGoodreadActivity = $goodreadRepository->getGoodreadsUpdatedSince($lastGoodreadActivityDateTime);
166 166
 foreach ($newGoodreadActivity as $goodread) {
167
-    $uniqueGoodreadCheck = $activityRepository->getActivityByTypeId('book', $goodread['id']);
168
-    if ($uniqueGoodreadCheck !== false) {
169
-        continue;
170
-    }
171
-
172
-    $goodreadData = json_decode($goodread['metadata'], true);
173
-
174
-    if (empty($goodreadData['user_read_at'])) {
175
-        continue;
176
-    }
177
-
178
-    $message = sprintf(
179
-        'Just finished reading %s by %s.',
180
-        $goodreadData['title'],
181
-        $goodreadData['author_name']
182
-    );
183
-    if (isset($goodreadData['book_large_image_url'])) {
184
-        $messageLong = sprintf(
185
-            "<img alt=\"Goodreads | %s\" src=\"%s\" />\n",
186
-            $goodreadData['title'],
187
-            $goodreadData['book_large_image_url']
188
-        );
189
-    }
190
-    $messageLong .= "<p>{$message}</p>";
191
-
192
-    $activityRepository->insertActivity(
193
-        $message,
194
-        $messageLong,
195
-        (new DateTime($goodread['datetime'])),
196
-        [],
197
-        'book',
198
-        $goodread['id']
199
-    );
167
+	$uniqueGoodreadCheck = $activityRepository->getActivityByTypeId('book', $goodread['id']);
168
+	if ($uniqueGoodreadCheck !== false) {
169
+		continue;
170
+	}
171
+
172
+	$goodreadData = json_decode($goodread['metadata'], true);
173
+
174
+	if (empty($goodreadData['user_read_at'])) {
175
+		continue;
176
+	}
177
+
178
+	$message = sprintf(
179
+		'Just finished reading %s by %s.',
180
+		$goodreadData['title'],
181
+		$goodreadData['author_name']
182
+	);
183
+	if (isset($goodreadData['book_large_image_url'])) {
184
+		$messageLong = sprintf(
185
+			"<img alt=\"Goodreads | %s\" src=\"%s\" />\n",
186
+			$goodreadData['title'],
187
+			$goodreadData['book_large_image_url']
188
+		);
189
+	}
190
+	$messageLong .= "<p>{$message}</p>";
191
+
192
+	$activityRepository->insertActivity(
193
+		$message,
194
+		$messageLong,
195
+		(new DateTime($goodread['datetime'])),
196
+		[],
197
+		'book',
198
+		$goodread['id']
199
+	);
200 200
 }
201 201
 
202 202
 
Please login to merge, or discard this patch.