Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MigrateDataFrom.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 
21 {
25  const MATCH_PATTERN = '/migrateDataFrom\(([^\)]+)\)/';
26 
30  private $resourceConnection;
31 
37  public function __construct(ResourceConnection $resourceConnection)
38  {
39  $this->resourceConnection = $resourceConnection;
40  }
41 
45  public function isApplicable(string $statement) : bool
46  {
47  return (bool) preg_match(self::MATCH_PATTERN, $statement);
48  }
49 
53  public function getCallback(ElementHistory $columnHistory) : callable
54  {
56  $column = $columnHistory->getNew();
57  preg_match(self::MATCH_PATTERN, $column->getOnCreate(), $matches);
58  return function () use ($column, $matches) {
59  $tableName = $column->getTable()->getName();
60  $adapter = $this->resourceConnection->getConnection(
61  $column->getTable()->getResource()
62  );
63  $adapter
64  ->update(
65  $this->resourceConnection->getTableName($tableName),
66  [
67  $column->getName() => new Expression($matches[1])
68  ]
69  );
70  };
71  }
72 }
$tableName
Definition: trigger.php:13
$adapter
Definition: webapi_user.php:16