[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/phpbb/install/module/install_data/task/ -> add_languages.php (source)

   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\module\install_data\task;
  15  
  16  class add_languages extends \phpbb\install\task_base
  17  {
  18      /**
  19       * @var \phpbb\db\driver\driver_interface
  20       */
  21      protected $db;
  22  
  23      /**
  24       * @var \phpbb\install\helper\iohandler\iohandler_interface
  25       */
  26      protected $iohandler;
  27  
  28      /**
  29       * @var \phpbb\language\language_file_helper
  30       */
  31      protected $language_helper;
  32  
  33      /**
  34       * Constructor
  35       *
  36       * @param \phpbb\install\helper\iohandler\iohandler_interface    $iohandler            Installer's input-output handler
  37       * @param \phpbb\install\helper\container_factory                $container            Installer's DI container
  38       * @param \phpbb\language\language_file_helper                    $language_helper    Language file helper service
  39       */
  40  	public function __construct(\phpbb\install\helper\iohandler\iohandler_interface $iohandler,
  41                                  \phpbb\install\helper\container_factory $container,
  42                                  \phpbb\language\language_file_helper $language_helper)
  43      {
  44          $this->db                = $container->get('dbal.conn');
  45          $this->iohandler        = $iohandler;
  46          $this->language_helper    = $language_helper;
  47  
  48          parent::__construct(true);
  49      }
  50  
  51      /**
  52       * {@inheritdoc}
  53       */
  54  	public function run()
  55      {
  56          $this->db->sql_return_on_error(true);
  57  
  58          $languages = $this->language_helper->get_available_languages();
  59          $installed_languages = array();
  60  
  61          foreach ($languages as $lang_info)
  62          {
  63              $lang_pack = array(
  64                  'lang_iso'            => $lang_info['iso'],
  65                  'lang_dir'            => $lang_info['iso'],
  66                  'lang_english_name'    => htmlspecialchars($lang_info['name'], ENT_COMPAT),
  67                  'lang_local_name'    => htmlspecialchars($lang_info['local_name'], ENT_COMPAT, 'UTF-8'),
  68                  'lang_author'        => htmlspecialchars($lang_info['author'], ENT_COMPAT, 'UTF-8'),
  69              );
  70  
  71              $this->db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $this->db->sql_build_array('INSERT', $lang_pack));
  72  
  73              $installed_languages[] = (int) $this->db->sql_nextid();
  74              if ($this->db->get_sql_error_triggered())
  75              {
  76                  $error = $this->db->sql_error($this->db->get_sql_error_sql());
  77                  $this->iohandler->add_error_message($error['message']);
  78              }
  79          }
  80  
  81          $sql = 'SELECT * FROM ' . PROFILE_FIELDS_TABLE;
  82          $result = $this->db->sql_query($sql);
  83  
  84          $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, PROFILE_LANG_TABLE);
  85          while ($row = $this->db->sql_fetchrow($result))
  86          {
  87              foreach ($installed_languages as $lang_id)
  88              {
  89                  $insert_buffer->insert(array(
  90                      'field_id'                => $row['field_id'],
  91                      'lang_id'                => $lang_id,
  92  
  93                      // Remove phpbb_ from field name
  94                      'lang_name'                => strtoupper(substr($row['field_name'], 6)),
  95                      'lang_explain'            => '',
  96                      'lang_default_value'    => '',
  97                  ));
  98              }
  99          }
 100  
 101          $this->db->sql_freeresult($result);
 102  
 103          $insert_buffer->flush();
 104      }
 105  
 106      /**
 107       * {@inheritdoc}
 108       */
 109  	static public function get_step_count()
 110      {
 111          return 1;
 112      }
 113  
 114      /**
 115       * {@inheritdoc}
 116       */
 117  	public function get_task_lang_name()
 118      {
 119          return 'TASK_ADD_LANGUAGES';
 120      }
 121  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1