Commit 9fd0e50dbb345667588bc4365481b83a21c3951e
1 parent
6f34b6e3
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 | 145 | $this->addForeignKey('discussion_comments', 'in_reply_to', 'discussion_comments', 'id'); |
| 146 | 146 | |
| 147 | 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 | 152 | $this->addForeignKey('document_archiving_link', 'document_id', 'documents', 'id'); |
| 150 | 153 | $this->addForeignKey('document_archiving_link', 'archiving_settings_id', 'archiving_settings', 'id'); |
| ... | ... | @@ -185,9 +188,6 @@ class IndexRecreator |
| 185 | 188 | |
| 186 | 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 | 191 | $this->addForeignKey('document_type_fields_link','document_type_id', 'document_types_lookup','id'); |
| 192 | 192 | $this->addForeignKey('document_type_fields_link','field_id','document_fields','id'); |
| 193 | 193 | |
| ... | ... | @@ -221,6 +221,9 @@ class IndexRecreator |
| 221 | 221 | |
| 222 | 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 | 227 | $this->addForeignKey('folder_doctypes_link','folder_id','folders','id'); |
| 225 | 228 | $this->addForeignKey('folder_doctypes_link','document_type_id','document_types_lookup','id'); |
| 226 | 229 | |
| ... | ... | @@ -229,16 +232,13 @@ class IndexRecreator |
| 229 | 232 | $this->addForeignKey('folder_subscriptions','user_id','users','id'); |
| 230 | 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 | 235 | $this->addForeignKey('folder_workflow_map','folder_id', 'folders','id'); |
| 236 | 236 | $this->addForeignKey('folder_workflow_map','workflow_id', 'workflows','id'); |
| 237 | 237 | |
| 238 | 238 | $this->addForeignKey('folders','creator_id','users','id'); |
| 239 | 239 | $this->addForeignKey('folders','permission_object_id','permission_objects','id'); |
| 240 | 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 | 243 | $this->addForeignKey('folders_users_roles_link','user_id','users','id'); |
| 244 | 244 | $this->addForeignKey('folders_users_roles_link','document_id','documents','id'); |
| ... | ... | @@ -318,6 +318,12 @@ class IndexRecreator |
| 318 | 318 | |
| 319 | 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 | 327 | $this->addForeignKey('users','authentication_source_id','authentication_sources','id'); |
| 322 | 328 | |
| 323 | 329 | $this->addForeignKey('users_groups_link', 'user_id','users','id'); |
| ... | ... | @@ -386,6 +392,7 @@ class IndexRecreator |
| 386 | 392 | $this->addIndex('document_transaction_types_lookup','namespace', 'UNIQUE'); |
| 387 | 393 | |
| 388 | 394 | $this->addIndex('document_transactions','session_id'); |
| 395 | + $this->addIndex('document_transactions','document_id'); | |
| 389 | 396 | |
| 390 | 397 | $this->addIndex('document_types_lookup','name'); |
| 391 | 398 | //$this->addIndex('document_types_lookup','disabled'); ? used |
| ... | ... | @@ -400,14 +407,17 @@ class IndexRecreator |
| 400 | 407 | $this->addIndex('fieldsets','is_complete'); |
| 401 | 408 | $this->addIndex('fieldsets','is_system'); |
| 402 | 409 | |
| 410 | + $this->addIndex('field_orders','child_field_id', 'UNIQUE'); | |
| 411 | + | |
| 403 | 412 | $this->addIndex('folder_searchable_text','folder_text' ,'FULLTEXT'); |
| 404 | 413 | |
| 414 | + $this->addIndex('folder_transactions','folder_id'); | |
| 405 | 415 | $this->addIndex('folder_transactions','session_id'); |
| 406 | 416 | |
| 407 | - $this->addIndex('folders','name'); | |
| 417 | +// $this->addIndex('folders','name'); | |
| 408 | 418 | $this->addIndex('folders', array('parent_id','name')); |
| 409 | 419 | |
| 410 | - $this->addIndex('groups_lookup','name'); | |
| 420 | + $this->addIndex('groups_lookup','name', 'UNIQUE'); | |
| 411 | 421 | $this->addIndex('groups_lookup', array('authentication_source_id','authentication_details_s1')); |
| 412 | 422 | |
| 413 | 423 | $this->addIndex('interceptor_instances','interceptor_namespace'); // unique? |
| ... | ... | @@ -417,7 +427,7 @@ class IndexRecreator |
| 417 | 427 | |
| 418 | 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 | 431 | $this->addIndex('mime_types','mimetypes'); |
| 422 | 432 | |
| 423 | 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 | 447 | //$this->dropIndex('permission_descriptor_users','descriptor_id'); // in primary |
| 438 | 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 | 453 | //$this->dropIndex('permission_lookup_assignments','permission_lookup_id'); // in composite |
| 444 | 454 | |
| 445 | 455 | $this->addIndex('permissions','name', 'UNIQUE'); |
| ... | ... | @@ -455,7 +465,7 @@ class IndexRecreator |
| 455 | 465 | $this->addIndex('system_settings','name', 'UNIQUE'); |
| 456 | 466 | |
| 457 | 467 | $this->addIndex('units_lookup','name' ,'UNIQUE'); |
| 458 | - $this->dropIndex('units_lookup','folder_id'); | |
| 468 | +// $this->dropIndex('units_lookup','folder_id'); | |
| 459 | 469 | $this->addIndex('units_lookup','folder_id' ,'UNIQUE'); |
| 460 | 470 | |
| 461 | 471 | $this->addIndex('upgrades','descriptor'); |
| ... | ... | @@ -488,7 +498,7 @@ class IndexRecreator |
| 488 | 498 | |
| 489 | 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 | 528 | |
| 519 | 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 | 534 | $sql = "alter table $table add foreign key ($field) references $othertable ($otherfield) "; |
| 522 | 535 | if ($ondelete != '') |
| 523 | 536 | $sql .= " on delete $ondelete"; |
| ... | ... | @@ -555,7 +568,6 @@ class IndexRecreator |
| 555 | 568 | $this->addPrimaryKey('document_text', 'document_id'); |
| 556 | 569 | $this->addPrimaryKey('document_transaction_types_lookup', 'id'); |
| 557 | 570 | $this->addPrimaryKey('document_transaction_text', 'document_id'); |
| 558 | - $this->addPrimaryKey('document_transaction_types_lookup','id'); | |
| 559 | 571 | $this->addPrimaryKey('document_transactions','id'); |
| 560 | 572 | $this->addPrimaryKey('document_type_fields_link','id'); |
| 561 | 573 | $this->addPrimaryKey('document_type_fieldsets_link','id'); |
| ... | ... | @@ -576,6 +588,7 @@ class IndexRecreator |
| 576 | 588 | $this->addPrimaryKey('groups_lookup','id'); |
| 577 | 589 | $this->addPrimaryKey('help','id'); |
| 578 | 590 | $this->addPrimaryKey('help_replacement','id'); |
| 591 | + $this->addPrimaryKey('index_files','document_id'); | |
| 579 | 592 | $this->addPrimaryKey('interceptor_instances','id'); |
| 580 | 593 | $this->addPrimaryKey('links','id'); |
| 581 | 594 | $this->addPrimaryKey('metadata_lookup','id'); |
| ... | ... | @@ -625,6 +638,7 @@ class IndexRecreator |
| 625 | 638 | $this->addPrimaryKey('workflow_documents','document_id'); |
| 626 | 639 | $this->addPrimaryKey('workflow_state_permission_assignments','id'); |
| 627 | 640 | $this->addPrimaryKey('workflow_states','id'); |
| 641 | + $this->addPrimaryKey('workflow_state_transitions',array('state_id','transition_id')); | |
| 628 | 642 | $this->addPrimaryKey('workflow_transitions','id'); |
| 629 | 643 | $this->addPrimaryKey('workflow_trigger_instances','id'); |
| 630 | 644 | $this->addPrimaryKey('workflows','id'); |
| ... | ... | @@ -652,6 +666,7 @@ class IndexRecreator |
| 652 | 666 | { |
| 653 | 667 | $result = DBUtil::getResultArray("show tables"); |
| 654 | 668 | $tables=array(); |
| 669 | + $this->tables = array(); | |
| 655 | 670 | |
| 656 | 671 | foreach($result as $table) |
| 657 | 672 | { |
| ... | ... | @@ -664,6 +679,7 @@ class IndexRecreator |
| 664 | 679 | } |
| 665 | 680 | |
| 666 | 681 | $stmt = DBUtil::getResultArray("show create table $tablename"); |
| 682 | + $this->tables[] = $tablename; | |
| 667 | 683 | |
| 668 | 684 | $keys = array_keys($stmt[0]); |
| 669 | 685 | ... | ... |