Пример #1
0
 public function __construct(array $config = null, $id = null)
 {
     if (!isset($config['cache'])) {
         $config['cache'] = 'default';
     }
     $this->cache = \Cache\Cache::ins($config['cache']);
     parent::__construct($config, $id);
 }
Пример #2
0
 public function testCacheWorkingProperlyAndNotThrowingAnyErrorsOrWarnings()
 {
     $newTestClass = function () {
         return new TestClass();
     };
     Cache::getCache("test", $newTestClass, 3);
     for ($i = 0; $i <= 5; $i++) {
         echo "Cache is " . (Cache::isValid("test") ? "still" : "not") . " valid!\n";
         echo "Cache has " . Cache::getCache("test", $newTestClass, 3)->value . "\n";
         sleep(1);
     }
 }
Пример #3
0
 /**
  * Return the version number for Firefox Aurora
  *
  * @return string version number for Aurora
  */
 private function getAuroraNumber()
 {
     $cache_id = "product_details";
     if (Cache::isActivated()) {
         if (!($json_data = Cache::getKey($cache_id))) {
             // No cache for this request. Read remote and cache answer on disk.
             $json_data = json_decode(file_get_contents($this->json_source), true)['FIREFOX_AURORA'];
             if ($json_data !== null) {
                 Cache::setKey($cache_id, $json_data);
             }
         }
     } else {
         // Cache is disabled. Just read the value.
         $json_data = json_decode(file_get_contents($this->json_source), true)['FIREFOX_AURORA'];
     }
     return $json_data;
 }
    $csv_l10ncomponent = file($bugzilla_query_l10ncomponent . '&ctype=csv');
    $bugs_l10ncomponent = Bugzilla::getBugsFromCSV($csv_l10ncomponent);
    Cache::setKey($cache_id, $bugs_l10ncomponent);
}
$bugs = $bugs_mozillaorg + $bugs_l10ncomponent;
$rss_data = [];
if (count($bugs) > 0) {
    foreach ($bugs as $bug_number => $bug_description) {
        $rss_data[] = ["Bug {$bug_number}: {$bug_description}", "https://bugzilla.mozilla.org/show_bug.cgi?id={$bug_number}", $bug_description];
    }
}
// Read status of external web projects, cache expires after 1 hour.
$cache_id = 'external_webprojects';
if (!($webprojects = Cache::getKey($cache_id, 60 * 60))) {
    $webprojects = $json_data->setURI(WEBPROJECTS_JSON)->fetchContent();
    Cache::setKey($cache_id, $webprojects);
}
// RSS feed data
$total_missing_strings = 0;
$total_errors = 0;
$total_missing_files = 0;
$link = LANG_CHECKER . "?locale={$locale}";
foreach ($lang_files as $site => $site_files) {
    foreach ($site_files as $file => $details) {
        $message = '';
        if ($details['data_source'] == 'lang') {
            // Standard lang file
            $count = $details['identical'] + $details['missing'];
            if ($count > 0) {
                $message = "You have {$count} untranslated ";
                $message .= $count == 1 ? 'string' : 'strings';
Пример #5
0
 /**
  * Return an array of entities for a locale from a repository
  * @param  string $locale     Locale we want to have entities for
  * @param  string $repository string repository such as gaia_2_0, central...
  * @return array  Entities or empty array if no match
  */
 public static function getRepoEntities($locale, $repository)
 {
     $key = $locale . $repository . 'entities';
     if (!($entities = Cache::getKey($key))) {
         if ($entities = array_keys(self::getRepoStrings($locale, $repository))) {
             Cache::setKey($key, $entities);
         }
     }
     return isset($entities) ? $entities : [];
 }
Пример #6
0
 public function afterTestMethod($method)
 {
     switch ($method) {
         case 'testGetRepoStrings':
             // Destroy cached files created by getRepoStrings()
             $obj = new _Cache();
             $obj->flush();
             break;
     }
 }
Пример #7
0
     unset($commits);
     /* cache the data */
     Cache::setKey($cache_id, $stats);
 }
 // Utility closure to create a cache file of filtered strings
 $cache_filtered_strings = function ($lang, $cache_id) use($repo) {
     // Get all the strings (English and locale), ignore empty entities
     $filter_empty = function ($arr) {
         // return $arr;
         return array_filter($arr, 'strlen');
     };
     if ($cache = Cache::getKey($cache_id)) {
         return $cache;
     } else {
         $filtered_strings = $filter_empty(Utils::getRepoStrings($lang, $repo));
         Cache::setKey($cache_id, $filtered_strings);
         return $filtered_strings;
     }
 };
 $strings[$locale][$repo] = $cache_filtered_strings($locale, $locale . $repo . 'filteredstrings');
 $strings[$ref_locale][$repo] = $cache_filtered_strings($ref_locale, $ref_locale . $repo . 'filteredstrings');
 // If Desktop, parse the strings to get components
 if (in_array($repo, Project::getDesktopRepositories())) {
     foreach (Project::getComponents($strings[$locale][$repo]) as $component) {
         $filter_pattern = function ($locale_code) use($component, $repo, $strings) {
             return array_filter(preg_grep('#^' . $component . '/.*#', array_keys($strings[$locale_code][$repo])), 'strlen');
         };
         $locale_entities = $filter_pattern($locale);
         $english_entities = $filter_pattern($ref_locale);
         // Skip some special cases (mostly optional strings)
         $path = [];
Пример #8
0
 /**
  * 清除缓存,按需重载
  *
  * @param string $cachename
  * @return boolean
  */
 protected function removeCache($cachename)
 {
     return Cache::ins()->delete($cachename);
 }
Пример #9
0
<?php

namespace Transvision;

use Cache\Cache;
$cache_id = $repo . $entity . 'alllocales';
if (!($translations = Cache::getKey($cache_id))) {
    $translations = [];
    foreach (Project::getRepositoryLocales($repo) as $locale_code) {
        $strings = Utils::getRepoStrings($locale_code, $repo);
        if (isset($strings[$entity])) {
            $strings[$entity] = trim($strings[$entity]);
            if (Strings::endsWith(strtolower($strings[$entity]), '{ok}')) {
                $strings[$entity] = trim(substr($strings[$entity], 0, -4));
            }
            $translations[$locale_code] = $strings[$entity];
        }
        // Releasing memory in the loop saves 15% memory on the script
        unset($strings);
    }
    Cache::setKey($cache_id, $translations);
}
return $json = $translations;
Пример #10
0
*/
namespace Webdashboard;

use Bugzilla\Bugzilla;
use Cache\Cache;
require_once __DIR__ . '/../config/init.php';
// Include all data about our locales
include __DIR__ . '/../data/locales.php';
$results = [];
$results['types']["Webbugs"] = ["pluralLabel" => "Webbugs"];
$results['properties']["total_webbugs"] = ["valueType" => "number"];
$results['properties']["missing_webbugs"] = ["valueType" => "number"];
// All opened bugs for a locale in the mozilla.org/l10n component
foreach ($locales as $locale) {
    $bugzilla_query = 'https://bugzilla.mozilla.org/buglist.cgi?' . 'f1=cf_locale' . '&o1=equals' . '&query_format=advanced' . '&v1=' . urlencode(Bugzilla::getBugzillaLocaleField($locale)) . '&o2=equals' . '&f2=component' . '&v2=L10N' . '&bug_status=UNCONFIRMED' . '&bug_status=NEW' . '&bug_status=ASSIGNED' . '&bug_status=REOPENED' . '&classification=Other' . '&product=www.mozilla.org';
    /* Check if there is a cached request for this element.
     * For this request I use a ttl of 6 hours instead of default (15 minutes),
     * since it requires a lot of time.
     */
    $cache_id = "bugs_mozillaorg_{$locale}";
    $bugs = Cache::getKey($cache_id, 6 * 60 * 60);
    if ($bugs === false) {
        $csv = file($bugzilla_query . '&ctype=csv');
        $bugs = Bugzilla::getBugsFromCSV($csv);
        Cache::setKey($cache_id, $bugs);
    }
    // Generate all the bugs
    $results['items'][] = ["type" => "Webbugs", "label" => $locale, "missing_webbugs" => count($bugs), "total_webbugs" => count($bugs)];
}
$json_data = new Json();
print $json_data->outputContent($results, false, true);
Пример #11
0
    }
    $locales = array_merge($locales, array_keys($data_page));
}
$locales = array_unique($locales);
sort($locales);
$total_locales = count(array_unique($locales));
$locales_per_page = [];
$page_descriptions = [];
// Get status from all locales for each page
foreach ($pages as $page) {
    $filename = $page['file'];
    $json_string = $langchecker_query . '&file=' . $filename . '&website=' . $page['site'];
    $cache_id = 'page_' . $filename . '_' . $page['site'];
    if (!($data_page = Cache::getKey($cache_id))) {
        $data_page = $json_data->setURI($json_string)->fetchContent()[$filename];
        Cache::setKey($cache_id, $data_page);
    }
    $locales_per_page[$filename] = array_keys($data_page);
    foreach ($locales as $locale) {
        if (in_array($locale, $locales_per_page[$filename])) {
            $status[$locale][$filename] = $data_page[$locale];
            continue;
        }
        $status[$locale][$filename] = 'none';
    }
    $page_descriptions[$filename] = $page['description'];
}
ksort($status);
// For each locale and each page, check the status and store it into a new array
$status_formatted = [];
$locale_done_per_page = [];