@@ -25,7 +25,7 @@ |
||
25 | 25 | * any deleted datatyes |
26 | 26 | * @return an array data types |
27 | 27 | */ |
28 | - public function listDataTypes($includeDeleted=false); |
|
28 | + public function listDataTypes($includeDeleted = false); |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Create a datatype. |
@@ -17,5 +17,5 @@ |
||
17 | 17 | * does and has been deleted. |
18 | 18 | * @return mixed |
19 | 19 | */ |
20 | - public function addObjectDeletionChecksOnJoin(\yii\db\Query $query, $tables, $join='innerJoin'); |
|
20 | + public function addObjectDeletionChecksOnJoin(\yii\db\Query $query, $tables, $join = 'innerJoin'); |
|
21 | 21 | } |
22 | 22 | \ No newline at end of file |
@@ -45,7 +45,7 @@ |
||
45 | 45 | $this->addDateColumn('when')->setWidth("10em"); |
46 | 46 | |
47 | 47 | $this->addButtonColumn('View') |
48 | - ->addButton('view', ['/daedalus/change-log/view-object' , 'uuid' => '{{object_uuid}}', 'logUuid' => '{{log_uuid}}'], '', 'fa fa-eye', '', ['data-toggle' => 'tooltip', 'title'=>'View Object']); |
|
48 | + ->addButton('view', ['/daedalus/change-log/view-object', 'uuid' => '{{object_uuid}}', 'logUuid' => '{{log_uuid}}'], '', 'fa fa-eye', '', ['data-toggle' => 'tooltip', 'title'=>'View Object']); |
|
49 | 49 | |
50 | 50 | $this->setPageSize(100); |
51 | 51 | } |
@@ -23,19 +23,23 @@ |
||
23 | 23 | { |
24 | 24 | $this->query = (new \yii\db\Query()) |
25 | 25 | ->from('{{dds_change_log}}'); |
26 | - if ($this->classType) |
|
27 | - $this->query->where(['class_type'=>$this->classType]); |
|
28 | - if ($this->objectUuid) |
|
29 | - $this->query->andWhere(['object_uuid'=>$this->objectUuid]); |
|
26 | + if ($this->classType) { |
|
27 | + $this->query->where(['class_type'=>$this->classType]); |
|
28 | + } |
|
29 | + if ($this->objectUuid) { |
|
30 | + $this->query->andWhere(['object_uuid'=>$this->objectUuid]); |
|
31 | + } |
|
30 | 32 | $this->query->orderBy(['when'=>SORT_DESC, 'log_id'=>SORT_DESC]); |
31 | 33 | |
32 | - if (!$this->classType) |
|
33 | - $this->title = 'Full Change Log'; |
|
34 | - else |
|
35 | - $this->title = 'Change Log for class '.$this->classType; |
|
34 | + if (!$this->classType) { |
|
35 | + $this->title = 'Full Change Log'; |
|
36 | + } else { |
|
37 | + $this->title = 'Change Log for class '.$this->classType; |
|
38 | + } |
|
36 | 39 | |
37 | - if ($this->objectUuid) |
|
38 | - $this->title .= " and object '$this->objectUuid'"; |
|
40 | + if ($this->objectUuid) { |
|
41 | + $this->title .= " and object '$this->objectUuid'"; |
|
42 | + } |
|
39 | 43 | |
40 | 44 | $this->addTextColumn('log_uuid')->setWidth("10em"); |
41 | 45 | $this->addTextColumn('object_uuid')->setWidth("10em"); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | public function hasChangeLog($classType) |
47 | 47 | { |
48 | 48 | if ($this->findClass($classType, $class)) { |
49 | - return (boolean)$class->hasChangeLog(); |
|
49 | + return (boolean) $class->hasChangeLog(); |
|
50 | 50 | } |
51 | 51 | return false; |
52 | 52 | } |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function setChangeLog($classType, $to) |
58 | 58 | { |
59 | - $to = (boolean)$to; |
|
59 | + $to = (boolean) $to; |
|
60 | 60 | if ($this->findClass($classType, $class)) { |
61 | - $hasChangeLog = (boolean)$class->hasChangeLog(); |
|
61 | + $hasChangeLog = (boolean) $class->hasChangeLog(); |
|
62 | 62 | // only change if different to current |
63 | 63 | if ($hasChangeLog !== $to) { |
64 | 64 | neon('dds')->IDdsClassManagement->editClass($classType, ['change_log'=>$to]); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'log_uuid' => Hash::uuid64(), |
73 | 73 | 'class_type' => $class['class_type'], |
74 | 74 | 'change_key' => 'COMMENT', |
75 | - 'description' => sprintf($description, ($to?'ON':'OFF')), |
|
75 | + 'description' => sprintf($description, ($to ? 'ON' : 'OFF')), |
|
76 | 76 | 'who' => $whoUid, |
77 | 77 | 'when' => date('Y-m-d H:i:s'), |
78 | 78 | ])->execute(); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | /** |
85 | 85 | * @inheritdoc |
86 | 86 | */ |
87 | - public function listChangeLog($fromDate=null, Iterator $iterator=null) |
|
87 | + public function listChangeLog($fromDate = null, Iterator $iterator = null) |
|
88 | 88 | { |
89 | 89 | return $this->getChangeLog($fromDate, $iterator, null); |
90 | 90 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * @inheritdoc |
94 | 94 | */ |
95 | - public function listObjectChangeLog($uuid, $fromDate=null, Iterator $iterator=null) |
|
95 | + public function listObjectChangeLog($uuid, $fromDate = null, Iterator $iterator = null) |
|
96 | 96 | { |
97 | 97 | return $this->getChangeLog($fromDate, $iterator, $uuid); |
98 | 98 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | /** |
101 | 101 | * @inheritdoc |
102 | 102 | */ |
103 | - public function listObjectHistory($uuid, $fromDate=null, Iterator $iterator=null) |
|
103 | + public function listObjectHistory($uuid, $fromDate = null, Iterator $iterator = null) |
|
104 | 104 | { |
105 | 105 | $changeLog = $this->getChangeLog($fromDate, $iterator, $uuid); |
106 | 106 | return $this->convertChangeLogToHistory($uuid, $changeLog); |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * @inheritdoc |
111 | 111 | */ |
112 | - public function clearChangeLog($toDate, $classList=[], $clearClassList=true) |
|
112 | + public function clearChangeLog($toDate, $classList = [], $clearClassList = true) |
|
113 | 113 | { |
114 | 114 | $deleteConditions = '[[when]] <= :toDate'; |
115 | - $bindValues = [ ':toDate'=>$toDate ]; |
|
115 | + $bindValues = [':toDate'=>$toDate]; |
|
116 | 116 | if (!empty($classList)) { |
117 | 117 | $clearClause = ($clearClassList ? '' : '!'); |
118 | 118 | $deleteConditions .= " AND $clearClause([[class_type]]=:".implode(" OR [[class_type]]=:", $classList).")"; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | public function clearObjectChangeLog($uuid, $toDate) |
133 | 133 | { |
134 | 134 | $deleteConditions = '[[when]] <= :toDate AND [[object_uuid]] = :uuid'; |
135 | - $bindValues = [ ':toDate'=>$toDate, ':uuid' => $uuid ]; |
|
135 | + $bindValues = [':toDate'=>$toDate, ':uuid' => $uuid]; |
|
136 | 136 | neon()->db->createCommand() |
137 | 137 | ->delete('{{dds_change_log}}', $deleteConditions) |
138 | 138 | ->bindValues($bindValues) |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | /** |
143 | 143 | * @inheritdoc |
144 | 144 | */ |
145 | - public function addLogEntry($objectUuid, $class, $changeKey, $before=[], $after=[]) |
|
145 | + public function addLogEntry($objectUuid, $class, $changeKey, $before = [], $after = []) |
|
146 | 146 | { |
147 | 147 | if (!in_array($changeKey, $this->changeLogEntryActions)) |
148 | 148 | throw new \InvalidArgumentException('Invalid change key in addLogEntry. Allowed values are ['.implode(', ', $this->changeLogEntryActions)); |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | /** |
250 | 250 | * @inheritdoc |
251 | 251 | */ |
252 | - public function addGeneralComment($module, $classType, $comment, $objectUuid=null, array $associateObjectUuids=[]) |
|
252 | + public function addGeneralComment($module, $classType, $comment, $objectUuid = null, array $associateObjectUuids = []) |
|
253 | 253 | { |
254 | 254 | // check we can make a comment |
255 | 255 | if (empty($comment)) |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | * @throws \RuntimeException if the restore point could not be reached |
349 | 349 | * using a sensible number of change log points (<=1000). |
350 | 350 | */ |
351 | - private function getChangeLog($fromDate, $iterator, $objectUuid, $logId=null) |
|
351 | + private function getChangeLog($fromDate, $iterator, $objectUuid, $logId = null) |
|
352 | 352 | { |
353 | 353 | $fromDate = ($fromDate === null ? date('Y-m-d 00:00:00') : $fromDate); |
354 | 354 | $iterator = ($iterator === null ? new Iterator : $iterator); |
@@ -398,9 +398,9 @@ discard block |
||
398 | 398 | */ |
399 | 399 | private function convertFromDb(&$entry) |
400 | 400 | { |
401 | - $entry['before'] = json_decode($entry['before'],true); |
|
402 | - $entry['after'] = json_decode($entry['after'],true); |
|
403 | - $entry['associated_objects'] = json_decode($entry['associated_objects'],true); |
|
401 | + $entry['before'] = json_decode($entry['before'], true); |
|
402 | + $entry['after'] = json_decode($entry['after'], true); |
|
403 | + $entry['associated_objects'] = json_decode($entry['associated_objects'], true); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | * @param array &$currentObject the value of the current object |
413 | 413 | * @return array a history log |
414 | 414 | */ |
415 | - private function convertChangeLogToHistory($uuid, $log, &$currentObject=[]) |
|
415 | + private function convertChangeLogToHistory($uuid, $log, &$currentObject = []) |
|
416 | 416 | { |
417 | 417 | // get the current object and work backwards from there to get history |
418 | 418 | // first see if we can the object and if not check that the last action |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | } |
550 | 550 | $before = $beforeChangedFields; |
551 | 551 | $after = $afterChangedFields; |
552 | - return count($after)>0; |
|
552 | + return count($after) > 0; |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | */ |
609 | 609 | private function isEquivalentBoolean($before, $after) |
610 | 610 | { |
611 | - return (is_bool($before) && (bool)($after) == $before); |
|
611 | + return (is_bool($before) && (bool) ($after) == $before); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | /** |
@@ -621,8 +621,8 @@ discard block |
||
621 | 621 | */ |
622 | 622 | private function isEquivalentNull($before, $after) |
623 | 623 | { |
624 | - if ($before === null || $before === '' || (is_array($before) && count($before)==0)) |
|
625 | - return ($after === null || $after === '' || (is_array($after) && count($after)==0)); |
|
624 | + if ($before === null || $before === '' || (is_array($before) && count($before) == 0)) |
|
625 | + return ($after === null || $after === '' || (is_array($after) && count($after) == 0)); |
|
626 | 626 | return false; |
627 | 627 | } |
628 | 628 |
@@ -144,14 +144,16 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function addLogEntry($objectUuid, $class, $changeKey, $before=[], $after=[]) |
146 | 146 | { |
147 | - if (!in_array($changeKey, $this->changeLogEntryActions)) |
|
148 | - throw new \InvalidArgumentException('Invalid change key in addLogEntry. Allowed values are ['.implode(', ', $this->changeLogEntryActions)); |
|
147 | + if (!in_array($changeKey, $this->changeLogEntryActions)) { |
|
148 | + throw new \InvalidArgumentException('Invalid change key in addLogEntry. Allowed values are ['.implode(', ', $this->changeLogEntryActions)); |
|
149 | + } |
|
149 | 150 | |
150 | 151 | $class = $this->getClass($class); |
151 | 152 | |
152 | 153 | // check the class does have a change log |
153 | - if (!$class['change_log']) |
|
154 | - return; |
|
154 | + if (!$class['change_log']) { |
|
155 | + return; |
|
156 | + } |
|
155 | 157 | |
156 | 158 | // get who this was |
157 | 159 | $whoUid = $name = null; |
@@ -167,8 +169,9 @@ discard block |
||
167 | 169 | break; |
168 | 170 | case 'EDIT': |
169 | 171 | $changeCount = $this->calculateMinimumFieldsChangedDuringEdit($before, $after); |
170 | - if ($changeCount == 0) |
|
171 | - return; |
|
172 | + if ($changeCount == 0) { |
|
173 | + return; |
|
174 | + } |
|
172 | 175 | $description = sprintf($baseDescription, 'edited an') |
173 | 176 | ." The fields changed were ['".implode("', '", array_keys($after))."']."; |
174 | 177 | break; |
@@ -213,8 +216,9 @@ discard block |
||
213 | 216 | $entry = neon()->db->createCommand("SELECT * FROM {{dds_change_log}} WHERE [[log_uuid]] = :logUuid") |
214 | 217 | ->bindParam(":logUuid", $logUuid) |
215 | 218 | ->queryOne(); |
216 | - if ($entry) |
|
217 | - $this->convertFromDb($entry); |
|
219 | + if ($entry) { |
|
220 | + $this->convertFromDb($entry); |
|
221 | + } |
|
218 | 222 | return $entry; |
219 | 223 | } |
220 | 224 | return null; |
@@ -227,8 +231,9 @@ discard block |
||
227 | 231 | { |
228 | 232 | // check this has a change log |
229 | 233 | $class = $this->getClassFromObject($objectUuid); |
230 | - if (empty($class) || !$class['change_log']) |
|
231 | - return; |
|
234 | + if (empty($class) || !$class['change_log']) { |
|
235 | + return; |
|
236 | + } |
|
232 | 237 | |
233 | 238 | // find out who did this |
234 | 239 | $whoUid = $name = null; |
@@ -252,8 +257,9 @@ discard block |
||
252 | 257 | public function addGeneralComment($module, $classType, $comment, $objectUuid=null, array $associateObjectUuids=[]) |
253 | 258 | { |
254 | 259 | // check we can make a comment |
255 | - if (empty($comment)) |
|
256 | - return; |
|
260 | + if (empty($comment)) { |
|
261 | + return; |
|
262 | + } |
|
257 | 263 | |
258 | 264 | // find out who did this |
259 | 265 | $whoUid = $name = null; |
@@ -280,8 +286,9 @@ discard block |
||
280 | 286 | { |
281 | 287 | $initialObject = $restorePoint = null; |
282 | 288 | $this->calculateObjectAtRestorePoint($objectUuid, $logEntryUuid, $initialObject, $restorePoint); |
283 | - if ($restorePoint) |
|
284 | - return $restorePoint['object']; |
|
289 | + if ($restorePoint) { |
|
290 | + return $restorePoint['object']; |
|
291 | + } |
|
285 | 292 | return []; |
286 | 293 | } |
287 | 294 | |
@@ -315,8 +322,9 @@ discard block |
||
315 | 322 | $dds->editObject($objectUuid, $restoreObject); |
316 | 323 | } |
317 | 324 | // and make a log entry |
318 | - if (!empty($restorePoint)) |
|
319 | - $this->addLogEntry($objectUuid, $restorePoint['class_type'], 'RESTORE', $initialObject, $restorePoint); |
|
325 | + if (!empty($restorePoint)) { |
|
326 | + $this->addLogEntry($objectUuid, $restorePoint['class_type'], 'RESTORE', $initialObject, $restorePoint); |
|
327 | + } |
|
320 | 328 | } |
321 | 329 | |
322 | 330 | |
@@ -360,8 +368,9 @@ discard block |
||
360 | 368 | ->orderBy(['log_id'=>SORT_DESC]); |
361 | 369 | |
362 | 370 | // check for a particular object if required |
363 | - if ($objectUuid) |
|
364 | - $query->andWhere(['object_uuid'=>$objectUuid]); |
|
371 | + if ($objectUuid) { |
|
372 | + $query->andWhere(['object_uuid'=>$objectUuid]); |
|
373 | + } |
|
365 | 374 | |
366 | 375 | // start from a particular log id point |
367 | 376 | if ($logId) { |
@@ -373,8 +382,9 @@ discard block |
||
373 | 382 | // and check sensible limits |
374 | 383 | $query->limit($iterator->length) |
375 | 384 | ->offset($iterator->start); |
376 | - if ($iterator->shouldReturnTotal()) |
|
377 | - $iterator->total = $query->count(); |
|
385 | + if ($iterator->shouldReturnTotal()) { |
|
386 | + $iterator->total = $query->count(); |
|
387 | + } |
|
378 | 388 | |
379 | 389 | $changeLog = $query->all(); |
380 | 390 | |
@@ -421,8 +431,9 @@ discard block |
||
421 | 431 | $lastAction = $this->getLastActionFromLog($log); |
422 | 432 | if ($currentObject == null) { |
423 | 433 | $currentObject = []; |
424 | - if (!($lastAction == 'DESTROY' || $lastAction == 'RESTORE')) |
|
425 | - return []; |
|
434 | + if (!($lastAction == 'DESTROY' || $lastAction == 'RESTORE')) { |
|
435 | + return []; |
|
436 | + } |
|
426 | 437 | } |
427 | 438 | $object = $currentObject; |
428 | 439 | $objectHistory = []; |
@@ -456,8 +467,9 @@ discard block |
||
456 | 467 | private function getLastActionFromLog($log) |
457 | 468 | { |
458 | 469 | foreach ($log as $l) { |
459 | - if (!in_array($l['change_key'], $this->changeLogEntryActions)) |
|
460 | - continue; |
|
470 | + if (!in_array($l['change_key'], $this->changeLogEntryActions)) { |
|
471 | + continue; |
|
472 | + } |
|
461 | 473 | return $l['change_key']; |
462 | 474 | } |
463 | 475 | return null; |
@@ -500,17 +512,20 @@ discard block |
||
500 | 512 | static $ddc = null; |
501 | 513 | |
502 | 514 | // see if this is already an array in which case no need to look up |
503 | - if (is_array($class)) |
|
504 | - return $class; |
|
515 | + if (is_array($class)) { |
|
516 | + return $class; |
|
517 | + } |
|
505 | 518 | |
506 | 519 | // otherwise check this is a string for a class type |
507 | - if (!is_string($class)) |
|
508 | - throw new \InvalidArgumentException("Invalid type of class passed in. Should be either a string or an array. Type passed in was ".gettype($class)); |
|
520 | + if (!is_string($class)) { |
|
521 | + throw new \InvalidArgumentException("Invalid type of class passed in. Should be either a string or an array. Type passed in was ".gettype($class)); |
|
522 | + } |
|
509 | 523 | |
510 | 524 | // and get hold of the class |
511 | 525 | if (!isset($classes[$class])) { |
512 | - if (empty($ddc)) |
|
513 | - $ddc = neon('dds')->IDdsClassManagement; |
|
526 | + if (empty($ddc)) { |
|
527 | + $ddc = neon('dds')->IDdsClassManagement; |
|
528 | + } |
|
514 | 529 | $classes[$class] = $ddc->getClass($class); |
515 | 530 | } |
516 | 531 | return $classes[$class]; |
@@ -537,8 +552,9 @@ discard block |
||
537 | 552 | if (array_key_exists($k, $before)) { |
538 | 553 | $b = $before[$k]; |
539 | 554 | // check for a few expected changes that aren't actual changes |
540 | - if ($this->isEquivalentNull($b, $v) || $this->isEquivalentBoolean($b, $v) || $this->isEquivalentChoice($b, $v)) |
|
541 | - continue; |
|
555 | + if ($this->isEquivalentNull($b, $v) || $this->isEquivalentBoolean($b, $v) || $this->isEquivalentChoice($b, $v)) { |
|
556 | + continue; |
|
557 | + } |
|
542 | 558 | if ($v !== $before[$k]) { |
543 | 559 | $beforeChangedFields[$k] = $b; |
544 | 560 | $afterChangedFields[$k] = $v; |
@@ -566,10 +582,12 @@ discard block |
||
566 | 582 | $restorePoint = neon()->db->createCommand("SELECT * FROM dds_change_log WHERE log_uuid = :log_uuid") |
567 | 583 | ->bindValue(':log_uuid', $logEntryUuid) |
568 | 584 | ->queryOne(); |
569 | - if (!$restorePoint) |
|
570 | - throw new \InvalidArgumentException("The requested log point ($logEntryUuid) doesn't exist."); |
|
571 | - if ($objectUuid != $restorePoint['object_uuid']) |
|
572 | - throw new \InvalidArgumentException("The requested object ($objectUuid) and the object at the log point ($logEntryUuid) don't match"); |
|
585 | + if (!$restorePoint) { |
|
586 | + throw new \InvalidArgumentException("The requested log point ($logEntryUuid) doesn't exist."); |
|
587 | + } |
|
588 | + if ($objectUuid != $restorePoint['object_uuid']) { |
|
589 | + throw new \InvalidArgumentException("The requested object ($objectUuid) and the object at the log point ($logEntryUuid) don't match"); |
|
590 | + } |
|
573 | 591 | |
574 | 592 | $initialObject = null; |
575 | 593 | $changeLog = $this->getChangeLog($restorePoint['when'], null, $objectUuid, $restorePoint['log_id']); |
@@ -621,8 +639,9 @@ discard block |
||
621 | 639 | */ |
622 | 640 | private function isEquivalentNull($before, $after) |
623 | 641 | { |
624 | - if ($before === null || $before === '' || (is_array($before) && count($before)==0)) |
|
625 | - return ($after === null || $after === '' || (is_array($after) && count($after)==0)); |
|
642 | + if ($before === null || $before === '' || (is_array($before) && count($before)==0)) { |
|
643 | + return ($after === null || $after === '' || (is_array($after) && count($after)==0)); |
|
644 | + } |
|
626 | 645 | return false; |
627 | 646 | } |
628 | 647 |
@@ -18,8 +18,9 @@ |
||
18 | 18 | */ |
19 | 19 | public static function createMigrator($path) |
20 | 20 | { |
21 | - if (self::$migrator == null) |
|
22 | - self::$migrator = new DdsAppMigrator($path); |
|
21 | + if (self::$migrator == null) { |
|
22 | + self::$migrator = new DdsAppMigrator($path); |
|
23 | + } |
|
23 | 24 | return self::$migrator; |
24 | 25 | } |
25 | 26 |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | /** |
128 | 128 | * @inheritdoc |
129 | 129 | */ |
130 | - public function closeMigrationFile($delete=false) |
|
130 | + public function closeMigrationFile($delete = false) |
|
131 | 131 | { |
132 | 132 | if (!$this->_file) |
133 | 133 | return; |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | // create a migration file |
180 | 180 | $templateFile = __DIR__.'/templates/ddsMigration.php'; |
181 | 181 | $input = file_get_contents($templateFile); |
182 | - $output = str_replace('__MIGRATION__',$this->_classname,$input); |
|
182 | + $output = str_replace('__MIGRATION__', $this->_classname, $input); |
|
183 | 183 | file_put_contents($this->_file, $output, LOCK_EX); |
184 | 184 | return $this->_filename; |
185 | 185 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | return; |
196 | 196 | if (!$this->_file) |
197 | 197 | throw new \RuntimeException('Attempting to store migrations without first opening a migration file'); |
198 | - $migrations = is_array($migration) ? $migration : [ $migration ]; |
|
198 | + $migrations = is_array($migration) ? $migration : [$migration]; |
|
199 | 199 | foreach ($migrations as $m) |
200 | 200 | $this->saveToFile($this->_classname."::addMigration('$direction', \"$m\");"); |
201 | 201 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | private function fixMigration($migration) |
245 | 245 | { |
246 | 246 | // get the number of backslashed backslashes correct for migration file |
247 | - return str_replace('\\\\','\\\\\\\\',$migration); |
|
247 | + return str_replace('\\\\', '\\\\\\\\', $migration); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | */ |
253 | 253 | private function prepareMigration($migration) |
254 | 254 | { |
255 | - $migrations = is_array($migration) ? $migration : [ $migration ]; |
|
255 | + $migrations = is_array($migration) ? $migration : [$migration]; |
|
256 | 256 | $prepared = []; |
257 | 257 | foreach ($migrations as $m) |
258 | 258 | $prepared[] = $this->fixMigration($m); |
@@ -93,8 +93,9 @@ discard block |
||
93 | 93 | mkdir($this->_path, 0755, true); |
94 | 94 | } |
95 | 95 | |
96 | - if (!empty($this->_file)) |
|
97 | - throw new \RuntimeException('Migration Open: You cannot open a new migration without first closing the previous one'); |
|
96 | + if (!empty($this->_file)) { |
|
97 | + throw new \RuntimeException('Migration Open: You cannot open a new migration without first closing the previous one'); |
|
98 | + } |
|
98 | 99 | |
99 | 100 | // clear any migrations that may have been created just in case they were needed |
100 | 101 | $this->clearMigrations(); |
@@ -129,8 +130,9 @@ discard block |
||
129 | 130 | */ |
130 | 131 | public function closeMigrationFile($delete=false) |
131 | 132 | { |
132 | - if (!$this->_file) |
|
133 | - return; |
|
133 | + if (!$this->_file) { |
|
134 | + return; |
|
135 | + } |
|
134 | 136 | if ($delete || !$this->_hasMigrations) { |
135 | 137 | $this->deleteMigration(); |
136 | 138 | return; |
@@ -149,8 +151,9 @@ discard block |
||
149 | 151 | // save the down migrations |
150 | 152 | $this->saveToFile(PHP_EOL.PHP_EOL."//".PHP_EOL."// Down Migrations".PHP_EOL."//"); |
151 | 153 | $this->saveMigration('down', $foreignKeysOff); |
152 | - foreach (array_reverse($this->_downMigrations) as $down) |
|
153 | - $this->saveMigration('down', $down); |
|
154 | + foreach (array_reverse($this->_downMigrations) as $down) { |
|
155 | + $this->saveMigration('down', $down); |
|
156 | + } |
|
154 | 157 | $this->saveMigration('down', $foreignKeysOn); |
155 | 158 | |
156 | 159 | // save this migration in the current users migration table |
@@ -191,13 +194,16 @@ discard block |
||
191 | 194 | */ |
192 | 195 | protected function saveMigration($direction, $migration) |
193 | 196 | { |
194 | - if (empty($migration)) |
|
195 | - return; |
|
196 | - if (!$this->_file) |
|
197 | - throw new \RuntimeException('Attempting to store migrations without first opening a migration file'); |
|
197 | + if (empty($migration)) { |
|
198 | + return; |
|
199 | + } |
|
200 | + if (!$this->_file) { |
|
201 | + throw new \RuntimeException('Attempting to store migrations without first opening a migration file'); |
|
202 | + } |
|
198 | 203 | $migrations = is_array($migration) ? $migration : [ $migration ]; |
199 | - foreach ($migrations as $m) |
|
200 | - $this->saveToFile($this->_classname."::addMigration('$direction', \"$m\");"); |
|
204 | + foreach ($migrations as $m) { |
|
205 | + $this->saveToFile($this->_classname."::addMigration('$direction', \"$m\");"); |
|
206 | + } |
|
201 | 207 | } |
202 | 208 | |
203 | 209 | protected function saveToFile($message) |
@@ -210,8 +216,9 @@ discard block |
||
210 | 216 | */ |
211 | 217 | private function deleteMigration() |
212 | 218 | { |
213 | - if ($this->_file && file_exists($this->_file)) |
|
214 | - unlink($this->_file); |
|
219 | + if ($this->_file && file_exists($this->_file)) { |
|
220 | + unlink($this->_file); |
|
221 | + } |
|
215 | 222 | } |
216 | 223 | |
217 | 224 | /** |
@@ -254,8 +261,9 @@ discard block |
||
254 | 261 | { |
255 | 262 | $migrations = is_array($migration) ? $migration : [ $migration ]; |
256 | 263 | $prepared = []; |
257 | - foreach ($migrations as $m) |
|
258 | - $prepared[] = $this->fixMigration($m); |
|
264 | + foreach ($migrations as $m) { |
|
265 | + $prepared[] = $this->fixMigration($m); |
|
266 | + } |
|
259 | 267 | return $prepared; |
260 | 268 | } |
261 | 269 | } |
262 | 270 | \ No newline at end of file |
@@ -25,7 +25,7 @@ |
||
25 | 25 | |
26 | 26 | public static function addMigration($direction, $migration) |
27 | 27 | { |
28 | - switch($direction) { |
|
28 | + switch ($direction) { |
|
29 | 29 | case 'up': |
30 | 30 | self::$upMigrations[] = $migration; |
31 | 31 | break; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * requests to the database within one call |
23 | 23 | * @var array |
24 | 24 | */ |
25 | - private static $_mapResultsCache=[]; |
|
25 | + private static $_mapResultsCache = []; |
|
26 | 26 | /** |
27 | 27 | * The set of map requests |
28 | 28 | * An array with the requests and the maximum number in the chain |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | /** |
46 | 46 | * @inheritdoc |
47 | 47 | */ |
48 | - public function getObjectMap($classType, $filters=[], $fields=[], $start=0, $length=1000, $includeDeleted=false) |
|
48 | + public function getObjectMap($classType, $filters = [], $fields = [], $start = 0, $length = 1000, $includeDeleted = false) |
|
49 | 49 | { |
50 | 50 | if (!$classType) |
51 | 51 | throw new \InvalidArgumentException("Invalid classType '$classType' in getObjectMap. Correct calling code"); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $cacheKey = md5(serialize(func_get_args())); |
54 | 54 | if (empty(self::$_mapResultsCache[$cacheKey])) { |
55 | 55 | try { |
56 | - $limit = ['start' => max(0, (integer)$start), 'length' => min(1000, (integer)$length)]; |
|
56 | + $limit = ['start' => max(0, (integer) $start), 'length' => min(1000, (integer) $length)]; |
|
57 | 57 | $classType = $this->canonicaliseRef($classType); |
58 | 58 | $fieldsClause = ''; |
59 | 59 | $linkJoins = []; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $filterClause = ''; |
110 | 110 | $filterValues = []; |
111 | 111 | if ($filters) { |
112 | - $ddsObjectFields = ['_uuid','_created','_deleted','_updated']; |
|
112 | + $ddsObjectFields = ['_uuid', '_created', '_deleted', '_updated']; |
|
113 | 113 | // whitelist filter keys to prevent sql injection |
114 | 114 | $members = $this->getClassMembers($classType); |
115 | 115 | $filterSubClause = []; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $filterValues[":$field$vcount"] = $v; |
132 | 132 | $vcount++; |
133 | 133 | } |
134 | - $inClause = implode(',',$inClause); |
|
134 | + $inClause = implode(',', $inClause); |
|
135 | 135 | if (!empty($members[$field]) && $members[$field]['data_type_ref'] == 'link_multi') { |
136 | 136 | $linkName = "link$field"; |
137 | 137 | if (!isset($linkJoins[$linkName])) |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | $filterSubClause[] = "AND $keyClause IN ($inClause)"; |
142 | 142 | } |
143 | 143 | } |
144 | - $filterClause = implode (' ', $filterSubClause); |
|
144 | + $filterClause = implode(' ', $filterSubClause); |
|
145 | 145 | } |
146 | 146 | $linkJoinsClause = implode(' ', $linkJoins); |
147 | 147 | |
148 | - $query = "SELECT DISTINCT `o`.`_uuid`, $fieldsClause FROM `dds_object` `o` LEFT JOIN `$table` `t` ON `o`.`_uuid`=`t`.`_uuid` " . |
|
149 | - "$linkJoinsClause WHERE `o`.`_class_type` = '$classType' $filterClause $notDeleted ORDER BY $fieldsClause " . |
|
148 | + $query = "SELECT DISTINCT `o`.`_uuid`, $fieldsClause FROM `dds_object` `o` LEFT JOIN `$table` `t` ON `o`.`_uuid`=`t`.`_uuid` ". |
|
149 | + "$linkJoinsClause WHERE `o`.`_class_type` = '$classType' $filterClause $notDeleted ORDER BY $fieldsClause ". |
|
150 | 150 | "LIMIT $limit[start], $limit[length]"; |
151 | 151 | $command = neon()->db->createCommand($query); |
152 | 152 | if ($filters) |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | unset($r['_uuid']); |
159 | 159 | |
160 | 160 | // set the map |
161 | - $map[$uuid] = (count($fields)==1) ? current($r) : $r; |
|
161 | + $map[$uuid] = (count($fields) == 1) ? current($r) : $r; |
|
162 | 162 | } |
163 | 163 | self::$_mapResultsCache[$cacheKey] = $map; |
164 | 164 | } catch (\Exception $e) { |
165 | 165 | $errorMessage = "Exception during getting a map. This may be caused by empty filters - you cannot filter on null. ". |
166 | - "Your filters were: ".print_r($filters,true).". The error message is ".$e->getMessage(); |
|
166 | + "Your filters were: ".print_r($filters, true).". The error message is ".$e->getMessage(); |
|
167 | 167 | \Neon::error($errorMessage, 'DDS'); |
168 | 168 | debug_message($errorMessage); |
169 | 169 | return []; |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | /** |
176 | 176 | * @inheritdoc |
177 | 177 | */ |
178 | - public function makeMapLookupRequest($objectUuids, $chainMapFields=[], $classType=null) |
|
178 | + public function makeMapLookupRequest($objectUuids, $chainMapFields = [], $classType = null) |
|
179 | 179 | { |
180 | 180 | if (empty($objectUuids)) |
181 | 181 | return null; |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | foreach ($linkedMembers as $lm) { |
199 | 199 | $requestKeys[] = $this->makeMapChainLookupRequest($objectUuids, [$lm]); |
200 | 200 | } |
201 | - return implode('|',$requestKeys); |
|
201 | + return implode('|', $requestKeys); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | foreach ($partials[0] as $u=>$p) { |
218 | 218 | foreach ($p as $i=>$v) { |
219 | 219 | if ($this->isUuid($v)) { |
220 | - for ($i=1; $i<count($requestKeys); $i++) { |
|
220 | + for ($i = 1; $i < count($requestKeys); $i++) { |
|
221 | 221 | if (array_key_exists($v, $partials[$i][1])) { |
222 | 222 | $partials[0][$u][$i] = $partials[$i][1][$v]; |
223 | 223 | continue; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | /** |
234 | 234 | * @inheritdoc |
235 | 235 | */ |
236 | - public function makeMapChainLookupRequest($objectUuids, $chainMembers=[], $chainMapFields=[], $inReverse=false) |
|
236 | + public function makeMapChainLookupRequest($objectUuids, $chainMembers = [], $chainMapFields = [], $inReverse = false) |
|
237 | 237 | { |
238 | 238 | if (empty($objectUuids)) |
239 | 239 | return null; |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | $this->getMapLookupByLevel($chain); |
274 | 274 | foreach ($chain as $k=>$r) { |
275 | 275 | if ($r['next_uuid']) |
276 | - $requests['chains'][($i+1)][$k]['uuid'] = $r['next_uuid']; |
|
276 | + $requests['chains'][($i + 1)][$k]['uuid'] = $r['next_uuid']; |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | $this->convertMapRequestResults(); |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | $requestsByUuid[$r['uuid']][] = $r; |
333 | 333 | } |
334 | 334 | $objectRows = DdsObject::find() |
335 | - ->select(['_uuid','_class_type']) |
|
335 | + ->select(['_uuid', '_class_type']) |
|
336 | 336 | ->where(['_uuid'=>$endpoints]) |
337 | 337 | ->andWhere(['_deleted'=>0]) |
338 | 338 | ->asArray() |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | |
353 | 353 | // now find all the maps members for the required classes |
354 | 354 | $mapFields = DdsMember::find() |
355 | - ->select(['class_type','member_ref']) |
|
355 | + ->select(['class_type', 'member_ref']) |
|
356 | 356 | ->where(['class_type'=>$classTypes, 'deleted'=>0, 'map_field'=>1]) |
357 | 357 | ->asArray() |
358 | 358 | ->all(); |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | foreach ($objectsByClassMapsAndChain as $class => $chainMapObjects) { |
369 | 369 | foreach ($chainMapObjects as $chain => $mapObjects) { |
370 | 370 | foreach ($mapObjects as $mapField => $objectUuids) { |
371 | - $objs = "'".implode("','",$objectUuids)."'"; |
|
371 | + $objs = "'".implode("','", $objectUuids)."'"; |
|
372 | 372 | // make sure a map field can be created |
373 | 373 | $mapFieldsClause = ''; |
374 | 374 | if ($mapField === self::$_defaultMapChain) { |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | $mapFieldsClause = "CAST(`$mapsByClass[$class]` AS CHAR)"; |
378 | 378 | } else { |
379 | 379 | $mapFieldsClause = "CONCAT_WS('$hackySeparator'"; |
380 | - foreach (explode(',',$mapField) as $m) { |
|
380 | + foreach (explode(',', $mapField) as $m) { |
|
381 | 381 | $mapFieldsClause .= ",CAST(`$m` AS CHAR)"; |
382 | 382 | } |
383 | 383 | $mapFieldsClause .= ')'; |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | $mapsByChainAndUuid = []; |
403 | 403 | foreach ($maps as $m) { |
404 | 404 | if (strpos($m['map'], $hackySeparator) !== false) { |
405 | - $m['map'] = explode($hackySeparator,$m['map']); |
|
405 | + $m['map'] = explode($hackySeparator, $m['map']); |
|
406 | 406 | } |
407 | 407 | $mapsByChainAndUuid[$m['chain']][$m['mapFields']][$m['uuid']] = $m; |
408 | 408 | } |
@@ -473,14 +473,14 @@ discard block |
||
473 | 473 | $chainCount = count($chainMembers); |
474 | 474 | // split the chain up into requests per chain level if there are any |
475 | 475 | foreach ($chainMembers as $i=>$mc) { |
476 | - $mapFieldKey = ($i == 0 ? 0 : $chainMembers[$i-1]); |
|
477 | - $mapFields = !empty($chainMapFields[$mapFieldKey]) ? implode(',',$chainMapFields[$mapFieldKey]) : self::$_defaultMapChain; |
|
478 | - $requests['chains'][$i][$requestKey] = ['uuid'=>($i===0?$objectUuid:null), 'map'=>null, 'mapFields'=>$mapFields, 'chain'=>$mc, 'key'=>$requestKey]; |
|
476 | + $mapFieldKey = ($i == 0 ? 0 : $chainMembers[$i - 1]); |
|
477 | + $mapFields = !empty($chainMapFields[$mapFieldKey]) ? implode(',', $chainMapFields[$mapFieldKey]) : self::$_defaultMapChain; |
|
478 | + $requests['chains'][$i][$requestKey] = ['uuid'=>($i === 0 ? $objectUuid : null), 'map'=>null, 'mapFields'=>$mapFields, 'chain'=>$mc, 'key'=>$requestKey]; |
|
479 | 479 | } |
480 | 480 | // add a final chain for the last item |
481 | - $mapFieldKey = ($chainCount == 0 ? 0 : $chainMembers[$chainCount-1]); |
|
482 | - $mapFields = !empty($chainMapFields[$mapFieldKey]) ? implode(',',$chainMapFields[$mapFieldKey]) : self::$_defaultMapChain; |
|
483 | - $requests['chains'][$chainCount][$requestKey] = ['uuid'=>($chainCount===0?$objectUuid:null), 'map'=>null, 'mapFields'=>$mapFields, 'chain'=>'__FINAL__', 'key'=>$requestKey]; |
|
481 | + $mapFieldKey = ($chainCount == 0 ? 0 : $chainMembers[$chainCount - 1]); |
|
482 | + $mapFields = !empty($chainMapFields[$mapFieldKey]) ? implode(',', $chainMapFields[$mapFieldKey]) : self::$_defaultMapChain; |
|
483 | + $requests['chains'][$chainCount][$requestKey] = ['uuid'=>($chainCount === 0 ? $objectUuid : null), 'map'=>null, 'mapFields'=>$mapFields, 'chain'=>'__FINAL__', 'key'=>$requestKey]; |
|
484 | 484 | |
485 | 485 | // and add the requestKey so we don't calculate this again |
486 | 486 | $requests['keys'][$requestKey] = [ |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | $results = &static::$_mapResults; |
510 | 510 | |
511 | 511 | $tempResults = []; |
512 | - if (count($chains)===0) |
|
512 | + if (count($chains) === 0) |
|
513 | 513 | return; |
514 | 514 | foreach ($chains as $level => $maps) { |
515 | 515 | foreach ($maps as $key=>$map) { |
@@ -47,8 +47,9 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function getObjectMap($classType, $filters=[], $fields=[], $start=0, $length=1000, $includeDeleted=false) |
49 | 49 | { |
50 | - if (!$classType) |
|
51 | - throw new \InvalidArgumentException("Invalid classType '$classType' in getObjectMap. Correct calling code"); |
|
50 | + if (!$classType) { |
|
51 | + throw new \InvalidArgumentException("Invalid classType '$classType' in getObjectMap. Correct calling code"); |
|
52 | + } |
|
52 | 53 | |
53 | 54 | $cacheKey = md5(serialize(func_get_args())); |
54 | 55 | if (empty(self::$_mapResultsCache[$cacheKey])) { |
@@ -73,8 +74,9 @@ discard block |
||
73 | 74 | $class2Member = Arr::index($linkedMemberClasses, 'class_type'); |
74 | 75 | foreach ($linkedMembers as $lm) { |
75 | 76 | // only try to link through to tables that are within daedalus |
76 | - if (isset($class2Member[$lm['link_class']])) |
|
77 | - $field2link[$lm['member_ref']] = $class2Member[$lm['link_class']]; |
|
77 | + if (isset($class2Member[$lm['link_class']])) { |
|
78 | + $field2link[$lm['member_ref']] = $class2Member[$lm['link_class']]; |
|
79 | + } |
|
78 | 80 | } |
79 | 81 | } |
80 | 82 | foreach ($fields as $field) { |
@@ -82,9 +84,9 @@ discard block |
||
82 | 84 | $fl = $field2link[$field]; |
83 | 85 | $table = $this->getTableFromClassType($fl['class_type']); |
84 | 86 | $getFields[] = "`$table`.`$fl[member_ref]`"; |
85 | - if ($linkedMembers[$field]['data_type_ref'] == 'link_uni') |
|
86 | - $linkJoins[$table] = "LEFT JOIN `$table` ON `t`.`$field`=`$table`.`_uuid`"; |
|
87 | - else { |
|
87 | + if ($linkedMembers[$field]['data_type_ref'] == 'link_uni') { |
|
88 | + $linkJoins[$table] = "LEFT JOIN `$table` ON `t`.`$field`=`$table`.`_uuid`"; |
|
89 | + } else { |
|
88 | 90 | $linkName = 'link'.$field; |
89 | 91 | $linkJoins[$linkName] = "LEFT JOIN `dds_link` `$linkName` ON (`o`.`_uuid`=`$linkName`.`from_id` AND `$linkName`.`from_member`='$field')"; |
90 | 92 | $linkJoins[$table] = "LEFT JOIN `$table` ON `$linkName`.`to_id` =`$table`.`_uuid`"; |
@@ -96,8 +98,9 @@ discard block |
||
96 | 98 | $fieldsClause = implode(', ', $getFields); |
97 | 99 | } else { |
98 | 100 | $member = $this->getMapMemberForClass($classType); |
99 | - if (!$member) |
|
100 | - throw new \RuntimeException("There is no mappable member field set on class $classType"); |
|
101 | + if (!$member) { |
|
102 | + throw new \RuntimeException("There is no mappable member field set on class $classType"); |
|
103 | + } |
|
101 | 104 | // set this as an array for later |
102 | 105 | $fields = [$member['member_ref']]; |
103 | 106 | $fieldsClause = "`t`.`$member[member_ref]`"; |
@@ -116,12 +119,14 @@ discard block |
||
116 | 119 | foreach ($filters as $field=>$value) { |
117 | 120 | if ($field == '_map_field_') { |
118 | 121 | $mapMember = $this->getMapMemberForClass($classType); |
119 | - if ($mapMember && $value) |
|
120 | - $filterSubClause[] = "AND `t`.`$mapMember[member_ref]` LIKE '%$value%'"; |
|
122 | + if ($mapMember && $value) { |
|
123 | + $filterSubClause[] = "AND `t`.`$mapMember[member_ref]` LIKE '%$value%'"; |
|
124 | + } |
|
121 | 125 | continue; |
122 | 126 | } |
123 | - if (!(isset($members[$field]) || in_array($field, $ddsObjectFields))) |
|
124 | - continue; |
|
127 | + if (!(isset($members[$field]) || in_array($field, $ddsObjectFields))) { |
|
128 | + continue; |
|
129 | + } |
|
125 | 130 | $keyClause = (in_array($field, $ddsObjectFields)) ? "`o`.`$field`" : "`t`.`$field`"; |
126 | 131 | $value = is_array($value) ? $value : [$value]; |
127 | 132 | $vcount = 1; |
@@ -134,8 +139,9 @@ discard block |
||
134 | 139 | $inClause = implode(',',$inClause); |
135 | 140 | if (!empty($members[$field]) && $members[$field]['data_type_ref'] == 'link_multi') { |
136 | 141 | $linkName = "link$field"; |
137 | - if (!isset($linkJoins[$linkName])) |
|
138 | - $linkJoins[$linkName] = "LEFT JOIN `dds_link` `$linkName` ON (`o`.`_uuid`=`$linkName`.`from_id` AND `$linkName`.`from_member`='$field')"; |
|
142 | + if (!isset($linkJoins[$linkName])) { |
|
143 | + $linkJoins[$linkName] = "LEFT JOIN `dds_link` `$linkName` ON (`o`.`_uuid`=`$linkName`.`from_id` AND `$linkName`.`from_member`='$field')"; |
|
144 | + } |
|
139 | 145 | $filterSubClause[] = "AND `$linkName`.`to_id` IN ($inClause)"; |
140 | 146 | } else { |
141 | 147 | $filterSubClause[] = "AND $keyClause IN ($inClause)"; |
@@ -149,8 +155,9 @@ discard block |
||
149 | 155 | "$linkJoinsClause WHERE `o`.`_class_type` = '$classType' $filterClause $notDeleted ORDER BY $fieldsClause " . |
150 | 156 | "LIMIT $limit[start], $limit[length]"; |
151 | 157 | $command = neon()->db->createCommand($query); |
152 | - if ($filters) |
|
153 | - $command->bindValues($filterValues); |
|
158 | + if ($filters) { |
|
159 | + $command->bindValues($filterValues); |
|
160 | + } |
|
154 | 161 | $rows = $command->queryAll(); |
155 | 162 | foreach ($rows as $r) { |
156 | 163 | // extract out the uuid result |
@@ -177,8 +184,9 @@ discard block |
||
177 | 184 | */ |
178 | 185 | public function makeMapLookupRequest($objectUuids, $chainMapFields=[], $classType=null) |
179 | 186 | { |
180 | - if (empty($objectUuids)) |
|
181 | - return null; |
|
187 | + if (empty($objectUuids)) { |
|
188 | + return null; |
|
189 | + } |
|
182 | 190 | /* See if there are any linked fields that we need to get |
183 | 191 | The implementation here is somewhat crude. Generally speaking we are probably looking |
184 | 192 | at needing to implement graphql or something similar to easily manage all the possible |
@@ -235,8 +243,9 @@ discard block |
||
235 | 243 | */ |
236 | 244 | public function makeMapChainLookupRequest($objectUuids, $chainMembers=[], $chainMapFields=[], $inReverse=false) |
237 | 245 | { |
238 | - if (empty($objectUuids)) |
|
239 | - return null; |
|
246 | + if (empty($objectUuids)) { |
|
247 | + return null; |
|
248 | + } |
|
240 | 249 | |
241 | 250 | // create a request key based on the input parameters |
242 | 251 | $requestKey = md5(serialize(func_get_args())); |
@@ -265,15 +274,17 @@ discard block |
||
265 | 274 | { |
266 | 275 | $requests = &static::$_mapRequests; |
267 | 276 | // check we have any requests to make |
268 | - if (count($requests['chains']) === 0) |
|
269 | - return; |
|
277 | + if (count($requests['chains']) === 0) { |
|
278 | + return; |
|
279 | + } |
|
270 | 280 | // run through the chain and get the reverse maps for each level of requests |
271 | 281 | foreach ($requests['chains'] as $i=>&$chain) { |
272 | 282 | // the requests will be filled in during this call |
273 | 283 | $this->getMapLookupByLevel($chain); |
274 | 284 | foreach ($chain as $k=>$r) { |
275 | - if ($r['next_uuid']) |
|
276 | - $requests['chains'][($i+1)][$k]['uuid'] = $r['next_uuid']; |
|
285 | + if ($r['next_uuid']) { |
|
286 | + $requests['chains'][($i+1)][$k]['uuid'] = $r['next_uuid']; |
|
287 | + } |
|
277 | 288 | } |
278 | 289 | } |
279 | 290 | $this->convertMapRequestResults(); |
@@ -322,8 +333,9 @@ discard block |
||
322 | 333 | */ |
323 | 334 | private function getMapLookupByLevel(&$requests) |
324 | 335 | { |
325 | - if (empty($requests)) |
|
326 | - return; |
|
336 | + if (empty($requests)) { |
|
337 | + return; |
|
338 | + } |
|
327 | 339 | |
328 | 340 | $endpoints = []; |
329 | 341 | $requestsByUuid = []; |
@@ -372,8 +384,9 @@ discard block |
||
372 | 384 | // make sure a map field can be created |
373 | 385 | $mapFieldsClause = ''; |
374 | 386 | if ($mapField === self::$_defaultMapChain) { |
375 | - if (!isset($mapsByClass[$class])) |
|
376 | - continue; |
|
387 | + if (!isset($mapsByClass[$class])) { |
|
388 | + continue; |
|
389 | + } |
|
377 | 390 | $mapFieldsClause = "CAST(`$mapsByClass[$class]` AS CHAR)"; |
378 | 391 | } else { |
379 | 392 | $mapFieldsClause = "CONCAT_WS('$hackySeparator'"; |
@@ -436,8 +449,9 @@ discard block |
||
436 | 449 | */ |
437 | 450 | private function addRequest($requestKey, $objectUuid, $chainMembers, $chainMapFields, $inReverse) |
438 | 451 | { |
439 | - if (empty($objectUuid)) |
|
440 | - return; |
|
452 | + if (empty($objectUuid)) { |
|
453 | + return; |
|
454 | + } |
|
441 | 455 | |
442 | 456 | // Treat a request for objectUuids as multiple single object map requests |
443 | 457 | // TODO NJ 20190415 - make this work properly with multiple uuids without needing multiple requests |
@@ -466,8 +480,9 @@ discard block |
||
466 | 480 | $requests = &static::$_mapRequests; // to make the code slightly shorter |
467 | 481 | |
468 | 482 | // check to see if the request has already added |
469 | - if (isset($requests['keys'][$requestKey])) |
|
470 | - return; |
|
483 | + if (isset($requests['keys'][$requestKey])) { |
|
484 | + return; |
|
485 | + } |
|
471 | 486 | |
472 | 487 | // calculate how many chains we are going down |
473 | 488 | $chainCount = count($chainMembers); |
@@ -509,8 +524,9 @@ discard block |
||
509 | 524 | $results = &static::$_mapResults; |
510 | 525 | |
511 | 526 | $tempResults = []; |
512 | - if (count($chains)===0) |
|
513 | - return; |
|
527 | + if (count($chains)===0) { |
|
528 | + return; |
|
529 | + } |
|
514 | 530 | foreach ($chains as $level => $maps) { |
515 | 531 | foreach ($maps as $key=>$map) { |
516 | 532 | $tempResults[$key][$level][$map['uuid']] = $map['map']; |
@@ -31,8 +31,9 @@ |
||
31 | 31 | */ |
32 | 32 | public function hasChangeLog() |
33 | 33 | { |
34 | - if (isset($this->attributes['change_log'])) |
|
35 | - return $this->attributes['change_log']; |
|
34 | + if (isset($this->attributes['change_log'])) { |
|
35 | + return $this->attributes['change_log']; |
|
36 | + } |
|
36 | 37 | return false; |
37 | 38 | } |
38 | 39 |