Commit b8634f46fca6bda14680138b498bdf969f640a49
1 parent
a6873315
KTS-2460
"Allow reindexing of knowledgetree tables" Updated. Committed By: Conrad Vermeulen Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7342 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
31 additions
and
15 deletions
bin/recreateIndexes.php
| @@ -145,6 +145,9 @@ class IndexRecreator | @@ -145,6 +145,9 @@ class IndexRecreator | ||
| 145 | $this->addForeignKey('discussion_comments', 'in_reply_to', 'discussion_comments', 'id'); | 145 | $this->addForeignKey('discussion_comments', 'in_reply_to', 'discussion_comments', 'id'); |
| 146 | 146 | ||
| 147 | $this->addForeignKey('discussion_threads', 'document_id', 'documents', 'id'); | 147 | $this->addForeignKey('discussion_threads', 'document_id', 'documents', 'id'); |
| 148 | + $this->addForeignKey('discussion_threads', 'first_comment_id', 'discussion_comments', 'id'); | ||
| 149 | + $this->addForeignKey('discussion_threads', 'last_comment_id', 'discussion_comments', 'id'); | ||
| 150 | + $this->addForeignKey('discussion_threads', 'creator_id', 'users', 'id'); | ||
| 148 | 151 | ||
| 149 | $this->addForeignKey('document_archiving_link', 'document_id', 'documents', 'id'); | 152 | $this->addForeignKey('document_archiving_link', 'document_id', 'documents', 'id'); |
| 150 | $this->addForeignKey('document_archiving_link', 'archiving_settings_id', 'archiving_settings', 'id'); | 153 | $this->addForeignKey('document_archiving_link', 'archiving_settings_id', 'archiving_settings', 'id'); |
| @@ -185,9 +188,6 @@ class IndexRecreator | @@ -185,9 +188,6 @@ class IndexRecreator | ||
| 185 | 188 | ||
| 186 | $this->addForeignKey('document_transaction_text','document_id','documents','id'); | 189 | $this->addForeignKey('document_transaction_text','document_id','documents','id'); |
| 187 | 190 | ||
| 188 | - $this->addForeignKey('document_transactions','document_id','documents','id', 'SET NULL', 'SET NULL'); | ||
| 189 | - $this->addForeignKey('document_transactions','user_id','users','id', 'SET NULL', 'SET NULL'); | ||
| 190 | - | ||
| 191 | $this->addForeignKey('document_type_fields_link','document_type_id', 'document_types_lookup','id'); | 191 | $this->addForeignKey('document_type_fields_link','document_type_id', 'document_types_lookup','id'); |
| 192 | $this->addForeignKey('document_type_fields_link','field_id','document_fields','id'); | 192 | $this->addForeignKey('document_type_fields_link','field_id','document_fields','id'); |
| 193 | 193 | ||
| @@ -221,6 +221,9 @@ class IndexRecreator | @@ -221,6 +221,9 @@ class IndexRecreator | ||
| 221 | 221 | ||
| 222 | $this->addForeignKey('fieldsets','master_field','document_fields','id'); | 222 | $this->addForeignKey('fieldsets','master_field','document_fields','id'); |
| 223 | 223 | ||
| 224 | + $this->addForeignKey('folder_descendants','parent_id','folders','id'); | ||
| 225 | + $this->addForeignKey('folder_descendants','folder_id','folders','id'); | ||
| 226 | + | ||
| 224 | $this->addForeignKey('folder_doctypes_link','folder_id','folders','id'); | 227 | $this->addForeignKey('folder_doctypes_link','folder_id','folders','id'); |
| 225 | $this->addForeignKey('folder_doctypes_link','document_type_id','document_types_lookup','id'); | 228 | $this->addForeignKey('folder_doctypes_link','document_type_id','document_types_lookup','id'); |
| 226 | 229 | ||
| @@ -229,16 +232,13 @@ class IndexRecreator | @@ -229,16 +232,13 @@ class IndexRecreator | ||
| 229 | $this->addForeignKey('folder_subscriptions','user_id','users','id'); | 232 | $this->addForeignKey('folder_subscriptions','user_id','users','id'); |
| 230 | $this->addForeignKey('folder_subscriptions','folder_id','folders','id'); | 233 | $this->addForeignKey('folder_subscriptions','folder_id','folders','id'); |
| 231 | 234 | ||
| 232 | - $this->addForeignKey('folder_transactions','folder_id','folders','id', 'SET NULL', 'SET NULL'); | ||
| 233 | - $this->addForeignKey('folder_transactions','user_id','users','id', 'SET NULL', 'SET NULL'); | ||
| 234 | - | ||
| 235 | $this->addForeignKey('folder_workflow_map','folder_id', 'folders','id'); | 235 | $this->addForeignKey('folder_workflow_map','folder_id', 'folders','id'); |
| 236 | $this->addForeignKey('folder_workflow_map','workflow_id', 'workflows','id'); | 236 | $this->addForeignKey('folder_workflow_map','workflow_id', 'workflows','id'); |
| 237 | 237 | ||
| 238 | $this->addForeignKey('folders','creator_id','users','id'); | 238 | $this->addForeignKey('folders','creator_id','users','id'); |
| 239 | $this->addForeignKey('folders','permission_object_id','permission_objects','id'); | 239 | $this->addForeignKey('folders','permission_object_id','permission_objects','id'); |
| 240 | $this->addForeignKey('folders','permission_lookup_id','permission_lookups','id'); | 240 | $this->addForeignKey('folders','permission_lookup_id','permission_lookups','id'); |
| 241 | -// $this->addForeignKey('folders','parent_id','folders','id'); // cant do this because of root that is 0... need to make it null! | 241 | + $this->addForeignKey('folders','parent_id','folders','id'); |
| 242 | 242 | ||
| 243 | $this->addForeignKey('folders_users_roles_link','user_id','users','id'); | 243 | $this->addForeignKey('folders_users_roles_link','user_id','users','id'); |
| 244 | $this->addForeignKey('folders_users_roles_link','document_id','documents','id'); | 244 | $this->addForeignKey('folders_users_roles_link','document_id','documents','id'); |
| @@ -318,6 +318,12 @@ class IndexRecreator | @@ -318,6 +318,12 @@ class IndexRecreator | ||
| 318 | 318 | ||
| 319 | $this->addForeignKey('user_history','user_id','users','id'); | 319 | $this->addForeignKey('user_history','user_id','users','id'); |
| 320 | 320 | ||
| 321 | + $this->addForeignKey('user_history_documents','document_id','documents','id'); | ||
| 322 | + $this->addForeignKey('user_history_documents','user_id','users','id'); | ||
| 323 | + | ||
| 324 | + $this->addForeignKey('user_history_folders','folder_id','folders','id'); | ||
| 325 | + $this->addForeignKey('user_history_folders','user_id','users','id'); | ||
| 326 | + | ||
| 321 | $this->addForeignKey('users','authentication_source_id','authentication_sources','id'); | 327 | $this->addForeignKey('users','authentication_source_id','authentication_sources','id'); |
| 322 | 328 | ||
| 323 | $this->addForeignKey('users_groups_link', 'user_id','users','id'); | 329 | $this->addForeignKey('users_groups_link', 'user_id','users','id'); |
| @@ -386,6 +392,7 @@ class IndexRecreator | @@ -386,6 +392,7 @@ class IndexRecreator | ||
| 386 | $this->addIndex('document_transaction_types_lookup','namespace', 'UNIQUE'); | 392 | $this->addIndex('document_transaction_types_lookup','namespace', 'UNIQUE'); |
| 387 | 393 | ||
| 388 | $this->addIndex('document_transactions','session_id'); | 394 | $this->addIndex('document_transactions','session_id'); |
| 395 | + $this->addIndex('document_transactions','document_id'); | ||
| 389 | 396 | ||
| 390 | $this->addIndex('document_types_lookup','name'); | 397 | $this->addIndex('document_types_lookup','name'); |
| 391 | //$this->addIndex('document_types_lookup','disabled'); ? used | 398 | //$this->addIndex('document_types_lookup','disabled'); ? used |
| @@ -400,14 +407,17 @@ class IndexRecreator | @@ -400,14 +407,17 @@ class IndexRecreator | ||
| 400 | $this->addIndex('fieldsets','is_complete'); | 407 | $this->addIndex('fieldsets','is_complete'); |
| 401 | $this->addIndex('fieldsets','is_system'); | 408 | $this->addIndex('fieldsets','is_system'); |
| 402 | 409 | ||
| 410 | + $this->addIndex('field_orders','child_field_id', 'UNIQUE'); | ||
| 411 | + | ||
| 403 | $this->addIndex('folder_searchable_text','folder_text' ,'FULLTEXT'); | 412 | $this->addIndex('folder_searchable_text','folder_text' ,'FULLTEXT'); |
| 404 | 413 | ||
| 414 | + $this->addIndex('folder_transactions','folder_id'); | ||
| 405 | $this->addIndex('folder_transactions','session_id'); | 415 | $this->addIndex('folder_transactions','session_id'); |
| 406 | 416 | ||
| 407 | - $this->addIndex('folders','name'); | 417 | +// $this->addIndex('folders','name'); |
| 408 | $this->addIndex('folders', array('parent_id','name')); | 418 | $this->addIndex('folders', array('parent_id','name')); |
| 409 | 419 | ||
| 410 | - $this->addIndex('groups_lookup','name'); | 420 | + $this->addIndex('groups_lookup','name', 'UNIQUE'); |
| 411 | $this->addIndex('groups_lookup', array('authentication_source_id','authentication_details_s1')); | 421 | $this->addIndex('groups_lookup', array('authentication_source_id','authentication_details_s1')); |
| 412 | 422 | ||
| 413 | $this->addIndex('interceptor_instances','interceptor_namespace'); // unique? | 423 | $this->addIndex('interceptor_instances','interceptor_namespace'); // unique? |
| @@ -417,7 +427,7 @@ class IndexRecreator | @@ -417,7 +427,7 @@ class IndexRecreator | ||
| 417 | 427 | ||
| 418 | $this->addIndex('metadata_lookup_tree','metadata_lookup_tree_parent'); | 428 | $this->addIndex('metadata_lookup_tree','metadata_lookup_tree_parent'); |
| 419 | 429 | ||
| 420 | - $this->addIndex('mime_types','filetypes'); // should be unique... | 430 | + $this->addIndex('mime_types','filetypes'); |
| 421 | $this->addIndex('mime_types','mimetypes'); | 431 | $this->addIndex('mime_types','mimetypes'); |
| 422 | 432 | ||
| 423 | $this->addIndex('notifications','data_int_1'); // document id seems to be stored in this. used by clearnotifications. | 433 | $this->addIndex('notifications','data_int_1'); // document id seems to be stored in this. used by clearnotifications. |
| @@ -437,9 +447,9 @@ class IndexRecreator | @@ -437,9 +447,9 @@ class IndexRecreator | ||
| 437 | //$this->dropIndex('permission_descriptor_users','descriptor_id'); // in primary | 447 | //$this->dropIndex('permission_descriptor_users','descriptor_id'); // in primary |
| 438 | $this->addIndex('permission_descriptor_users','user_id'); | 448 | $this->addIndex('permission_descriptor_users','user_id'); |
| 439 | 449 | ||
| 440 | - $this->addIndex('permission_descriptors','descriptor'); | 450 | + $this->addIndex('permission_descriptors','descriptor','UNIQUE'); |
| 441 | 451 | ||
| 442 | - $this->addIndex('permission_lookup_assignments', array('permission_lookup_id', 'permission_id')); | 452 | + $this->addIndex('permission_lookup_assignments', array('permission_lookup_id', 'permission_id'), 'UNIQUE'); |
| 443 | //$this->dropIndex('permission_lookup_assignments','permission_lookup_id'); // in composite | 453 | //$this->dropIndex('permission_lookup_assignments','permission_lookup_id'); // in composite |
| 444 | 454 | ||
| 445 | $this->addIndex('permissions','name', 'UNIQUE'); | 455 | $this->addIndex('permissions','name', 'UNIQUE'); |
| @@ -455,7 +465,7 @@ class IndexRecreator | @@ -455,7 +465,7 @@ class IndexRecreator | ||
| 455 | $this->addIndex('system_settings','name', 'UNIQUE'); | 465 | $this->addIndex('system_settings','name', 'UNIQUE'); |
| 456 | 466 | ||
| 457 | $this->addIndex('units_lookup','name' ,'UNIQUE'); | 467 | $this->addIndex('units_lookup','name' ,'UNIQUE'); |
| 458 | - $this->dropIndex('units_lookup','folder_id'); | 468 | +// $this->dropIndex('units_lookup','folder_id'); |
| 459 | $this->addIndex('units_lookup','folder_id' ,'UNIQUE'); | 469 | $this->addIndex('units_lookup','folder_id' ,'UNIQUE'); |
| 460 | 470 | ||
| 461 | $this->addIndex('upgrades','descriptor'); | 471 | $this->addIndex('upgrades','descriptor'); |
| @@ -488,7 +498,7 @@ class IndexRecreator | @@ -488,7 +498,7 @@ class IndexRecreator | ||
| 488 | 498 | ||
| 489 | $this->addIndex('workflow_trigger_instances','namespace'); | 499 | $this->addIndex('workflow_trigger_instances','namespace'); |
| 490 | 500 | ||
| 491 | - $this->addIndex('workflows','name'); | 501 | + $this->addIndex('workflows','name', 'UNIQUE'); |
| 492 | 502 | ||
| 493 | 503 | ||
| 494 | } | 504 | } |
| @@ -518,6 +528,9 @@ class IndexRecreator | @@ -518,6 +528,9 @@ class IndexRecreator | ||
| 518 | 528 | ||
| 519 | function addForeignKey($table, $field, $othertable, $otherfield, $ondelete='cascade', $onupdate='cascade') | 529 | function addForeignKey($table, $field, $othertable, $otherfield, $ondelete='cascade', $onupdate='cascade') |
| 520 | { | 530 | { |
| 531 | + if (!in_array($table, $this->tables)) continue; | ||
| 532 | + if (!in_array($othertable, $this->tables)) continue; | ||
| 533 | + | ||
| 521 | $sql = "alter table $table add foreign key ($field) references $othertable ($otherfield) "; | 534 | $sql = "alter table $table add foreign key ($field) references $othertable ($otherfield) "; |
| 522 | if ($ondelete != '') | 535 | if ($ondelete != '') |
| 523 | $sql .= " on delete $ondelete"; | 536 | $sql .= " on delete $ondelete"; |
| @@ -555,7 +568,6 @@ class IndexRecreator | @@ -555,7 +568,6 @@ class IndexRecreator | ||
| 555 | $this->addPrimaryKey('document_text', 'document_id'); | 568 | $this->addPrimaryKey('document_text', 'document_id'); |
| 556 | $this->addPrimaryKey('document_transaction_types_lookup', 'id'); | 569 | $this->addPrimaryKey('document_transaction_types_lookup', 'id'); |
| 557 | $this->addPrimaryKey('document_transaction_text', 'document_id'); | 570 | $this->addPrimaryKey('document_transaction_text', 'document_id'); |
| 558 | - $this->addPrimaryKey('document_transaction_types_lookup','id'); | ||
| 559 | $this->addPrimaryKey('document_transactions','id'); | 571 | $this->addPrimaryKey('document_transactions','id'); |
| 560 | $this->addPrimaryKey('document_type_fields_link','id'); | 572 | $this->addPrimaryKey('document_type_fields_link','id'); |
| 561 | $this->addPrimaryKey('document_type_fieldsets_link','id'); | 573 | $this->addPrimaryKey('document_type_fieldsets_link','id'); |
| @@ -576,6 +588,7 @@ class IndexRecreator | @@ -576,6 +588,7 @@ class IndexRecreator | ||
| 576 | $this->addPrimaryKey('groups_lookup','id'); | 588 | $this->addPrimaryKey('groups_lookup','id'); |
| 577 | $this->addPrimaryKey('help','id'); | 589 | $this->addPrimaryKey('help','id'); |
| 578 | $this->addPrimaryKey('help_replacement','id'); | 590 | $this->addPrimaryKey('help_replacement','id'); |
| 591 | + $this->addPrimaryKey('index_files','document_id'); | ||
| 579 | $this->addPrimaryKey('interceptor_instances','id'); | 592 | $this->addPrimaryKey('interceptor_instances','id'); |
| 580 | $this->addPrimaryKey('links','id'); | 593 | $this->addPrimaryKey('links','id'); |
| 581 | $this->addPrimaryKey('metadata_lookup','id'); | 594 | $this->addPrimaryKey('metadata_lookup','id'); |
| @@ -625,6 +638,7 @@ class IndexRecreator | @@ -625,6 +638,7 @@ class IndexRecreator | ||
| 625 | $this->addPrimaryKey('workflow_documents','document_id'); | 638 | $this->addPrimaryKey('workflow_documents','document_id'); |
| 626 | $this->addPrimaryKey('workflow_state_permission_assignments','id'); | 639 | $this->addPrimaryKey('workflow_state_permission_assignments','id'); |
| 627 | $this->addPrimaryKey('workflow_states','id'); | 640 | $this->addPrimaryKey('workflow_states','id'); |
| 641 | + $this->addPrimaryKey('workflow_state_transitions',array('state_id','transition_id')); | ||
| 628 | $this->addPrimaryKey('workflow_transitions','id'); | 642 | $this->addPrimaryKey('workflow_transitions','id'); |
| 629 | $this->addPrimaryKey('workflow_trigger_instances','id'); | 643 | $this->addPrimaryKey('workflow_trigger_instances','id'); |
| 630 | $this->addPrimaryKey('workflows','id'); | 644 | $this->addPrimaryKey('workflows','id'); |
| @@ -652,6 +666,7 @@ class IndexRecreator | @@ -652,6 +666,7 @@ class IndexRecreator | ||
| 652 | { | 666 | { |
| 653 | $result = DBUtil::getResultArray("show tables"); | 667 | $result = DBUtil::getResultArray("show tables"); |
| 654 | $tables=array(); | 668 | $tables=array(); |
| 669 | + $this->tables = array(); | ||
| 655 | 670 | ||
| 656 | foreach($result as $table) | 671 | foreach($result as $table) |
| 657 | { | 672 | { |
| @@ -664,6 +679,7 @@ class IndexRecreator | @@ -664,6 +679,7 @@ class IndexRecreator | ||
| 664 | } | 679 | } |
| 665 | 680 | ||
| 666 | $stmt = DBUtil::getResultArray("show create table $tablename"); | 681 | $stmt = DBUtil::getResultArray("show create table $tablename"); |
| 682 | + $this->tables[] = $tablename; | ||
| 667 | 683 | ||
| 668 | $keys = array_keys($stmt[0]); | 684 | $keys = array_keys($stmt[0]); |
| 669 | 685 |