Skip to content

Commit 96b0599

Browse files
committed
IMP: Move blog-table to blog-addon, make client public, and add readibility
1 parent 4f61ccc commit 96b0599

3 files changed

Lines changed: 13 additions & 33 deletions

File tree

Model/HttpClient/Wordpress.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Wordpress
1616
/**
1717
* @var \Symfony\Contracts\HttpClient\HttpClientInterface
1818
*/
19-
private $client;
19+
public $client;
2020

2121
/**
2222
* @var LoggerInterface
@@ -49,7 +49,7 @@ public function setBaseUrl(string $baseUrl)
4949
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
5050
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
5151
*/
52-
public function all(int $pageSize = 10): \Generator
52+
public function all(int $pageSize = 10, array $filters = []): \Generator
5353
{
5454
$peekHeaders = $this->peek($pageSize);
5555

@@ -64,14 +64,18 @@ public function all(int $pageSize = 10): \Generator
6464
while ($pageCount < $totalPages) {
6565
$response = $this->client->request(
6666
'GET',
67-
static::WP_JSON_URL_PREFIX . static::WP_JSON_URL_SUFFIX . '?' . http_build_query([
68-
'page' => $pageNumber++,
69-
'per_page' => $pageSize
70-
])
67+
static::WP_JSON_URL_PREFIX .
68+
static::WP_JSON_URL_SUFFIX .
69+
'?' .
70+
http_build_query(
71+
array_merge([
72+
'page' => $pageNumber++,
73+
'per_page' => $pageSize
74+
], $filters)
75+
)
7176
);
7277

7378
foreach (json_decode($response->getContent(), true) as $page) {
74-
$page['modified_date_formatted'] = date('j M y', strtotime($page['modified']));
7579
yield $page;
7680
$pageCount++;
7781
}
@@ -100,7 +104,7 @@ public function postMetaDataToPage(int $pageId, string $key, string $value, stri
100104
try {
101105
$response = $this->client->request(
102106
'POST',
103-
static::WP_JSON_URL_PREFIX . static::WP_JSON_URL_SUFFIX . '/' . $pageId . '?'. $key .'=' . $value,
107+
static::WP_JSON_URL_PREFIX . static::WP_JSON_URL_SUFFIX . '/' . $pageId . '?' . $key . '=' . $value,
104108

105109
[
106110
'auth_basic' => $authentication

Model/RemotePageRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function getList(): array
7575
$pages[$site->getSiteId()]['id'] = $site->getSiteId();
7676

7777
foreach ($this->pageClient->all($pageSize) as $page) {
78+
$page['modified_date_formatted'] = date('j M y', strtotime($page['modified']));
7879
$pages[$site->getSiteId()]['data'][] = $page;
7980
}
8081
} catch (ExceptionInterface $exception) {

etc/db_schema.xml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,6 @@
22
<schema
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
5-
<table name="mooore_wordpressintegration_wordpress_post" resource="default" engine="innodb" comment="WordpressPost">
6-
<column xsi:type="int" name="wordpress_post_id" padding="10" unsigned="true" nullable="false" identity="true"
7-
comment="Wordpress Post Id"/>
8-
<column xsi:type="int" name="site_id" padding="10" unsigned="true" nullable="false"
9-
comment="Wordpress Site Id"/>
10-
<column xsi:type="int" name="post_id" padding="10" unsigned="true" nullable="false"
11-
comment="Wordpress Page Id"/>
12-
<column xsi:type="varchar" name="slug" nullable="false" length="255"
13-
comment="Wordpress Slug"/>
14-
<column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP"
15-
comment="Update Time"/>
16-
<column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP"
17-
comment="Creation Time"/>
18-
19-
<constraint xsi:type="primary" referenceId="PRIMARY">
20-
<column name="wordpress_post_id"/>
21-
</constraint>
22-
<constraint xsi:type="unique" referenceId="SITE_POST_IDS">
23-
<column name="site_id"/>
24-
<column name="post_id"/>
25-
</constraint>
26-
<index referenceId="WORDPRESS_POST_WORDPRESS_POST_ID" indexType="btree">
27-
<column name="wordpress_post_id"/>
28-
</index>
29-
</table>
305
<table name="cms_page">
316
<column
327
name="wordpress_page_id"

0 commit comments

Comments
 (0)