[feature/migrations] Test for calling a step multiple times

This is used when a long-running process is needed during an update. For
example, iterating over all posts and applying some transformation. This
allows the process to be broken apart into multiple shorter steps to prevent
hitting the time limit.

PHPBB3-9737
This commit is contained in:
Nathan Guse 2013-01-10 12:49:13 -06:00
parent 44c10f661e
commit ddb1eaab68
2 changed files with 66 additions and 0 deletions

View file

@ -0,0 +1,43 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
class phpbb_dbal_migration_recall extends phpbb_db_migration
{
function depends_on()
{
return array();
}
function update_schema()
{
return array();
}
function update_data()
{
return array(
array('custom', array(array(&$this, 'test_call'))),
);
}
// This function should be called 10 times
function test_call($input)
{
global $migrator_test_call_input;
$migrator_test_call_input = (int) $input;
if ($migrator_test_call_input < 10)
{
return ($migrator_test_call_input + 1);
}
return;
}
}

View file

@ -15,6 +15,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';
require_once dirname(__FILE__) . '/migration/dummy.php';
require_once dirname(__FILE__) . '/migration/unfulfillable.php';
require_once dirname(__FILE__) . '/migration/if.php';
require_once dirname(__FILE__) . '/migration/recall.php';
class phpbb_dbal_migrator_test extends phpbb_database_test_case
{
@ -127,4 +128,26 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$this->fail('False test failed');
}
}
public function test_recall()
{
$this->migrator->set_migrations(array('phpbb_dbal_migration_recall'));
global $migrator_test_call_input;
// Run the schema first
$this->migrator->update();
$i = 0;
while (!$this->migrator->finished())
{
$this->migrator->update();
$this->assertSame($i, $migrator_test_call_input);
$i++;
}
$this->assertSame(10, $migrator_test_call_input);
}
}