set_config()
request_var()
$config->set()
$request->variable()
isset($_POST['submit'])
with $request->is_set_post('submit')
Code: Select all
class acp_foobar_module
{
public $u_action;
protected $config;
protected $request;
public function main($id, $mode)
{
global $config, $request;
$this->config = $config;
$this->request = $request;
$form_key = 'acp_foobar';
add_form_key($form_key);
if ($this->request->is_set_post('submit'))
{
if (!check_form_key($form_key))
{
trigger_error('FORM_INVALID');
}
$foobar_option = $this->request->variable('foobar_option', 0);
$this->config->set('foobar_option', $foobar_option);
trigger_error($this->user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
}
}
}
This is no longer necessary in my opinion, since it in ACP at build # 1045 gives thebut with a little htaccess rule this can be rewritten to phpBB/newspage
Enable URL rewriting
module. When activated, it gives the url phpBB/newspage.Note, when you don't have the rule in your htaccess the acp option will only send you to 404 pageswintstar wrote:This is no longer necessary in my opinion, since it in ACP at build # 1045 gives thebut with a little htaccess rule this can be rewritten to phpBB/newspage
Enable URL rewriting
module. When activated, it gives the url phpBB/newspage.
Thanks for Infonickvergessen wrote:Note, when you don't have the rule in your htaccess the acp option will only send you to 404 pageswintstar wrote:This is no longer necessary in my opinion, since it in ACP at build # 1045 gives thebut with a little htaccess rule this can be rewritten to phpBB/newspage
Enable URL rewriting
module. When activated, it gives the url phpBB/newspage.
Code: Select all
public function update_schema()
{
return array(
'add_tables' => [
$this->table_prefix . 'my_special_table' => [
'COLUMNS' => [
'config_name' => ['VCHAR', ''],
'config_value' => ['MTEXT', ''],
'config_default' => ['MTEXT', ''],
],
'PRIMARY_KEY' => 'config_name',
],
],
);
}
public function revert_schema()
{
return array(
'drop_tables' => [
$this->table_prefix . 'my_special_table',
],
);
}
Code: Select all
public function update_data()
{
return array(
???
);
}
Code: Select all
public function update_data()
{
return array(
array('custom', array(array($this, 'my_special_table_update'))),
);
}
public function my_special_table_update()
{
$sql_ary = array(
'config_name' => 'foobar',
'config_value' => 'foobar',
'config_default' => 'foobar',
);
$sql = 'INSERT INTO ' . $this->table_prefix . 'my_special_table ' . $this->db->sql_build_array('INSERT', $sql_ary);
$this->sql_query($sql);
}
Code: Select all
public function update_data()
{
return array(
array('custom', array(array($this, 'set_initial_data'))),
);
}
public function set_initial_data()
{
$sql_ary = array(
array(
'config_name' => 'foobar',
'config_value' => 'foobar',
'config_default' => 'foobar',
), array(
'config_name' => 'bar',
'config_value' => 'bar',
'config_default' => 'bar',
));
$sql = $this->db->sql_multi_insert($this->table_prefix . 'my_special_table', $sql_ary);
$this->sql_query($sql);
}
Code: Select all
Duplicate entry 'foo' for key 'PRIMARY' [1062]
Code: Select all
public function revert_data()
{
return array(
array('custom', array(array($this, 'delete_data'))),
);
}
public function delete_data()
{
$sql = 'DELETE * FROM ' . $this->table_prefix . 'my_special_table';
$this->sql_query($sql);
}
Code: Select all
public function set_initial_data()
{
// Check if my table exists and holds data
if ($this->db_tools->sql_table_exists($this->table_prefix . 'my_special_table'))
{
$sql = 'SELECT * FROM ' . $this->table_prefix . 'my_special_table';
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
if (!empty($row))
{
return;
}
}
else
{
return;
}
$sql_ary = array(
array(
'config_name' => 'foobar',
'config_value' => 'foobar',
'config_default' => 'foobar',
), array(
'config_name' => 'bar',
'config_value' => 'bar',
'config_default' => 'bar',
));
$sql = $this->db->sql_multi_insert($this->table_prefix . 'my_special_table', $sql_ary);
$this->sql_query($sql);
}
Thanks. I eventually used a similar method after trying some other things. I just got confused because I couldn't understand why a roll-back migration would call update_data() instead of revert_data().VSE wrote:At the start of your custom function, the first thing you should do is check to see if the table already exists and if it holds data.
If it does, return, otherwise, proceed with the populating of your data table.