Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AutoIncrementColumnValidation.php
Go to the documentation of this file.
1 <?php
7 
12 
19 {
23  const ERROR_TYPE = 'auto_increment_column_is_valid';
24 
28  const ERROR_MESSAGE = 'Auto Increment column do not have index. Column - "%s", table - "%s"';
29 
33  public function validate(Schema $schema)
34  {
35  $errors = [];
36  foreach ($schema->getTables() as $table) {
37  foreach ($table->getColumns() as $column) {
38  if ($column instanceof ColumnIdentityAwareInterface && $column->isIdentity()) {
39  foreach ($table->getConstraints() as $constraint) {
40  if ($constraint instanceof Internal &&
41  in_array($column->getName(), $constraint->getColumnNames())
42  ) {
43  //If we find that for auto increment column we have index or key
44  continue 3;
45  }
46  }
47 
48  foreach ($table->getIndexes() as $index) {
49  if (in_array($column->getName(), $index->getColumnNames())) {
50  //If we find that for auto increment column we have index or key
51  continue 3;
52  }
53  }
54 
55  $errors[] = [
56  'column' => $column->getName(),
57  'message' => sprintf(self::ERROR_MESSAGE, $column->getName(), $table->getName())
58  ];
59  }
60  }
61  }
62 
63  return $errors;
64  }
65 }
$table
Definition: trigger.php:14
$index
Definition: list.phtml:44
$errors
Definition: overview.phtml:9