Skip to content

Commit 2a7c1af

Browse files
authored
Merge pull request #105 from VSEphpbb/ideas-bot
Remove the Ideas Bot
2 parents d329140 + 363501c commit 2a7c1af

17 files changed

Lines changed: 148 additions & 123 deletions

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# Opt into fully virtualized infrastructure
2-
sudo: required
3-
dist: precise
4-
51
language: php
2+
sudo: required
63

74
matrix:
85
include:

adm/style/acp_phpbb_ideas.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ <h3>{{ lang('WARNING') }}</h3>
2020
<dt><label for="ideas_forum_id">{{ lang('ACP_IDEAS_FORUM_ID') ~ lang('COLON') }}</label><br /><span>{{ lang('ACP_IDEAS_FORUM_ID_EXPLAIN') }}</span></dt>
2121
<dd>{{ S_FORUM_SELECT_BOX }}</dd>
2222
</dl>
23-
<dl>
24-
<dt><label for="ideas_poster_id">{{ lang('ACP_IDEAS_POSTER_ID') ~ lang('COLON') }}</label><br /><span>{{ lang('ACP_IDEAS_POSTER_ID_EXPLAIN') }}</span></dt>
25-
<dd><input id="ideas_poster_id" type="text" size="45" maxlength="255" name="config[ideas_poster_id]" value="{{ IDEAS_POSTER }}" /></dd>
26-
<dd>[ <a href="{{ U_FIND_USERNAME }}" onclick="find_username(this.href); return false;">{{ lang('FIND_USERNAME') }}</a> ]</dd>
27-
</dl>
2823
<dl>
2924
<dt><label for="ideas_base_url">{{ lang('ACP_IDEAS_BASE_URL') ~ lang('COLON') }}</label><br /><span>{{ lang('ACP_IDEAS_BASE_URL_EXPLAIN') }}</span></dt>
3025
<dd><input id="ideas_base_url" type="text" size="45" maxlength="255" name="config[ideas_base_url]" value="{{ IDEAS_BASE_URL }}" /></dd>

controller/admin_controller.php

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,12 @@ public function __construct(\phpbb\config\config $config, \phpbb\db\driver\drive
8484
public function display_options()
8585
{
8686
$this->template->assign_vars(array(
87-
'IDEAS_POSTER' => $this->get_ideas_topics_poster_username(),
8887
'IDEAS_BASE_URL' => $this->config['ideas_base_url'] ?: '',
8988

9089
'S_FORUM_SELECT_BOX' => $this->select_ideas_forum(),
9190
'S_IDEAS_FORUM_ID' => !empty($this->config['ideas_forum_id']),
9291

9392
'U_ACTION' => $this->u_action,
94-
'U_FIND_USERNAME' => append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=searchuser&amp;form=acp_phpbb_ideas_settings&amp;field=ideas_poster_id&amp;select_single=true'),
9593
));
9694
}
9795

@@ -116,15 +114,8 @@ public function set_config_options()
116114
$errors[] = $this->language->lang('FORM_INVALID');
117115
}
118116

119-
// Check if selected user exists
120-
$user_id = $this->get_ideas_topics_poster_id();
121-
if (!$user_id)
122-
{
123-
$errors[] = $this->language->lang('NO_USER');
124-
}
125-
126117
// Don't save settings if errors have occurred
127-
if (sizeof($errors))
118+
if (count($errors))
128119
{
129120
$submit = false;
130121

@@ -136,13 +127,9 @@ public function set_config_options()
136127

137128
if ($submit)
138129
{
139-
// If selected user does exist, reassign the config value to its ID
140-
$this->cfg_array['ideas_poster_id'] = $user_id;
141-
142130
// Configuration options to list through
143131
$display_vars = array(
144132
'ideas_forum_id',
145-
'ideas_poster_id',
146133
'ideas_base_url',
147134
'ideas_forum_setup',
148135
);
@@ -225,40 +212,6 @@ public function set_ideas_forum_options()
225212
}
226213
}
227214

228-
/**
229-
* Get Ideas poster bot user ID
230-
*
231-
* @return int user_id Ideas bot user ID
232-
* @access protected
233-
*/
234-
protected function get_ideas_topics_poster_id()
235-
{
236-
$sql = 'SELECT user_id
237-
FROM ' . USERS_TABLE . "
238-
WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($this->cfg_array['ideas_poster_id'])) . "'";
239-
$result = $this->db->sql_query($sql);
240-
$user_id = (int) $this->db->sql_fetchfield('user_id');
241-
$this->db->sql_freeresult($result);
242-
243-
return $user_id;
244-
}
245-
246-
/**
247-
* Get Ideas poster bot username
248-
*
249-
* @return string Ideas bot username
250-
* @access protected
251-
*/
252-
protected function get_ideas_topics_poster_username()
253-
{
254-
$sql = 'SELECT username FROM ' . USERS_TABLE . '
255-
WHERE user_id = ' . (int) $this->config['ideas_poster_id'];
256-
$this->db->sql_query($sql);
257-
$username = $this->db->sql_fetchfield('username');
258-
259-
return ($username !== false) ? $username : '';
260-
}
261-
262215
/**
263216
* Generate ideas forum select options
264217
*

controller/base.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ public function __construct(auth $auth, config $config, helper $helper, ideas $i
9393

9494
/**
9595
* Check if Ideas is properly configured after installation
96-
* Ideas is available only after forum and poster settings have been set in ACP
96+
* Ideas is available only after forum settings have been set in ACP
9797
*
9898
* @return bool Depending on whether or not the extension is properly configured
9999
*/
100100
public function is_available()
101101
{
102-
return (bool) $this->config['ideas_forum_id'] && (bool) $this->config['ideas_poster_id'];
102+
return (bool) $this->config['ideas_forum_id'];
103103
}
104104

105105
/**

event/listener.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,8 @@ public function show_post_buttons($event)
151151

152152
if ($event['topic_data']['topic_first_post_id'] == $event['row']['post_id'])
153153
{
154-
$post_row = $event['post_row'];
155-
156-
$post_row['U_DELETE'] = false;
157-
$post_row['U_QUOTE'] = false;
158-
$post_row['U_WARN'] = false;
159-
160-
$event['post_row'] = $post_row;
154+
$event->update_subarray('post_row', 'U_DELETE', false);
155+
$event->update_subarray('post_row', 'U_WARN', false);
161156
}
162157
}
163158

factory/ideas.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ public function submit($title, $message, $user_id)
631631
'forum_id' => (int) $this->config['ideas_forum_id'],
632632
'topic_id' => 0,
633633
'icon_id' => false,
634-
'poster_id' => (int) $this->config['ideas_poster_id'],
634+
'poster_id' => (int) $this->user->data['user_id'],
635635

636636
'enable_bbcode' => true,
637637
'enable_smilies' => true,
@@ -657,24 +657,9 @@ public function submit($title, $message, $user_id)
657657
'force_approved_state' => (!$this->auth->acl_get('f_noapprove', $this->config['ideas_forum_id'])) ? ITEM_UNAPPROVED : true,
658658
);
659659

660-
// Get Ideas Bot info
661-
$sql = 'SELECT *
662-
FROM ' . USERS_TABLE . '
663-
WHERE user_id = ' . (int) $this->config['ideas_poster_id'];
664-
$result = $this->db->sql_query_limit($sql, 1);
665-
$poster_bot = $this->db->sql_fetchrow($result);
666-
$this->db->sql_freeresult($result);
667-
668-
$poster_bot['is_registered'] = true;
669-
670-
$tmpdata = $this->user->data;
671-
$this->user->data = $poster_bot;
672-
673660
$poll = array();
674661
submit_post('post', $title, $this->user->data['username'], POST_NORMAL, $poll, $data);
675662

676-
$this->user->data = $tmpdata;
677-
678663
// Edit topic ID into idea; both should link to each other
679664
$sql_ary = array(
680665
'topic_id' => $data['topic_id'],

language/en/phpbb_ideas_acp.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
'ACP_IDEAS_FORUM_SETUP_EXPLAIN' => 'Sets up the Ideas forum. Users will not be able to start new topics. Additionally, auto-pruning will be disabled. Note: you have to set the Ideas forum first.',
2828
'ACP_IDEAS_FORUM_SETUP_UPDATED' => 'phpBB Ideas forum settings successfully updated.',
2929
'ACP_IDEAS_NO_FORUM' => 'No forum selected',
30-
'ACP_IDEAS_POSTER_ID' => 'Ideas user bot',
31-
'ACP_IDEAS_POSTER_ID_EXPLAIN' => 'Enter a username for the Idea-bot that will post Ideas topics into the forum.',
3230
'ACP_IDEAS_SETTINGS_UPDATED' => 'phpBB Ideas settings updated.',
3331
'ACP_IDEAS_UTILITIES' => 'Ideas utilities',
3432
'ACP_IDEAS_BASE_URL' => 'Ideas base URL (optional)',

migrations/m9_remove_idea_bot.php

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
*
4+
* Ideas extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\ideas\migrations;
12+
13+
class m9_remove_idea_bot extends \phpbb\db\migration\migration
14+
{
15+
public function effectively_installed()
16+
{
17+
return !$this->config->offsetExists('ideas_poster_id');
18+
}
19+
20+
static public function depends_on()
21+
{
22+
return [
23+
'\phpbb\ideas\migrations\m1_initial_schema',
24+
'\phpbb\ideas\migrations\m3_acp_data',
25+
'\phpbb\ideas\migrations\m4_update_statuses',
26+
'\phpbb\ideas\migrations\m6_migrate_old_tables',
27+
'\phpbb\ideas\migrations\m7_drop_old_tables',
28+
];
29+
}
30+
31+
public function update_data()
32+
{
33+
return [
34+
['custom', [[$this, 'update_topic_authors']]],
35+
['config.remove', ['ideas_poster_id']],
36+
];
37+
}
38+
39+
/**
40+
* Replace the Ideas Bot stored in the posts and topics tables with the
41+
* original author's information. Bot gone, order restored to universe.
42+
*/
43+
public function update_topic_authors()
44+
{
45+
// Return if the Ideas Bot does not exist at this point for some reason.
46+
if (!$this->config->offsetExists('ideas_poster_id'))
47+
{
48+
return;
49+
}
50+
51+
// Get real author info for ideas that were posted by the Ideas Bot
52+
$topics = [];
53+
$sql_array = [
54+
'SELECT' => 'i.topic_id, i.idea_author, u.username, u.user_colour, t.topic_first_post_id',
55+
'FROM' => [
56+
$this->table_prefix . 'ideas_ideas' => 'i',
57+
],
58+
'LEFT_JOIN' => [
59+
[
60+
'FROM' => [$this->table_prefix . 'topics' => 't'],
61+
'ON' => 't.topic_id = i.topic_id',
62+
],
63+
[
64+
'FROM' => [$this->table_prefix . 'users' => 'u'],
65+
'ON' => 'u.user_id = i.idea_author',
66+
],
67+
],
68+
'WHERE' => 't.topic_poster = ' . (int) $this->config->offsetGet('ideas_poster_id'),
69+
];
70+
71+
$sql = $this->db->sql_build_query('SELECT', $sql_array);
72+
$result = $this->db->sql_query($sql);
73+
while ($row = $this->db->sql_fetchrow($result))
74+
{
75+
$topics[$row['topic_id']] = [
76+
'topic_poster_id' => $row['idea_author'] ?: ANONYMOUS,
77+
'topic_poster_name' => $row['username'] ?: '',
78+
'topic_poster_colour' => $row['user_colour'] ?: '',
79+
'topic_first_post_id' => $row['topic_first_post_id'] ?: 0,
80+
];
81+
}
82+
$this->db->sql_freeresult($result);
83+
84+
// Begin updating topics and posts
85+
$this->db->sql_transaction('begin');
86+
foreach ($topics as $topic_id => $data)
87+
{
88+
// Update topic author (first poster)
89+
$sql = 'UPDATE ' . $this->table_prefix . 'topics
90+
SET ' . $this->db->sql_build_array('UPDATE', [
91+
'topic_poster' => $data['topic_poster_id'],
92+
'topic_first_poster_name' => $data['topic_poster_name'],
93+
'topic_first_poster_colour' => $data['topic_poster_colour'],
94+
]) . '
95+
WHERE topic_id = ' . (int) $topic_id;
96+
$this->db->sql_query($sql);
97+
98+
// Update last poster if it's also the Ideas Bot (i.e: no replies)
99+
$sql = 'UPDATE ' . $this->table_prefix . 'topics
100+
SET ' . $this->db->sql_build_array('UPDATE', [
101+
'topic_last_poster_id' => $data['topic_poster_id'],
102+
'topic_last_poster_name' => $data['topic_poster_name'],
103+
'topic_last_poster_colour' => $data['topic_poster_colour'],
104+
]) . '
105+
WHERE topic_id = ' . (int) $topic_id . '
106+
AND topic_last_poster_id = ' . (int) $this->config->offsetGet('ideas_poster_id');
107+
$this->db->sql_query($sql);
108+
109+
// Update first post's poster id if it's the Ideas Bot
110+
$sql = 'UPDATE ' . $this->table_prefix . 'posts' . '
111+
SET poster_id = ' . (int) $data['topic_poster_id'] . '
112+
WHERE post_id = ' . (int) $data['topic_first_post_id'] . '
113+
AND poster_id = ' . (int) $this->config->offsetGet('ideas_poster_id');
114+
$this->db->sql_query($sql);
115+
}
116+
$this->db->sql_transaction('commit');
117+
}
118+
}

styles/prosilver/template/idea_body.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
{% if IDEA_DUPLICATE or S_IS_MOD %}
7878
<dt class="duplicatetoggle idealabel"{% if IDEA_STATUS_ID != STATUS_ARY.DUPLICATE %} style="display:none"{% endif %}>{{ lang('DUPLICATE') ~ lang('COLON') }}</dt>
7979
<dd class="duplicatetoggle" {% if IDEA_STATUS_ID != STATUS_ARY.DUPLICATE %}style="display:none"{% endif %}>
80-
<a id="duplicatelink" class="ideamodbtn" data-link="{{ U_IDEA_DUPLICATE }}" data-l-msg="{{ lang('IDEA_NUM') }}" {% if IDEA_DUPLICATE %}href="{{ U_IDEA_DUPLICATE }}">{{ lang('IDEA_NUM') }}{{ IDEA_DUPLICATE }}{% else %}style="display:none">{% endif %}</a>
80+
<a id="duplicatelink" class="ideamodbtn" data-link="{{ U_IDEA_DUPLICATE }}" data-l-msg="{{ lang('IDEA_NUM') }}" {% if IDEA_DUPLICATE %}href="{{ U_IDEA_DUPLICATE }}">{{ lang('IDEA_NUM') ~ IDEA_DUPLICATE }}{% else %}style="display:none">{% endif %}</a>
8181
{% if S_IS_MOD %}
8282
<a href="{{ U_EDIT_DUPLICATE }}" id="duplicateedit" data-l-add="{{ lang('ADD') }}" data-l-edit="{{ lang('EDIT') }}">{% if IDEA_DUPLICATE %}<i class="fa fa-fw fa-pencil"></i>{{ lang('EDIT') }}{% else %}<i class="fa fa-fw fa-plus-circle"></i>{{ lang('ADD') }}{% endif %}</a>
8383
<input type="text" id="duplicateeditinput" class="ideainput"{% if IDEA_DUPLICATE %} value="{{ IDEA_DUPLICATE }}"{% endif %} placeholder="###" data-l-err="{{ lang('ERROR') }}" data-l-msg="{{ lang('TICKET_ERROR_DUP') }}" />

tests/controller/controller_base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function setUp()
6060
$this->auth = $this->getMockBuilder('\phpbb\auth\auth')
6161
->disableOriginalConstructor()
6262
->getMock();
63-
$this->config = new \phpbb\config\config(array('ideas_forum_id' => 2, 'ideas_poster_id' => 2));
63+
$this->config = new \phpbb\config\config(array('ideas_forum_id' => 2));
6464
$this->controller_helper = $this->getMockBuilder('\phpbb\controller\helper')
6565
->disableOriginalConstructor()
6666
->getMock();

0 commit comments

Comments
 (0)