@@ -19,6 +19,22 @@ public function transformActionlogs (Collection $actionlogs, $total)
1919 return (new DatatablesTransformer )->transformDatatables ($ array , $ total );
2020 }
2121
22+ private function clean_field ($ value )
23+ {
24+ // This object stuff is weird, and is used to make up for the fact that
25+ // older data can get strangely formatted if an asset existed,
26+ // then a new custom field is added, and the asset is saved again.
27+ // It can result in funnily-formatted strings like:
28+ //
29+ // {"_snipeit_right_sized_fault_tolerant_localareanetwo_1":
30+ // {"old":null,"new":{"value":"1579490695972","_snipeit_new_field_2":2,"_snipeit_new_field_3":"Monday, 20 January 2020 2:24:55 PM"}}
31+ // so we have to walk down that next level
32+ if (is_object ($ value ) && isset ($ value ->value )) {
33+ return $ this ->clean_field ($ value ->value );
34+ }
35+ return is_scalar ($ value ) || is_null ($ value ) ? e ($ value ) : e (json_encode ($ value ));
36+ }
37+
2238 public function transformActionlog (Actionlog $ actionlog , $ settings = null )
2339 {
2440 $ icon = $ actionlog ->present ()->icon ();
@@ -31,49 +47,9 @@ public function transformActionlog (Actionlog $actionlog, $settings = null)
3147 $ meta_array = json_decode ($ actionlog ->log_meta );
3248
3349 if ($ meta_array ) {
34- foreach ($ meta_array as $ key => $ value ) {
35- foreach ($ value as $ meta_key => $ meta_value ) {
36-
37- if (is_array ($ meta_value )) {
38- foreach ($ meta_value as $ meta_value_key => $ meta_value_value ) {
39- if (is_scalar ($ meta_value_value )) {
40- $ clean_meta [$ key ][$ meta_value_key ] = e ($ meta_value_value );
41- } else {
42- $ clean_meta [$ key ][$ meta_value_key ] = 'invalid scalar: ' .print_r ($ meta_value_value , true );
43- }
44- }
45- } else {
46-
47- // This object stuff is weird, and is used to make up for the fact that
48- // older data can get strangely formatted if an asset existed,
49- // then a new custom field is added, and the asset is saved again.
50- // It can result in funnily-formatted strings like:
51- //
52- // {"_snipeit_right_sized_fault_tolerant_localareanetwo_1":
53- // {"old":null,"new":{"value":"1579490695972","_snipeit_new_field_2":2,"_snipeit_new_field_3":"Monday, 20 January 2020 2:24:55 PM"}}
54- // so we have to walk down that next level
55-
56- if (is_object ($ meta_value )) {
57-
58- foreach ($ meta_value as $ meta_value_key => $ meta_value_value ) {
59-
60- if ($ meta_value_key == 'value ' ) {
61- $ clean_meta [$ key ]['old ' ] = null ;
62- $ clean_meta [$ key ]['new ' ] = e ($ meta_value ->value );
63- } else {
64- $ clean_meta [$ meta_value_key ]['old ' ] = null ;
65- $ clean_meta [$ meta_value_key ]['new ' ] = e ($ meta_value_value );
66- }
67- }
68-
69-
70-
71- } else {
72- $ clean_meta [$ key ][$ meta_key ] = e ($ meta_value );
73- }
74- }
75-
76- }
50+ foreach ($ meta_array as $ fieldname => $ fieldata ) {
51+ $ clean_meta [$ fieldname ]['old ' ] = $ this ->clean_field ($ fieldata ->old );
52+ $ clean_meta [$ fieldname ]['new ' ] = $ this ->clean_field ($ fieldata ->new );
7753 }
7854
7955 }
@@ -122,6 +98,7 @@ public function transformActionlog (Actionlog $actionlog, $settings = null)
12298 'action_date ' => ($ actionlog ->action_date ) ? Helper::getFormattedDateObject ($ actionlog ->action_date , 'datetime ' ): Helper::getFormattedDateObject ($ actionlog ->created_at , 'datetime ' ),
12399
124100 ];
101+ //\Log::info("Clean Meta is: ".print_r($clean_meta,true));
125102
126103 return $ array ;
127104 }
0 commit comments