r62250 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62249‎ | r62250 | r62251 >
Date:17:17, 10 February 2010
Author:yaron
Status:deferred
Tags:
Comment:
Added support for SMW 1.5, and 'Text' type properties
Modified paths:
  • /trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticInternalObjects/SemanticInternalObjects_body.php
@@ -57,19 +57,29 @@
5858 $io_id = $this->makeSMWPageID( $internal_object->getName(), $namespace, '' );
5959 $up_rels2 = array();
6060 $up_atts2 = array();
 61+ $up_text2 = array();
6162 // set all the properties pointing from this internal object
6263 foreach ( $internal_object->property_value_pairs as $property_value_pair ) {
6364 list( $property, $value ) = $property_value_pair;
64 - $mode = SMWSQLStore2::getStorageMode( $property->getPropertyTypeID() );
65 - switch ( $mode ) {
66 - case SMW_SQL2_RELS2:
 65+ // handling changed in SMW 1.5
 66+ if (method_exists('SMWSQLStore2', 'findPropertyTableID')) {
 67+ $tableid = SMWSQLStore2::findPropertyTableID( $property );
 68+ $is_relation = ($tableid == 'smw_rels2');
 69+ $is_attribute = ($tableid == 'smw_atts2');
 70+ $is_text = ($tableid == 'smw_text2');
 71+ } else {
 72+ $mode = SMWSQLStore2::getStorageMode( $property->getPropertyTypeID() );
 73+ $is_relation = ($mode == SMW_SQL2_RELS2);
 74+ $is_attribute = ($mode == SMW_SQL2_ATTS2);
 75+ $is_text = ($mode == SMW_SQL2_TEXT2);
 76+ }
 77+ if ($is_relation) {
6778 $up_rels2[] = array(
6879 's_id' => $io_id,
6980 'p_id' => $this->makeSMWPropertyID( $property ),
7081 'o_id' => $this->makeSMWPageID( $value->getDBkey(), $value->getNamespace(), $value->getInterwiki() )
7182 );
72 - break;
73 - case SMW_SQL2_ATTS2:
 83+ } elseif ($is_attribute) {
7484 $keys = $value->getDBkeys();
7585 $up_atts2[] = array(
7686 's_id' => $io_id,
@@ -78,10 +88,16 @@
7989 'value_xsd' => $keys[0],
8090 'value_num' => $value->getNumericValue()
8191 );
82 - break;
 92+ } elseif ($is_text) {
 93+ $keys = $value->getDBkeys();
 94+ $up_text2[] = array(
 95+ 's_id' => $io_id,
 96+ 'p_id' => $this->makeSMWPropertyID($property),
 97+ 'value_blob' => $keys[0]
 98+ );
8399 }
84100 }
85 - return array( $up_rels2, $up_atts2 );
 101+ return array( $up_rels2, $up_atts2, $up_text2 );
86102 }
87103 }
88104
@@ -136,10 +152,12 @@
137153
138154 $all_rels2_inserts = array();
139155 $all_atts2_inserts = array();
 156+ $all_text2_inserts = array();
140157 foreach (self::$internal_objects as $internal_object) {
141 - list($up_rels2, $up_atts2) = $sio_sql_store->getStorageSQL($page_name, $namespace, $internal_object);
 158+ list($up_rels2, $up_atts2, $up_text2) = $sio_sql_store->getStorageSQL($page_name, $namespace, $internal_object);
142159 $all_rels2_inserts = array_merge($all_rels2_inserts, $up_rels2);
143160 $all_atts2_inserts = array_merge($all_atts2_inserts, $up_atts2);
 161+ $all_text2_inserts = array_merge($all_text2_inserts, $up_text2);
144162 }
145163
146164 // now save everything to the database
@@ -149,6 +167,7 @@
150168 $ids_string = '(' . implode (', ', $ids_for_deletion) . ')';
151169 $db->delete('smw_rels2', array("(s_id IN $ids_string) OR (o_id IN $ids_string)"), 'SIO::deleteRels2Data');
152170 $db->delete('smw_atts2', array("s_id IN $ids_string"), 'SIO::deleteAtts2Data');
 171+ $db->delete('smw_text2', array("s_id IN $ids_string"), 'SIO::deleteText2Data');
153172 }
154173
155174 if (count($all_rels2_inserts) > 0) {
@@ -157,6 +176,9 @@
158177 if (count($all_atts2_inserts) > 0) {
159178 $db->insert( 'smw_atts2', $all_atts2_inserts, 'SIO::updateAtts2Data');
160179 }
 180+ if (count($all_text2_inserts) > 0) {
 181+ $db->insert( 'smw_text2', $all_text2_inserts, 'SIO::updateText2Data');
 182+ }
161183 $db->commit('SIO::updatePageData');
162184 self::$internal_objects = array();
163185 return true;

Status & tagging log