@@ -95,9 +95,6 @@ public static function call(OkapiRequest $request)
95
95
if (!in_array ($ attribution_append , array ('none ' , 'static ' , 'full ' )))
96
96
throw new InvalidParam ('attribution_append ' );
97
97
98
- $ log_fields = $ request ->get_parameter ('log_fields ' );
99
- if (!$ log_fields ) $ log_fields = "uuid|date|user|type|comment " ; // validation is done on call
100
-
101
98
$ user_uuid = $ request ->get_parameter ('user_uuid ' );
102
99
if ($ user_uuid != null )
103
100
{
@@ -112,6 +109,9 @@ public static function call(OkapiRequest $request)
112
109
else
113
110
$ user_id = null ;
114
111
112
+ $ log_fields = $ request ->get_parameter ('log_fields ' );
113
+ if (!$ log_fields ) $ log_fields = "uuid|date|user|type|comment " ; // validation is done on call
114
+
115
115
$ lpc = $ request ->get_parameter ('lpc ' );
116
116
if ($ lpc === null ) $ lpc = 10 ;
117
117
if ($ lpc == 'all ' )
@@ -125,6 +125,10 @@ public static function call(OkapiRequest $request)
125
125
throw new InvalidParam ('lpc ' , "Must be a positive value. " );
126
126
}
127
127
128
+ $ user_logs_only = $ request ->get_parameter ('user_logs_only ' );
129
+ if (!in_array ($ user_logs_only , array ('true ' , 'false ' )))
130
+ throw new InvalidParam ('user_logs_only ' , "Unknown option: ' $ user_logs_only'. " );
131
+
128
132
if (in_array ('distance ' , $ fields ) || in_array ('bearing ' , $ fields ) || in_array ('bearing2 ' , $ fields )
129
133
|| in_array ('bearing3 ' , $ fields ))
130
134
{
@@ -693,6 +697,19 @@ public static function call(OkapiRequest $request)
693
697
694
698
if (in_array ('latest_logs ' , $ fields ))
695
699
{
700
+ if ($ user_logs_only == 'true ' ) {
701
+ if ($ user_id == null ) {
702
+ # This error can also be triggered via caches/formatters/gpx, which has
703
+ # the "latest_logs=user" option instead of "only_user_logs=true".
704
+ # Therefore we avoid to mention "only_user_logs" in the error message.
705
+
706
+ throw new BadRequest ("Either 'user_uuid' parameter OR Level 3 Authentication is required to retrieve the user's logs. " );
707
+ }
708
+ $ add_where_sql = " and cache_logs.user_id = ' " .Db::escape_string ($ user_id )."' " ;
709
+ } else {
710
+ $ add_where_sql = "" ;
711
+ }
712
+
696
713
foreach ($ results as &$ result_ref )
697
714
$ result_ref ['latest_logs ' ] = array ();
698
715
@@ -718,8 +735,9 @@ public static function call(OkapiRequest $request)
718
735
from cache_logs
719
736
where
720
737
cache_id in (' " .implode ("',' " , array_map ('\okapi\core\Db::escape_string ' , array_keys ($ cacheid2wptcode )))."')
721
- and " .((Settings::get ('OC_BRANCH ' ) == 'oc.pl ' ) ? "deleted = 0 " : "true " )."
722
- order by cache_id, " .$ logs_order_field_SQL ." desc, date_created desc, id desc
738
+ and " .((Settings::get ('OC_BRANCH ' ) == 'oc.pl ' ) ? "deleted = 0 " : "true " ).
739
+ $ add_where_sql ."
740
+ order by cache_id, " .$ logs_order_field_SQL ." desc, cache_logs.date_created desc, cache_logs.id desc
723
741
" );
724
742
725
743
$ loguuids = array ();
0 commit comments