Ejemplo n.º 1
0
 public function addEntity(TranslationEntity $entity)
 {
     $id = $entity->getObjectId();
     $kind = $entity->getObjectKind();
     if (!$this->idWasCached($id, $kind)) {
         $tOfKey = $this->translationOfKeyPrefix . $entity->getOriginalObjectId();
         $idKey = $this->pIdKeyPrefix . $id;
         if (!array_key_exists($kind, $this->entitiesMap)) {
             $this->entitiesMap[$kind] = array();
         }
         if (!array_key_exists($tOfKey, $this->entitiesMap[$kind])) {
             $this->entitiesMap[$kind][$tOfKey] = array();
         }
         $this->entitiesMap[$kind][$tOfKey][] = $entity;
         $this->entitiesIds[$kind][$idKey] = $entity;
     }
 }
Ejemplo n.º 2
0
 protected function cachePageAtId($id)
 {
     global $wpdb;
     $this->logger->logQueryStart();
     $app = Strata::app();
     $configValue = (int) $app->getConfig("i18n.cache_page_size");
     $cachePageSize = $configValue > 0 ? $configValue : $this->pageSize;
     // Don't reload the same ids, if we have already cached rows.
     $count = count($this->cachedIds);
     $notIn = $count > 0 ? " AND polyglot_ID NOT IN (" . implode(",", $this->cachedIds) . ")" : "";
     $records = $wpdb->get_results($wpdb->prepare("\n            SELECT *\n            FROM {$wpdb->prefix}polyglot\n            WHERE polyglot_ID > %d\n            {$notIn}\n            ORDER BY polyglot_ID\n            LIMIT {$cachePageSize}", $id));
     $this->logger->logQueryCompletion($wpdb->last_query);
     foreach ($records as $record) {
         $this->cache->addEntity(TranslationEntity::factory($record));
     }
     $this->nbPageSaved++;
 }