public function findMeta(DatabaseInterface $db, NodeRef $originNodeRef, $ids, $metaPartials = 'fields', $forceReadWrite = false, $restrictedPartials = '') { $results = array(); if (empty($metaPartials)) { return $results; } $this->Logger->debug('findMeta with partials [' . $metaPartials . '] restrict [' . $restrictedPartials . ']'); $returnOne = false; if (!is_array($ids)) { $returnOne = $ids; $ids = array($originNodeRef->getRefURL() => $ids); } $partials = PartialUtils::unserializeMetaPartials($metaPartials); $restrictedPartials = PartialUtils::unserializeMetaPartials($restrictedPartials); if ($restrictedPartials == 'all' || ($x = array_search('all', $restrictedPartials)) !== false) { return array(); } $tableid = $this->NodeDBMeta->getPrimaryKey($originNodeRef); $now = $this->DateFactory->newLocalDate(); $metaPartials = array(); $all = false; $metaDefs = $originNodeRef->getElement()->getSchema()->getMetaDefs(); $metaSchemas = $originNodeRef->getElement()->getSchema()->getMetaStorageDatatypes(); if ($partials == 'all' || ($x = array_search('all', $partials)) !== false) { if ($partials == 'all' || isset($x) && $x !== false) { $all = true; if (is_array($partials)) { unset($partials[$x]); } else { $partials = array(); } } } foreach ($partials as $z => $metaPartial) { if (!array_key_exists($metaPartial->getMetaName(), $metaDefs)) { unset($partials[$z]); continue; } $metaPartials[] = $metaPartial; } $rows = array(); $cachedIds = array(); // retrieve from cache list($cachedIds, $rows) = $this->NodeCache->getMeta('', $ids, $forceReadWrite); $remainingIds = array_diff($ids, $cachedIds); if (!empty($remainingIds)) { $dbToCacheRows = array(); // perform a SQL statement per partial foreach ($metaSchemas as $datatype) { $table = $this->NodeDBMeta->getMetaTable($originNodeRef, $datatype); $q = new Query(); $q->SELECT($tableid . ' as ID'); $q->SELECT(array('Name as MetaName')); if (($datatypeCol = $this->NodeDBMeta->getMetaDatatypeColumn($datatype)) != null) { $q->SELECT("{$datatypeCol}Value as MetaValue"); } $q->FROM($db->quoteIdentifier($table)); $q->WHERE("{$tableid} IN ({$db->joinQuote((array) $remainingIds)})"); $dbRows = $this->getConnectionForWrite($originNodeRef)->readAll($q); foreach ($dbRows as $row) { $dbToCacheRows[$row['ID']][] = $row; $rows[] = $row; } unset($dbRows); unset($datatype); unset($q); unset($table); } $this->NodeCache->putMeta('', $remainingIds, $dbToCacheRows, $forceReadWrite); unset($dbToCacheRows); unset($remainingIds); unset($metaSchemas); } foreach ($rows as $row) { $id = $row['ID']; unset($row['ID']); if (!array_key_exists($row['MetaName'], $metaDefs)) { continue; } foreach ($restrictedPartials as $dPartial) { if (strcmp($dPartial->getMetaName(), $row['MetaName']) === 0) { continue 2; } } if (!$all) { $found = false; foreach ($metaPartials as $dPartial) { if (strcmp($dPartial->getMetaName(), $row['MetaName']) === 0) { $found = true; break; } } if (!$found) { continue; } } $metaDef = $metaDefs[$row['MetaName']]; $row['MetaTitle'] = $metaDef->Title; $row['MetaStorageDatatype'] = (string) $metaDef->Datatype; $row['MetaValidationDatatype'] = $metaDef->Validation->getDatatype(); if ($row['MetaValidationDatatype'] == 'date') { $row['MetaValue'] = $this->TypeConverter->convertFromString($metaDef->Validation, $row['MetaValue'], null, true); } else { if ($row['MetaStorageDatatype'] == 'flag') { $row['MetaValue'] = 1; } } $row['NoValidation'] = true; $results[$id][$row['MetaName']] = new Meta($row); } if ($returnOne) { return isset($results[$returnOne]) ? $results[$returnOne] : array(); } return $results; }