Ejemplo n.º 1
0
 /**
  * Returns full path the the cache file.
  * @return string
  */
 protected function getCacheFileName()
 {
     return TranslateUtils::cacheFile("translate_groupcache-{$this->group->getId()}-{$this->code}.cdb");
 }
Ejemplo n.º 2
0
 protected function store(array $array)
 {
     $file = TranslateUtils::cacheFile($this->filename);
     file_put_contents($file, serialize($array));
 }
 /**
  * Writes change array as a serialized file into a known place.
  * @param array $array Array of changes as returned by processGroup
  * indexed by message group id.
  * @todo does not belong to this class.
  */
 public static function writeChanges($array)
 {
     // This method is almost identical with MessageIndex::store
     /* This will overwrite the previous cache file if any. Once the cache
      * file is processed with Special:ManageMessageGroups, it is
      * renamed so that it wont be processed again. */
     $file = TranslateUtils::cacheFile(SpecialManageGroups::CHANGEFILE);
     $cache = CdbWriter::open($file);
     $keys = array_keys($array);
     $cache->set('#keys', serialize($keys));
     foreach ($array as $key => $value) {
         $value = serialize($value);
         $cache->set($key, $value);
     }
     $cache->close();
 }
 protected function processSubmit()
 {
     $req = $this->getRequest();
     $out = $this->getOutput();
     $jobs = array();
     $jobs[] = MessageIndexRebuildJob::newJob();
     $changefile = TranslateUtils::cacheFile(self::CHANGEFILE);
     $reader = CdbReader::open($changefile);
     $groups = unserialize($reader->get('#keys'));
     $postponed = array();
     foreach ($groups as $groupId) {
         $group = MessageGroups::getGroup($groupId);
         $changes = unserialize($reader->get($groupId));
         foreach ($changes as $code => $subchanges) {
             foreach ($subchanges as $type => $messages) {
                 foreach ($messages as $index => $params) {
                     $id = self::changeId($groupId, $code, $type, $params['key']);
                     if ($req->getVal($id) === null) {
                         // We probably hit the limit with number of post parameters.
                         $postponed[$groupId][$code][$type][$index] = $params;
                         continue;
                     }
                     if ($type === 'deletion' || $req->getCheck("i/{$id}")) {
                         continue;
                     }
                     $fuzzy = $req->getCheck("f/{$id}") ? 'fuzzy' : false;
                     $key = $params['key'];
                     $title = Title::makeTitleSafe($group->getNamespace(), "{$key}/{$code}");
                     $jobs[] = MessageUpdateJob::newJob($title, $params['content'], $fuzzy);
                 }
             }
             if (!isset($postponed[$groupId][$code])) {
                 $cache = new MessageGroupCache($groupId, $code);
                 $cache->create();
             }
         }
     }
     JobQueueGroup::singleton()->push($jobs);
     $reader->close();
     rename($changefile, $changefile . '-' . wfTimestamp());
     if (count($postponed)) {
         $changefile = TranslateUtils::cacheFile(self::CHANGEFILE);
         $writer = CdbWriter::open($changefile);
         $keys = array_keys($postponed);
         $writer->set('#keys', serialize($keys));
         foreach ($postponed as $groupId => $changes) {
             $writer->set($groupId, serialize($changes));
         }
         $writer->close();
         $this->showChanges(true, $this->getLimit());
     } else {
         $out->addWikiMsg('translate-smg-submitted');
     }
 }
 /**
  * Returns full path to the old cache file location.
  * @return string
  */
 protected function getOldCacheFileName()
 {
     $cacheFileName = "translate_groupcache-{$this->group->getId()}-{$this->code}.cdb";
     return TranslateUtils::cacheFile($cacheFileName);
 }
 protected function getReader()
 {
     if ($this->reader) {
         return $this->reader;
     }
     $file = TranslateUtils::cacheFile($this->filename);
     if (!file_exists($file)) {
         // Create an empty index to allow rebuild
         $this->store(array());
         $this->index = $this->rebuild();
     }
     return $this->reader = CdbReader::open($file);
 }