summaryrefslogtreecommitdiff
path: root/bin/refresh-fb-cache.php
blob: b8711a056be119a169fdcaf93451c33f7f168207 (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
#!/usr/bin/env php
<?php

$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', $fileToFetch];

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

?>