Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

module_base.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 4.60 KiB


001  <?php
002  /**
003   *
004   * This file is part of the phpBB Forum Software package.
005   *
006   * @copyright (c) phpBB Limited <https://www.phpbb.com>
007   * @license GNU General Public License, version 2 (GPL-2.0)
008   *
009   * For full copyright and license information, please see
010   * the docs/CREDITS.txt file.
011   *
012   */
013   
014  namespace phpbb\install;
015   
016  use phpbb\di\ordered_service_collection;
017  use phpbb\install\exception\resource_limit_reached_exception;
018  use phpbb\install\helper\config;
019  use phpbb\install\helper\iohandler\iohandler_interface;
020   
021  /**
022   * Base class for installer module
023   */
024  abstract class module_base implements module_interface
025  {
026      /**
027       * @var config
028       */
029      protected $install_config;
030   
031      /**
032       * @var iohandler_interface
033       */
034      protected $iohandler;
035   
036      /**
037       * @var bool
038       */
039      protected $is_essential;
040   
041      /**
042       * Array of tasks for installer module
043       *
044       * @var ordered_service_collection
045       */
046      protected $task_collection;
047   
048      /**
049       * @var array
050       */
051      protected $task_step_count;
052   
053      /**
054       * @var bool
055       */
056      protected $allow_progress_bar;
057   
058      /**
059       * Installer module constructor
060       *
061       * @param ordered_service_collection    $tasks                array of installer tasks for installer module
062       * @param bool                            $essential            flag indicating whether the module is essential or not
063       * @param bool                            $allow_progress_bar    flag indicating whether or not to send progress information from within the module
064       */
065      public function __construct(ordered_service_collection $tasks, $essential = true, $allow_progress_bar = true)
066      {
067          $this->task_collection        = $tasks;
068          $this->is_essential            = $essential;
069          $this->allow_progress_bar    = $allow_progress_bar;
070      }
071   
072      /**
073       * Dependency getter
074       *
075       * @param config                $config
076       * @param iohandler_interface    $iohandler
077       */
078      public function setup(config $config, iohandler_interface $iohandler)
079      {
080          $this->install_config    = $config;
081          $this->iohandler        = $iohandler;
082      }
083   
084      /**
085       * {@inheritdoc}
086       */
087      public function is_essential()
088      {
089          return $this->is_essential;
090      }
091   
092      /**
093       * {@inheritdoc}
094       *
095       * Overwrite this method if your task is non-essential!
096       */
097      public function check_requirements()
098      {
099          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]);
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  }
214