Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStoreLight.php |
— | — | @@ -929,57 +929,98 @@ |
930 | 930 | */ |
931 | 931 | protected function setupTables( $verbose, $db ) { |
932 | 932 | global $wgDBtype; |
933 | | - extract( $db->tableNames( 'smw_ids', 'smw_spec2', 'smw_conccache', 'smw_conc2' ) ); |
934 | | - $reportTo = $verbose ? $this:null; // use $this to report back from static SMWSQLHelpers |
935 | | - // repeatedly used DB field types defined here for convenience |
936 | | - $dbtypes = array( 't' => SMWSQLHelpers::getStandardDBType( 'title' ), |
937 | | - 'u' => ( $wgDBtype == 'postgres' ? 'TEXT':'VARCHAR(63) binary' ), |
938 | | - 'l' => SMWSQLHelpers::getStandardDBType( 'blob' ), |
939 | | - 'f' => ( $wgDBtype == 'postgres' ? 'DOUBLE PRECISION':'DOUBLE' ), |
940 | | - 'i' => ( $wgDBtype == 'postgres' ? 'INTEGER':'INT(8)' ), |
941 | | - 'j' => ( $wgDBtype == 'postgres' ? 'INTEGER':'INT(8) UNSIGNED' ), |
942 | | - 'p' => SMWSQLHelpers::getStandardDBType( 'id' ), |
943 | | - 'n' => SMWSQLHelpers::getStandardDBType( 'namespace' ), |
944 | | - 'w' => SMWSQLHelpers::getStandardDBType( 'iw' ) ); |
| 933 | + |
| 934 | + $reportTo = $verbose ? $this : null; // Use $this to report back from static SMWSQLHelpers. |
| 935 | + |
| 936 | + // Repeatedly used DB field types defined here for convenience. |
| 937 | + $dbtypes = array( |
| 938 | + 't' => SMWSQLHelpers::getStandardDBType( 'title' ), |
| 939 | + 'u' => ( $wgDBtype == 'postgres' ? 'TEXT' : 'VARCHAR(63) binary' ), |
| 940 | + 'l' => SMWSQLHelpers::getStandardDBType( 'blob' ), |
| 941 | + 'f' => ( $wgDBtype == 'postgres' ? 'DOUBLE PRECISION' : 'DOUBLE' ), |
| 942 | + 'i' => ( $wgDBtype == 'postgres' ? 'INTEGER' : 'INT(8)' ), |
| 943 | + 'j' => ( $wgDBtype == 'postgres' ? 'INTEGER' : 'INT(8) UNSIGNED' ), |
| 944 | + 'p' => SMWSQLHelpers::getStandardDBType( 'id' ), |
| 945 | + 'n' => SMWSQLHelpers::getStandardDBType( 'namespace' ), |
| 946 | + 'w' => SMWSQLHelpers::getStandardDBType( 'iw' ) |
| 947 | + ); |
945 | 948 | |
946 | | - // DB update: field renaming between SMW 1.3 and SMW 1.4 |
947 | | - if ( ( $db->tableExists( $smw_spec2 ) ) && ( $db->fieldExists( $smw_spec2, 'sp_id', 'SMWSQLStoreLight::setup' ) ) ) { |
| 949 | + $smw_spec2 = $db->tableName( 'smw_spec2' ); |
| 950 | + |
| 951 | + // DB update: field renaming between SMW 1.3 and SMW 1.4. |
| 952 | + if ( ( $db->tableExists( $smw_spec2 ) ) && ( $db->fieldExists( $smw_spec2, 'sp_id', 'SMWSQLStore2::setup' ) ) ) { |
948 | 953 | if ( $wgDBtype == 'postgres' ) { |
949 | | - $db->query( "ALTER TABLE $smw_spec2 ALTER COLUMN sp_id RENAME TO p_id", 'SMWSQLStoreLight::setup' ); |
| 954 | + $db->query( "ALTER TABLE $smw_spec2 ALTER COLUMN sp_id RENAME TO p_id", 'SMWSQLStore2::setup' ); |
950 | 955 | } else { |
951 | | - $db->query( "ALTER TABLE $smw_spec2 CHANGE `sp_id` `p_id` " . $dbtypes['p'] . " NOT NULL", 'SMWSQLStoreLight::setup' ); |
| 956 | + $db->query( "ALTER TABLE $smw_spec2 CHANGE `sp_id` `p_id` " . $dbtypes['p'] . " NOT NULL", 'SMWSQLStore2::setup' ); |
952 | 957 | } |
953 | 958 | } |
954 | 959 | |
955 | | - // set up table for internal IDs used in this store: |
956 | | - SMWSQLHelpers::setupTable( $smw_ids, |
957 | | - array( 'smw_id' => $dbtypes['p'] . ' NOT NULL' . ( $wgDBtype == 'postgres' ? ' PRIMARY KEY':' KEY AUTO_INCREMENT' ), |
958 | | - 'smw_namespace' => $dbtypes['n'] . ' NOT NULL', |
959 | | - 'smw_title' => $dbtypes['t'] . ' NOT NULL', |
960 | | - 'smw_iw' => $dbtypes['w'], |
961 | | - 'smw_sortkey' => $dbtypes['t'] . ' NOT NULL' ), $db, $reportTo ); |
962 | | - SMWSQLHelpers::setupIndex( $smw_ids, array( 'smw_id', 'smw_title,smw_namespace,smw_iw', 'smw_sortkey' ), $db ); |
| 960 | + // Set up table for internal IDs used in this store: |
| 961 | + SMWSQLHelpers::setupTable( |
| 962 | + 'smw_ids', |
| 963 | + array( |
| 964 | + 'smw_id' => $dbtypes['p'] . ' NOT NULL' . ( $wgDBtype == 'postgres' ? ' PRIMARY KEY' : ' KEY AUTO_INCREMENT' ), |
| 965 | + 'smw_namespace' => $dbtypes['n'] . ' NOT NULL', |
| 966 | + 'smw_title' => $dbtypes['t'] . ' NOT NULL', |
| 967 | + 'smw_iw' => $dbtypes['w'], |
| 968 | + 'smw_sortkey' => $dbtypes['t'] . ' NOT NULL' |
| 969 | + ), |
| 970 | + $db, |
| 971 | + $reportTo |
| 972 | + ); |
| 973 | + |
| 974 | + SMWSQLHelpers::setupIndex( 'smw_ids', array( 'smw_id', 'smw_title,smw_namespace,smw_iw', 'smw_sortkey' ), $db ); |
963 | 975 | |
964 | | - // set up concept cache: member elements (s)->concepts (o) |
965 | | - SMWSQLHelpers::setupTable( $smw_conccache, |
966 | | - array( 's_id' => $dbtypes['p'] . ' NOT NULL', |
967 | | - 'o_id' => $dbtypes['p'] . ' NOT NULL' ), $db, $reportTo ); |
968 | | - SMWSQLHelpers::setupIndex( $smw_conccache, array( 'o_id' ), $db ); |
969 | | - // set up concept descriptions |
970 | | - SMWSQLHelpers::setupTable( $smw_conc2, |
971 | | - array( 's_id' => $dbtypes['p'] . ' NOT NULL' . |
972 | | - ( $wgDBtype == 'postgres' ? ' PRIMARY KEY':' KEY' ), |
973 | | - 'concept_txt' => $dbtypes['l'], |
974 | | - 'concept_docu' => $dbtypes['l'], |
975 | | - 'concept_features' => $dbtypes['i'], |
976 | | - 'concept_size' => $dbtypes['i'], |
977 | | - 'concept_depth' => $dbtypes['i'], |
978 | | - 'cache_date' => $dbtypes['j'], |
979 | | - 'cache_count' => $dbtypes['j'] ), $db, $reportTo ); |
980 | | - SMWSQLHelpers::setupIndex( $smw_conc2, array( 's_id' ), $db ); |
| 976 | + // Set up concept cache: member elements (s)->concepts (o) |
| 977 | + SMWSQLHelpers::setupTable( |
| 978 | + 'smw_conccache', |
| 979 | + array( |
| 980 | + 's_id' => $dbtypes['p'] . ' NOT NULL', |
| 981 | + 'o_id' => $dbtypes['p'] . ' NOT NULL' |
| 982 | + ), |
| 983 | + $db, |
| 984 | + $reportTo |
| 985 | + ); |
| 986 | + |
| 987 | + SMWSQLHelpers::setupIndex( 'smw_conccache', array( 'o_id' ), $db ); |
| 988 | + |
| 989 | + // Set up concept descriptions. |
| 990 | + SMWSQLHelpers::setupTable( |
| 991 | + 'smw_conc2', |
| 992 | + array( |
| 993 | + 's_id' => $dbtypes['p'] . ' NOT NULL' . ( $wgDBtype == 'postgres' ? ' PRIMARY KEY' : ' KEY' ), |
| 994 | + 'concept_txt' => $dbtypes['l'], |
| 995 | + 'concept_docu' => $dbtypes['l'], |
| 996 | + 'concept_features' => $dbtypes['i'], |
| 997 | + 'concept_size' => $dbtypes['i'], |
| 998 | + 'concept_depth' => $dbtypes['i'], |
| 999 | + 'cache_date' => $dbtypes['j'], |
| 1000 | + 'cache_count' => $dbtypes['j'] |
| 1001 | + ), |
| 1002 | + $db, |
| 1003 | + $reportTo |
| 1004 | + ); |
| 1005 | + |
| 1006 | + SMWSQLHelpers::setupIndex( 'smw_conc2', array( 's_id' ), $db ); |
981 | 1007 | |
982 | 1008 | // Set up all property tables as defined: |
983 | | - foreach ( SMWSQLStoreLight::getPropertyTables() as $proptable ) { |
| 1009 | + $this->setupPropertyTables( $dbtypes, $db, $reportTo ); |
| 1010 | + |
| 1011 | + $this->reportProgress( "Database initialised successfully.\n\n", $verbose ); |
| 1012 | + } |
| 1013 | + |
| 1014 | + /** |
| 1015 | + * Sets up the property tables. |
| 1016 | + * |
| 1017 | + * @param array $dbtypes |
| 1018 | + * @param $db |
| 1019 | + * @param $reportTo SMWSQLStore2 or null |
| 1020 | + */ |
| 1021 | + protected function setupPropertyTables( array $dbtypes, $db, $reportTo ) { |
| 1022 | + $addedCustomTypeSignatures = false; |
| 1023 | + |
| 1024 | + foreach ( self::getPropertyTables() as $proptable ) { |
984 | 1025 | if ( $proptable->idsubject ) { |
985 | 1026 | $fieldarray = array( 's_id' => $dbtypes['p'] . ' NOT NULL' ); |
986 | 1027 | $indexes = array( 's_id' ); |
— | — | @@ -987,19 +1028,30 @@ |
988 | 1029 | $fieldarray = array( 's_title' => $dbtypes['t'] . ' NOT NULL', 's_namespace' => $dbtypes['n'] . ' NOT NULL' ); |
989 | 1030 | $indexes = array( 's_title,s_namespace' ); |
990 | 1031 | } |
991 | | - if ( $proptable->fixedproperty == false ) { |
| 1032 | + |
| 1033 | + if ( !$proptable->fixedproperty ) { |
992 | 1034 | $fieldarray['p_id'] = $dbtypes['p'] . ' NOT NULL'; |
993 | 1035 | $indexes[] = 'p_id'; |
994 | 1036 | } |
| 1037 | + |
995 | 1038 | foreach ( $proptable->objectfields as $fieldname => $typeid ) { |
996 | | - $fieldarray[$fieldname] = $dbtypes[$typeid]; |
| 1039 | + // If the type signature is not recognized and the custom signatures have not been added, add them. |
| 1040 | + if ( !$addedCustomTypeSignatures && !array_key_exists( $typeid, $dbtypes ) ) { |
| 1041 | + wfRunHooks( 'SMWCustomSQLStoreFieldType', array( &$dbtypes ) ); |
| 1042 | + $addedCustomTypeSignatures = true; |
| 1043 | + } |
| 1044 | + |
| 1045 | + // Only add the type when the signature was recognized, otherwise ignore it silently. |
| 1046 | + if ( array_key_exists( $typeid, $dbtypes ) ) { |
| 1047 | + $fieldarray[$fieldname] = $dbtypes[$typeid]; |
| 1048 | + } |
997 | 1049 | } |
| 1050 | + |
998 | 1051 | $indexes = array_merge( $indexes, $proptable->indexes ); |
| 1052 | + |
999 | 1053 | SMWSQLHelpers::setupTable( $proptable->name, $fieldarray, $db, $reportTo ); |
1000 | | - SMWSQLHelpers::setupIndex( $proptable->name, $indexes, $db ); |
1001 | | - } |
1002 | | - |
1003 | | - $this->reportProgress( "Database initialised successfully.\n\n", $verbose ); |
| 1054 | + SMWSQLHelpers::setupIndex( $proptable->name, $indexes, $db ); |
| 1055 | + } |
1004 | 1056 | } |
1005 | 1057 | |
1006 | 1058 | /** |