Exemple #1
0
/**
 * @param $config
 * @param MessageService $service
 * @param MessageStore $store
 * @param $channel
 * @param $by
 * @throws Exception
 */
function catchupParticipant($config, $service, $store, $channel, $by)
{
    $latest = null;
    $count = 1000;
    do {
        echo "fetch  - {$latest} - {$count} - ";
        switch ($by) {
            case 'channel':
                $res = $service->channelsHistory($channel, $latest, $count);
                break;
            case 'im':
                $res = $service->imHistory($channel, $latest, $count);
                break;
        }
        $messages = $res->messages;
        print_r(count($messages));
        echo "importing - ";
        var_dump($saveRes = $store->save($messages, $channel));
        if ($saveRes['total'] == 0) {
            echo "end, stopping\n";
            break;
        }
        if ($saveRes['success'] == 0) {
            echo "failures, stopping\n";
            break;
        }
        $latest = $messages[count($messages) - 1]->ts;
    } while (true);
}