summaryrefslogtreecommitdiff
path: root/bin/refresh-fb-cache.php
blob: 4b702efd63e0121f95bab31338cf94a19adb0f0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env php
<?php

sleep(rand(35, 70));

$BASEPATH = dirname(__FILE__);
chdir($BASEPATH);

require_once('../providers/Facebook.php');

$cacheFiles = glob('../cache/facebook.*');

$fileToFetch = NULL;
$oldestCache = PHP_INT_MAX;

foreach ($cacheFiles as $file) {
    if (!preg_match('/\.Piwoteka$/', $file)) {
        $cacheTime = filemtime($file);
        if ($cacheTime < $oldestCache) {
            $oldestCache = $cacheTime;
            $fileToFetch = explode('.', basename($file));
            array_shift($fileToFetch);
            $fileToFetch = implode('.', $fileToFetch);
        }
    }
}

$filesToFetch = ['Piwoteka', 'fermentlodz', '103731068463865', $fileToFetch];

foreach ($filesToFetch as $feed) {
    sleep(rand(60, 90));
    $provider = new \Providers\Facebook($feed, ['force' => TRUE]);
    if (!$provider->get()) {
        throw new \Exception(sprintf('Feed %s failed to fetch!', $feed));
    }
}

?>