Completed
Push — master ( d8871c...3e8b02 )
by Florian
02:26
created
Command/SyncCommand.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -69,15 +69,15 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	protected function execute(InputInterface $input, OutputInterface $output) {
71 71
 		// Detect upload path
72
-		if(!self::$defaultUploadPath) {
72
+		if (!self::$defaultUploadPath) {
73 73
 			$root = $this->getContainer()->get('kernel')->getRootDir();
74
-			self::$defaultUploadPath = $root . '/../web/uploads';
74
+			self::$defaultUploadPath = $root.'/../web/uploads';
75 75
 		}
76 76
 
77 77
 		// Get the entity argument
78 78
 		$entity = $input->getArgument('entity');
79 79
 
80
-		if($entity == 'all') {
80
+		if ($entity == 'all') {
81 81
 			/**
82 82
 			 * @var EntityManager $entityManager
83 83
 			 */
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
 			/**
94 94
 			 * @var ClassMetadata $m
95 95
 			 */
96
-			foreach($meta as $m) {
96
+			foreach ($meta as $m) {
97 97
 
98
-				if($m->getReflectionClass()->isAbstract() || $m->getReflectionClass()->isInterface()) {
98
+				if ($m->getReflectionClass()->isAbstract() || $m->getReflectionClass()->isInterface()) {
99 99
 					continue;
100 100
 				}
101
-				if(!$mapper->isClassIndexable($m->getReflectionClass()->getName())) {
101
+				if (!$mapper->isClassIndexable($m->getReflectionClass()->getName())) {
102 102
 					continue;
103 103
 				}
104 104
 				$this->indexEntity($input, $output, $m->getReflectionClass()->getName());
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 		try {
120 120
 			// Get repository for the given entity type
121 121
 			$repository = $entityManager->getRepository($entity);
122
-		} catch(\Exception $e) {
122
+		} catch (\Exception $e) {
123 123
 			$output->writeln(sprintf('<error>No repository found for "%s", check your input</error>', $entity));
124 124
 			return;
125 125
 		}
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		$useBatch = !($entityManager->getConnection()->getDatabasePlatform() instanceof SQLServerPlatform);
133 133
 
134 134
 		$iterableResult = $useBatch ? $queryBuilder->getQuery()->iterate() : $queryBuilder->getQuery()->getResult();
135
-		if($entityCount == 0) {
135
+		if ($entityCount == 0) {
136 136
 			$output->writeln('<comment>No entities found for indexing</comment>');
137 137
 			return;
138 138
 		}
@@ -140,18 +140,18 @@  discard block
 block discarded – undo
140 140
 		$entitiesIndexed = 0;
141 141
 
142 142
 		// Index each entity separate
143
-		foreach($iterableResult as $row) {
143
+		foreach ($iterableResult as $row) {
144 144
 			$entity = $useBatch ? $row[0] : $row;
145
-			if($this->getEntityToDocumentMapper()->isIndexable($entity)) {
145
+			if ($this->getEntityToDocumentMapper()->isIndexable($entity)) {
146 146
 				$document = $this->getEntityToDocumentMapper()->createDocument($entityManager, $entity);
147
-				if($document === false) continue;
147
+				if ($document === false) continue;
148 148
 				try {
149 149
 					$this->getSearchService($entityManager)->saveDocument($document);
150 150
 					$entitiesIndexed++;
151
-				} catch(\Exception $e) {
152
-					$output->writeln('<error>Failed to index entity with ID ' . $document->getEntityId() . '</error>');
151
+				} catch (\Exception $e) {
152
+					$output->writeln('<error>Failed to index entity with ID '.$document->getEntityId().'</error>');
153 153
 				}
154
-				if($entitiesIndexed % 50 == 0) {
154
+				if ($entitiesIndexed % 50 == 0) {
155 155
 					$entityManager->flush();
156 156
 				}
157 157
 			}
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 		}
160 160
 		$entityManager->flush();
161 161
 		$entityManager->clear();
162
-		$output->writeln('<comment>Indexed ' . $entitiesIndexed . ' entities</comment>');
162
+		$output->writeln('<comment>Indexed '.$entitiesIndexed.' entities</comment>');
163 163
 	}
164 164
 
165 165
 	/**
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 * @return EntityToDocumentMapperInterface
168 168
 	 */
169 169
 	protected function getEntityToDocumentMapper() {
170
-		if(!$this->entityToDocumentMapper) {
170
+		if (!$this->entityToDocumentMapper) {
171 171
 			$this->entityToDocumentMapper = $this->getContainer()->get(EntityToDocumentMapperInterface::SERVICE_ID);
172 172
 		}
173 173
 		return $this->entityToDocumentMapper;
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 * @return SearchService
179 179
 	 */
180 180
 	protected function getSearchService(ObjectManager $manager) {
181
-		if(!$this->searchService) {
181
+		if (!$this->searchService) {
182 182
 			$this->searchService = $this->getContainer()->get(SearchService::SERVICE_ID);
183 183
 		}
184 184
 		$this->searchService->setObjectManager($manager);
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -144,7 +144,9 @@
 block discarded – undo
144 144
 			$entity = $useBatch ? $row[0] : $row;
145 145
 			if($this->getEntityToDocumentMapper()->isIndexable($entity)) {
146 146
 				$document = $this->getEntityToDocumentMapper()->createDocument($entityManager, $entity);
147
-				if($document === false) continue;
147
+				if($document === false) {
148
+					continue;
149
+				}
148 150
 				try {
149 151
 					$this->getSearchService($entityManager)->saveDocument($document);
150 152
 					$entitiesIndexed++;
Please login to merge, or discard this patch.