Skip to content

Commit

Permalink
Add PunBB support 2 (add pun_pm)
Browse files Browse the repository at this point in the history
  • Loading branch information
MioVisman committed Sep 11, 2023
1 parent d4eaeaa commit be1cfb9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 110 deletions.
10 changes: 10 additions & 0 deletions app/Models/Transformer/Driver/AbstractDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,16 @@ public function pm_topics_againEnd(DB $db): bool
/*************************************************************************/
/* pm_block */
/*************************************************************************/
public function pm_blockPre(DB $db, int $id): ?bool
{
return null;
}

public function pm_blockGet(int &$id): ?array
{
return null;
}

public function pm_blockSet(DB $db, array $vars): bool
{
return false !== $db->exec($this->insertQuery, $vars);
Expand Down
1 change: 0 additions & 1 deletion app/Models/Transformer/Driver/FluxBB/FluxBB.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,6 @@ public function postsGet(int &$id): ?array
public function warningsPre(DB $db, int $id): ?bool
{
return null;

}

public function warningsGet(int &$id): ?array
Expand Down
145 changes: 36 additions & 109 deletions app/Models/Transformer/Driver/PunBB/PunBB.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,6 @@ public function postsGet(int &$id): ?array
public function warningsPre(DB $db, int $id): ?bool
{
return null;

}

public function warningsGet(int &$id): ?array
Expand Down Expand Up @@ -1030,7 +1029,7 @@ public function pm_topicsPre(DB $db, int $id): ?bool
{
$tables = $db->getMap();

if (empty($tables['pms_new_topics'])) {
if (empty($tables['pun_pm_messages'])) {
return null;
}

Expand All @@ -1046,7 +1045,7 @@ public function pm_topicsPre(DB $db, int $id): ?bool
':limit' => $this->c->LIMIT,
];
$query = 'SELECT *
FROM ::pms_new_topics
FROM ::pun_pm_messages
WHERE id>=?i:id
ORDER BY id
LIMIT ?i:limit';
Expand All @@ -1056,21 +1055,6 @@ public function pm_topicsPre(DB $db, int $id): ?bool
return false !== $this->stmt;
}

protected function pmStatus(int $status, int $visit): int
{
switch ($status) {
case 0:
case 1:
$status = 2;

break;
case 2:
$status = empty($visit) ? 1 : 0;
}

return $status;
}

public function pm_topicsGet(int &$id): ?array
{
$vars = $this->stmt->fetch();
Expand All @@ -1086,20 +1070,32 @@ public function pm_topicsGet(int &$id): ?array

return [
'id_old' => $id,
'subject' => (string) $vars['topic'],
'poster' => (string) $vars['starter'],
'poster_id' => (int) $vars['starter_id'],
'poster_status' => $this->pmStatus((int) $vars['topic_st'], (int) $vars['see_st']),
'poster_visit' => (int) $vars['see_st'],
'target' => (string) $vars['to_user'],
'target_id' => (int) $vars['to_id'],
'target_status' => $this->pmStatus((int) $vars['topic_to'], (int) $vars['see_to']),
'target_visit' => (int) $vars['see_to'],
'num_replies' => (int) $vars['replies'],
'subject' => (string) $vars['subject'],
'poster' => '???',
'poster_id' => (int) $vars['sender_id'],
'poster_status' => ! empty((int) $vars['deleted_by_sender'])
? 0
: (
'draft' === $vars['status']
? 3
: 2
),
'poster_visit' => (int) $vars['lastedited_at'],
'target' => '???',
'target_id' => (int) $vars['receiver_id'],
'target_status' => ! empty((int) $vars['deleted_by_receiver'])
? 0
: (
'draft' === $vars['status']
? 1
: 2
),
'target_visit' => (int) $vars['read_at'],
'num_replies' => 0,
'first_post_id' => 0,
'last_post' => (int) $vars['last_posted'],
'last_post' => (int) $vars['lastedited_at'],
'last_post_id' => 0,
'last_number' => (int) $vars['last_poster'],
'last_number' => 0,
];
}

Expand All @@ -1110,7 +1106,7 @@ public function pm_postsPre(DB $db, int $id): ?bool
{
$tables = $db->getMap();

if (empty($tables['pms_new_posts'])) {
if (empty($tables['pun_pm_messages'])) {
return null;
}

Expand All @@ -1126,7 +1122,7 @@ public function pm_postsPre(DB $db, int $id): ?bool
':limit' => $this->c->LIMIT,
];
$query = 'SELECT *
FROM ::pms_new_posts
FROM ::pun_pm_messages
WHERE id>=?i:id
ORDER BY id
LIMIT ?i:limit';
Expand All @@ -1151,14 +1147,14 @@ public function pm_postsGet(int &$id): ?array

return [
'id_old' => $id,
'poster' => (string) $vars['poster'],
'poster_id' => (int) $vars['poster_id'],
'poster_ip' => (string) $vars['poster_ip'],
'message' => (string) $vars['message'],
'hide_smilies' => (int) $vars['hide_smilies'],
'posted' => (int) $vars['posted'],
'edited' => (int) $vars['edited'],
'topic_id' => (int) $vars['topic_id'],
'poster' => '???',
'poster_id' => (int) $vars['sender_id'],
'poster_ip' => '0.0.0.0',
'message' => (string) $vars['body'],
'hide_smilies' => 0,
'posted' => (int) $vars['lastedited_at'],
'edited' => 0,
'topic_id' => $id,
];
}

Expand All @@ -1169,75 +1165,6 @@ public function pm_postsGet(int &$id): ?array
/*************************************************************************/
/* pm_block */
/*************************************************************************/
public function pm_blockPre(DB $db, int $id): ?bool
{
$tables = $db->getMap();

if (empty($tables['pms_new_block'])) {
return null;
}

$vars = [
':id' => $id,
':limit' => $this->c->LIMIT,
];
$query = 'SELECT bl_id
FROM ::pms_new_block
WHERE bl_id>=?i:id
ORDER BY bl_id
LIMIT ?i:limit';

$ids = $db->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN);

if (empty($ids)) {
$max = $id;
} else {
$max = \array_pop($ids);
}

$this->insertQuery = 'INSERT INTO ::pm_block (bl_first_id, bl_second_id)
SELECT (
SELECT id
FROM ::users
WHERE id_old=?i:bl_first_id
), (
SELECT id
FROM ::users
WHERE id_old=?i:bl_second_id
)';

$vars = [
':id' => $id,
':max' => $max,
];
$query = 'SELECT *
FROM ::pms_new_block
WHERE bl_id>=?i:id AND bl_id<=?i:max
ORDER BY bl_id';

$this->stmt = $db->query($query, $vars);

return false !== $this->stmt;
}

public function pm_blockGet(int &$id): ?array
{
$vars = $this->stmt->fetch();

if (false === $vars) {
$this->stmt->closeCursor();
$this->stmt = null;

return null;
}

$id = (int) $vars['bl_id'];

return [
'bl_first_id' => (int) $vars['bl_id'],
'bl_second_id' => (int) $vars['bl_user_id'],
];
}

/*************************************************************************/
/* bans */
Expand Down

0 comments on commit be1cfb9

Please sign in to comment.