getPersistence()->insert( self::REVISION_TABLE_NAME, [ self::REVISION_RESOURCE => $revision->getResourceId(), self::REVISION_VERSION => $revision->getVersion(), self::REVISION_USER => $revision->getAuthorId(), self::REVISION_MESSAGE => $revision->getMessage(), self::REVISION_CREATED => $revision->getDateCreated(), ] ); if (!empty($data)) { $this->saveData($revision, $data); } return $revision; } /** * @param Revision $revision * @param array $data * @return bool * @throws Exception */ protected function saveData(Revision $revision, array $data) { $dataToSave = []; foreach ($data as $triple) { $dataToSave[] = [ self::DATA_RESOURCE_ID => (string)$this->getUniquePrimaryKey(), self::DATA_RESOURCE => (string)$revision->getResourceId(), self::DATA_VERSION => (string)$revision->getVersion(), self::DATA_SUBJECT => (string)$triple->subject, self::DATA_PREDICATE => (string)$triple->predicate, self::DATA_OBJECT => (string)$triple->object, self::DATA_LANGUAGE => (string)$triple->lg ]; } return $this->getPersistence()->insertMultiple(self::DATA_TABLE_NAME, $dataToSave); } /** * @param string $resourceId * @return Revision[] */ public function getAllRevisions(string $resourceId) { $queryBuilder = $this->getQueryBuilder() ->select('*') ->from(self::REVISION_TABLE_NAME) ->where(sprintf(' `%s` = ? ', self::REVISION_RESOURCE)) ->setParameters([$resourceId]); $variables = $this->getPersistence() ->query($queryBuilder->getSQL()) ->fetchAll(); return $this->buildRevisionCollection($variables); } /** * @inheritDoc */ public function getSchema(Schema $schema) { return $this->getServiceLocator()->get(NewSqlSchema::class)->getSchema($schema); } }