1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-30 04:38:21 +02:00

Merge pull request #2675 from lucifer4o/ticket/12786

[ticket/12786] Extend profilefield_base_migration.php class

* lucifer4o/ticket/12786:
  [ticket/12786] Correcting some tabs
  [ticket/12786] Array_merge instead copy array parts
  [ticket/12786] Some changes of the comments.
  [ticket/12786] Dixing a typo
  [ticket/12786] Some minor fixes of comments and function naming
  [ticket/12786] Add clean_cpf_db_entries
  [ticket/12786] White spaces found
  [ticket/12786] Add create_language_entries
  [ticket/12786] Add get_custom_field_id
  [ticket/12786] Extend profilefield_base_migration.php class
This commit is contained in:
Joas Schilling 2014-07-09 17:00:43 +02:00
commit d5fd1ecfc8

View File

@ -21,6 +21,23 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration
protected $profilefield_data;
/**
* Language data should be in array -> each language_data in separate key
* array(
* array(
* 'option_id' => value,
* 'field_type' => value,
* 'lang_value' => value,
* ),
* array(
* 'option_id' => value,
* 'field_type' => value,
* 'lang_value' => value,
* ),
* )
*/
protected $profilefield_language_data;
protected $user_column_name;
public function effectively_installed()
@ -58,6 +75,13 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration
);
}
public function revert_data()
{
return array(
array('custom', array(array($this, 'delete_custom_profile_field_data'))),
);
}
public function create_custom_field()
{
$sql = 'SELECT MAX(field_order) as max_field_order
@ -95,6 +119,69 @@ abstract class profilefield_base_migration extends \phpbb\db\migration\migration
$insert_buffer->flush();
}
/**
* Create Custom profile fields languguage entries
*/
public function create_language_entries()
{
$field_id = $this->get_custom_profile_field_id();
$insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, PROFILE_FIELDS_LANG_TABLE);
$sql = 'SELECT lang_id
FROM ' . LANG_TABLE;
$result = $this->db->sql_query($sql);
while ($lang_id = (int) $this->db->sql_fetchfield('lang_id'))
{
foreach ($this->profilefield_language_data as $language_data)
{
$insert_buffer->insert(array_merge(array(
'field_id' => $field_id,
'lang_id' => $lang_id,
), $language_data));
}
}
$this->db->sql_freeresult($result);
$insert_buffer->flush();
}
/**
* Clean database when reverting the migration
*/
public function delete_custom_profile_field_data()
{
$field_id = $this->get_custom_profile_field_id();
$sql = 'DELETE FROM ' . PROFILE_FIELDS_TABLE . '
WHERE field_id = ' . $field_id;
$this->db->sql_query($sql);
$sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . '
WHERE field_id = ' . $field_id;
$this->db->sql_query($sql);
$sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . '
WHERE field_id = ' . $field_id;
$this->db->sql_query($sql);
}
/**
* Get custom profile field id
* @return int custom profile filed id
*/
public function get_custom_profile_field_id()
{
$sql = 'SELECT field_id
FROM ' . PROFILE_FIELDS_TABLE . "
WHERE field_name = '" . $this->profilefield_name . "'";
$result = $this->db->sql_query($sql);
$field_id = (int) $this->db->sql_fetchfield('field_id');
$this->db->sql_freeresult($result);
return $field_id;
}
/**
* @param int $start Start of staggering step
* @return mixed int start of the next step, null if the end was reached