resourceConnection = $resourceConnection; } /** * Read and cache data patches from db * * All patches are store in patch_list table * @see self::TABLE_NAME * * @return array */ private function getAppliedPatches() { if ($this->patchesRegistry === null) { $adapter = $this->resourceConnection->getConnection(); $filterSelect = $adapter ->select() ->from($this->resourceConnection->getTableName(self::TABLE_NAME), self::CLASS_NAME); $this->patchesRegistry = $adapter->fetchCol($filterSelect); } return $this->patchesRegistry; } /** * Fix patch in patch table in order to avoid reapplying of patch * * @param string $patchName * @return void */ public function fixPatch($patchName) { if ($this->isApplied($patchName)) { throw new \LogicException(sprintf("Patch %s cannot be applied twice", $patchName)); } $adapter = $this->resourceConnection->getConnection(); $adapter->insert($this->resourceConnection->getTableName(self::TABLE_NAME), [self::CLASS_NAME => $patchName]); } /** * Revert patch from history * * @param $patchName * @return void */ public function revertPatchFromHistory($patchName) { if (!$this->isApplied($patchName)) { throw new \LogicException( sprintf("Patch %s should be applied, before you can revert it", $patchName) ); } $adapter = $this->resourceConnection->getConnection(); $adapter->delete( $this->resourceConnection->getTableName(self::TABLE_NAME), [self::CLASS_NAME . "= ?" => $patchName] ); } /** * Check whether patch was applied on the system or not * * @param string $patchName * @return bool */ public function isApplied($patchName) { return in_array($patchName, $this->getAppliedPatches()); } }