info() публичный статический Метод

public static info ( $msg )
Пример #1
0
 public function getDiff($table, $key)
 {
     Logger::info("Now calculating data diff for table `{$table}`");
     $diffSequence1 = $this->getOldNewDiff($table, $key);
     $diffSequence2 = $this->getChangeDiff($table, $key);
     $diffSequence = array_merge($diffSequence1, $diffSequence2);
     return $diffSequence;
 }
Пример #2
0
 public function output()
 {
     $content = $this->getComments();
     $content .= $this->getContent();
     if (is_null($this->params->output)) {
         Logger::info("Writing migration file to " . getcwd() . "/migration.sql");
         file_put_contents('migration.sql', $content);
     } else {
         Logger::info("Writing migration file to " . $this->params->output);
         return file_put_contents($this->params->output, $content);
     }
 }
Пример #3
0
 public function getOldData($table)
 {
     Logger::info("Now getting old data from table `{$table}`");
     $diffSequence = [];
     $iterator = $this->getIterator('target', $table);
     $key = $this->manager->getKey('target', $table);
     while ($iterator->hasNext()) {
         $data = $iterator->next(ArrayDiff::$size);
         foreach ($data as $entry) {
             $diffSequence[] = new DeleteData($table, ['keys' => array_only($entry, $key), 'diff' => new \Diff\DiffOp\DiffOpRemove($entry)]);
         }
     }
     return $diffSequence;
 }
Пример #4
0
 public function getDiff($table, $key)
 {
     Logger::info("Now calculating data diff for table `{$table}`");
     $diffs = $this->getDataDiff($table, $key);
     $diffSequence = [];
     foreach ($diffs as $name => $diff) {
         if ($diff['diff'] instanceof \Diff\DiffOp\DiffOpRemove) {
             $diffSequence[] = new DeleteData($table, $diff);
         } else {
             if (is_array($diff['diff'])) {
                 $diffSequence[] = new UpdateData($table, $diff);
             } else {
                 if ($diff['diff'] instanceof \Diff\DiffOp\DiffOpAdd) {
                     $diffSequence[] = new InsertData($table, $diff);
                 }
             }
         }
     }
     return $diffSequence;
 }
Пример #5
0
 public function run()
 {
     // Increase memory limit
     ini_set('memory_limit', '512M');
     try {
         // Params
         $paramsFactory = new ParamsFactory();
         $params = $paramsFactory->get();
         // Diff
         $diffCalculator = new DiffCalculator();
         $diff = $diffCalculator->getDiff($params);
         // Empty diff
         if (empty($diff['schema']) && empty($diff['data'])) {
             Logger::info("Identical resources");
         } else {
             // SQL
             $sqlGenerator = new SQLGenerator($diff);
             $up = '';
             $down = '';
             if ($params->include !== 'down') {
                 $up = $sqlGenerator->getUp();
             }
             if ($params->include !== 'up') {
                 $down = $sqlGenerator->getDown();
             }
             // Generate
             $templater = new Templater($params, $up, $down);
             $templater->output();
         }
         Logger::success("Completed");
     } catch (\Exception $e) {
         if ($e instanceof BaseException) {
             Logger::error($e->getMessage(), true);
         } else {
             Logger::error("Unexpected error: ");
             throw $e;
         }
     }
 }
Пример #6
0
 public function getDown()
 {
     Logger::info("Now generating DOWN migration");
     $diff = $this->diffSorter->sort($this->diff, 'down');
     return MigrationGenerator::generate($diff, 'getDown');
 }
Пример #7
0
 public function getDiff($table)
 {
     Logger::info("Now calculating schema diff for table `{$table}`");
     $diffSequence = [];
     $sourceSchema = $this->getSchema('source', $table);
     $targetSchema = $this->getSchema('target', $table);
     // Engine
     $sourceEngine = $sourceSchema['engine'];
     $targetEngine = $targetSchema['engine'];
     if ($sourceEngine != $targetEngine) {
         $diffSequence[] = new AlterTableEngine($table, $sourceEngine, $targetEngine);
     }
     // Collation
     $sourceCollation = $sourceSchema['collation'];
     $targetCollation = $targetSchema['collation'];
     if ($sourceCollation != $targetCollation) {
         $diffSequence[] = new AlterTableCollation($table, $sourceCollation, $targetCollation);
     }
     // Columns
     $sourceColumns = $sourceSchema['columns'];
     $targetColumns = $targetSchema['columns'];
     $differ = new MapDiffer();
     $diffs = $differ->doDiff($targetColumns, $sourceColumns);
     foreach ($diffs as $column => $diff) {
         if ($diff instanceof \Diff\DiffOp\DiffOpRemove) {
             $diffSequence[] = new AlterTableDropColumn($table, $column, $diff);
         } else {
             if ($diff instanceof \Diff\DiffOp\DiffOpChange) {
                 $diffSequence[] = new AlterTableChangeColumn($table, $column, $diff);
             } else {
                 if ($diff instanceof \Diff\DiffOp\DiffOpAdd) {
                     $diffSequence[] = new AlterTableAddColumn($table, $column, $diff);
                 }
             }
         }
     }
     // Keys
     $sourceKeys = $sourceSchema['keys'];
     $targetKeys = $targetSchema['keys'];
     $differ = new MapDiffer();
     $diffs = $differ->doDiff($targetKeys, $sourceKeys);
     foreach ($diffs as $key => $diff) {
         if ($diff instanceof \Diff\DiffOp\DiffOpRemove) {
             $diffSequence[] = new AlterTableDropKey($table, $key, $diff);
         } else {
             if ($diff instanceof \Diff\DiffOp\DiffOpChange) {
                 $diffSequence[] = new AlterTableChangeKey($table, $key, $diff);
             } else {
                 if ($diff instanceof \Diff\DiffOp\DiffOpAdd) {
                     $diffSequence[] = new AlterTableAddKey($table, $key, $diff);
                 }
             }
         }
     }
     // Constraints
     $sourceConstraints = $sourceSchema['constraints'];
     $targetConstraints = $targetSchema['constraints'];
     $differ = new MapDiffer();
     $diffs = $differ->doDiff($targetConstraints, $sourceConstraints);
     foreach ($diffs as $name => $diff) {
         if ($diff instanceof \Diff\DiffOp\DiffOpRemove) {
             $diffSequence[] = new AlterTableDropConstraint($table, $name, $diff);
         } else {
             if ($diff instanceof \Diff\DiffOp\DiffOpChange) {
                 $diffSequence[] = new AlterTableChangeConstraint($table, $name, $diff);
             } else {
                 if ($diff instanceof \Diff\DiffOp\DiffOpAdd) {
                     $diffSequence[] = new AlterTableAddConstraint($table, $name, $diff);
                 }
             }
         }
     }
     return $diffSequence;
 }