Esempio n. 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);
}
Esempio n. 2
0
/**
 * @param $config
 * @param MessageService $service
 * @param MessageStore $store
 * @param $participant
 * @param $by
 * @throws Exception
 */
function catchupParticipant($config, $service, $store, $participant, $by)
{
    $timestamp = time() * 1000;
    $offset = 0;
    $limit = 1000;
    do {
        echo "fetch {$timestamp} limit {$limit} - ";
        $res = $service->getThreadRange($participant, $timestamp, $offset, $limit, $by);
        $messages = $res->payload->actions;
        var_dump(count($messages));
        echo "importing - ";
        var_dump($saveRes = $store->save($messages));
        if ($saveRes['success'] == 0) {
            echo "failures, stopping\n";
            break;
        }
        $timestamp = $messages[0]->timestamp;
    } while (true);
}