[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/phpbb/extension/ -> base.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\extension;
  15  
  16  use Symfony\Component\DependencyInjection\ContainerInterface;
  17  
  18  /**
  19  * A base class for extensions without custom enable/disable/purge code.
  20  */
  21  class base implements \phpbb\extension\extension_interface
  22  {
  23      /** @var ContainerInterface */
  24      protected $container;
  25  
  26      /** @var \phpbb\finder */
  27      protected $finder;
  28  
  29      /** @var \phpbb\db\migrator */
  30      protected $migrator;
  31  
  32      /** @var string */
  33      protected $extension_name;
  34  
  35      /** @var string */
  36      protected $extension_path;
  37  
  38      /** @var string[] */
  39      private $migrations = false;
  40  
  41      /**
  42      * Constructor
  43      *
  44      * @param ContainerInterface $container Container object
  45      * @param \phpbb\finder $extension_finder
  46      * @param \phpbb\db\migrator $migrator
  47      * @param string $extension_name Name of this extension (from ext.manager)
  48      * @param string $extension_path Relative path to this extension
  49      */
  50  	public function __construct(ContainerInterface $container, \phpbb\finder $extension_finder, \phpbb\db\migrator $migrator, $extension_name, $extension_path)
  51      {
  52          $this->container = $container;
  53          $this->extension_finder = $extension_finder;
  54          $this->migrator = $migrator;
  55  
  56          $this->extension_name = $extension_name;
  57          $this->extension_path = $extension_path;
  58      }
  59  
  60      /**
  61      * {@inheritdoc}
  62      */
  63  	public function is_enableable()
  64      {
  65          return true;
  66      }
  67  
  68      /**
  69      * Single enable step that installs any included migrations
  70      *
  71      * @param mixed $old_state State returned by previous call of this method
  72      * @return false Indicates no further steps are required
  73      */
  74  	public function enable_step($old_state)
  75      {
  76          $migrations = $this->get_migration_file_list();
  77  
  78          $this->migrator->set_migrations($migrations);
  79  
  80          $this->migrator->update();
  81  
  82          return !$this->migrator->finished();
  83      }
  84  
  85      /**
  86      * Single disable step that does nothing
  87      *
  88      * @param mixed $old_state State returned by previous call of this method
  89      * @return false Indicates no further steps are required
  90      */
  91  	public function disable_step($old_state)
  92      {
  93          return false;
  94      }
  95  
  96      /**
  97      * Single purge step that reverts any included and installed migrations
  98      *
  99      * @param mixed $old_state State returned by previous call of this method
 100      * @return false Indicates no further steps are required
 101      */
 102  	public function purge_step($old_state)
 103      {
 104          $migrations = $this->get_migration_file_list();
 105  
 106          $this->migrator->set_migrations($migrations);
 107  
 108          foreach ($migrations as $migration)
 109          {
 110              while ($this->migrator->migration_state($migration) !== false)
 111              {
 112                  $this->migrator->revert($migration);
 113  
 114                  return true;
 115              }
 116          }
 117  
 118          return false;
 119      }
 120  
 121      /**
 122      * Get the list of migration files from this extension
 123      *
 124      * @return array
 125      */
 126  	protected function get_migration_file_list()
 127      {
 128          if ($this->migrations !== false)
 129          {
 130              return $this->migrations;
 131          }
 132  
 133          // Only have the finder search in this extension path directory
 134          $migrations = $this->extension_finder
 135              ->extension_directory('/migrations')
 136              ->find_from_extension($this->extension_name, $this->extension_path);
 137  
 138          $migrations = $this->extension_finder->get_classes_from_files($migrations);
 139  
 140          return $migrations;
 141      }
 142  }


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