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

helper.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 2.57 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\db\migration;
015   
016  /**
017  * The migrator is responsible for applying new migrations in the correct order.
018  */
019  class helper
020  {
021      /**
022       * Get the schema steps from an array of schema changes
023       *
024       * This splits up $schema_changes into individual changes so that the
025       * changes can be chunked
026       *
027       * @param array $schema_changes from migration
028       * @return array
029       */
030      public function get_schema_steps($schema_changes)
031      {
032          $steps = array();
033   
034          // Nested level of data (only supports 1/2 currently)
035          $nested_level = array(
036              'drop_tables'        => 1,
037              'add_tables'        => 1,
038              'change_columns'    => 2,
039              'add_columns'        => 2,
040              'drop_keys'            => 2,
041              'drop_columns'        => 2,
042              'add_primary_keys'    => 2, // perform_schema_changes only uses one level, but second is in the function
043              'add_unique_index'    => 2,
044              'add_index'            => 2,
045          );
046   
047          foreach ($nested_level as $change_type => $data_depth)
048          {
049              if (!empty($schema_changes[$change_type]))
050              {
051                  foreach ($schema_changes[$change_type] as $key => $value)
052                  {
053                      if ($data_depth === 1)
054                      {
055                          $steps[] = array(
056                              'dbtools.perform_schema_changes', array(array(
057                                      $change_type    => array(
058                                          (!is_int($key)) ? $key : 0    => $value,
059                                  ),
060                              )),
061                          );
062                      }
063                      else if ($data_depth === 2)
064                      {
065                          foreach ($value as $key2 => $value2)
066                          {
067                              $steps[] = array(
068                                  'dbtools.perform_schema_changes', array(array(
069                                      $change_type    => array(
070                                          $key => array(
071                                              $key2    => $value2,
072                                          ),
073                                      ),
074                                  )),
075                              );
076                          }
077                      }
078                  }
079              }
080          }
081   
082          return $steps;
083      }
084   
085      /**
086       * Reverse the update steps from an array of data changes
087       *
088       * 'If' statements and custom methods will be skipped, for all
089       * other calls the reverse method of the tool class will be called
090       *
091       * @param array $steps Update changes from migration
092       *
093       * @return array
094       */
095      public function reverse_update_data($steps)
096      {
097          $reversed_array = array();
098   
099          foreach ($steps as $step)
100          {
101              $parts = explode('.', $step[0]);
102              $parameters = $step[1];
103   
104              $class = $parts[0];
105              $method = isset($parts[1]) ? $parts[1] : false;
106   
107              if ($class !== 'if' && $class !== 'custom')
108              {
109                  array_unshift($parameters, $method);
110                  $reversed_array[] = array($class . '.reverse', $parameters);
111              }
112          }
113   
114          return array_reverse($reversed_array);
115      }
116  }
117