@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param bool $includeDeleted |
54 | 54 | * @return \yii\db\ActiveQuery |
55 | 55 | */ |
56 | - public function countClasses($module=null, $includeDeleted=false) |
|
56 | + public function countClasses($module = null, $includeDeleted = false) |
|
57 | 57 | { |
58 | 58 | $query = $this->_getClassesQuery($module, $includeDeleted); |
59 | 59 | return $query->count(); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * @inheritdoc |
64 | 64 | */ |
65 | - public function listClasses($module, &$total, $includeDeleted=false, $start=0, $length=100, $orderBy='label') |
|
65 | + public function listClasses($module, &$total, $includeDeleted = false, $start = 0, $length = 100, $orderBy = 'label') |
|
66 | 66 | { |
67 | 67 | $query = $this->_getClassesQuery($module, $includeDeleted); |
68 | 68 | if ($start == 0) |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $c->class_type = $classType; |
123 | 123 | $c->module = (empty($module) ? null : $module); |
124 | 124 | if (!$c->save()) |
125 | - throw new \RuntimeException("Couldn't save the class: ".print_r($c->errors,true)); |
|
125 | + throw new \RuntimeException("Couldn't save the class: ".print_r($c->errors, true)); |
|
126 | 126 | $upSql = $this->getClassTypeMigrationSql($classType); |
127 | 127 | $downSql = "DELETE FROM `dds_class` WHERE `class_type`='$classType';"; |
128 | 128 | $this->storeMigration($upSql, $downSql); |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | /** |
134 | 134 | * @inheritdoc |
135 | 135 | */ |
136 | - public function getClass($classType, $includeMembers=false) |
|
136 | + public function getClass($classType, $includeMembers = false) |
|
137 | 137 | { |
138 | 138 | if ($this->findClass($classType, $class)) { |
139 | 139 | $data = $class->toArray(); |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | public function editClass($classType, $changes) |
151 | 151 | { |
152 | 152 | $allowed = array_intersect_key($changes, array_flip(['label', 'description', 'module', 'change_log'])); |
153 | - if (count($allowed)==0) |
|
153 | + if (count($allowed) == 0) |
|
154 | 154 | return; |
155 | 155 | $this->clearClassCache($classType); |
156 | 156 | $downSql = $this->getClassTypeMigrationSql($classType); |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | /** |
235 | 235 | * @inheritdoc |
236 | 236 | */ |
237 | - public function listMembers($classType, $includeDeleted=false, $keyBy='member_ref') |
|
237 | + public function listMembers($classType, $includeDeleted = false, $keyBy = 'member_ref') |
|
238 | 238 | { |
239 | 239 | return $this->listMembersForClass($classType, $includeDeleted, $keyBy); |
240 | 240 | } |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | /** |
243 | 243 | * @inheritdoc |
244 | 244 | */ |
245 | - public function addMember($classType, &$memberRef, $dataTypeRef, $label, $description, $additional=null) |
|
245 | + public function addMember($classType, &$memberRef, $dataTypeRef, $label, $description, $additional = null) |
|
246 | 246 | { |
247 | 247 | $classType = $this->canonicaliseRef($classType); |
248 | 248 | $memberRef = $this->canonicaliseRef($memberRef); |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | // extract out any additional information |
252 | 252 | $choices = ((!empty($additional['choices']) && is_array($additional['choices'])) ? $additional['choices'] : []); |
253 | 253 | $linkClass = (!empty($additional['link_class']) ? $additional['link_class'] : null); |
254 | - if (DdsMember::findOne(['class_type' => $classType, 'member_ref' => $memberRef])!==null) |
|
254 | + if (DdsMember::findOne(['class_type' => $classType, 'member_ref' => $memberRef]) !== null) |
|
255 | 255 | throw new \InvalidArgumentException("The member $memberRef already exists"); |
256 | 256 | if (in_array($dataTypeRef, ['link_uni', 'link_multi']) && !$linkClass) { |
257 | 257 | throw new \InvalidArgumentException("Link_uni, link_multi data types require a link_class to be passed for member '$classType::$memberRef'. You passed in ".print_r($additional, true)); |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | $mId = $this->storeMigration($upMember, $downMember); |
276 | 276 | |
277 | 277 | // and create the member column |
278 | - if (($error=$this->addClassMemberColumn($classType, $member->member_ref)) !== true) { |
|
278 | + if (($error = $this->addClassMemberColumn($classType, $member->member_ref)) !== true) { |
|
279 | 279 | $member->delete(); |
280 | 280 | $this->removeMigration($mId); |
281 | 281 | throw new \RuntimeException("Couldn't create the member column. Error=".$error); |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | /** |
289 | 289 | * @inheritdoc |
290 | 290 | */ |
291 | - public function getMember($classType, $memberRef, $fields=[]) |
|
291 | + public function getMember($classType, $memberRef, $fields = []) |
|
292 | 292 | { |
293 | 293 | // !! keep member as an object so it runs all conversion code |
294 | 294 | $query = DdsMember::find(); |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | { |
311 | 311 | // check that only allowed updates are made |
312 | 312 | $allowed = array_intersect_key($changes, array_flip(['label', 'description', 'definition', 'choices', 'link_class'])); |
313 | - if (count($allowed)==0) |
|
313 | + if (count($allowed) == 0) |
|
314 | 314 | return; |
315 | 315 | |
316 | 316 | // find the member and remove any illegitamate updates |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | $downSql = $this->getTableRowReplaceSql('dds_member', $member); |
333 | 333 | $member->attributes = $updates; |
334 | 334 | if (!$member->save()) |
335 | - throw new \RuntimeException("Couldn't update the member: ".print_r ($member->errors, true)); |
|
335 | + throw new \RuntimeException("Couldn't update the member: ".print_r($member->errors, true)); |
|
336 | 336 | $upSql = $this->getTableRowReplaceSql('dds_member', $member); |
337 | 337 | $this->storeMigration($upSql, $downSql); |
338 | 338 | $this->clearClassMemberCache($classType); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | public function deleteMember($classType, $memberRef) |
366 | 366 | { |
367 | 367 | // delete a member if it isn't already deleted |
368 | - if ($this->findMember($classType, $memberRef, $member) && $member->deleted==0) { |
|
368 | + if ($this->findMember($classType, $memberRef, $member) && $member->deleted == 0) { |
|
369 | 369 | $upSql = "UPDATE `dds_member` SET `deleted`=1 WHERE `class_type`='$classType' AND `member_ref`='$memberRef';"; |
370 | 370 | $downSql = "UPDATE `dds_member` SET `deleted`=0 WHERE `class_type`='$classType' AND `member_ref`='$memberRef';"; |
371 | 371 | neon()->db->createCommand($upSql)->execute(); |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | public function undeleteMember($classType, $memberRef) |
381 | 381 | { |
382 | 382 | // undelete a member if it is already deleted |
383 | - if ($this->findMember($classType, $memberRef, $member) && $member->deleted==1) { |
|
383 | + if ($this->findMember($classType, $memberRef, $member) && $member->deleted == 1) { |
|
384 | 384 | // create migrations |
385 | 385 | $upSql = "UPDATE `dds_member` SET `deleted`=0 WHERE `class_type`='$classType' AND `member_ref`='$memberRef';"; |
386 | 386 | $downSql = "UPDATE `dds_member` SET `deleted`=1 WHERE `class_type`='$classType' AND `member_ref`='$memberRef';"; |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | /** |
428 | 428 | * @inheritdoc |
429 | 429 | */ |
430 | - public function listDataTypes($includeDeleted=false) |
|
430 | + public function listDataTypes($includeDeleted = false) |
|
431 | 431 | { |
432 | 432 | $query = DdsDataType::find(); |
433 | 433 | $select = ['data_type_ref', 'label', 'description', 'definition', 'storage_ref']; |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | $downSql = $this->getTableRowReplaceSql('dds_data_type', $dataType); |
489 | 489 | $dataType->attributes = $updates; |
490 | 490 | if (!$dataType->save()) |
491 | - throw new \RuntimeException("Couldn't save the datatype: ".print_r($dataType->errors(),true)); |
|
491 | + throw new \RuntimeException("Couldn't save the datatype: ".print_r($dataType->errors(), true)); |
|
492 | 492 | $upSql = $this->getTableRowReplaceSql('dds_data_type', $dataType); |
493 | 493 | $this->storeMigration($upSql, $downSql); |
494 | 494 | } |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | if (count($diff)) |
607 | 607 | $diffs[$k] = $v; |
608 | 608 | } else { |
609 | - if ((string)$v !== (string)$b[$k]) |
|
609 | + if ((string) $v !== (string) $b[$k]) |
|
610 | 610 | $diffs[$k] = $v; |
611 | 611 | } |
612 | 612 | } else { |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | */ |
624 | 624 | private static $_classCache = []; |
625 | 625 | |
626 | - private function _getClassesQuery($module=null, $includeDeleted=false) |
|
626 | + private function _getClassesQuery($module = null, $includeDeleted = false) |
|
627 | 627 | { |
628 | 628 | $query = DdsClass::find(); |
629 | 629 | $select = ['class_type', 'label', 'description', 'module', 'count_total', 'count_deleted', 'change_log']; |
@@ -39,8 +39,9 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function isMemberRefUnique($classType, $candidate) |
41 | 41 | { |
42 | - if ($this->isClassTypeUnique($classType)) |
|
43 | - throw new \InvalidArgumentException("Class type ".$this->canonicaliseRef($classType)." unknown"); |
|
42 | + if ($this->isClassTypeUnique($classType)) { |
|
43 | + throw new \InvalidArgumentException("Class type ".$this->canonicaliseRef($classType)." unknown"); |
|
44 | + } |
|
44 | 45 | $mr = $this->canonicaliseRef($candidate); |
45 | 46 | $member = DdsMember::find()->where(['class_type'=>$classType, 'member_ref'=>$mr])->one(); |
46 | 47 | return ($member == null); |
@@ -65,15 +66,17 @@ discard block |
||
65 | 66 | public function listClasses($module, &$total, $includeDeleted=false, $start=0, $length=100, $orderBy='label') |
66 | 67 | { |
67 | 68 | $query = $this->_getClassesQuery($module, $includeDeleted); |
68 | - if ($start == 0) |
|
69 | - $total = (int) $query->count(); |
|
69 | + if ($start == 0) { |
|
70 | + $total = (int) $query->count(); |
|
71 | + } |
|
70 | 72 | $results = $query->asArray() |
71 | 73 | ->offset($start) |
72 | 74 | ->limit($length) |
73 | 75 | ->orderBy($orderBy) |
74 | 76 | ->all(); |
75 | - foreach ($results as &$r) |
|
76 | - $r['count_current'] = $r['count_total'] - $r['count_deleted']; |
|
77 | + foreach ($results as &$r) { |
|
78 | + $r['count_current'] = $r['count_total'] - $r['count_deleted']; |
|
79 | + } |
|
77 | 80 | return $results; |
78 | 81 | } |
79 | 82 | |
@@ -95,8 +98,9 @@ discard block |
||
95 | 98 | ->asArray() |
96 | 99 | ->all(); |
97 | 100 | $map = []; |
98 | - foreach ($mappable as $m) |
|
99 | - $map[$m['class_type']] = $m['label']; |
|
101 | + foreach ($mappable as $m) { |
|
102 | + $map[$m['class_type']] = $m['label']; |
|
103 | + } |
|
100 | 104 | return $map; |
101 | 105 | } |
102 | 106 | |
@@ -116,13 +120,15 @@ discard block |
||
116 | 120 | public function addClass(&$classType, $module) |
117 | 121 | { |
118 | 122 | $classType = $this->canonicaliseRef($classType); |
119 | - if (DdsClass::findOne(['class_type'=>$classType]) !== null) |
|
120 | - throw new \InvalidArgumentException("The class $classType already exists"); |
|
123 | + if (DdsClass::findOne(['class_type'=>$classType]) !== null) { |
|
124 | + throw new \InvalidArgumentException("The class $classType already exists"); |
|
125 | + } |
|
121 | 126 | $c = new DdsClass(); |
122 | 127 | $c->class_type = $classType; |
123 | 128 | $c->module = (empty($module) ? null : $module); |
124 | - if (!$c->save()) |
|
125 | - throw new \RuntimeException("Couldn't save the class: ".print_r($c->errors,true)); |
|
129 | + if (!$c->save()) { |
|
130 | + throw new \RuntimeException("Couldn't save the class: ".print_r($c->errors,true)); |
|
131 | + } |
|
126 | 132 | $upSql = $this->getClassTypeMigrationSql($classType); |
127 | 133 | $downSql = "DELETE FROM `dds_class` WHERE `class_type`='$classType';"; |
128 | 134 | $this->storeMigration($upSql, $downSql); |
@@ -137,8 +143,9 @@ discard block |
||
137 | 143 | { |
138 | 144 | if ($this->findClass($classType, $class)) { |
139 | 145 | $data = $class->toArray(); |
140 | - if ($includeMembers) |
|
141 | - $data['members'] = $this->listMembers($class['class_type']); |
|
146 | + if ($includeMembers) { |
|
147 | + $data['members'] = $this->listMembers($class['class_type']); |
|
148 | + } |
|
142 | 149 | return $data; |
143 | 150 | } |
144 | 151 | return null; |
@@ -150,8 +157,9 @@ discard block |
||
150 | 157 | public function editClass($classType, $changes) |
151 | 158 | { |
152 | 159 | $allowed = array_intersect_key($changes, array_flip(['label', 'description', 'module', 'change_log'])); |
153 | - if (count($allowed)==0) |
|
154 | - return; |
|
160 | + if (count($allowed)==0) { |
|
161 | + return; |
|
162 | + } |
|
155 | 163 | $this->clearClassCache($classType); |
156 | 164 | $downSql = $this->getClassTypeMigrationSql($classType); |
157 | 165 | if ($this->findClass($classType, $class)) { |
@@ -159,8 +167,9 @@ discard block |
||
159 | 167 | $updates = array_diff_assoc($allowed, $class->attributes); |
160 | 168 | if (count($updates)) { |
161 | 169 | $class->attributes = $updates; |
162 | - if (!$class->save()) |
|
163 | - throw new \RuntimeException("Dds: Couldn't update the class '$classType': ".print_r($class->errors)); |
|
170 | + if (!$class->save()) { |
|
171 | + throw new \RuntimeException("Dds: Couldn't update the class '$classType': ".print_r($class->errors)); |
|
172 | + } |
|
164 | 173 | $upSql = $this->getClassTypeMigrationSql($classType); |
165 | 174 | $this->storeMigration($upSql, $downSql); |
166 | 175 | } |
@@ -203,8 +212,9 @@ discard block |
||
203 | 212 | public function destroyClass($classType) |
204 | 213 | { |
205 | 214 | if ($this->findClass($classType, $class)) { |
206 | - if ($this->hasObjects($classType)) |
|
207 | - throw new \RunTimeException("You need to delete all objects before you can destroy a class"); |
|
215 | + if ($this->hasObjects($classType)) { |
|
216 | + throw new \RunTimeException("You need to delete all objects before you can destroy a class"); |
|
217 | + } |
|
208 | 218 | |
209 | 219 | // now delete the rows |
210 | 220 | $members = DdsMember::find()->where(['class_type'=>$class->class_type])->asArray()->all(); |
@@ -216,12 +226,14 @@ discard block |
||
216 | 226 | $errors[] = $e->getMessage(); |
217 | 227 | } |
218 | 228 | } |
219 | - if (count($errors)) |
|
220 | - throw new \RuntimeException("Couldn't destroy all of the members: ".print_r($errors, true)); |
|
229 | + if (count($errors)) { |
|
230 | + throw new \RuntimeException("Couldn't destroy all of the members: ".print_r($errors, true)); |
|
231 | + } |
|
221 | 232 | // now delete the class |
222 | 233 | // can also return 0 - which is valid - false means there has been an error |
223 | - if ($class->delete() === false) |
|
224 | - throw new \RuntimeException("Couldn't destroy the class: ".print_r($class->errors, true)); |
|
234 | + if ($class->delete() === false) { |
|
235 | + throw new \RuntimeException("Couldn't destroy the class: ".print_r($class->errors, true)); |
|
236 | + } |
|
225 | 237 | // and clear away the table |
226 | 238 | $this->dropClassTable($class->class_type); |
227 | 239 | $this->clearClassCache($classType); |
@@ -251,8 +263,9 @@ discard block |
||
251 | 263 | // extract out any additional information |
252 | 264 | $choices = ((!empty($additional['choices']) && is_array($additional['choices'])) ? $additional['choices'] : []); |
253 | 265 | $linkClass = (!empty($additional['link_class']) ? $additional['link_class'] : null); |
254 | - if (DdsMember::findOne(['class_type' => $classType, 'member_ref' => $memberRef])!==null) |
|
255 | - throw new \InvalidArgumentException("The member $memberRef already exists"); |
|
266 | + if (DdsMember::findOne(['class_type' => $classType, 'member_ref' => $memberRef])!==null) { |
|
267 | + throw new \InvalidArgumentException("The member $memberRef already exists"); |
|
268 | + } |
|
256 | 269 | if (in_array($dataTypeRef, ['link_uni', 'link_multi']) && !$linkClass) { |
257 | 270 | throw new \InvalidArgumentException("Link_uni, link_multi data types require a link_class to be passed for member '$classType::$memberRef'. You passed in ".print_r($additional, true)); |
258 | 271 | } |
@@ -265,8 +278,9 @@ discard block |
||
265 | 278 | $member->choices = ($this->memberAllowedChoices($dataTypeRef) ? $choices : null); |
266 | 279 | $member->link_class = ($this->memberAllowedLinks($dataTypeRef) ? $linkClass : null); |
267 | 280 | $member->created = $this->now(); |
268 | - if (!$member->save()) |
|
269 | - throw new \RuntimeException("Couldn't save the member: ".print_r($member->errors, true)); |
|
281 | + if (!$member->save()) { |
|
282 | + throw new \RuntimeException("Couldn't save the member: ".print_r($member->errors, true)); |
|
283 | + } |
|
270 | 284 | |
271 | 285 | // create the migrations |
272 | 286 | $savedMember = $this->getMember($classType, $memberRef); |
@@ -310,12 +324,14 @@ discard block |
||
310 | 324 | { |
311 | 325 | // check that only allowed updates are made |
312 | 326 | $allowed = array_intersect_key($changes, array_flip(['label', 'description', 'definition', 'choices', 'link_class'])); |
313 | - if (count($allowed)==0) |
|
314 | - return; |
|
327 | + if (count($allowed)==0) { |
|
328 | + return; |
|
329 | + } |
|
315 | 330 | |
316 | 331 | // find the member and remove any illegitamate updates |
317 | - if (!$this->findMember($classType, $memberRef, $member)) |
|
318 | - throw new \InvalidArgumentException("No member found"); |
|
332 | + if (!$this->findMember($classType, $memberRef, $member)) { |
|
333 | + throw new \InvalidArgumentException("No member found"); |
|
334 | + } |
|
319 | 335 | if (isset($allowed['choices'])) { |
320 | 336 | $allowed['choices'] = empty($allowed['choices']) ? [] : $allowed['choices']; |
321 | 337 | if (!(is_array($allowed['choices']) && $this->memberAllowedChoices($member->data_type_ref))) { |
@@ -323,16 +339,18 @@ discard block |
||
323 | 339 | } |
324 | 340 | } |
325 | 341 | |
326 | - if (isset($allowed['link_class']) && !$this->memberAllowedLinks($member->data_type_ref)) |
|
327 | - unset($allowed['link_class']); |
|
342 | + if (isset($allowed['link_class']) && !$this->memberAllowedLinks($member->data_type_ref)) { |
|
343 | + unset($allowed['link_class']); |
|
344 | + } |
|
328 | 345 | |
329 | 346 | // finally check to see if there are any actual updates and if so save the provided updates |
330 | 347 | $updates = $this->getMemberUpdateDifferences($allowed, $member->attributes); |
331 | 348 | if (count($updates)) { |
332 | 349 | $downSql = $this->getTableRowReplaceSql('dds_member', $member); |
333 | 350 | $member->attributes = $updates; |
334 | - if (!$member->save()) |
|
335 | - throw new \RuntimeException("Couldn't update the member: ".print_r ($member->errors, true)); |
|
351 | + if (!$member->save()) { |
|
352 | + throw new \RuntimeException("Couldn't update the member: ".print_r ($member->errors, true)); |
|
353 | + } |
|
336 | 354 | $upSql = $this->getTableRowReplaceSql('dds_member', $member); |
337 | 355 | $this->storeMigration($upSql, $downSql); |
338 | 356 | $this->clearClassMemberCache($classType); |
@@ -344,13 +362,15 @@ discard block |
||
344 | 362 | */ |
345 | 363 | public function setMemberAsMapField($classType, $memberRef) |
346 | 364 | { |
347 | - if (!$this->findMember($classType, $memberRef, $member)) |
|
348 | - throw new \InvalidArgumentException("No member found"); |
|
365 | + if (!$this->findMember($classType, $memberRef, $member)) { |
|
366 | + throw new \InvalidArgumentException("No member found"); |
|
367 | + } |
|
349 | 368 | |
350 | 369 | // find out which member had the map field set for migrations |
351 | 370 | $oldMember = DdsMember::findOne(['class_type'=>$classType, 'map_field'=>1]); |
352 | - if ($oldMember && $oldMember->member_ref == $memberRef) |
|
353 | - return; |
|
371 | + if ($oldMember && $oldMember->member_ref == $memberRef) { |
|
372 | + return; |
|
373 | + } |
|
354 | 374 | $upSql = "UPDATE `dds_member` SET `map_field`=(IF (`member_ref`='$memberRef', 1, 0)) WHERE `class_type`='$classType';"; |
355 | 375 | $downSql = ($oldMember ? "UPDATE `dds_member` SET `map_field`=(IF (`member_ref`='{$oldMember->member_ref}', 1, 0)) WHERE `class_type`='$classType';" : null); |
356 | 376 | neon()->db->createCommand($upSql)->execute(); |
@@ -445,16 +465,18 @@ discard block |
||
445 | 465 | public function addDataType(&$dataTypeRef, $label, $description, $definition, $storageRef) |
446 | 466 | { |
447 | 467 | $dataTypeRef = $this->canonicaliseRef($dataTypeRef); |
448 | - if ($this->findDataType($dataTypeRef)) |
|
449 | - throw new \InvalidArgumentException("The dataType $dataTypeRef already exists"); |
|
468 | + if ($this->findDataType($dataTypeRef)) { |
|
469 | + throw new \InvalidArgumentException("The dataType $dataTypeRef already exists"); |
|
470 | + } |
|
450 | 471 | $dt = new DdsDataType(); |
451 | 472 | $dt->data_type_ref = $dataTypeRef; |
452 | 473 | $dt->label = $label; |
453 | 474 | $dt->description = $description; |
454 | 475 | $dt->definition = $definition; |
455 | 476 | $dt->storage_ref = $storageRef; |
456 | - if (!$dt->save()) |
|
457 | - throw new \RuntimeException("Couldn't create the datatype $dataTypeRef: ".print_r($dt->errors, true)); |
|
477 | + if (!$dt->save()) { |
|
478 | + throw new \RuntimeException("Couldn't create the datatype $dataTypeRef: ".print_r($dt->errors, true)); |
|
479 | + } |
|
458 | 480 | |
459 | 481 | // store the migration |
460 | 482 | $this->findDataType($dataTypeRef, $dt); |
@@ -479,16 +501,18 @@ discard block |
||
479 | 501 | public function editDataType($dataTypeRef, $changes) |
480 | 502 | { |
481 | 503 | $allowed = array_intersect_key($changes, array_flip(['label', 'description', 'definition'])); |
482 | - if (count($allowed) == 0) |
|
483 | - return; |
|
504 | + if (count($allowed) == 0) { |
|
505 | + return; |
|
506 | + } |
|
484 | 507 | if ($this->findDataType($dataTypeRef, $dataType)) { |
485 | 508 | // make the updates if there is anything to change |
486 | 509 | $updates = array_diff($allowed, $dataType->attributes); |
487 | 510 | if (count($updates)) { |
488 | 511 | $downSql = $this->getTableRowReplaceSql('dds_data_type', $dataType); |
489 | 512 | $dataType->attributes = $updates; |
490 | - if (!$dataType->save()) |
|
491 | - throw new \RuntimeException("Couldn't save the datatype: ".print_r($dataType->errors(),true)); |
|
513 | + if (!$dataType->save()) { |
|
514 | + throw new \RuntimeException("Couldn't save the datatype: ".print_r($dataType->errors(),true)); |
|
515 | + } |
|
492 | 516 | $upSql = $this->getTableRowReplaceSql('dds_data_type', $dataType); |
493 | 517 | $this->storeMigration($upSql, $downSql); |
494 | 518 | } |
@@ -552,8 +576,9 @@ discard block |
||
552 | 576 | private function getClassTypeMigrationSql($classType) |
553 | 577 | { |
554 | 578 | $ddsClass = DdsClass::findOne(['class_type'=>$classType]); |
555 | - if ($ddsClass == null) |
|
556 | - return null; |
|
579 | + if ($ddsClass == null) { |
|
580 | + return null; |
|
581 | + } |
|
557 | 582 | return $this->getTableRowReplaceSql('dds_class', $ddsClass); |
558 | 583 | } |
559 | 584 | |
@@ -603,11 +628,13 @@ discard block |
||
603 | 628 | if (is_array($v)) { |
604 | 629 | $diff = $this->getMemberUpdateDifferences($v, $b[$k]); |
605 | 630 | // we want all of the array if there were any differences |
606 | - if (count($diff)) |
|
607 | - $diffs[$k] = $v; |
|
631 | + if (count($diff)) { |
|
632 | + $diffs[$k] = $v; |
|
633 | + } |
|
608 | 634 | } else { |
609 | - if ((string)$v !== (string)$b[$k]) |
|
610 | - $diffs[$k] = $v; |
|
635 | + if ((string)$v !== (string)$b[$k]) { |
|
636 | + $diffs[$k] = $v; |
|
637 | + } |
|
611 | 638 | } |
612 | 639 | } else { |
613 | 640 | $diffs[$k] = $v; |
@@ -633,8 +660,9 @@ discard block |
||
633 | 660 | $query->andWhere(['deleted' => 0]); |
634 | 661 | } |
635 | 662 | $query->select($select); |
636 | - if ($module != null) |
|
637 | - $query->andWhere(['or', ['module' => $module], ['module' => NULL]]); |
|
663 | + if ($module != null) { |
|
664 | + $query->andWhere(['or', ['module' => $module], ['module' => NULL]]); |
|
665 | + } |
|
638 | 666 | return $query; |
639 | 667 | } |
640 | 668 |
@@ -18,7 +18,7 @@ |
||
18 | 18 | /** |
19 | 19 | * @inheritdoc |
20 | 20 | */ |
21 | - public function addObjectDeletionChecksOnJoin(\yii\db\Query $query, $tables, $join='innerJoin') |
|
21 | + public function addObjectDeletionChecksOnJoin(\yii\db\Query $query, $tables, $join = 'innerJoin') |
|
22 | 22 | { |
23 | 23 | foreach ($tables as $table) { |
24 | 24 | if ($join == 'innerJoin') { |
@@ -13,8 +13,9 @@ |
||
13 | 13 | */ |
14 | 14 | function smarty_function_getDdsObject($params, $template) |
15 | 15 | { |
16 | - if (!isset($params['uuid'])) |
|
17 | - throw new InvalidArgumentException("DdsObjectToJson - you need to pass in the 'uuid'"); |
|
16 | + if (!isset($params['uuid'])) { |
|
17 | + throw new InvalidArgumentException("DdsObjectToJson - you need to pass in the 'uuid'"); |
|
18 | + } |
|
18 | 19 | $assign = !empty($params['assign']) ? $params['assign'] : 'ddsObject'; |
19 | 20 | $asJson = isset($params['asJson']) ? $params['asJson'] : false; |
20 | 21 | $dds = neon('dds')->IDdsObjectManagement; |
@@ -244,7 +244,7 @@ |
||
244 | 244 | if ($count) |
245 | 245 | $classes = array_merge($classes, $nextSet); |
246 | 246 | $start += $count; |
247 | - } while ($count>0); |
|
247 | + } while ($count > 0); |
|
248 | 248 | $classesByType = array_column($classes, null, 'class_type'); |
249 | 249 | |
250 | 250 | // get the full definition of these |
@@ -103,8 +103,9 @@ discard block |
||
103 | 103 | $form = $this->getPhoebeForm($type); |
104 | 104 | $object = $this->ddo()->getObject($id); |
105 | 105 | $form->loadFromDb($object); |
106 | - if (neon()->request->getIsAjax()) |
|
107 | - return $form->ajaxValidation(); |
|
106 | + if (neon()->request->getIsAjax()) { |
|
107 | + return $form->ajaxValidation(); |
|
108 | + } |
|
108 | 109 | |
109 | 110 | if ($form->processRequest()) { |
110 | 111 | $this->ddo()->editObject($id, $form->getData()); |
@@ -128,8 +129,9 @@ discard block |
||
128 | 129 | public function actionDeleteObject($type, $id, $redirect = true) |
129 | 130 | { |
130 | 131 | $this->ddo()->deleteObject($id); |
131 | - if ($redirect) |
|
132 | - $this->redirect(['/daedalus/index/list', 'type' => $type]); |
|
132 | + if ($redirect) { |
|
133 | + $this->redirect(['/daedalus/index/list', 'type' => $type]); |
|
134 | + } |
|
133 | 135 | } |
134 | 136 | |
135 | 137 | /** |
@@ -141,8 +143,9 @@ discard block |
||
141 | 143 | public function actionUndeleteObject($type, $id, $redirect = true) |
142 | 144 | { |
143 | 145 | $this->ddo()->undeleteObject($id); |
144 | - if ($redirect) |
|
145 | - $this->redirect(['/daedalus/index/list', 'type' => $type]); |
|
146 | + if ($redirect) { |
|
147 | + $this->redirect(['/daedalus/index/list', 'type' => $type]); |
|
148 | + } |
|
146 | 149 | } |
147 | 150 | |
148 | 151 | /** |
@@ -154,8 +157,9 @@ discard block |
||
154 | 157 | public function actionDestroyObject($type, $id, $redirect = true) |
155 | 158 | { |
156 | 159 | $this->ddo()->destroyObject($id); |
157 | - if ($redirect) |
|
158 | - $this->redirect(['/daedalus/index/list', 'type' => $type]); |
|
160 | + if ($redirect) { |
|
161 | + $this->redirect(['/daedalus/index/list', 'type' => $type]); |
|
162 | + } |
|
159 | 163 | } |
160 | 164 | |
161 | 165 | |
@@ -170,8 +174,9 @@ discard block |
||
170 | 174 | while ($rows > 0) { |
171 | 175 | $count = min($rows, 100); |
172 | 176 | $data = []; |
173 | - for ($i = 0; $i < $count; $i++) |
|
174 | - $data[] = $form->fake(); |
|
177 | + for ($i = 0; $i < $count; $i++) { |
|
178 | + $data[] = $form->fake(); |
|
179 | + } |
|
175 | 180 | $this->ddo()->addObjects($type, $data); |
176 | 181 | $rows -= $count; |
177 | 182 | } |
@@ -281,8 +286,9 @@ discard block |
||
281 | 286 | do { |
282 | 287 | $nextSet = $ddc->listClasses(null, $total, false, $start, $length); |
283 | 288 | $count = count($nextSet); |
284 | - if ($count) |
|
285 | - $classes = array_merge($classes, $nextSet); |
|
289 | + if ($count) { |
|
290 | + $classes = array_merge($classes, $nextSet); |
|
291 | + } |
|
286 | 292 | $start += $count; |
287 | 293 | } while ($count>0); |
288 | 294 | $classesByType = array_column($classes, null, 'class_type'); |
@@ -295,8 +301,9 @@ discard block |
||
295 | 301 | foreach ($class['members'] as &$member) { |
296 | 302 | $member['data_type'] = $dataTypeByRef[$member['data_type_ref']]; |
297 | 303 | $member['links_to_table'] = null; |
298 | - if ($member['link_class'] && isset($classesByType[$member['link_class']])) |
|
299 | - $member['links_to_table'] = $classesByType[$member['link_class']]['label']; |
|
304 | + if ($member['link_class'] && isset($classesByType[$member['link_class']])) { |
|
305 | + $member['links_to_table'] = $classesByType[$member['link_class']]['label']; |
|
306 | + } |
|
300 | 307 | } |
301 | 308 | $definitions[$c['class_type']] = $class; |
302 | 309 | } |
@@ -82,8 +82,9 @@ discard block |
||
82 | 82 | */ |
83 | 83 | protected function ddo() |
84 | 84 | { |
85 | - if ($this->_ddo == null) |
|
86 | - $this->_ddo = neon('dds')->IDdsObjectManagement; |
|
85 | + if ($this->_ddo == null) { |
|
86 | + $this->_ddo = neon('dds')->IDdsObjectManagement; |
|
87 | + } |
|
87 | 88 | return $this->_ddo; |
88 | 89 | } |
89 | 90 | |
@@ -92,8 +93,9 @@ discard block |
||
92 | 93 | */ |
93 | 94 | protected function ddc() |
94 | 95 | { |
95 | - if ($this->_ddc == null) |
|
96 | - $this->_ddc = neon('dds')->IDdsClassManagement; |
|
96 | + if ($this->_ddc == null) { |
|
97 | + $this->_ddc = neon('dds')->IDdsClassManagement; |
|
98 | + } |
|
97 | 99 | return $this->_ddc; |
98 | 100 | } |
99 | 101 | |
@@ -102,8 +104,9 @@ discard block |
||
102 | 104 | */ |
103 | 105 | protected function ddt() |
104 | 106 | { |
105 | - if ($this->_ddt == null) |
|
106 | - $this->_ddt = neon('dds')->IDdsDataTypeManagement; |
|
107 | + if ($this->_ddt == null) { |
|
108 | + $this->_ddt = neon('dds')->IDdsDataTypeManagement; |
|
109 | + } |
|
107 | 110 | return $this->_ddt; |
108 | 111 | } |
109 | 112 |
@@ -39,7 +39,7 @@ |
||
39 | 39 | * @param array $options additional options for the form |
40 | 40 | * @return \neon\core\form\Form |
41 | 41 | */ |
42 | - protected function getPhoebeForm($type, $options=[]) |
|
42 | + protected function getPhoebeForm($type, $options = []) |
|
43 | 43 | { |
44 | 44 | return neon()->phoebe->getForm('daedalus', $type, $options); |
45 | 45 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | } catch (\Exception $e) { |
66 | 66 | // error occured lets see if it's because the class does not exist |
67 | 67 | if (neon()->getDds()->IDdsClassManagement->getClass($class) === null) { |
68 | - throw new HttpException(404, 'No class exists with name ' . $class); |
|
68 | + throw new HttpException(404, 'No class exists with name '.$class); |
|
69 | 69 | } |
70 | 70 | throw new HttpException(500, $e->getMessage()); |
71 | 71 | } |
@@ -47,15 +47,15 @@ discard block |
||
47 | 47 | * @return array uuid => map field |
48 | 48 | * @throws |
49 | 49 | */ |
50 | - public function actionObjects($class, $filter='', $length=100, $member='', $value='', $start=0) |
|
50 | + public function actionObjects($class, $filter = '', $length = 100, $member = '', $value = '', $start = 0) |
|
51 | 51 | { |
52 | 52 | $mapFilter = []; |
53 | 53 | if (!$class) |
54 | 54 | throw new HttpException(404, "No class name provided"); |
55 | 55 | if ($member && $value) |
56 | - $mapFilter[$member]=$value; |
|
56 | + $mapFilter[$member] = $value; |
|
57 | 57 | if ($filter && is_string($filter)) |
58 | - $mapFilter['_map_field_']=$filter; |
|
58 | + $mapFilter['_map_field_'] = $filter; |
|
59 | 59 | return neon()->getDds()->IDdsObjectManagement->getObjectMap($class, $mapFilter, [], $start, $length); |
60 | 60 | } |
61 | 61 | |
@@ -64,17 +64,17 @@ discard block |
||
64 | 64 | return neon('user')->getDataMapTypes(); |
65 | 65 | } |
66 | 66 | |
67 | - public function actionUsers($filter='') |
|
67 | + public function actionUsers($filter = '') |
|
68 | 68 | { |
69 | 69 | return neon('user')->getDataMap('users', $filter); |
70 | 70 | } |
71 | 71 | |
72 | - public function actionPages($filter='') |
|
72 | + public function actionPages($filter = '') |
|
73 | 73 | { |
74 | 74 | return neon('cms')->getDataMap('pages', $filter); |
75 | 75 | } |
76 | 76 | |
77 | - public function actionPhoebe($type='', $filter='') |
|
77 | + public function actionPhoebe($type = '', $filter = '') |
|
78 | 78 | { |
79 | 79 | $filters = []; |
80 | 80 | if (!$filter) { |
@@ -50,12 +50,15 @@ discard block |
||
50 | 50 | public function actionObjects($class, $filter='', $length=100, $member='', $value='', $start=0) |
51 | 51 | { |
52 | 52 | $mapFilter = []; |
53 | - if (!$class) |
|
54 | - throw new HttpException(404, "No class name provided"); |
|
55 | - if ($member && $value) |
|
56 | - $mapFilter[$member]=$value; |
|
57 | - if ($filter && is_string($filter)) |
|
58 | - $mapFilter['_map_field_']=$filter; |
|
53 | + if (!$class) { |
|
54 | + throw new HttpException(404, "No class name provided"); |
|
55 | + } |
|
56 | + if ($member && $value) { |
|
57 | + $mapFilter[$member]=$value; |
|
58 | + } |
|
59 | + if ($filter && is_string($filter)) { |
|
60 | + $mapFilter['_map_field_']=$filter; |
|
61 | + } |
|
59 | 62 | return neon()->getDds()->IDdsObjectManagement->getObjectMap($class, $mapFilter, [], $start, $length); |
60 | 63 | } |
61 | 64 | |
@@ -83,8 +86,7 @@ discard block |
||
83 | 86 | ['like', 'label', $filter], |
84 | 87 | ['like', 'class_type', $filter] |
85 | 88 | ]; |
86 | - } |
|
87 | - else if ($type === 'phoebe_object') { |
|
89 | + } else if ($type === 'phoebe_object') { |
|
88 | 90 | $filters = ['like', 'uuid', $filter]; |
89 | 91 | } |
90 | 92 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | ]); |
40 | 40 | } |
41 | 41 | |
42 | - public function actionList($type, $uuid=null) |
|
42 | + public function actionList($type, $uuid = null) |
|
43 | 43 | { |
44 | 44 | // sort out where we're going back to |
45 | 45 | $goBackTo = url(['index/list', 'type'=>$type]); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $goBackTo = url(['index/list', 'type'=>$type, 'uuid' => $uuid]); |
48 | 48 | |
49 | 49 | // check the class has a change log |
50 | - $class = ['class_type' => $type, 'label'=>ucwords(str_replace('_',' ',$type))]; |
|
50 | + $class = ['class_type' => $type, 'label'=>ucwords(str_replace('_', ' ', $type))]; |
|
51 | 51 | $hasChangeLog = $this->cl->hasChangeLog($type); |
52 | 52 | if (!$hasChangeLog) { |
53 | 53 | return $this->render('list.tpl', [ |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | case 'COMMENT': |
103 | 103 | if (!$uuid) |
104 | 104 | $render['title'] = "Comment added on ".date("d-m-Y \\a\\t H:i:s", strtotime($logEntry['when'])); |
105 | - if (is_array($logEntry['associated_objects']) && count($logEntry['associated_objects'])>0) |
|
105 | + if (is_array($logEntry['associated_objects']) && count($logEntry['associated_objects']) > 0) |
|
106 | 106 | $render['associated_objects'] = implode(', ', $logEntry['associated_objects']); |
107 | 107 | case 'DESTROY': |
108 | 108 | case 'DELETE': |
@@ -43,8 +43,9 @@ discard block |
||
43 | 43 | { |
44 | 44 | // sort out where we're going back to |
45 | 45 | $goBackTo = url(['index/list', 'type'=>$type]); |
46 | - if ($uuid) |
|
47 | - $goBackTo = url(['index/list', 'type'=>$type, 'uuid' => $uuid]); |
|
46 | + if ($uuid) { |
|
47 | + $goBackTo = url(['index/list', 'type'=>$type, 'uuid' => $uuid]); |
|
48 | + } |
|
48 | 49 | |
49 | 50 | // check the class has a change log |
50 | 51 | $class = ['class_type' => $type, 'label'=>ucwords(str_replace('_',' ',$type))]; |
@@ -77,16 +78,18 @@ discard block |
||
77 | 78 | public function actionViewObject($uuid, $logUuid) |
78 | 79 | { |
79 | 80 | $logEntry = $this->cl->getLogEntry($logUuid); |
80 | - if (!$logEntry) |
|
81 | - return 'Log not found'; |
|
81 | + if (!$logEntry) { |
|
82 | + return 'Log not found'; |
|
83 | + } |
|
82 | 84 | $type = $logEntry['class_type']; |
83 | 85 | |
84 | 86 | $class = $this->getClassAsArray($type); |
85 | 87 | $goBackTo = url(['change-log/list', 'type'=>$type, 'uuid' => $uuid]); |
86 | - if ($uuid) |
|
87 | - $headerTitle = "$class[label] [Object '$uuid'] Change Log"; |
|
88 | - else |
|
89 | - $headerTitle = "$class[label] Change Log"; |
|
88 | + if ($uuid) { |
|
89 | + $headerTitle = "$class[label] [Object '$uuid'] Change Log"; |
|
90 | + } else { |
|
91 | + $headerTitle = "$class[label] Change Log"; |
|
92 | + } |
|
90 | 93 | |
91 | 94 | $title = "Status of $uuid on ".date("d-m-Y \\a\\t H:i:s", strtotime($logEntry['when'])); |
92 | 95 | $render = [ |
@@ -100,10 +103,12 @@ discard block |
||
100 | 103 | ]; |
101 | 104 | switch ($logEntry['change_key']) { |
102 | 105 | case 'COMMENT': |
103 | - if (!$uuid) |
|
104 | - $render['title'] = "Comment added on ".date("d-m-Y \\a\\t H:i:s", strtotime($logEntry['when'])); |
|
105 | - if (is_array($logEntry['associated_objects']) && count($logEntry['associated_objects'])>0) |
|
106 | - $render['associated_objects'] = implode(', ', $logEntry['associated_objects']); |
|
106 | + if (!$uuid) { |
|
107 | + $render['title'] = "Comment added on ".date("d-m-Y \\a\\t H:i:s", strtotime($logEntry['when'])); |
|
108 | + } |
|
109 | + if (is_array($logEntry['associated_objects']) && count($logEntry['associated_objects'])>0) { |
|
110 | + $render['associated_objects'] = implode(', ', $logEntry['associated_objects']); |
|
111 | + } |
|
107 | 112 | case 'DESTROY': |
108 | 113 | case 'DELETE': |
109 | 114 | $renderFile = 'viewLogEntry.tpl'; |
@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | public function safeDown() |
16 | 16 | { |
17 | - $this->execute("ALTER TABLE dds_change_log MODIFY `object_uuid` char(22) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL COMMENT 'The object that was changed'"); $this->execute("ALTER TABLE dds_change_log DROP COLUMN `before`;"); |
|
17 | + $this->execute("ALTER TABLE dds_change_log MODIFY `object_uuid` char(22) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL COMMENT 'The object that was changed'"); $this->execute("ALTER TABLE dds_change_log DROP COLUMN `before`;"); |
|
18 | 18 | $this->execute("ALTER TABLE dds_change_log DROP COLUMN `after`;"); |
19 | 19 | $this->execute("ALTER TABLE dds_change_log ADD `changes` longblob COMMENT 'What the changes were' AFTER `when`;"); |
20 | 20 | } |