public static function deleteAllCached()
 {
     foreach (self::$_cached as $url => $tempFile) {
         if (XenForo_Application::debugMode()) {
             $fileSize = @filesize($tempFile);
         }
         $deleted = @unlink($tempFile);
         if (XenForo_Application::debugMode()) {
             XenForo_Helper_File::log(__CLASS__, call_user_func_array('sprintf', array('delete %s -> %s, %s, %d bytes', $url, $tempFile, $deleted ? 'succeeded' : 'failed', !empty($fileSize) ? $fileSize : 0)));
         }
     }
     self::$_cached = array();
 }
    private static function _onAddOnUpgrade(XenForo_ControllerResponse_View &$controllerResponse)
    {
        if (!empty($_GET[self::PARAM_AUTHORIZE]) && $_GET[self::PARAM_AUTHORIZE] === self::$_config['apiUrl']) {
            $downloadLink = XenForo_Link::buildAdminLink('full:add-ons/upgrade', $controllerResponse->params['addOn'], array(self::PARAM_DOWNLOAD => self::$_config['apiUrl']));
            $downloadLinkJson = json_encode($downloadLink);
            $accessTokenParamJson = json_encode(self::PARAM_ACCESS_TOKEN);
            $js = <<<EOF
<script>
var hash = window.location.hash.substr(1);
var regex = /access_token=(.+?)(&|\$)/;
var match = hash.match(regex);
if (match) {
    var accessToken = match[1];
    var downloadLink = {$downloadLinkJson};
    var redirect = downloadLink + '&' + {$accessTokenParamJson} + '=' + encodeURIComponent(accessToken);

    window.location = redirect;
}
</script>
EOF;
            die($js);
        }
        if (!empty($_GET[self::PARAM_DOWNLOAD]) && $_GET[self::PARAM_DOWNLOAD] === self::$_config['apiUrl']) {
            $accessToken = '';
            if (!empty($_GET[self::PARAM_ACCESS_TOKEN])) {
                $accessToken = $_GET[self::PARAM_ACCESS_TOKEN];
            }
            $addOnId = $controllerResponse->params['addOn']['addon_id'];
            $data = self::_fetchData(self::$_config['apiUrl'], array($addOnId), $accessToken);
            if (!empty($data[$addOnId]['links']['content'])) {
                $tempFile = WidgetFramework_ShippableHelper_TempFile::download($data[$addOnId]['links']['content']);
                $xmlPath = self::_updateAddOnFiles($addOnId, $tempFile);
                /** @noinspection BadExpressionStatementJS */
                die(sprintf('<script>window.location = %s;</script>', json_encode(XenForo_Link::buildAdminLink('add-ons/upgrade', array('addon_id' => $addOnId), array(self::PARAM_IMPORT_XML => self::$_config['apiUrl'], self::PARAM_IMPORT_XML_PATH => $xmlPath)))));
            }
        }
        if (!empty($_GET[self::PARAM_IMPORT_XML]) && $_GET[self::PARAM_IMPORT_XML] === self::$_config['apiUrl'] && !empty($_GET[self::PARAM_IMPORT_XML_PATH])) {
            $addOnId = $controllerResponse->params['addOn']['addon_id'];
            $xmlPath = $_GET[self::PARAM_IMPORT_XML_PATH];
            /** @var XenForo_Model_AddOn $addOnModel */
            $addOnModel = XenForo_Model::create('XenForo_Model_AddOn');
            $addOnModel->installAddOnXmlFromFile($xmlPath, $addOnId);
            $addOn = $addOnModel->getAddOnById($addOnId);
            echo sprintf('Updated add-on %1$s to v%2$s (#%3$d)', $addOn['title'], $addOn['version_string'], $addOn['version_id']);
            /** @noinspection BadExpressionStatementJS */
            die(sprintf('<script>window.f=function(){window.location=%s;};' . 'window.setTimeout("f()",5000);</script>', json_encode(XenForo_Link::buildAdminLink('full:tools/run-deferred', null, array('redirect' => XenForo_Link::buildAdminLink('full:add-ons'))))));
        }
    }