Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PatchHistory.php
Go to the documentation of this file.
1 <?php
8 
10 
15 {
19  const TABLE_NAME = 'patch_list';
20 
24  const CLASS_NAME = "patch_name";
25 
29  const SCHEMA_PATCH_TYPE = 'schema';
30 
34  const DATA_PATCH_TYPE = 'data';
35 
39  private $patchesRegistry = null;
40 
44  private $resourceConnection;
45 
50  public function __construct(ResourceConnection $resourceConnection)
51  {
52  $this->resourceConnection = $resourceConnection;
53  }
54 
63  private function getAppliedPatches()
64  {
65  if ($this->patchesRegistry === null) {
66  $adapter = $this->resourceConnection->getConnection();
67  $filterSelect = $adapter
68  ->select()
69  ->from($this->resourceConnection->getTableName(self::TABLE_NAME), self::CLASS_NAME);
70  $this->patchesRegistry = $adapter->fetchCol($filterSelect);
71  }
72 
73  return $this->patchesRegistry;
74  }
75 
82  public function fixPatch($patchName)
83  {
84  if ($this->isApplied($patchName)) {
85  throw new \LogicException(sprintf("Patch %s cannot be applied twice", $patchName));
86  }
87 
88  $adapter = $this->resourceConnection->getConnection();
89  $adapter->insert($this->resourceConnection->getTableName(self::TABLE_NAME), [self::CLASS_NAME => $patchName]);
90  }
91 
98  public function revertPatchFromHistory($patchName)
99  {
100  if (!$this->isApplied($patchName)) {
101  throw new \LogicException(
102  sprintf("Patch %s should be applied, before you can revert it", $patchName)
103  );
104  }
105 
106  $adapter = $this->resourceConnection->getConnection();
107  $adapter->delete(
108  $this->resourceConnection->getTableName(self::TABLE_NAME),
109  [self::CLASS_NAME . "= ?" => $patchName]
110  );
111  }
112 
119  public function isApplied($patchName)
120  {
121  return in_array($patchName, $this->getAppliedPatches());
122  }
123 }
$adapter
Definition: webapi_user.php:16
__construct(ResourceConnection $resourceConnection)