Example #1
0
/**
 * Handler for the LocalFilePurgeThumbnails hook.
 * To avoid excess inclusion of cloudfiles.php, a hook handler can be added
 * to CommonSettings.php which includes this file and calls this function.
 *
 * @param $file File
 * @param $archiveName string|false
 * @return true
 */
function wmfPurgeBackendThumbCache(File $file, $archiveName)
{
    global $site, $lang;
    // CommonSettings.php
    // Get thumbnail dir relative to thumb zone
    if ($archiveName !== false) {
        $thumbRel = $file->getArchiveThumbRel($archiveName);
        // old version
    } else {
        $thumbRel = $file->getRel();
        // current version
    }
    // Get the container for the thumb zone and delete the objects
    $container = wmfGetSwiftThumbContainer($site, $lang, "{$thumbRel}/");
    if ($container) {
        // sanity
        $files = $container->list_objects(0, NULL, "{$thumbRel}/");
        foreach ($files as $file) {
            try {
                $container->delete_object($file);
            } catch (NoSuchObjectException $e) {
                // probably a race condition
                wfDebugLog('swiftThumb', "Could not delete `{$file}`; object does not exist.");
            }
        }
    }
    return true;
}