/** * Does update. First deletes, then inserts. * @param $data */ function updateData(SMWSemanticData $data) { $export = SMWExporter::makeExportData($data); $sparqlDeleteText = ""; $sparqlUpdateText = "INSERT DATA {\n"; // let other extensions add additional RDF data for this page (i.e. Semantic Internal Objects) //this code is based on the modifications made on SemanticMediaWiki/includes/export/SMW_OWLExport.php $additionalDataArray = array(); $fullexport = true; $backlinks = false; wfRunHooks('smwAddToRDFExport', array($data->getSubject()->getTitle(), &$additionalDataArray, $fullexport, $backlinks)); // this writes update text for each of the Semantic Internal Objects foreach ($additionalDataArray as $additionalData) { $subject_uri = SMWExporter::expandURI($additionalData->getSubject()->getName()); // remove subject from triple store $sparqlDeleteText .= $this->writeDeleteText($subject_uri); //add new data associated with internal objects $sparqlUpdateText .= $this->writeUpdateText($additionalData->getTripleList()); } $subject_uri = SMWExporter::expandURI($export->getSubject()->getName()); // remove subject from triple store $sparqlDeleteText .= $this->writeDeleteText($subject_uri); $triple_list = $export->getTripleList(); $sparqlUpdateText .= $this->writeUpdateText($triple_list); $sparqlUpdateText .= "}"; //delete the old triples wfDebugLog('SPARQL_LOG', "#===DELETE===\n" . $sparqlDeleteText); $response = $this->do_joseki_post($sparqlDeleteText); //insert the new triples wfDebugLog('SPARQL_LOG', "#===INSERT===\n" . $sparqlUpdateText); $response = $this->do_joseki_post($sparqlUpdateText); //can the delete and insert statements be combined, or will this lead to concurrency issues? return parent::updateData($data); }
/** * Does update. First deletes, then inserts. * @param $data */ function updateData(SMWSemanticData $data) { $export = SMWExporter::makeExportData($data); // let other extensions add additional RDF data for this page (i.e. Semantic Internal Objects) //this code is based on the modifications made on SemanticMediaWiki/includes/export/SMW_OWLExport.php $additionalDataArray = array(); $fullexport = true; $backlinks = false; wfRunHooks('smwAddToRDFExport', array($data->getSubject()->getTitle(), &$additionalDataArray, $fullexport, $backlinks)); $addStatements = array(); foreach ($additionalDataArray as $additionalData) { //add new data associated with internal objects $addStatements = $this->createStatements($additionalData->getTripleList()); } $subject_uri = SMWExporter::expandURI($export->getSubject()->getName()); $this->removeDataForURI($subject_uri); $triple_list = $export->getTripleList(); $addStatements = array_merge($addStatements, $this->createStatements($export->getTripleList())); // create a transaction to execute the updates $statements = array('add' => $addStatements); $transaction = $this->createTransaction($statements); $response = $this->sendTransaction($transaction); //can the delete and insert statements be combined, or will this lead to concurrency issues? return parent::updateData($data); }
/** * Does update. First deletes, then inserts. * @param $data */ function updateData( SMWSemanticData $data ) { $export = SMWExporter::makeExportData( $data ); $subject_uri = SMWExporter::expandURI( $export->getSubject()->getUri() ); // remove subject from triple store $this->removeDataForURI( $subject_uri ); $triple_list = $export->getTripleList(); $sparqlUpdateText = "INSERT INTO <> {\n"; foreach ( $triple_list as $triple ) { $subject = $triple[0]; $predicate = $triple[1]; $object = $triple[2]; $obj_str = ""; $sub_str = ""; $pre_str = ""; if ( $object instanceof SMWExpLiteral ) { // @todo FIXME: Add escaping for results of getLexicalForm()? $obj_str = "\"" . $object->getLexicalForm() . "\"" . ( ( $object->getDatatype() == "" ) ? "" : "^^<" . $object->getDatatype() . ">" ); } elseif ( $object instanceof SMWExpResource ) { $obj_str = "<" . SMWExporter::expandURI( $object->getUri() ) . ">"; } else { $obj_str = "\"\""; } if ( $subject instanceof SMWExpResource ) { $sub_str = "<" . SMWExporter::expandURI( $subject->getUri() ) . ">"; } if ( $predicate instanceof SMWExpResource ) { $pre_str = "<" . SMWExporter::expandURI( $predicate->getUri() ) . ">"; } $sparqlUpdateText .= $sub_str . " " . $pre_str . " " . $obj_str . " .\n"; } $sparqlUpdateText .= "}\n"; // echo "<p style='background: #ccddff'><pre>SPARQL Update text:" . $this->unhtmlify( $sparqlUpdateText ) . " ... tjohoo</pre></p>"; // var_dump(); // TODO Debug-code wfDebugLog( 'SPARQL_LOG', "===INSERT===\n" . $sparqlUpdateText ); $response = $this->do_arc2_query( $sparqlUpdateText ); return parent::updateData( $data ); }
function doUpdateData(SMWSemanticData $data) { return parent::updateData($data); }