Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ticket/10346] Add drop_tables to perform_schema_changes and add tests #352

Merged
merged 1 commit into from Aug 29, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions phpBB/includes/db/db_tools.php
Expand Up @@ -649,6 +649,23 @@ function perform_schema_changes($schema_changes)
$sqlite = true;
}

// Drop tables?
if (!empty($schema_changes['drop_tables']))
{
foreach ($schema_changes['drop_tables'] as $table)
{
// only drop table if it exists
if ($this->sql_table_exists($table))
{
$result = $this->sql_table_drop($table);
if ($this->return_statements)
{
$statements = array_merge($statements, $result);
}
}
}
}

// Add tables?
if (!empty($schema_changes['add_tables']))
{
Expand Down
60 changes: 60 additions & 0 deletions tests/dbal/db_tools_test.php
Expand Up @@ -271,6 +271,66 @@ public function test_table_drop()
'foo' => array('UINT', 42)))
);

$this->assertTrue($this->tools->sql_table_exists('prefix_test_table'));

$this->tools->sql_table_drop('prefix_test_table');

$this->assertFalse($this->tools->sql_table_exists('prefix_test_table'));
}

public function test_peform_schema_changes_drop_tables()
{
$db_tools = $this->getMock('phpbb_db_tools', array(
'sql_table_exists',
'sql_table_drop',
), array(&$this->db));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the & here needed?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup db_tools expects a reference (since this is for 3.0 -> PHP4 support requires it) so you get a warning without it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, it's olympus. Maybe We should get rid of it for ascraeus.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really worth it ;-)


// pretend all tables exist
$db_tools->expects($this->any())->method('sql_table_exists')
->will($this->returnValue(true));

// drop tables
$db_tools->expects($this->exactly(2))->method('sql_table_drop');
$db_tools->expects($this->at(1))->method('sql_table_drop')
->with($this->equalTo('dropped_table_1'));
$db_tools->expects($this->at(3))->method('sql_table_drop')
->with($this->equalTo('dropped_table_2'));

$db_tools->perform_schema_changes(array(
'drop_tables' => array(
'dropped_table_1',
'dropped_table_2',
),
));
}

public function test_peform_schema_changes_drop_columns()
{
$db_tools = $this->getMock('phpbb_db_tools', array(
'sql_column_exists',
'sql_column_remove',
), array(&$this->db));

// pretend all columns exist
$db_tools->expects($this->any())->method('sql_column_exists')
->will($this->returnValue(true));
$db_tools->expects($this->any())->method('sql_column_exists')
->will($this->returnValue(true));

// drop columns
$db_tools->expects($this->exactly(2))->method('sql_column_remove');
$db_tools->expects($this->at(1))->method('sql_column_remove')
->with($this->equalTo('existing_table'), $this->equalTo('dropped_column_1'));
$db_tools->expects($this->at(3))->method('sql_column_remove')
->with($this->equalTo('existing_table'), $this->equalTo('dropped_column_2'));

$db_tools->perform_schema_changes(array(
'drop_columns' => array(
'existing_table' => array(
'dropped_column_1',
'dropped_column_2',
),
),
));
}
}