"Fossies" - the Fresh Open Source Software Archive

Member "contao-4.11.5/installation-bundle/src/Database/AbstractVersionUpdate.php" (23 Jun 2021, 1886 Bytes) of package /linux/www/contao-4.11.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AbstractVersionUpdate.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 declare(strict_types=1);
    4 
    5 /*
    6  * This file is part of Contao.
    7  *
    8  * (c) Leo Feyer
    9  *
   10  * @license LGPL-3.0-or-later
   11  */
   12 
   13 namespace Contao\InstallationBundle\Database;
   14 
   15 use Doctrine\DBAL\Connection;
   16 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
   17 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
   18 
   19 trigger_deprecation('contao/installation-bundle', '4.9', 'Using the "Contao\InstallationBundle\Database\AbstractVersionUpdate" class has been deprecated and will no longer work in Contao 5.0. Use the "Contao\CoreBundle\Migration\AbstractMigration" class instead.');
   20 
   21 /**
   22  * @deprecated Deprecated since Contao 4.9, to be removed in Contao 5.0; use the
   23  *             Contao\CoreBundle\Migration\AbstractMigration class instead
   24  */
   25 abstract class AbstractVersionUpdate implements ContainerAwareInterface
   26 {
   27     use ContainerAwareTrait;
   28 
   29     /**
   30      * @var Connection
   31      */
   32     protected $connection;
   33 
   34     /**
   35      * @var array
   36      */
   37     protected $messages = [];
   38 
   39     public function __construct(Connection $connection)
   40     {
   41         $this->connection = $connection;
   42     }
   43 
   44     /**
   45      * @return bool
   46      */
   47     public function hasMessage()
   48     {
   49         return !empty($this->messages);
   50     }
   51 
   52     /**
   53      * @return string
   54      */
   55     public function getMessage()
   56     {
   57         return implode('', $this->messages);
   58     }
   59 
   60     /**
   61      * Checks whether the update should be run.
   62      *
   63      * @return bool
   64      */
   65     abstract public function shouldBeRun();
   66 
   67     /**
   68      * Runs the update.
   69      */
   70     abstract public function run();
   71 
   72     /**
   73      * @param string $message
   74      */
   75     protected function addMessage($message): void
   76     {
   77         $this->messages[] = $message;
   78     }
   79 
   80     /**
   81      * @param string $message
   82      */
   83     protected function prependMessage($message): void
   84     {
   85         array_unshift($this->messages, $message);
   86     }
   87 }