/** * Updates the content of an existing Lingotek document with the current object contents. * * @param stdClass $translatable_object * A Drupal node object or another object, such as a config chunk, etc. * * @return bool * TRUE on success, FALSE on failure. */ public function updateContentDocument($translatable_object) { $parameters['documentId'] = $translatable_object->getMetadataValue('document_id'); $parameters['documentName'] = $translatable_object->getDocumentName(); $parameters['documentDesc'] = $translatable_object->getDescription(); $parameters['content'] = $translatable_object->documentLingotekXML(); $parameters['url'] = $translatable_object->getUrl(); $parameters['format'] = $this->xmlFormat(); $this->addAdvancedParameters($parameters, $translatable_object); $result = $this->request('updateContentDocumentAsync', $parameters); if ($result) { if (get_class($translatable_object) == 'LingotekConfigSet') { $translatable_object->setStatus(LingotekSync::STATUS_CURRENT); $translatable_object->setTargetsStatus(LingotekSync::STATUS_PENDING); // WTD: there is a race condition here where a user could modify a locales- // source entry between the time the dirty segments are pulled and the time // they are set to current at this point. This same race condition exists // for nodes as well; however, the odds may be lower due to number of entries. LingotekConfigSet::setSegmentStatusToCurrentById($translatable_object->getId()); } } return $result ? TRUE : FALSE; }
/** * Get all lids marked as current or not, in the lingotek_config_map table * * @param int $current * 1 to get lids of all current segments, 0 to get lids for segments that are not current * @param array $lids * a subset of lids to check, defaults to look for all current segments */ public static function getLidsToUpdate($current = 0, $lids = 'all') { $textgroups = array_merge(array(-1), LingotekConfigSet::getTextgroupsForTranslation()); $query = db_select('lingotek_config_map', 'lcm')->fields('lcm', array('lid')); if ($lids !== 'all') { $query->condition('lcm.lid', $lids, 'IN'); } $query->join('locales_source', 'ls', "lcm.lid = ls.lid"); $query->condition('ls.textgroup', $textgroups, 'IN'); $query->join('locales_target', 'lt', "lcm.lid = lt.lid"); $or = db_or(); $or->condition('lcm.current', $current); $or->condition('lt.i18n_status', 1); $query->condition($or); $lids = $query->execute()->fetchCol(); return array_unique($lids); }
public static function getDirtyConfigChunks() { // return the set of chunk IDs, which are the chunks that contain // lids that are in need of some translation. These IDs are calculated // as the segment ID of the first segment in the chunk, divided by // the configured chunk size. So, segments 1 through [chunk size] would // be in chunk #1, etc. $lids = self::getDirtySetLids(); $chunk_ids = array(); foreach ($lids as $lid) { $id = LingotekConfigSet::getSetId($lid); if (array_key_exists($id, $chunk_ids)) { $chunk_ids[$id]++; } else { $chunk_ids[$id] = 1; } } $chunk_ids = self::pruneChunksWithPendingTranslations($chunk_ids); return $chunk_ids; }