[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\install; 15 16 use phpbb\di\ordered_service_collection; 17 use phpbb\install\exception\resource_limit_reached_exception; 18 use phpbb\install\helper\config; 19 use phpbb\install\helper\iohandler\iohandler_interface; 20 21 /** 22 * Base class for installer module 23 */ 24 abstract class module_base implements module_interface 25 { 26 /** 27 * @var config 28 */ 29 protected $install_config; 30 31 /** 32 * @var iohandler_interface 33 */ 34 protected $iohandler; 35 36 /** 37 * @var bool 38 */ 39 protected $is_essential; 40 41 /** 42 * Array of tasks for installer module 43 * 44 * @var ordered_service_collection 45 */ 46 protected $task_collection; 47 48 /** 49 * @var array 50 */ 51 protected $task_step_count; 52 53 /** 54 * @var bool 55 */ 56 protected $allow_progress_bar; 57 58 /** 59 * Installer module constructor 60 * 61 * @param ordered_service_collection $tasks array of installer tasks for installer module 62 * @param bool $essential flag indicating whether the module is essential or not 63 * @param bool $allow_progress_bar flag indicating whether or not to send progress information from within the module 64 */ 65 public function __construct(ordered_service_collection $tasks, $essential = true, $allow_progress_bar = true) 66 { 67 $this->task_collection = $tasks; 68 $this->is_essential = $essential; 69 $this->allow_progress_bar = $allow_progress_bar; 70 } 71 72 /** 73 * Dependency getter 74 * 75 * @param config $config 76 * @param iohandler_interface $iohandler 77 */ 78 public function setup(config $config, iohandler_interface $iohandler) 79 { 80 $this->install_config = $config; 81 $this->iohandler = $iohandler; 82 } 83 84 /** 85 * {@inheritdoc} 86 */ 87 public function is_essential() 88 { 89 return $this->is_essential; 90 } 91 92 /** 93 * {@inheritdoc} 94 * 95 * Overwrite this method if your task is non-essential! 96 */ 97 public function check_requirements() 98 { 99 return true; 100 } 101 102 /** 103 * {@inheritdoc} 104 */ 105 public function run() 106 { 107 // Recover install progress 108 $task_index = $this->recover_progress(); 109 $iterator = $this->task_collection->getIterator(); 110 111 if ($task_index < $iterator->count()) 112 { 113 $iterator->seek($task_index); 114 } 115 else 116 { 117 $this->install_config->set_finished_task(0); 118 return; 119 } 120 121 while ($iterator->valid()) 122 { 123 $task = $iterator->current(); 124 $name = $iterator->key(); 125 126 // Check if we can run the task 127 if (!$task->is_essential() && !$task->check_requirements()) 128 { 129 $this->iohandler->add_log_message(array( 130 'SKIP_TASK', 131 $name, 132 )); 133 134 $this->install_config->increment_current_task_progress($this->task_step_count[$name] ?? false); 135 } 136 else 137 { 138 // Send progress information 139 if ($this->allow_progress_bar) 140 { 141 $this->iohandler->set_progress( 142 $task->get_task_lang_name(), 143 $this->install_config->get_current_task_progress() 144 ); 145 146 $this->iohandler->send_response(); 147 } 148 149 $task->run(); 150 151 if ($this->allow_progress_bar) 152 { 153 // Only increment progress by one, as if a task has more than one steps 154 // then that should be incremented in the task itself 155 $this->install_config->increment_current_task_progress(); 156 } 157 } 158 159 $task_index++; 160 $this->install_config->set_finished_task($task_index); 161 $iterator->next(); 162 163 // Send progress information 164 if ($this->allow_progress_bar) 165 { 166 $this->iohandler->set_progress( 167 $task->get_task_lang_name(), 168 $this->install_config->get_current_task_progress() 169 ); 170 } 171 172 $this->iohandler->send_response(); 173 174 // Stop execution if resource limit is reached 175 if ($iterator->valid() && ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)) 176 { 177 throw new resource_limit_reached_exception(); 178 } 179 } 180 181 // Module finished, so clear task progress 182 $this->install_config->set_finished_task(0); 183 } 184 185 /** 186 * Returns the next task's name 187 * 188 * @return string Index of the array element of the next task 189 */ 190 protected function recover_progress() 191 { 192 $progress_array = $this->install_config->get_progress_data(); 193 return $progress_array['last_task_index']; 194 } 195 196 /** 197 * {@inheritdoc} 198 */ 199 public function get_step_count() 200 { 201 $task_step_count = 0; 202 $task_class_names = $this->task_collection->get_service_classes(); 203 204 foreach ($task_class_names as $name => $task_class) 205 { 206 $step_count = $task_class::get_step_count(); 207 $task_step_count += $step_count; 208 $this->task_step_count[$name] = $step_count; 209 } 210 211 return $task_step_count; 212 } 213 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |