public function getCode()
 {
     $response = $this->getResponse();
     $response->setContentType('text/javascript; charset=utf-8');
     $storageModel = new MySQLKeyValueModel();
     try {
         $this->code = $storageModel->get(self::OPTIMIZELY_SCRIPT_KEY);
     } catch (Exception $e) {
         Wikia::log(__METHOD__, false, 'Cannot read Optimizely code from storage.');
         $this->code = '';
     }
     $response->setCacheValidity(self::CACHE_DURATION);
 }
Exemplo n.º 2
0
<?php

/**
 * @author Mateusz 'Warkot' Warkocki <mateusz-warkocki(at)wikia-inc.com>
 *
 * This script downloads a copy of Optimizely script and puts it into local CDN.
 * It is stored via MySQLKeyValueModel which uses 'specials' database.
 */
require_once dirname(__FILE__) . '/../../commandLine.inc';
global $wgDevelEnvironment, $wgOptimizelyUrl, $wgOptimizelyDevUrl;
$url = $wgDevelEnvironment ? $wgOptimizelyDevUrl : $wgOptimizelyUrl;
$data = trim(Http::get($url));
if (!empty($data)) {
    $storageModel = new MySQLKeyValueModel();
    $storedData = $storageModel->get(OptimizelyController::OPTIMIZELY_SCRIPT_KEY);
    if (empty($storedData) || $storedData !== $data) {
        $storageModel->set(OptimizelyController::OPTIMIZELY_SCRIPT_KEY, $data);
    }
}