1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-05 16:27:38 +02:00

[ticket/16643] Refactor installer tasks to use Doctrine DBAL

PHPBB3-16643
This commit is contained in:
Máté Bartus
2021-01-16 11:57:35 +01:00
parent aab2679966
commit 2a57477718
19 changed files with 1102 additions and 676 deletions

View File

@@ -0,0 +1,69 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\install;
use phpbb\install\exception\resource_limit_reached_exception;
use phpbb\install\helper\config;
/**
* Trait to execute tasks in steps with timeout management.
*/
trait sequential_task
{
/**
* Callback function to execute a unit of work.
*
* @param mixed $key The array key.
* @param mixed $value The array value.
*/
abstract protected function execute_step($key, $value) : void;
/**
* Execute the tasks with timeout management.
*
* @param config $config Installer config.
* @param array $data Array of elements to iterate over.
* @param string|null $counter_name The name of the counter or null.
*
* @throws resource_limit_reached_exception When resources are exhausted.
*/
protected function execute(config $config, array $data, ?string $counter_name = null) : void
{
if ($counter_name === null)
{
$counter_name = 'step_counter_' . get_class($this);
}
$counter = $config->get($counter_name, 0);
$total = count($data);
$data = array_slice($data, $counter);
foreach ($data as $key => $value)
{
if ($config->get_time_remaining() <= 0 || $config->get_memory_remaining() <= 0)
{
break;
}
$this->execute_step($key, $value);
++$counter;
}
$config->set($counter_name, $counter);
if ($counter < $total)
{
throw new resource_limit_reached_exception();
}
}
}