<commit_before><?php
chdir(dirname(__FILE__).'/..');
include('vendor/autoload.php');

/*
Periodically poll a user's history to find any checkins that were missed from the web hook.
For example, offline checkins do not run the web hook.
*/

$users = ORM::for_table('users')
  ->where('micropub_success', 1)
  ->where_not_equal('foursquare_access_token', '')
  ->where_not_equal('micropub_access_token', '')
  ->find_many();
foreach($users as $user) {
  if(import_disabled($user))
    continue;

  echo $user->url . "\n";

  // Get the most recent checkins
  $info = ProcessCheckin::getFoursquareCheckins($user, [
    'limit' => 100,
    'sort' => 'newestfirst'
  ]);

  $queued = 0;

  if(isset($info['response']['checkins']['items']) && count($info['response']['checkins']['items'])) {
    foreach($info['response']['checkins']['items'] as $data) {

      // Avoid importing checkins from before the user was using OwnYourSwarm
      if($data['createdAt'] < strtotime($user->date_created))
        continue;

      // Check the database to see if the checkin was already imported
      $exists = ORM::for_table('checkins')
        ->where('user_id', $user->id)
        ->where('foursquare_checkin_id', $data['id'])
        ->find_one();
      if(!$exists) {
        echo "Found a checkin that was not yet imported: ".$data['id']."\n";

        $checkin = ORM::for_table('checkins')->create();
        $checkin->user_id = $user->id;
        $checkin->foursquare_checkin_id = $data['id'];
        $checkin->published = date('Y-m-d H:i:s', $data['createdAt']);<commit_msg>dont backfill offline checkins before this script was enabled<commit_after><?php
chdir(dirname(__FILE__).'/..');
include('vendor/autoload.php');

/*
Periodically poll a user's history to find any checkins that were missed from the web hook.
For example, offline checkins do not run the web hook.
*/

$users = ORM::for_table('users')
  ->where('micropub_success', 1)
  ->where_not_equal('foursquare_access_token', '')
  ->where_not_equal('micropub_access_token', '')
  ->find_many();
foreach($users as $user) {
  if(import_disabled($user))
    continue;

  echo $user->url . "\n";

  // Get the most recent checkins
  $info = ProcessCheckin::getFoursquareCheckins($user, [
    'limit' => 100,
    'sort' => 'newestfirst'
  ]);

  $queued = 0;

  if(isset($info['response']['checkins']['items']) && count($info['response']['checkins']['items'])) {
    foreach($info['response']['checkins']['items'] as $data) {

      // Avoid importing checkins from before the user was using OwnYourSwarm
      if($data['createdAt'] < strtotime($user->date_created) || $data['createdAt'] < strtotime('2017-05-16T09:00:00+0200'))
        continue;

      // Check the database to see if the checkin was already imported
      $exists = ORM::for_table('checkins')
        ->where('user_id', $user->id)
        ->where('foursquare_checkin_id', $data['id'])
        ->find_one();
      if(!$exists) {
        echo "Found a checkin that was not yet imported: ".$data['id']."\n";

        $checkin = ORM::for_table('checkins')->create();
        $checkin->user_id = $user->id;
        $checkin->foursquare_checkin_id = $data['id'];
        $checkin->published = date('Y-m-d H:i:s', $data['createdAt']);
{'fraction_non_alphanumeric': 0.18318965517241378, 'fraction_numerical': 0.008620689655172414, 'mean_word_length': 3.871064467766117, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6160250', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1045, 'n_words': 237}