Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

migration.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 4.38 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  * Abstract base class for database migrations
018  *
019  * Each migration consists of a set of schema and data changes to be implemented
020  * in a subclass. This class provides various utility methods to simplify editing
021  * a phpBB.
022  */
023  abstract class migration
024  {
025      /** @var \phpbb\config\config */
026      protected $config;
027   
028      /** @var \phpbb\db\driver\driver_interface */
029      protected $db;
030   
031      /** @var \phpbb\db\tools */
032      protected $db_tools;
033   
034      /** @var string */
035      protected $table_prefix;
036   
037      /** @var string */
038      protected $phpbb_root_path;
039   
040      /** @var string */
041      protected $php_ext;
042   
043      /** @var array Errors, if any occurred */
044      protected $errors;
045   
046      /** @var array List of queries executed through $this->sql_query() */
047      protected $queries = array();
048   
049      /**
050      * Constructor
051      *
052      * @param \phpbb\config\config $config
053      * @param \phpbb\db\driver\driver_interface $db
054      * @param \phpbb\db\tools $db_tools
055      * @param string $phpbb_root_path
056      * @param string $php_ext
057      * @param string $table_prefix
058      */
059      public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\db\tools $db_tools, $phpbb_root_path, $php_ext, $table_prefix)
060      {
061          $this->config = $config;
062          $this->db = $db;
063          $this->db_tools = $db_tools;
064          $this->table_prefix = $table_prefix;
065   
066          $this->phpbb_root_path = $phpbb_root_path;
067          $this->php_ext = $php_ext;
068   
069          $this->errors = array();
070      }
071   
072      /**
073      * Defines other migrations to be applied first
074      *
075      * @return array An array of migration class names
076      */
077      static public function depends_on()
078      {
079          return array();
080      }
081   
082      /**
083      * Allows you to check if the migration is effectively installed (entirely optional)
084      *
085      * This is checked when a migration is installed. If true is returned, the migration will be set as
086      * installed without performing the database changes.
087      * This function is intended to help moving to migrations from a previous database updater, where some
088      * migrations may have been installed already even though they are not yet listed in the migrations table.
089      *
090      * @return bool True if this migration is installed, False if this migration is not installed (checked on install)
091      */
092      public function effectively_installed()
093      {
094          return false;
095      }
096   
097      /**
098      * Updates the database schema by providing a set of change instructions
099      *
100      * @return array Array of schema changes (compatible with db_tools->perform_schema_changes())
101      */
102      public function update_schema()
103      {
104          return array();
105      }
106   
107      /**
108      * Reverts the database schema by providing a set of change instructions
109      *
110      * @return array Array of schema changes (compatible with db_tools->perform_schema_changes())
111      */
112      public function revert_schema()
113      {
114          return array();
115      }
116   
117      /**
118      * Updates data by returning a list of instructions to be executed
119      *
120      * @return array Array of data update instructions
121      */
122      public function update_data()
123      {
124          return array();
125      }
126   
127      /**
128      * Reverts data by returning a list of instructions to be executed
129      *
130      * @return array Array of data instructions that will be performed on revert
131      *     NOTE: calls to tools (such as config.add) are automatically reverted when
132      *         possible, so you should not attempt to revert those, this is mostly for
133      *         otherwise unrevertable calls (custom functions for example)
134      */
135      public function revert_data()
136      {
137          return array();
138      }
139   
140      /**
141      * Wrapper for running queries to generate user feedback on updates
142      *
143      * @param string $sql SQL query to run on the database
144      * @return mixed Query result from db->sql_query()
145      */
146      protected function sql_query($sql)
147      {
148          $this->queries[] = $sql;
149   
150          $this->db->sql_return_on_error(true);
151   
152          if ($sql === 'begin')
153          {
154              $result = $this->db->sql_transaction('begin');
155          }
156          else if ($sql === 'commit')
157          {
158              $result = $this->db->sql_transaction('commit');
159          }
160          else
161          {
162              $result = $this->db->sql_query($sql);
163              if ($this->db->get_sql_error_triggered())
164              {
165                  $this->errors[] = array(
166                      'sql'    => $this->db->get_sql_error_sql(),
167                      'code'    => $this->db->get_sql_error_returned(),
168                  );
169              }
170          }
171   
172          $this->db->sql_return_on_error(false);
173   
174          return $result;
175      }
176   
177      /**
178      * Get the list of queries run
179      *
180      * @return array
181      */
182      public function get_queries()
183      {
184          return $this->queries;
185      }
186  }
187