[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/phpbb/console/command/db/ -> migrate.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  namespace phpbb\console\command\db;
  14  
  15  use Symfony\Component\Console\Input\InputInterface;
  16  use Symfony\Component\Console\Output\OutputInterface;
  17  
  18  class migrate extends \phpbb\console\command\command
  19  {
  20      /** @var \phpbb\db\migrator */
  21      protected $migrator;
  22  
  23      /** @var \phpbb\extension\manager */
  24      protected $extension_manager;
  25  
  26      /** @var \phpbb\config\config */
  27      protected $config;
  28  
  29      /** @var \phpbb\cache\service */
  30      protected $cache;
  31  
  32      /** @var \phpbb\log\log */
  33      protected $log;
  34  
  35      /** @var string phpBB root path */
  36      protected $phpbb_root_path;
  37  
  38  	function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log, $phpbb_root_path)
  39      {
  40          $this->migrator = $migrator;
  41          $this->extension_manager = $extension_manager;
  42          $this->config = $config;
  43          $this->cache = $cache;
  44          $this->log = $log;
  45          $this->phpbb_root_path = $phpbb_root_path;
  46          parent::__construct($user);
  47          $this->user->add_lang(array('common', 'install', 'migrator'));
  48      }
  49  
  50  	protected function configure()
  51      {
  52          $this
  53              ->setName('db:migrate')
  54              ->setDescription($this->user->lang('CLI_DESCRIPTION_DB_MIGRATE'))
  55          ;
  56      }
  57  
  58  	protected function execute(InputInterface $input, OutputInterface $output)
  59      {
  60          $this->migrator->set_output_handler(new \phpbb\db\log_wrapper_migrator_output_handler($this->user, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log'));
  61  
  62          $this->migrator->create_migrations_table();
  63  
  64          $this->cache->purge();
  65  
  66          $this->load_migrations();
  67          $orig_version = $this->config['version'];
  68          while (!$this->migrator->finished())
  69          {
  70              try
  71              {
  72                  $this->migrator->update();
  73              }
  74              catch (\phpbb\db\migration\exception $e)
  75              {
  76                  $output->writeln('<error>' . $e->getLocalisedMessage($this->user) . '</error>');
  77                  $this->finalise_update();
  78                  return 1;
  79              }
  80          }
  81  
  82          if ($orig_version != $this->config['version'])
  83          {
  84              $this->log->add('admin', ANONYMOUS, '', 'LOG_UPDATE_DATABASE', time(), array($orig_version, $this->config['version']));
  85          }
  86  
  87          $this->finalise_update();
  88          $output->writeln($this->user->lang['DATABASE_UPDATE_COMPLETE']);
  89      }
  90  
  91  	protected function load_migrations()
  92      {
  93          $migrations = $this->extension_manager
  94              ->get_finder()
  95              ->core_path('phpbb/db/migration/data/')
  96              ->extension_directory('/migrations')
  97              ->get_classes();
  98  
  99          $this->migrator->set_migrations($migrations);
 100      }
 101  
 102  	protected function finalise_update()
 103      {
 104          $this->cache->purge();
 105          $this->config->increment('assets_version', 1);
 106      }
 107  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1