@@ -14,9 +14,9 @@ class DT_Data_Reporting_Tools
1414 'type ' => true ,
1515 'last_modified ' => true ,
1616 'date ' => true ,
17+ 'snapshot_date ' => true ,
1718 ];
1819
19-
2020 private static $ excluded_fields = array (
2121 'contacts ' => array ( 'name ' , 'nickname ' , 'tasks ' , 'facebook_data ' ),
2222 'default ' => array ( 'name ' ),
@@ -86,7 +86,7 @@ public static function get_data( string $data_type, $config_key, $flatten = fals
8686 'start ' => $ last_exported_value ,
8787 ];
8888 }
89-
89+ // dt_write_log( 'Filters: ' . json_encode( $filter ) );
9090 // Fetch the data
9191 $ result = null ;
9292 if ( $ is_activity ) {
@@ -101,8 +101,9 @@ public static function get_data( string $data_type, $config_key, $flatten = fals
101101 }
102102
103103 public static function get_post_snapshots ( $ post_type , $ flatten = false , $ filter = null ) {
104+ $ filter = $ filter ? array_intersect_key ( $ filter , self ::$ supported_filters ) : array ();
104105
105- // Fetch all post data
106+ // Fetch all post data
106107 try {
107108 $ snapshots = self ::query_post_snapshots ( $ post_type , $ filter );
108109 dt_write_log ( sizeof ( $ snapshots ['snapshots ' ] ) . ' of ' . $ snapshots ['total ' ] . " - $ post_type snapshots " );
@@ -118,7 +119,7 @@ public static function get_post_snapshots( $post_type, $flatten = false, $filter
118119 $ base_url = self ::get_current_site_base_url ();
119120 $ locations = self ::get_location_data ( $ snapshots ['posts ' ] );
120121
121- // process each post
122+ // process each post
122123 foreach ( $ snapshots ['snapshots ' ] as $ index => $ snapshot ) {
123124 $ result = $ snapshot ['post_content ' ];
124125// dt_write_log( json_encode( $result ) );
@@ -664,17 +665,20 @@ private static function query_post_snapshots( $post_type, $filter ) {
664665 $ wpdb ->query ( "SET time_zone='+00:00'; " );
665666
666667 $ table = $ wpdb ->prefix . 'dt_post_snapshots ' ;
668+ $ where = 'WHERE s.post_type=%s ' ;
669+ $ params = [ $ post_type ];
670+ if ( isset ( $ filter ['snapshot_date ' ] ) && isset ( $ filter ['snapshot_date ' ]['start ' ] ) ) {
671+ $ start = $ filter ['snapshot_date ' ]['start ' ];
672+ $ since = strtotime ( $ start );
673+
674+ $ where .= ' AND s.snapshot_date >= %s ' ;
675+ $ params [] = $ filter ['snapshot_date ' ]['start ' ] ?? '2000-01-01 00:00:00 ' ;
676+ }
667677 $ query = "SELECT s.*
668678 FROM ` $ table` as s
669- WHERE
670- s.post_type = %s
671- AND s.snapshot_date >= %s
679+ $ where
672680 ORDER BY s.snapshot_date ASC
673681 " ;
674- $ params = [
675- $ post_type ,
676- $ filter ['date ' ]['start ' ] ?? '2000-01-01 00:00:00 ' ,
677- ];
678682
679683 $ temp_query = "SELECT count(*) from ( $ query) as temp " ;
680684 $ total = $ wpdb ->get_var ($ wpdb ->prepare (
0 commit comments