diff --git a/lib/Alchemy/Phrasea/Command/BuildSubdefs.php b/lib/Alchemy/Phrasea/Command/BuildSubdefs.php index 6903d1e5ee..2fc61bc35a 100644 --- a/lib/Alchemy/Phrasea/Command/BuildSubdefs.php +++ b/lib/Alchemy/Phrasea/Command/BuildSubdefs.php @@ -131,28 +131,30 @@ class BuildSubdefs extends Command */ protected function generateSQL(array $subdefNames, array $recordTypes, $min, $max, $withSubstitution, $substitutionOnly) { - $sql = "SELECT DISTINCT(r.record_id) AS record_id" - . " FROM record r LEFT JOIN subdef s ON (r.record_id = s.record_id AND s.name IN (?))" - . " WHERE r.type IN (?)"; + $sql = <<<'SQL' +SELECT DISTINCT(r.record_id) AS record_id +FROM record r LEFT JOIN subdef s ON (r.record_id = s.record_id AND s.name IN (?)) +WHERE r.type IN (?) +SQL; $types = array(Connection::PARAM_STR_ARRAY, Connection::PARAM_STR_ARRAY); $params = array($subdefNames, $recordTypes); if (null !== $min) { - $sql .= " AND (r.record_id >= ?)"; + $sql .= ' AND (r.record_id >= ?)'; $params[] = (int)$min; $types[] = \PDO::PARAM_INT; } if (null !== $max) { - $sql .= " AND (r.record_id <= ?)"; + $sql .= ' AND (r.record_id <= ?)'; $params[] = (int)$max; $types[] = \PDO::PARAM_INT; } if (false === $withSubstitution) { - $sql .= " AND (ISNULL(s.substit) OR s.substit = ?)"; + $sql .= ' AND (ISNULL(s.substit) OR s.substit = ?)'; $params[] = $substitutionOnly ? 1 : 0; $types[] = \PDO::PARAM_INT; } diff --git a/lib/classes/caption/record.php b/lib/classes/caption/record.php index f769f2dad8..1457fd1faa 100644 --- a/lib/classes/caption/record.php +++ b/lib/classes/caption/record.php @@ -75,10 +75,12 @@ class caption_record implements caption_interface, cache_cacheableInterface try { $fields = $this->get_data_from_cache(); } catch (\Exception $e) { - $sql = "SELECT m.id AS meta_id, s.id AS structure_id, value, VocabularyType, VocabularyId" - . " FROM metadatas m, metadatas_structure s" - . " WHERE m.record_id = :record_id AND s.id = m.meta_struct_id" - . " ORDER BY s.sorter ASC"; + $sql = <<<'SQL' +SELECT m.id AS meta_id, s.id AS structure_id, value, VocabularyType, VocabularyId +FROM metadatas m INNER JOIN metadatas_structure s ON s.id = m.meta_struct_id +WHERE m.record_id = :record_id +ORDER BY s.sorter ASC +SQL; $stmt = $this->databox->get_connection()->prepare($sql); $stmt->execute([':record_id' => $this->record->getRecordId()]); $fields = $stmt->fetchAll(PDO::FETCH_ASSOC);