Merge pull request #4010 from Elsensee/ticket/14264

[ticket/14264] Don't use constants as return values
This commit is contained in:
Máté Bartus 2015-11-05 21:43:00 +01:00
commit 402f36e42d
17 changed files with 31 additions and 75 deletions

View file

@ -17,6 +17,7 @@ services:
class: phpbb\textreparser\plugins\forum_description class: phpbb\textreparser\plugins\forum_description
arguments: arguments:
- @dbal.conn - @dbal.conn
- %tables.forums%
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -24,6 +25,7 @@ services:
class: phpbb\textreparser\plugins\forum_rules class: phpbb\textreparser\plugins\forum_rules
arguments: arguments:
- @dbal.conn - @dbal.conn
- %tables.forums%
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -31,6 +33,7 @@ services:
class: phpbb\textreparser\plugins\group_description class: phpbb\textreparser\plugins\group_description
arguments: arguments:
- @dbal.conn - @dbal.conn
- %tables.groups%
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -38,6 +41,7 @@ services:
class: phpbb\textreparser\plugins\pm_text class: phpbb\textreparser\plugins\pm_text
arguments: arguments:
- @dbal.conn - @dbal.conn
- %tables.privmsgs%
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -52,6 +56,7 @@ services:
class: phpbb\textreparser\plugins\poll_title class: phpbb\textreparser\plugins\poll_title
arguments: arguments:
- @dbal.conn - @dbal.conn
- %tables.topics%
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -59,6 +64,7 @@ services:
class: phpbb\textreparser\plugins\post_text class: phpbb\textreparser\plugins\post_text
arguments: arguments:
- @dbal.conn - @dbal.conn
- %tables.posts%
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }
@ -66,5 +72,6 @@ services:
class: phpbb\textreparser\plugins\user_signature class: phpbb\textreparser\plugins\user_signature
arguments: arguments:
- @dbal.conn - @dbal.conn
- %tables.users%
tags: tags:
- { name: text_reparser.plugin } - { name: text_reparser.plugin }

View file

@ -27,12 +27,4 @@ class forum_description extends \phpbb\textreparser\row_based_plugin
'options' => 'forum_desc_options', 'options' => 'forum_desc_options',
); );
} }
/**
* {@inheritdoc}
*/
public function get_table_name()
{
return FORUMS_TABLE;
}
} }

View file

@ -27,12 +27,4 @@ class forum_rules extends \phpbb\textreparser\row_based_plugin
'options' => 'forum_rules_options', 'options' => 'forum_rules_options',
); );
} }
/**
* {@inheritdoc}
*/
public function get_table_name()
{
return FORUMS_TABLE;
}
} }

View file

@ -27,12 +27,4 @@ class group_description extends \phpbb\textreparser\row_based_plugin
'options' => 'group_desc_options', 'options' => 'group_desc_options',
); );
} }
/**
* {@inheritdoc}
*/
public function get_table_name()
{
return GROUPS_TABLE;
}
} }

View file

@ -29,12 +29,4 @@ class pm_text extends \phpbb\textreparser\row_based_plugin
'bbcode_uid' => 'bbcode_uid', 'bbcode_uid' => 'bbcode_uid',
); );
} }
/**
* {@inheritdoc}
*/
public function get_table_name()
{
return PRIVMSGS_TABLE;
}
} }

View file

@ -39,12 +39,4 @@ class poll_title extends \phpbb\textreparser\row_based_plugin
return $sql; return $sql;
} }
/**
* {@inheritdoc}
*/
public function get_table_name()
{
return TOPICS_TABLE;
}
} }

View file

@ -29,12 +29,4 @@ class post_text extends \phpbb\textreparser\row_based_plugin
'bbcode_uid' => 'bbcode_uid', 'bbcode_uid' => 'bbcode_uid',
); );
} }
/**
* {@inheritdoc}
*/
public function get_table_name()
{
return POSTS_TABLE;
}
} }

View file

@ -54,14 +54,6 @@ class user_signature extends \phpbb\textreparser\row_based_plugin
); );
} }
/**
* {@inheritdoc}
*/
public function get_table_name()
{
return USERS_TABLE;
}
/** /**
* Save the keyoptions var from \phpbb\user * Save the keyoptions var from \phpbb\user
*/ */

View file

@ -20,14 +20,21 @@ abstract class row_based_plugin extends base
*/ */
protected $db; protected $db;
/**
* @var string
*/
protected $table;
/** /**
* Constructor * Constructor
* *
* @param \phpbb\db\driver\driver_interface $db Database connection * @param \phpbb\db\driver\driver_interface $db Database connection
* @param string $table
*/ */
public function __construct(\phpbb\db\driver\driver_interface $db) public function __construct(\phpbb\db\driver\driver_interface $db, $table)
{ {
$this->db = $db; $this->db = $db;
$this->table = $table;
} }
/** /**
@ -37,13 +44,6 @@ abstract class row_based_plugin extends base
*/ */
abstract public function get_columns(); abstract public function get_columns();
/**
* Return the name of the table used by this plugin
*
* @return string
*/
abstract public function get_table_name();
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -51,7 +51,7 @@ abstract class row_based_plugin extends base
{ {
$columns = $this->get_columns(); $columns = $this->get_columns();
$sql = 'SELECT MAX(' . $columns['id'] . ') AS max_id FROM ' . $this->get_table_name(); $sql = 'SELECT MAX(' . $columns['id'] . ') AS max_id FROM ' . $this->table;
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
$max_id = (int) $this->db->sql_fetchfield('max_id'); $max_id = (int) $this->db->sql_fetchfield('max_id');
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
@ -96,7 +96,7 @@ abstract class row_based_plugin extends base
} }
$sql = 'SELECT ' . implode(', ', $fields) . ' $sql = 'SELECT ' . implode(', ', $fields) . '
FROM ' . $this->get_table_name() . ' FROM ' . $this->table . '
WHERE ' . $columns['id'] . ' BETWEEN ' . $min_id . ' AND ' . $max_id; WHERE ' . $columns['id'] . ' BETWEEN ' . $min_id . ' AND ' . $max_id;
return $sql; return $sql;
@ -109,7 +109,7 @@ abstract class row_based_plugin extends base
{ {
$columns = $this->get_columns(); $columns = $this->get_columns();
$sql = 'UPDATE ' . $this->get_table_name() . ' $sql = 'UPDATE ' . $this->table . '
SET ' . $columns['text'] . " = '" . $this->db->sql_escape($record['text']) . "' SET ' . $columns['text'] . " = '" . $this->db->sql_escape($record['text']) . "'
WHERE " . $columns['id'] . ' = ' . $record['id']; WHERE " . $columns['id'] . ' = ' . $record['id'];
$this->db->sql_query($sql); $this->db->sql_query($sql);

View file

@ -21,6 +21,6 @@ class phpbb_textreparser_forum_description_test extends phpbb_textreparser_test_
protected function get_reparser() protected function get_reparser()
{ {
return new \phpbb\textreparser\plugins\forum_description($this->db); return new \phpbb\textreparser\plugins\forum_description($this->db, FORUMS_TABLE);
} }
} }

View file

@ -21,6 +21,6 @@ class phpbb_textreparser_forum_rules_test extends phpbb_textreparser_test_row_ba
protected function get_reparser() protected function get_reparser()
{ {
return new \phpbb\textreparser\plugins\forum_rules($this->db); return new \phpbb\textreparser\plugins\forum_rules($this->db, FORUMS_TABLE);
} }
} }

View file

@ -21,6 +21,6 @@ class phpbb_textreparser_group_description_test extends phpbb_textreparser_test_
protected function get_reparser() protected function get_reparser()
{ {
return new \phpbb\textreparser\plugins\group_description($this->db); return new \phpbb\textreparser\plugins\group_description($this->db, GROUPS_TABLE);
} }
} }

View file

@ -21,6 +21,6 @@ class phpbb_textreparser_pm_text_test extends phpbb_textreparser_test_row_based_
protected function get_reparser() protected function get_reparser()
{ {
return new \phpbb\textreparser\plugins\pm_text($this->db); return new \phpbb\textreparser\plugins\pm_text($this->db, PRIVMSGS_TABLE);
} }
} }

View file

@ -21,6 +21,6 @@ class phpbb_textreparser_poll_title_test extends phpbb_textreparser_test_row_bas
protected function get_reparser() protected function get_reparser()
{ {
return new \phpbb\textreparser\plugins\poll_title($this->db); return new \phpbb\textreparser\plugins\poll_title($this->db, TOPICS_TABLE);
} }
} }

View file

@ -21,6 +21,6 @@ class phpbb_textreparser_post_text_test extends phpbb_textreparser_test_row_base
protected function get_reparser() protected function get_reparser()
{ {
return new \phpbb\textreparser\plugins\post_text($this->db); return new \phpbb\textreparser\plugins\post_text($this->db, POSTS_TABLE);
} }
} }

View file

@ -24,8 +24,13 @@ abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_t
{ {
$reparser = $this->get_reparser(); $reparser = $this->get_reparser();
$columns = $reparser->get_columns(); $columns = $reparser->get_columns();
$reflection_reparser = new ReflectionClass(get_class($reparser));
$table_property = $reflection_reparser->getProperty('table');
$table_property->setAccessible(true);
$sql = 'SELECT ' . $columns['id'] . ' AS id, ' . $columns['text'] . ' AS text $sql = 'SELECT ' . $columns['id'] . ' AS id, ' . $columns['text'] . ' AS text
FROM ' . $reparser->get_table_name() . ' FROM ' . $table_property->getValue($reparser) . '
WHERE ' . $this->db->sql_in_set($columns['id'], $ids) . ' WHERE ' . $this->db->sql_in_set($columns['id'], $ids) . '
ORDER BY id'; ORDER BY id';
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);

View file

@ -21,6 +21,6 @@ class phpbb_textreparser_user_signature_test extends phpbb_textreparser_test_row
protected function get_reparser() protected function get_reparser()
{ {
return new \phpbb\textreparser\plugins\user_signature($this->db); return new \phpbb\textreparser\plugins\user_signature($this->db, USERS_TABLE);
} }
} }