@@ -121,6 +121,9 @@ |
||
| 121 | 121 | return $failure ? 1 : 0; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | + /** |
|
| 125 | + * @param OutputInterface $output |
|
| 126 | + */ |
|
| 124 | 127 | private function findMissingEntities($entity, $output) { |
| 125 | 128 | $dql = "SELECT _inner, _outer\n" |
| 126 | 129 | ." FROM ".$entity['sourceEntity']." _inner\n" |
@@ -123,10 +123,10 @@ |
||
| 123 | 123 | |
| 124 | 124 | private function findMissingEntities($entity, $output) { |
| 125 | 125 | $dql = "SELECT _inner, _outer\n" |
| 126 | - ." FROM ".$entity['sourceEntity']." _inner\n" |
|
| 127 | - ." LEFT JOIN ".$entity['targetEntity']." _outer" |
|
| 128 | - .$this->with($entity) |
|
| 129 | - .$this->where($entity); |
|
| 126 | + ." FROM ".$entity['sourceEntity']." _inner\n" |
|
| 127 | + ." LEFT JOIN ".$entity['targetEntity']." _outer" |
|
| 128 | + .$this->with($entity) |
|
| 129 | + .$this->where($entity); |
|
| 130 | 130 | |
| 131 | 131 | $entityManager = $this->getHelper('em')->getEntityManager(); |
| 132 | 132 | try { |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | $classNames = $entityManager->getConfiguration()->getMetadataDriverImpl()->getAllClassNames(); |
| 71 | 71 | |
| 72 | - if (!$classNames) { |
|
| 72 | + if ( ! $classNames) { |
|
| 73 | 73 | throw new \Exception( |
| 74 | 74 | 'You do not have any mapped Doctrine ORM entities according to the current configuration. '. |
| 75 | 75 | 'If you have entities or mapping files you should check your mapping configuration for errors.' |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $output->writeln(sprintf("Found <info>%d</info> mapped entities:", count($classNames))); |
| 80 | 80 | |
| 81 | 81 | $tableNames = array(); |
| 82 | - foreach($classNames as $className) { |
|
| 82 | + foreach ($classNames as $className) { |
|
| 83 | 83 | $tableNames[$entityManager->getClassMetadata($className)->getTableName()] = $className; |
| 84 | 84 | } |
| 85 | 85 | $failure = false; |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | $keys = $schema->listTableForeignKeys($tableName); |
| 91 | 91 | $output->writeln('<info>'.$className.'('.$tableName.')'.'</info> '.count($keys).' foreign key(s)'); |
| 92 | 92 | $assoc = $entityManager->getClassMetadata($className)->getAssociationMappings(); |
| 93 | - foreach($assoc as $a) { |
|
| 94 | - if(array_key_exists('sourceToTargetKeyColumns', $a)) { |
|
| 93 | + foreach ($assoc as $a) { |
|
| 94 | + if (array_key_exists('sourceToTargetKeyColumns', $a)) { |
|
| 95 | 95 | $output->writeln('-> Entity: '.$a['targetEntity'].'('.array_search($a['targetEntity'], $tableNames).')'); |
| 96 | 96 | $sourceFields = array(); |
| 97 | 97 | $sourceColumns = array(); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | $targetFields = array(); |
| 104 | 104 | $targetColumns = array(); |
| 105 | - foreach($a['sourceToTargetKeyColumns'] as $fcolumn => $ffield) { |
|
| 105 | + foreach ($a['sourceToTargetKeyColumns'] as $fcolumn => $ffield) { |
|
| 106 | 106 | $output->writeln("\t\tForeign key: $ffield($fcolumn)"); |
| 107 | 107 | $targetFields[] = $ffield; |
| 108 | 108 | $targetColumns[] = $fcolumn; |
@@ -132,13 +132,13 @@ discard block |
||
| 132 | 132 | try { |
| 133 | 133 | $query = $entityManager->createQuery($dql); |
| 134 | 134 | $ret = $query->getResult(); |
| 135 | - } catch(QueryException $e) { |
|
| 135 | + } catch (QueryException $e) { |
|
| 136 | 136 | $output->writeln("<error>Data model too complex to analyze.</error>"); |
| 137 | 137 | return; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - foreach($ret as $key) { |
|
| 141 | - if($key == null) { |
|
| 140 | + foreach ($ret as $key) { |
|
| 141 | + if ($key == null) { |
|
| 142 | 142 | continue; |
| 143 | 143 | } |
| 144 | 144 | $output->writeln("\t".$entity['targetEntity'].' id with missing reference '.$key->getId()); |
@@ -146,20 +146,20 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | private function with($entity) { |
| 149 | - if(count($entity['joinColumns']) == 1 || true) { |
|
| 149 | + if (count($entity['joinColumns']) == 1 || true) { |
|
| 150 | 150 | return "\n WITH _inner.".$entity['fieldName']." = _outer"; |
| 151 | 151 | } |
| 152 | 152 | $ret = "\n WITH "; |
| 153 | - foreach($entity['joinColumns'] as $column) { |
|
| 153 | + foreach ($entity['joinColumns'] as $column) { |
|
| 154 | 154 | $ret .= "_inner.".$column['name']." = _outer.".$column['referencedColumnName']."\n AND "; |
| 155 | 155 | } |
| 156 | 156 | return substr($ret, 0, strlen($ret) - 6); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | private function where($entity) { |
| 160 | - if(count($entity['joinColumns']) != 0) { |
|
| 160 | + if (count($entity['joinColumns']) != 0) { |
|
| 161 | 161 | $ret = "\n WHERE "; |
| 162 | - foreach($entity['joinColumns'] as $column) { |
|
| 162 | + foreach ($entity['joinColumns'] as $column) { |
|
| 163 | 163 | $ret .= "_outer.".$column['referencedColumnName']." IS NULL\n AND "; |
| 164 | 164 | } |
| 165 | 165 | return substr($ret, 0, strlen($ret) - 6); |