Commit 02bf537fdce525f11802b4e3e8f7bdc21cef9559

Authored by kevin_fourie
1 parent 457ab620

Merged in from DEV trunk...

KTS-2442
"Some database tables use unsigned int, but relations are mostly to signed int fields. This means foreign key constraints cannot be added easily."
Fixed. Meant to update folders table, not documents.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2468
"Add foreign key constraints to the database"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2442
"Some database tables use unsigned int, but relations are mostly to signed int fields. This means foreign key constraints cannot be added easily."
Fixed. Meant to update folders table, not documents.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2469
"Deleted user can login"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2360
"Remove cache logging."
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2470
"Make triggers more failure proof so it can load it's own class file incase it has not been loaded"
Updated.

Updated By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2471
"create search2 dashets"
Updated. Added function  to KTUtil to deal with period calculations.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2471
"create search2 dashets"
Added. 

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-673
"The search algorithm needs some work"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2460
"Allow reindexing of knowledgetree tables"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

KTS-2373
"Update structure.sql and data.sql"
Updated. Upgrades added and now using mysqldump to produce dumps.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7346 c91229c3-7414-0410-bfa2-8a42b809f60b
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  
... ...
docs/VERSION-NAME.txt
1   -OSS 3.5
  1 +OSS DEV 3.5
... ...
lib/authentication/authenticationutil.inc.php
... ... @@ -36,6 +36,10 @@ require_once(KT_LIB_DIR . '/authentication/authenticationproviderregistry.inc.p
36 36 class KTAuthenticationUtil {
37 37 function checkPassword ($oUser, $sPassword) {
38 38 $oUser =& KTUtil::getObject('User', $oUser);
  39 + if ($oUser->getDisabled() == 2)
  40 + {
  41 + return false;
  42 + }
39 43 $oAuthenticator =& KTAuthenticationUtil::getAuthenticatorForUser($oUser);
40 44 return $oAuthenticator->checkPassword($oUser, $sPassword);
41 45 }
... ...
lib/session/Session.inc
... ... @@ -187,12 +187,12 @@ class Session {
187 187 $version = KTUtil::getSystemSetting('databaseVersion');
188 188  
189 189 if ($default->systemVersion != $version) {
190   - $default->log->info("Session::verify : Database not upgraded");
  190 + if (KTLOG_CACHE) $default->log->info("Session::verify : Database not upgraded");
191 191 return PEAR::raiseError(sprintf(_kt('Incompatible database version (%s, expected version %s) - contact the administrator'), $version, $default->systemVersion));
192 192 }
193 193  
194 194 if (empty($sessionID)) {
195   - $default->log->info("Session::verify session not in db");
  195 + if (KTLOG_CACHE) $default->log->info("Session::verify session not in db");
196 196 return PEAR::raiseError(_kt('You need to login to access this page'));
197 197 }
198 198  
... ... @@ -204,7 +204,7 @@ class Session {
204 204 // FIXME: if there aren't more rows that the max sessions for this user
205 205 if ($numrows < 1) {
206 206 // the session doesn't exist in the db
207   - $default->log->info("Session::verify sessionID=$sessionID, not in db");
  207 + if (KTLOG_CACHE) $default->log->info("Session::verify sessionID=$sessionID, not in db");
208 208 return PEAR::raiseError(_kt('You need to login to access this page'));
209 209 return false;
210 210 }
... ...
lib/session/SiteMap.inc
... ... @@ -353,7 +353,7 @@ class SiteMap {
353 353 function getPageArray($action) {
354 354 global $default;
355 355  
356   - $default->log->info("SiteMap::getPage: checking ($action, " . (isset($_SESSION["userID"]) ? $_SESSION["userID"] : "") . ")");
  356 + if (KTLOG_CACHE) $default->log->info("SiteMap::getPage: checking ($action, " . (isset($_SESSION["userID"]) ? $_SESSION["userID"] : "") . ")");
357 357 $groupIDs = array();
358 358  
359 359 // for each section
... ... @@ -377,7 +377,7 @@ class SiteMap {
377 377 }
378 378 // if the function hasn't returned already then the current
379 379 // user does not have access to the action
380   - $default->log->info("Sitemap::getPage: access denied for ($action, " . $_SESSION["userID"] . ")");
  380 + if (KTLOG_CACHE) $default->log->info("Sitemap::getPage: access denied for ($action, " . $_SESSION["userID"] . ")");
381 381 return false;
382 382 }
383 383  
... ...
lib/subscriptions/subscriptions.inc.php
... ... @@ -684,7 +684,7 @@ class SubscriptionEvent {
684 684 // based on the old SubscriptionEngine::retrieveSubscribers.
685 685 function _getSubscribers($iObjectId, $iSubType) {
686 686 global $default; // for the logging.
687   - $default->log->debug("_getSubscribers(id=$iObjectId, type=$iSubType); table=" .Subscription::getTableName($iSubType). "; id=" .Subscription::getIdFieldName($iSubType));
  687 + if (KTLOG_CACHE) $default->log->debug("_getSubscribers(id=$iObjectId, type=$iSubType); table=" .Subscription::getTableName($iSubType). "; id=" .Subscription::getIdFieldName($iSubType));
688 688  
689 689 $aUsers = array();
690 690 $sQuery = "SELECT user_id FROM " . Subscription::getTableName($iSubType) . " WHERE " . Subscription::getIdFieldName($iSubType) . " = ?";
... ... @@ -708,7 +708,7 @@ class SubscriptionEvent {
708 708 }
709 709 }
710 710  
711   - $default->log->debug('retrieveSubscribers found count=' . count($aUsers));
  711 + if (KTLOG_CACHE) $default->log->debug('retrieveSubscribers found count=' . count($aUsers));
712 712 return $aUsers;
713 713 }
714 714 }
... ...
lib/triggers/triggerregistry.inc.php
... ... @@ -63,6 +63,20 @@ class KTTriggerRegistry {
63 63 if (empty($ret)) {
64 64 return array();
65 65 }
  66 +
  67 + foreach($ret as $trigger)
  68 + {
  69 + if (!class_exists($trigger[0]))
  70 + {
  71 + require_once($trigger[1]);
  72 + if (!class_exists($trigger[0]))
  73 + {
  74 + global $default;
  75 + $defailt->log->error(sprintf(_kt('Cannot locate trigger class \'%s\' for action \'%s\' slot \'%s\'.'), $trigger[0], $action, $slot));
  76 + }
  77 + }
  78 + }
  79 +
66 80 return $ret;
67 81 }
68 82 // }}}
... ...
lib/util/ktutil.inc
... ... @@ -33,6 +33,45 @@
33 33 require_once(KT_LIB_DIR . '/util/KTStopwords.php');
34 34  
35 35 class KTUtil {
  36 +
  37 + const MIN_IN_SECS = 60;
  38 + const HOUR_IN_SECS = 3600;
  39 + const DAY_IN_SECS = 86400;
  40 +
  41 + static function computePeriodToDate($start, $suffix = null, $returnArray=false)
  42 + {
  43 + if (is_null($suffix))
  44 + {
  45 + $suffix = _kt('ago');
  46 + }
  47 + $diff = time() - $start;
  48 +
  49 + $days = floor($diff / KTUtil::DAY_IN_SECS);
  50 + $hours = floor(($diff - $days * KTUtil::DAY_IN_SECS) / KTUtil::HOUR_IN_SECS);
  51 + $mins = floor(($diff - $days * KTUtil::DAY_IN_SECS - $hours * KTUtil::HOUR_IN_SECS) / KTUtil::MIN_IN_SECS);
  52 + $secs = $diff % KTUtil::MIN_IN_SECS;
  53 +
  54 + $str = '';
  55 + if ($days > 0) $str .= sprintf(_kt(' %d day(s)'), $days);
  56 + if ($hours > 0) $str .= sprintf(_kt(' %d hour(s)'), $hours);
  57 + if ($mins > 0) $str .= sprintf(_kt(' %d minute(s)'), $mins);
  58 + if ($secs > 0) $str .= sprintf(_kt(' %d second(s)'), $secs);
  59 +
  60 + $str .= " $suffix";
  61 +
  62 + if ($returnArray)
  63 + {
  64 + return array(
  65 + 'str'=>$str,
  66 + 'days'=>$days,
  67 + 'mins'=>$mins,
  68 + 'secs'=>$secs
  69 + );
  70 + }
  71 +
  72 + return $str;
  73 + }
  74 +
36 75 function extractGPC () {
37 76 foreach (func_get_args() as $var) {
38 77 if (array_key_exists($var, $_REQUEST)) {
... ... @@ -96,13 +135,13 @@ class KTUtil {
96 135 }
97 136 return $sString;
98 137 }
99   -
  138 +
100 139 //this function fudges the strlen. It returns a ? when the character is a multi-byte character.
101 140 //str len is therefore measured correctly.
102 141 //http://www.phpwact.org/php/i18n/charsets
103 142 function utf8_strlen($string){
104 143 return strlen(utf8_decode($str));
105   - }
  144 + }
106 145  
107 146 static function &arrayGet($aArray, $sKey, $mDefault = null, $bDefaultIfEmpty = true) {
108 147 if (!is_array($aArray)) {
... ... @@ -668,7 +707,7 @@ class KTUtil {
668 707 return null;
669 708 }
670 709  
671   - function getSystemSetting($name, $default = null) {
  710 + static function getSystemSetting($name, $default = null) {
672 711 // XXX make this use a cache layer?
673 712 $sTable = KTUtil::getTableName('system_settings');
674 713 $aQuery = array(
... ...
plugins/ktcore/KTCorePlugin.php
... ... @@ -56,6 +56,7 @@ class KTCorePlugin extends KTPlugin {
56 56 $this->registerAction('documentaction', 'KTDocumentMoveAction', 'ktcore.actions.document.move', 'KTDocumentActions.php');
57 57 $this->registerAction('documentaction', 'KTDocumentCopyAction', 'ktcore.actions.document.copy', 'KTDocumentActions.php');
58 58 $this->registerAction('documentaction', 'KTDocumentRenameAction', 'ktcore.actions.document.rename', 'document/Rename.php');
  59 + $this->registerAction('documentaction', 'DocumentIndexAction', 'ktcore.search2.index.action', KT_DIR . '/plugins/search2/DocumentIndexAction.php');
59 60 $this->registerAction('documentinfo', 'KTDocumentTransactionHistoryAction', 'ktcore.actions.document.transactionhistory', 'KTDocumentActions.php');
60 61 $this->registerAction('documentinfo', 'KTDocumentVersionHistoryAction', 'ktcore.actions.document.versionhistory', 'KTDocumentActions.php');
61 62 $this->registerAction('documentaction', 'KTDocumentArchiveAction', 'ktcore.actions.document.archive', 'KTDocumentActions.php');
... ... @@ -97,17 +98,22 @@ class KTCorePlugin extends KTPlugin {
97 98 $this->registerDashlet('KTInfoDashlet', 'ktcore.dashlet.info', 'KTDashlets.php');
98 99 $this->registerDashlet('KTNotificationDashlet', 'ktcore.dashlet.notifications', 'KTDashlets.php');
99 100 $this->registerDashlet('KTCheckoutDashlet', 'ktcore.dashlet.checkout', 'KTDashlets.php');
100   - $this->registerDashlet('KTIndexerStatusDashlet', 'ktcore.dashlet.indexer_status', 'KTDashlets.php');
101 101 $this->registerDashlet('KTMailServerDashlet', 'ktcore.dashlet.mail_server', 'KTDashlets.php');
  102 + $this->registerDashlet('ExternalResourceStatusDashlet', 'ktcore.dashlet.resource_status', KT_DIR . '/plugins/search2/ExternalDashlet.php');
  103 + $this->registerDashlet('LuceneMigrationDashlet', 'ktcore.dashlet.lucene_migration', KT_DIR . '/plugins/search2/MigrationDashlet.php');
  104 + $this->registerDashlet('IndexingStatusDashlet', 'ktcore.dashlet.indexing_status', KT_DIR . '/plugins/search2/IndexingStatusDashlet.php');
  105 + $this->registerDashlet('LuceneStatisticsDashlet', 'ktcore.dashlet.indexing_statss', KT_DIR . '/plugins/search2/LuceneStatisticsDashlet.php');
102 106  
103 107 $this->registerAdminPage('authentication', 'KTAuthenticationAdminPage', 'principals', _kt('Authentication'), sprintf(_kt('By default, %s controls its own users and groups and stores all information about them inside the database. In many situations, an organisation will already have a list of users and groups, and needs to use that existing information to allow access to the DMS. These <strong>Authentication Sources</strong> allow the system administrator to specify additional sources of authentication data.'), APP_NAME), 'authentication/authenticationadminpage.inc.php');
104 108  
  109 + $this->registerPortlet(array('browse', 'dashboard'),
  110 + 'Search2Portlet', 'ktcore.search2.portlet',
  111 + KT_DIR . '/plugins/search2/Search2Portlet.php');
  112 +
105 113 $this->registerPortlet(array('browse'),
106 114 'KTAdminModePortlet', 'ktcore.portlets.admin_mode',
107 115 'KTPortlets.php');
108   - /* NEW SEARCH $this->registerPortlet(array('browse', 'dashboard'),
109   - 'KTSearchPortlet', 'ktcore.portlets.search',
110   - 'KTPortlets.php');*/
  116 +
111 117 $this->registerPortlet(array('browse'),
112 118 'KTBrowseModePortlet', 'ktcore.portlets.browsemodes',
113 119 'KTPortlets.php');
... ... @@ -140,6 +146,11 @@ class KTCorePlugin extends KTPlugin {
140 146 $this->registerWorkflowTrigger('ktcore.workflowtriggers.copyaction', 'CopyActionTrigger', 'KTWorkflowTriggers.inc.php');
141 147 $this->registerWorkflowTrigger('ktcore.workflowtriggers.moveaction', 'MoveActionTrigger', 'KTWorkflowTriggers.inc.php');
142 148  
  149 + // search triggers
  150 + $this->registerTrigger('edit', 'postValidate', 'SavedSearchSubscriptionTrigger', 'ktcore.search2.savedsearch.subscription.edit', KT_DIR . '/plugins/search2/Search2Triggers.php');
  151 + $this->registerTrigger('add', 'postValidate', 'SavedSearchSubscriptionTrigger', 'ktcore.search2.savedsearch.subscription.add', KT_DIR . '/plugins/search2/Search2Triggers.php');
  152 + $this->registerTrigger('discussion', 'postValidate', 'SavedSearchSubscriptionTrigger', 'ktcore.search2.savedsearch.subscription.discussion', KT_DIR . '/plugins/search2/Search2Triggers.php');
  153 +
143 154 // widgets
144 155 $this->registerWidget('KTCoreHiddenWidget', 'ktcore.widgets.hidden', 'KTWidgets.php');
145 156 $this->registerWidget('KTCoreStringWidget', 'ktcore.widgets.string', 'KTWidgets.php');
... ... @@ -183,11 +194,7 @@ class KTCorePlugin extends KTPlugin {
183 194 $this->registerCriterion('DocumentTypeCriterion', 'ktcore.criteria.documenttype', KT_LIB_DIR . '/browse/Criteria.inc');
184 195 $this->registerCriterion('DateModifiedCriterion', 'ktcore.criteria.datemodified', KT_LIB_DIR . '/browse/Criteria.inc');
185 196 $this->registerCriterion('SizeCriterion', 'ktcore.criteria.size', KT_LIB_DIR . '/browse/Criteria.inc');
186   - // NEW SEARCH $this->registerCriterion('ContentCriterion', 'ktcore.criteria.content', KT_LIB_DIR . '/browse/Criteria.inc');
187 197 $this->registerCriterion('WorkflowStateCriterion', 'ktcore.criteria.workflowstate', KT_LIB_DIR . '/browse/Criteria.inc');
188   - // NEW SEARCH $this->registerCriterion('DiscussionTextCriterion', 'ktcore.criteria.discussiontext', KT_LIB_DIR . '/browse/Criteria.inc');
189   - // NEW SEARCH $this->registerCriterion('SearchableTextCriterion', 'ktcore.criteria.searchabletext', KT_LIB_DIR . '/browse/Criteria.inc');
190   - // NEW SEARCH $this->registerCriterion('TransactionTextCriterion', 'ktcore.criteria.transactiontext', KT_LIB_DIR . '/browse/Criteria.inc');
191 198 $this->registerCriterion('DateCreatedDeltaCriterion', 'ktcore.criteria.datecreateddelta', KT_LIB_DIR . '/browse/Criteria.inc');
192 199 $this->registerCriterion('DateModifiedDeltaCriterion', 'ktcore.criteria.datemodifieddelta', KT_LIB_DIR . '/browse/Criteria.inc');
193 200 $this->registerCriterion('GeneralMetadataCriterion', 'ktcore.criteria.generalmetadata', KT_LIB_DIR . '/browse/Criteria.inc');
... ... @@ -265,14 +272,12 @@ class KTCorePlugin extends KTPlugin {
265 272 _kt('Restore or Expunge Deleted Documents'), _kt('Restore previously deleted documents, or permanently expunge them.'),
266 273 'admin/deletedDocuments.php', null);
267 274  
  275 +
  276 +
268 277 // misc
269 278 $this->registerAdminPage('helpmanagement', 'ManageHelpDispatcher', 'misc',
270 279 _kt('Edit Help files'), _kt('Change the help files that are displayed to users.'),
271 280 'admin/manageHelp.php', null);
272   - /* NEW SEARCH $this->registerAdminPage('savedsearch', 'KTSavedSearchDispatcher', 'misc',
273   - _kt('Saved searches'),
274   - _kt('Manage saved searches - searches available by default to all users.'),
275   - 'admin/savedSearch.php', null); */
276 281 $this->registerAdminPage('plugins', 'KTPluginDispatcher', 'misc',
277 282 _kt('Manage plugins'), _kt('Register new plugins, disable plugins, and so forth'),
278 283 'admin/plugins.php', null);
... ...
plugins/search2/ExternalDashlet.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +/**
  4 + * $Id
  5 + *
  6 + * The contents of this file are subject to the KnowledgeTree Public
  7 + * License Version 1.1.2 ("License"); You may not use this file except in
  8 + * compliance with the License. You may obtain a copy of the License at
  9 + * http://www.knowledgetree.com/KPL
  10 + *
  11 + * Software distributed under the License is distributed on an "AS IS"
  12 + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing rights and
  14 + * limitations under the License.
  15 + *
  16 + * All copies of the Covered Code must include on each user interface screen:
  17 + * (i) the "Powered by KnowledgeTree" logo and
  18 + * (ii) the KnowledgeTree copyright notice
  19 + * in the same form as they appear in the distribution. See the License for
  20 + * requirements.
  21 + *
  22 + * The Original Code is: KnowledgeTree Open Source
  23 + *
  24 + * The Initial Developer of the Original Code is The Jam Warehouse Software
  25 + * (Pty) Ltd, trading as KnowledgeTree.
  26 + * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
  27 + * (C) 2007 The Jam Warehouse Software (Pty) Ltd;
  28 + * All Rights Reserved.
  29 + * Contributor( s): ______________________________________
  30 + *
  31 + */
  32 +
  33 +class ExternalResourceStatusDashlet extends KTBaseDashlet
  34 +{
  35 + var $resources = array();
  36 +
  37 + function ExternalResourceStatusDashlet()
  38 + {
  39 + $this->sTitle = _kt('External Resource Dependancy Status');
  40 + $this->sClass = 'ktError';
  41 + }
  42 +
  43 + function addIssue($resource, $status)
  44 + {
  45 + $this->resources[] = array(
  46 + 'name'=>$resource,
  47 + 'status'=>str_replace(
  48 +
  49 + array("\n",_kt('Administrator Guide')),
  50 + array('<br>', sprintf("<a target='_blank' href=\"http://www.knowledgetree.com/go/ktAdminManual\">%s</a>", _kt('Administrator Guide'))), $status));
  51 + }
  52 +
  53 + function checkResources()
  54 + {
  55 + $check = true;
  56 + // check if we have a cached result
  57 + if (isset($_SESSION['ExternalResourceStatus']))
  58 + {
  59 + // we will only do the check every 5 minutes
  60 + if (time() - $_SESSION['ExternalResourceStatus']['time'] < 5 * 60)
  61 + {
  62 + $check = false;
  63 + $this->resources = $_SESSION['ExternalResourceStatus']['resources'];
  64 + }
  65 + }
  66 +
  67 + // we will only check if the result is not cached, or after 5 minutes
  68 + if ($check)
  69 + {
  70 + $this->checkOpenOffice();
  71 + $this->checkLucene();
  72 + $_SESSION['ExternalResourceStatus']['time'] = time();
  73 + $_SESSION['ExternalResourceStatus']['resources'] = $this->resources;
  74 + }
  75 +
  76 + return (count($this->resources) > 0);
  77 + }
  78 +
  79 + function checkOpenOffice()
  80 + {
  81 + $diagnose = SearchHelper::checkOpenOfficeAvailablity();
  82 + if (!is_null($diagnose))
  83 + {
  84 + $this->addIssue(_kt('Open Office Server'), $diagnose);
  85 + }
  86 + }
  87 +
  88 + function checkLucene()
  89 + {
  90 + $indexer = Indexer::get();
  91 + $diagnose = $indexer->diagnose();
  92 + if (!is_null($diagnose))
  93 + {
  94 + $this->addIssue(_kt('Lucene Indexer'), $diagnose);
  95 + }
  96 + }
  97 +
  98 + function is_active($oUser)
  99 + {
  100 + if (!Permission::userIsSystemAdministrator($oUser))
  101 + {
  102 + return false;
  103 + }
  104 +
  105 + return $this->checkResources() > 0;
  106 + }
  107 +
  108 + function render()
  109 + {
  110 + $oTemplating =& KTTemplating::getSingleton();
  111 + $oTemplate = $oTemplating->loadTemplate('ktcore/search2/external_resources');
  112 +
  113 + $aTemplateData = array(
  114 + 'context' => $this,
  115 + 'resources' => $this->resources
  116 + );
  117 +
  118 + return $oTemplate->render($aTemplateData);
  119 + }
  120 +}
  121 +
  122 +?>
... ...
plugins/search2/IndexingStatusDashlet.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +/**
  4 + * $Id
  5 + *
  6 + * The contents of this file are subject to the KnowledgeTree Public
  7 + * License Version 1.1.2 ("License"); You may not use this file except in
  8 + * compliance with the License. You may obtain a copy of the License at
  9 + * http://www.knowledgetree.com/KPL
  10 + *
  11 + * Software distributed under the License is distributed on an "AS IS"
  12 + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing rights and
  14 + * limitations under the License.
  15 + *
  16 + * All copies of the Covered Code must include on each user interface screen:
  17 + * (i) the "Powered by KnowledgeTree" logo and
  18 + * (ii) the KnowledgeTree copyright notice
  19 + * in the same form as they appear in the distribution. See the License for
  20 + * requirements.
  21 + *
  22 + * The Original Code is: KnowledgeTree Open Source
  23 + *
  24 + * The Initial Developer of the Original Code is The Jam Warehouse Software
  25 + * (Pty) Ltd, trading as KnowledgeTree.
  26 + * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
  27 + * (C) 2007 The Jam Warehouse Software (Pty) Ltd;
  28 + * All Rights Reserved.
  29 + * Contributor( s): ______________________________________
  30 + *
  31 + */
  32 +
  33 +class IndexingStatusDashlet extends KTBaseDashlet
  34 +{
  35 + var $indexerName;
  36 +
  37 + function IndexingStatusDashlet()
  38 + {
  39 + $this->sTitle = _kt('Indexing Status');
  40 + $this->sClass = 'ktError';
  41 + }
  42 +
  43 + function is_active($oUser)
  44 + {
  45 + if (!Permission::userIsSystemAdministrator($oUser))
  46 + {
  47 + return false;
  48 + }
  49 +
  50 + if (isset($_SESSION['IndexingStatus']))
  51 + {
  52 + $this->indexerName = $_SESSION['IndexingStatus']['indexerName'];
  53 + $this->indexerDiagnosis = $_SESSION['IndexingStatus']['indexerDiagnosis'];
  54 + $this->extractorDiagnosis = $_SESSION['IndexingStatus']['extractorDiagnosis'];
  55 + }
  56 + else
  57 + {
  58 + $indexer = Indexer::get();
  59 + $this->indexerName = $indexer->getDisplayName();
  60 + $this->indexerDiagnosis = $indexer->diagnose();
  61 + $this->extractorDiagnosis = array();
  62 + $extractorDiagnosis = $indexer->diagnoseExtractors();
  63 +
  64 +
  65 + $result = array();
  66 + foreach($extractorDiagnosis as $class=>$diagnosis)
  67 + {
  68 + $name=$diagnosis['name'];
  69 + $diag = $diagnosis['diagnosis'];
  70 + $result[$diag][] = $name;
  71 + }
  72 +
  73 + foreach($result as $problem=>$indexers)
  74 + {
  75 + if (empty($problem)) continue;
  76 + $this->extractorDiagnosis[] = array('problem'=>$problem, 'indexers'=>$indexers);
  77 + }
  78 +
  79 + $this->indexerDiagnosis = str_replace(
  80 +
  81 + array("\n",_kt('Administrator Guide')),
  82 + array('<br>', sprintf("<a target='_blank' href=\"http://www.knowledgetree.com/go/ktAdminManual\">%s</a>", _kt('Administrator Guide'))), $this->indexerDiagnosis);
  83 +
  84 + $_SESSION['IndexingStatus']['indexerName'] = $this->indexerName;
  85 + $_SESSION['IndexingStatus']['indexerDiagnosis'] = $this->indexerDiagnosis;
  86 + $_SESSION['IndexingStatus']['extractorDiagnosis'] = $this->extractorDiagnosis;
  87 + }
  88 +
  89 +
  90 + return true;
  91 + }
  92 +
  93 + function render()
  94 + {
  95 + $oTemplating =& KTTemplating::getSingleton();
  96 + $oTemplate = $oTemplating->loadTemplate('ktcore/search2/indexing_status');
  97 +
  98 + $aTemplateData = array(
  99 + 'context' => $this,
  100 + 'indexerName' => $this->indexerName,
  101 + 'indexerDiagnosis' => $this->indexerDiagnosis,
  102 + 'extractorDiagnosis' => $this->extractorDiagnosis
  103 + );
  104 +
  105 + return $oTemplate->render($aTemplateData);
  106 + }
  107 +}
  108 +
  109 +?>
... ...
plugins/search2/LuceneStatisticsDashlet.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +/**
  4 + * $Id
  5 + *
  6 + * The contents of this file are subject to the KnowledgeTree Public
  7 + * License Version 1.1.2 ("License"); You may not use this file except in
  8 + * compliance with the License. You may obtain a copy of the License at
  9 + * http://www.knowledgetree.com/KPL
  10 + *
  11 + * Software distributed under the License is distributed on an "AS IS"
  12 + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing rights and
  14 + * limitations under the License.
  15 + *
  16 + * All copies of the Covered Code must include on each user interface screen:
  17 + * (i) the "Powered by KnowledgeTree" logo and
  18 + * (ii) the KnowledgeTree copyright notice
  19 + * in the same form as they appear in the distribution. See the License for
  20 + * requirements.
  21 + *
  22 + * The Original Code is: KnowledgeTree Open Source
  23 + *
  24 + * The Initial Developer of the Original Code is The Jam Warehouse Software
  25 + * (Pty) Ltd, trading as KnowledgeTree.
  26 + * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
  27 + * (C) 2007 The Jam Warehouse Software (Pty) Ltd;
  28 + * All Rights Reserved.
  29 + * Contributor( s): ______________________________________
  30 + *
  31 + */
  32 +
  33 +class LuceneStatisticsDashlet extends KTBaseDashlet
  34 +{
  35 + function LuceneStatisticsDashlet()
  36 + {
  37 + $this->sTitle = _kt('Lucene Statistics');
  38 + }
  39 +
  40 + function is_active($oUser)
  41 + {
  42 + return Permission::userIsSystemAdministrator($oUser);
  43 + }
  44 +
  45 + function render()
  46 + {
  47 + $oTemplating =& KTTemplating::getSingleton();
  48 + $oTemplate = $oTemplating->loadTemplate('ktcore/search2/lucene_statistics');
  49 +
  50 +
  51 + $check = true;
  52 + // check if we have a cached result
  53 + if (isset($_SESSION['LuceneStats']))
  54 + {
  55 + // we will only do the check every 5 minutes
  56 + if (time() - $_SESSION['LuceneStats']['time'] < 5 * 60)
  57 + {
  58 + $check = false;
  59 + $stats = $_SESSION['LuceneStats']['stats'];
  60 + }
  61 + }
  62 +
  63 + // we will only check if the result is not cached, or after 5 minutes
  64 + if ($check)
  65 + {
  66 + $optimisationDate = KTUtil::getSystemSetting('luceneOptimisationDate', '');
  67 +
  68 + $noOptimisation = false;
  69 + if ($optimisationDate == '')
  70 + {
  71 + $optimisationDate = _kt('N/A');
  72 + $optimisationPeriod = $optimisationDate;
  73 + }
  74 + else
  75 + {
  76 + $optimisationPeriod = KTUtil::computePeriodToDate($optimisationDate, null, true);
  77 + $noOptimisation = $optimisationPeriod['days'] > 2;
  78 + $optimisationPeriod = $optimisationPeriod['str'];
  79 + $optimisationDate = date('Y-m-d H:i:s', $optimisationDate);
  80 + }
  81 +
  82 + $indexingDate = KTUtil::getSystemSetting('luceneIndexingDate', '');
  83 + if ($indexingDate == '')
  84 + {
  85 + $indexingDate = _kt('N/A');
  86 + $indexingPeriod = $indexingDate;
  87 + }
  88 + else
  89 + {
  90 + $indexingPeriod = KTUtil::computePeriodToDate($indexingDate);
  91 + $indexingDate = date('Y-m-d H:i:s', $indexingDate);
  92 + }
  93 +
  94 + $index = Indexer::get();
  95 + $docsInIndex = $index->getDocumentsInIndex();
  96 +
  97 + $sql = "SELECT count(*) as docsInQueue FROM index_files";
  98 + $docsInQueue = DBUtil::getOneResultKey($sql, 'docsInQueue');
  99 +
  100 + $sql = "SELECT count(*) as docsInRepository FROM documents";
  101 + $docsInRepository = DBUtil::getOneResultKey($sql, 'docsInRepository');
  102 +
  103 + if ($docsInRepository == 0)
  104 + {
  105 + $indexingCoverage = '0.00%';
  106 + $queueCoverage = $indexingCoverage;
  107 + }
  108 + else
  109 + {
  110 + // compute indexing coverage
  111 + $indexingCoverage = _kt('Not Available');
  112 + if (is_numeric($docsInIndex))
  113 + {
  114 + $indexingCoverage = ($docsInIndex * 100) / $docsInRepository;
  115 + $indexingCoverage = number_format($indexingCoverage, 2, '.',',') . '%';
  116 + }
  117 +
  118 + // compute queue coverage
  119 + $queueCoverage = _kt('Not Available');
  120 + if (is_numeric($docsInQueue))
  121 + {
  122 + $queueCoverage = ($docsInQueue * 100) / $docsInRepository;
  123 + $queueCoverage = number_format($queueCoverage, 2, '.',',') . '%';
  124 + }
  125 + }
  126 +
  127 + $stats = array(
  128 + 'optimisationDate'=>$optimisationDate,
  129 + 'optimisationPeriod'=>$optimisationPeriod,
  130 + 'indexingDate'=>$indexingDate,
  131 + 'indexingPeriod'=>$indexingPeriod,
  132 + 'docsInIndex'=>$docsInIndex,
  133 + 'docsInQueue'=>$docsInQueue,
  134 + 'docsInRepository'=>$docsInRepository,
  135 + 'indexingCoverage'=>$indexingCoverage,
  136 + 'queueCoverage'=>$queueCoverage,
  137 + 'noOptimisation'=>$noOptimisation
  138 + );
  139 +
  140 + $_SESSION['LuceneStats']['time'] = time();
  141 + $_SESSION['LuceneStats']['stats'] = $stats;
  142 + }
  143 +
  144 + $aTemplateData = array(
  145 + 'context' => $this,
  146 + 'stats'=>$stats
  147 +
  148 + );
  149 +
  150 + return $oTemplate->render($aTemplateData);
  151 + }
  152 +}
  153 +
  154 +?>
... ...
plugins/search2/MigrationDashlet.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +/**
  4 + * $Id
  5 + *
  6 + * The contents of this file are subject to the KnowledgeTree Public
  7 + * License Version 1.1.2 ("License"); You may not use this file except in
  8 + * compliance with the License. You may obtain a copy of the License at
  9 + * http://www.knowledgetree.com/KPL
  10 + *
  11 + * Software distributed under the License is distributed on an "AS IS"
  12 + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing rights and
  14 + * limitations under the License.
  15 + *
  16 + * All copies of the Covered Code must include on each user interface screen:
  17 + * (i) the "Powered by KnowledgeTree" logo and
  18 + * (ii) the KnowledgeTree copyright notice
  19 + * in the same form as they appear in the distribution. See the License for
  20 + * requirements.
  21 + *
  22 + * The Original Code is: KnowledgeTree Open Source
  23 + *
  24 + * The Initial Developer of the Original Code is The Jam Warehouse Software
  25 + * (Pty) Ltd, trading as KnowledgeTree.
  26 + * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
  27 + * (C) 2007 The Jam Warehouse Software (Pty) Ltd;
  28 + * All Rights Reserved.
  29 + * Contributor( s): ______________________________________
  30 + *
  31 + */
  32 +
  33 +class LuceneMigrationDashlet extends KTBaseDashlet
  34 +{
  35 + function LuceneMigrationDashlet()
  36 + {
  37 + $this->sTitle = _kt('Lucene Migration Status');
  38 + }
  39 +
  40 + function is_active($oUser)
  41 + {
  42 + if (!Permission::userIsSystemAdministrator($oUser))
  43 + {
  44 + return false;
  45 + }
  46 +
  47 + return true;
  48 + }
  49 +
  50 + function render()
  51 + {
  52 + $oTemplating =& KTTemplating::getSingleton();
  53 + $oTemplate = $oTemplating->loadTemplate('ktcore/search2/lucene_migration');
  54 +
  55 + $aTemplateData = array(
  56 + 'context' => $this
  57 + );
  58 +
  59 + return $oTemplate->render($aTemplateData);
  60 + }
  61 +}
  62 +
  63 +?>
... ...
plugins/search2/searchPlugin.php deleted
1   -<?php
2   -
3   -require_once(KT_LIB_DIR . "/plugins/plugin.inc.php");
4   -require_once(KT_LIB_DIR . "/plugins/pluginregistry.inc.php");
5   -require_once('Search2Triggers.php');
6   -
7   - class Search2Plugin extends KTPlugin
8   - {
9   - var $autoRegister = true;
10   - var $sNamespace = 'ktcore.search2.plugin';
11   -
12   - function Search2Plugin($sFilename = null)
13   - {
14   - $res = parent::KTPlugin($sFilename);
15   - $this->sFriendlyName = _kt('Search2 Plugin');
16   - return $res;
17   - }
18   -
19   - function setup()
20   - {
21   - $this->registerAction('documentaction', 'DocumentIndexAction', 'ktcore.search2.index.action', 'DocumentIndexAction.php');
22   - $this->registerTrigger('edit', 'postValidate', 'SavedSearchSubscriptionTrigger', 'ktcore.search2.savedsearch.subscription.edit', 'Search2Triggers.php');
23   - $this->registerTrigger('add', 'postValidate', 'SavedSearchSubscriptionTrigger', 'ktcore.search2.savedsearch.subscription.add', 'Search2Triggers.php');
24   - $this->registerTrigger('discussion', 'postValidate', 'SavedSearchSubscriptionTrigger', 'ktcore.search2.savedsearch.subscription.discussion', 'Search2Triggers.php');
25   - $this->registerPortlet(array('browse', 'dashboard'),
26   - 'Search2Portlet', 'ktcore.search2.portlet',
27   - 'Search2Portlet.php');
28   - }
29   - }
30   -
31   -$oPluginRegistry =& KTPluginRegistry::getSingleton();
32   -$oPluginRegistry->registerPlugin('Search2Plugin', 'ktcore.search2.plugin', __FILE__);
33   -?>
34 0 \ No newline at end of file
search2.php
... ... @@ -66,6 +66,19 @@ class SearchDispatcher extends KTStandardDispatcher {
66 66 }
67 67 }
68 68  
  69 + function do_refreshLuceneStats()
  70 + {
  71 + session_unregister('LuceneStats');
  72 + redirect('/dashboard.php');
  73 + }
  74 +
  75 + function do_refreshDashboardStatus()
  76 + {
  77 + session_unregister('ExternalResourceStatus');
  78 + session_unregister('IndexingStatus');
  79 + redirect('/dashboard.php');
  80 + }
  81 +
69 82 /**
70 83 * Processes a query sent by HTTP POST in searchQuery.
71 84 *
... ...
search2/indexing/indexerCore.inc.php
... ... @@ -791,8 +791,13 @@ abstract class Indexer
791 791 $diagnoses = array();
792 792 $dir = opendir($path);
793 793 $extlen = - strlen($extension);
  794 +
794 795 while (($file = readdir($dir)) !== false)
795 796 {
  797 + if (substr($file,0,1) == '.')
  798 + {
  799 + continue;
  800 + }
796 801 if (substr($file,$extlen) != $extension)
797 802 {
798 803 $default->log->error(sprintf(_kt("diagnose: '%s' does not have extension '%s'."), $file, $extension));
... ... @@ -940,12 +945,28 @@ abstract class Indexer
940 945  
941 946 /**
942 947 * Possibly we can optimise indexes. This method must be overriden.
  948 + * The new function must call the parent!
943 949 *
944 950 */
945 951 public function optimise()
946 952 {
947   - // do nothing
  953 + KTUtil::setSystemSetting('luceneOptimisationDate', time());
948 954 }
  955 +
  956 + /**
  957 + * Returns the name of the indexer.
  958 + *
  959 + * @return string
  960 + */
  961 + public abstract function getDisplayName();
  962 +
  963 +
  964 + /**
  965 + * Returns the number of non-deleted documents in the index.
  966 + *
  967 + * @return int
  968 + */
  969 + public abstract function getDocumentsInIndex();
949 970 }
950 971  
951 972 ?>
952 973 \ No newline at end of file
... ...
search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php
... ... @@ -19,7 +19,7 @@ class JavaXMLRPCLuceneIndexer extends Indexer
19 19 parent::__construct();
20 20  
21 21 $config =& KTConfig::getSingleton();
22   - $javaServerUrl = $config->get('indexer/JavaLuceneURL', 'http://localhost:8875');
  22 + $javaServerUrl = $config->get('indexer/javaLuceneURL');
23 23 $this->lucene = new XmlRpcLucene($javaServerUrl);
24 24 }
25 25  
... ... @@ -99,6 +99,7 @@ class JavaXMLRPCLuceneIndexer extends Indexer
99 99 */
100 100 public function optimise()
101 101 {
  102 + parent::optimise();
102 103 $this->lucene->optimize();
103 104 }
104 105  
... ... @@ -149,22 +150,57 @@ class JavaXMLRPCLuceneIndexer extends Indexer
149 150 return $results;
150 151 }
151 152  
  153 + /**
  154 + * Diagnose the indexer. e.g. Check that the indexing server is running.
  155 + *
  156 + */
152 157 public function diagnose()
153 158 {
154   - $config =& KTConfig::getSingleton();
  159 + $config =& KTConfig::getSingleton();
  160 +
  161 + $javaLuceneURL = $config->get('indexer/javaLuceneURL');
  162 +
  163 + list($protocol, $host, $port) = explode(':', $javaLuceneURL);
  164 + if (empty($port)) $port == 8875;
  165 + if (substr($host, 0, 2) == '//') $host = substr($host, 2);
155 166  
156   - $ooHost = $config->get('openoffice/host', 'localhost');
157   - $ooPort = $config->get('openoffice/port', 8100);
158   - $connection = @fsockopen($ooHost, $ooPort,$errno, $errstr, 2);
  167 + $connection = @fsockopen($host, $port, $errno, $errstr, 2);
159 168 if (false === $connection)
160 169 {
161   - return _kt('Cannot connect to openoffice host');
  170 + $indexer = $this->getDisplayName();
  171 + return sprintf(_kt("Cannot connect to the %s on '%s'.\nPlease consult the Administrator Guide for more information on configuring the %s."), $indexer, $javaLuceneURL, $indexer);
162 172 }
163 173 fclose($connection);
164 174  
165 175 return null;
  176 +
166 177 }
167 178  
  179 + /**
  180 + * Returns the name of the indexer.
  181 + *
  182 + * @return string
  183 + */
  184 + public function getDisplayName()
  185 + {
  186 + return _kt('Lucene Indexing Server');
  187 + }
  188 +
  189 +
  190 + /**
  191 + * Returns the number of non-deleted documents in the index.
  192 + *
  193 + * @return int
  194 + */
  195 + public function getDocumentsInIndex()
  196 + {
  197 + $stats = $this->lucene->getStatistics();
  198 + if ($stats === false || !is_object($stats))
  199 + {
  200 + return _kt('Not Available');
  201 + }
  202 + return $stats->countDocuments;
  203 + }
168 204  
169 205 }
170 206 ?>
171 207 \ No newline at end of file
... ...
search2/indexing/indexers/PHPLuceneIndexer.inc.php
... ... @@ -131,10 +131,21 @@ class PHPLuceneIndexer extends Indexer
131 131 */
132 132 public function optimise()
133 133 {
  134 + parent::optimise();
134 135 $this->lucene->optimize();
135 136 }
136 137  
137 138 /**
  139 + * Returns the number of non-deleted documents in the index.
  140 + *
  141 + * @return int
  142 + */
  143 + public function getDocumentsInIndex()
  144 + {
  145 + return $this->lucene->numDocs();
  146 + }
  147 +
  148 + /**
138 149 * Removes a document from the index.
139 150 *
140 151 * @param int $docid
... ... @@ -190,13 +201,28 @@ class PHPLuceneIndexer extends Indexer
190 201 return $results;
191 202 }
192 203  
  204 + /**
  205 + * Diagnose the indexer. e.g. Check that the indexing server is running.
  206 + *
  207 + */
193 208 public function diagnose()
194 209 {
195 210 if ($this->lucene == null)
196 211 {
197   - return _kt("The lucene index has not been initialised correctly. Please review the documentation on how to setup the indexing.");
  212 + $indexer = $this->getDisplayName();
  213 + return sprintf(_kt("The %s has not been initialised correctly. Please review the documentation on how to setup the indexing."),$indexer);
198 214 }
199 215 return null;
200 216 }
  217 +
  218 + /**
  219 + * Returns the name of the indexer.
  220 + *
  221 + * @return string
  222 + */
  223 + public function getDisplayName()
  224 + {
  225 + return _kt('Lucene PHP Indexer');
  226 + }
201 227 }
202 228 ?>
203 229 \ No newline at end of file
... ...
search2/search/search.inc.php
... ... @@ -28,6 +28,22 @@ function search_alias_compare($a, $b)
28 28  
29 29 class SearchHelper
30 30 {
  31 + public static function checkOpenOfficeAvailablity()
  32 + {
  33 + $config =& KTConfig::getSingleton();
  34 + $ooHost = $config->get('openoffice/host', 'localhost');
  35 + $ooPort = $config->get('openoffice/port', 8100);
  36 +
  37 + $connection = @fsockopen($ooHost, $ooPort,$errno, $errstr, 2);
  38 + if (false === $connection)
  39 + {
  40 + return sprintf(_kt("Cannot connect to Open Office Server on host '%s:%s'.\nPlease consult the Administrator Guide for more information on configuring Open Office Server."), $ooHost, $ooPort);
  41 + }
  42 + fclose($connection);
  43 +
  44 + return null;
  45 + }
  46 +
31 47 public static function getSavedSearchEvents()
32 48 {
33 49 // TODO
... ...
sql/mysql/install/data.sql
No preview for this file type
sql/mysql/install/dump.sh
... ... @@ -8,10 +8,11 @@ case $1 in
8 8 *) DB=$1 ;;
9 9 esac
10 10  
  11 +PATH=$PATH:../../../../mysql/bin:/usr/local/mysql/bin
11 12 DATE=`date +%Y-%m-%d-%H-%M-%S`
12 13  
13 14 # Create the Structure Dump
14   -../../../../mysql/bin/mysqldump -u root -p $DB --no-data --skip-add-drop-table > structure-$DATE.sql
  15 +mysqldump -u root -p $DB --no-data --skip-add-drop-table > structure-$DATE.sql
15 16  
16 17 # Create the Data Dump
17   -../../../../mysql/bin/mysqldump -u root -p $DB --no-create-info > data-$DATE.sql
  18 +mysqldump -u root -p $DB --no-create-info > data-$DATE.sql
... ...
sql/mysql/install/structure.sql
... ... @@ -30,7 +30,7 @@
30 30 --
31 31 -- Host: localhost Database: dms_clean
32 32 -- ------------------------------------------------------
33   --- Server version 5.0.37
  33 +-- Server version 5.0.41-log
34 34  
35 35 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
36 36 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
... ... @@ -53,8 +53,10 @@ CREATE TABLE `active_sessions` (
53 53 `session_id` char(255) default NULL,
54 54 `lastused` datetime default NULL,
55 55 `ip` char(30) default NULL,
56   - UNIQUE KEY `id` (`id`),
57   - KEY `session_id_idx` (`session_id`)
  56 + PRIMARY KEY (`id`),
  57 + KEY `user_id` (`user_id`),
  58 + KEY `session_id` (`session_id`),
  59 + CONSTRAINT `active_sessions_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
58 60 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
59 61  
60 62 --
... ... @@ -67,7 +69,13 @@ CREATE TABLE `archive_restoration_request` (
67 69 `request_user_id` int(11) NOT NULL default '0',
68 70 `admin_user_id` int(11) NOT NULL default '0',
69 71 `datetime` datetime NOT NULL default '0000-00-00 00:00:00',
70   - UNIQUE KEY `id` (`id`)
  72 + PRIMARY KEY (`id`),
  73 + KEY `document_id` (`document_id`),
  74 + KEY `request_user_id` (`request_user_id`),
  75 + KEY `admin_user_id` (`admin_user_id`),
  76 + CONSTRAINT `archive_restoration_request_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  77 + CONSTRAINT `archive_restoration_request_ibfk_2` FOREIGN KEY (`request_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  78 + CONSTRAINT `archive_restoration_request_ibfk_3` FOREIGN KEY (`admin_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
71 79 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
72 80  
73 81 --
... ... @@ -80,7 +88,11 @@ CREATE TABLE `archiving_settings` (
80 88 `expiration_date` date default NULL,
81 89 `document_transaction_id` int(11) default NULL,
82 90 `time_period_id` int(11) default NULL,
83   - UNIQUE KEY `id` (`id`)
  91 + PRIMARY KEY (`id`),
  92 + KEY `archiving_type_id` (`archiving_type_id`),
  93 + KEY `time_period_id` (`time_period_id`),
  94 + CONSTRAINT `archiving_settings_ibfk_1` FOREIGN KEY (`archiving_type_id`) REFERENCES `archiving_type_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  95 + CONSTRAINT `archiving_settings_ibfk_2` FOREIGN KEY (`time_period_id`) REFERENCES `time_period` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
84 96 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
85 97  
86 98 --
... ... @@ -90,7 +102,7 @@ CREATE TABLE `archiving_settings` (
90 102 CREATE TABLE `archiving_type_lookup` (
91 103 `id` int(11) NOT NULL default '0',
92 104 `name` char(100) default NULL,
93   - UNIQUE KEY `id` (`id`)
  105 + PRIMARY KEY (`id`)
94 106 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
95 107  
96 108 --
... ... @@ -132,8 +144,9 @@ CREATE TABLE `comment_searchable_text` (
132 144 `comment_id` int(11) NOT NULL default '0',
133 145 `body` mediumtext,
134 146 `document_id` int(11) NOT NULL default '0',
135   - UNIQUE KEY `id` (`comment_id`),
136   - FULLTEXT KEY `comment_search_text` (`body`)
  147 + PRIMARY KEY (`comment_id`),
  148 + KEY `document_id` (`document_id`),
  149 + FULLTEXT KEY `body` (`body`)
137 150 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
138 151  
139 152 --
... ... @@ -144,9 +157,10 @@ CREATE TABLE `dashlet_disables` (
144 157 `id` int(11) NOT NULL default '0',
145 158 `user_id` int(11) NOT NULL default '0',
146 159 `dashlet_namespace` varchar(255) NOT NULL default '',
147   - UNIQUE KEY `id` (`id`),
  160 + PRIMARY KEY (`id`),
148 161 KEY `user_id` (`user_id`),
149   - KEY `dashlet_namespace` (`dashlet_namespace`)
  162 + KEY `dashlet_namespace` (`dashlet_namespace`),
  163 + CONSTRAINT `dashlet_disables_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
150 164 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
151 165  
152 166 --
... ... @@ -156,7 +170,7 @@ CREATE TABLE `dashlet_disables` (
156 170 CREATE TABLE `data_types` (
157 171 `id` int(11) NOT NULL default '0',
158 172 `name` char(255) NOT NULL default '',
159   - UNIQUE KEY `id` (`id`)
  173 + PRIMARY KEY (`id`)
160 174 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
161 175  
162 176 --
... ... @@ -171,7 +185,13 @@ CREATE TABLE `discussion_comments` (
171 185 `subject` mediumtext,
172 186 `body` mediumtext,
173 187 `date` datetime default NULL,
174   - UNIQUE KEY `id` (`id`)
  188 + PRIMARY KEY (`id`),
  189 + KEY `thread_id` (`thread_id`),
  190 + KEY `user_id` (`user_id`),
  191 + KEY `in_reply_to` (`in_reply_to`),
  192 + CONSTRAINT `discussion_comments_ibfk_1` FOREIGN KEY (`thread_id`) REFERENCES `discussion_threads` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  193 + CONSTRAINT `discussion_comments_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  194 + CONSTRAINT `discussion_comments_ibfk_3` FOREIGN KEY (`in_reply_to`) REFERENCES `discussion_comments` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
175 195 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
176 196  
177 197 --
... ... @@ -189,7 +209,15 @@ CREATE TABLE `discussion_threads` (
189 209 `close_reason` mediumtext NOT NULL,
190 210 `close_metadata_version` int(11) NOT NULL default '0',
191 211 `state` int(1) NOT NULL default '0',
192   - UNIQUE KEY `id` (`id`)
  212 + PRIMARY KEY (`id`),
  213 + KEY `document_id` (`document_id`),
  214 + KEY `first_comment_id` (`first_comment_id`),
  215 + KEY `last_comment_id` (`last_comment_id`),
  216 + KEY `creator_id` (`creator_id`),
  217 + CONSTRAINT `discussion_threads_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  218 + CONSTRAINT `discussion_threads_ibfk_2` FOREIGN KEY (`first_comment_id`) REFERENCES `discussion_comments` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  219 + CONSTRAINT `discussion_threads_ibfk_3` FOREIGN KEY (`last_comment_id`) REFERENCES `discussion_comments` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  220 + CONSTRAINT `discussion_threads_ibfk_4` FOREIGN KEY (`creator_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
193 221 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
194 222  
195 223 --
... ... @@ -200,7 +228,11 @@ CREATE TABLE `document_archiving_link` (
200 228 `id` int(11) NOT NULL default '0',
201 229 `document_id` int(11) NOT NULL default '0',
202 230 `archiving_settings_id` int(11) NOT NULL default '0',
203   - UNIQUE KEY `id` (`id`)
  231 + PRIMARY KEY (`id`),
  232 + KEY `document_id` (`document_id`),
  233 + KEY `archiving_settings_id` (`archiving_settings_id`),
  234 + CONSTRAINT `document_archiving_link_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  235 + CONSTRAINT `document_archiving_link_ibfk_2` FOREIGN KEY (`archiving_settings_id`) REFERENCES `archiving_settings` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
204 236 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
205 237  
206 238 --
... ... @@ -212,13 +244,16 @@ CREATE TABLE `document_content_version` (
212 244 `document_id` int(11) NOT NULL default '0',
213 245 `filename` mediumtext NOT NULL,
214 246 `size` bigint(20) NOT NULL default '0',
215   - `mime_id` int(11) NOT NULL default '0',
  247 + `mime_id` int(11) default '9',
216 248 `major_version` int(11) NOT NULL default '0',
217 249 `minor_version` int(11) NOT NULL default '0',
218 250 `storage_path` varchar(250) default NULL,
219   - UNIQUE KEY `id` (`id`),
  251 + PRIMARY KEY (`id`),
  252 + KEY `document_id` (`document_id`),
  253 + KEY `mime_id` (`mime_id`),
220 254 KEY `storage_path` (`storage_path`),
221   - KEY `document_id` (`document_id`)
  255 + CONSTRAINT `document_content_version_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  256 + CONSTRAINT `document_content_version_ibfk_2` FOREIGN KEY (`mime_id`) REFERENCES `mime_types` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
222 257 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
223 258  
224 259 --
... ... @@ -235,9 +270,9 @@ CREATE TABLE `document_fields` (
235 270 `parent_fieldset` int(11) default NULL,
236 271 `is_mandatory` tinyint(4) NOT NULL default '0',
237 272 `description` mediumtext NOT NULL,
238   - UNIQUE KEY `id` (`id`),
  273 + PRIMARY KEY (`id`),
239 274 KEY `parent_fieldset` (`parent_fieldset`),
240   - CONSTRAINT `document_fields_ibfk_1` FOREIGN KEY (`parent_fieldset`) REFERENCES `fieldsets` (`id`) ON DELETE CASCADE
  275 + CONSTRAINT `document_fields_ibfk_1` FOREIGN KEY (`parent_fieldset`) REFERENCES `fieldsets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
241 276 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
242 277  
243 278 --
... ... @@ -249,10 +284,11 @@ CREATE TABLE `document_fields_link` (
249 284 `document_field_id` int(11) NOT NULL default '0',
250 285 `value` char(255) NOT NULL default '',
251 286 `metadata_version_id` int(11) default NULL,
252   - UNIQUE KEY `id` (`id`),
  287 + PRIMARY KEY (`id`),
253 288 KEY `document_field_id` (`document_field_id`),
254 289 KEY `metadata_version_id` (`metadata_version_id`),
255   - CONSTRAINT `document_fields_link_ibfk_2` FOREIGN KEY (`document_field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE
  290 + CONSTRAINT `document_fields_link_ibfk_1` FOREIGN KEY (`document_field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  291 + CONSTRAINT `document_fields_link_ibfk_2` FOREIGN KEY (`metadata_version_id`) REFERENCES `document_metadata_version` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
256 292 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
257 293  
258 294 --
... ... @@ -275,7 +311,13 @@ CREATE TABLE `document_link` (
275 311 `parent_document_id` int(11) NOT NULL default '0',
276 312 `child_document_id` int(11) NOT NULL default '0',
277 313 `link_type_id` int(11) NOT NULL default '0',
278   - UNIQUE KEY `id` (`id`)
  314 + PRIMARY KEY (`id`),
  315 + KEY `parent_document_id` (`parent_document_id`),
  316 + KEY `child_document_id` (`child_document_id`),
  317 + KEY `link_type_id` (`link_type_id`),
  318 + CONSTRAINT `document_link_ibfk_1` FOREIGN KEY (`parent_document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  319 + CONSTRAINT `document_link_ibfk_2` FOREIGN KEY (`child_document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  320 + CONSTRAINT `document_link_ibfk_3` FOREIGN KEY (`link_type_id`) REFERENCES `document_link_types` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
279 321 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
280 322  
281 323 --
... ... @@ -287,7 +329,7 @@ CREATE TABLE `document_link_types` (
287 329 `name` char(100) NOT NULL default '',
288 330 `reverse_name` char(100) NOT NULL default '',
289 331 `description` char(255) NOT NULL default '',
290   - UNIQUE KEY `id` (`id`)
  332 + PRIMARY KEY (`id`)
291 333 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
292 334  
293 335 --
... ... @@ -307,21 +349,22 @@ CREATE TABLE `document_metadata_version` (
307 349 `version_creator_id` int(11) NOT NULL default '0',
308 350 `workflow_id` int(11) default NULL,
309 351 `workflow_state_id` int(11) default NULL,
310   - UNIQUE KEY `id` (`id`),
311   - KEY `fk_document_type_id` (`document_type_id`),
312   - KEY `fk_status_id` (`status_id`),
  352 + PRIMARY KEY (`id`),
  353 + KEY `document_type_id` (`document_type_id`),
  354 + KEY `status_id` (`status_id`),
313 355 KEY `document_id` (`document_id`),
314   - KEY `version_created` (`version_created`),
315 356 KEY `version_creator_id` (`version_creator_id`),
316 357 KEY `content_version_id` (`content_version_id`),
317 358 KEY `workflow_id` (`workflow_id`),
318 359 KEY `workflow_state_id` (`workflow_state_id`),
319   - CONSTRAINT `document_metadata_version_ibfk_4` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE,
320   - CONSTRAINT `document_metadata_version_ibfk_5` FOREIGN KEY (`document_type_id`) REFERENCES `document_types_lookup` (`id`),
321   - CONSTRAINT `document_metadata_version_ibfk_6` FOREIGN KEY (`status_id`) REFERENCES `status_lookup` (`id`),
322   - CONSTRAINT `document_metadata_version_ibfk_7` FOREIGN KEY (`version_creator_id`) REFERENCES `users` (`id`),
323   - CONSTRAINT `document_metadata_version_ibfk_8` FOREIGN KEY (`workflow_id`) REFERENCES `workflows` (`id`),
324   - CONSTRAINT `document_metadata_version_ibfk_9` FOREIGN KEY (`workflow_state_id`) REFERENCES `workflow_states` (`id`)
  360 + KEY `version_created` (`version_created`),
  361 + CONSTRAINT `document_metadata_version_ibfk_1` FOREIGN KEY (`document_type_id`) REFERENCES `document_types_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  362 + CONSTRAINT `document_metadata_version_ibfk_2` FOREIGN KEY (`status_id`) REFERENCES `status_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  363 + CONSTRAINT `document_metadata_version_ibfk_3` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  364 + CONSTRAINT `document_metadata_version_ibfk_4` FOREIGN KEY (`version_creator_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  365 + CONSTRAINT `document_metadata_version_ibfk_5` FOREIGN KEY (`content_version_id`) REFERENCES `document_content_version` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  366 + CONSTRAINT `document_metadata_version_ibfk_6` FOREIGN KEY (`workflow_id`) REFERENCES `workflows` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  367 + CONSTRAINT `document_metadata_version_ibfk_7` FOREIGN KEY (`workflow_state_id`) REFERENCES `workflow_states` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
325 368 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
326 369  
327 370 --
... ... @@ -333,8 +376,12 @@ CREATE TABLE `document_role_allocations` (
333 376 `document_id` int(11) NOT NULL default '0',
334 377 `role_id` int(11) NOT NULL default '0',
335 378 `permission_descriptor_id` int(11) NOT NULL default '0',
336   - UNIQUE KEY `id` (`id`),
337   - KEY `document_id` (`document_id`)
  379 + PRIMARY KEY (`id`),
  380 + KEY `role_id` (`role_id`),
  381 + KEY `permission_descriptor_id` (`permission_descriptor_id`),
  382 + KEY `document_id_role_id` (`document_id`,`role_id`),
  383 + CONSTRAINT `document_role_allocations_ibfk_1` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  384 + CONSTRAINT `document_role_allocations_ibfk_2` FOREIGN KEY (`permission_descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
338 385 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
339 386  
340 387 --
... ... @@ -344,7 +391,7 @@ CREATE TABLE `document_role_allocations` (
344 391 CREATE TABLE `document_searchable_text` (
345 392 `document_id` int(11) default NULL,
346 393 `document_text` longtext,
347   - KEY `document_text_document_id_indx` (`document_id`),
  394 + KEY `document_id` (`document_id`),
348 395 FULLTEXT KEY `document_text` (`document_text`)
349 396 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
350 397  
... ... @@ -357,7 +404,11 @@ CREATE TABLE `document_subscriptions` (
357 404 `user_id` int(11) NOT NULL default '0',
358 405 `document_id` int(11) NOT NULL default '0',
359 406 `is_alerted` tinyint(1) default NULL,
360   - UNIQUE KEY `id` (`id`)
  407 + PRIMARY KEY (`id`),
  408 + KEY `user_id` (`user_id`),
  409 + KEY `document_id` (`document_id`),
  410 + CONSTRAINT `document_subscriptions_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  411 + CONSTRAINT `document_subscriptions_ibfk_2` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
361 412 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
362 413  
363 414 --
... ... @@ -368,9 +419,9 @@ CREATE TABLE `document_tags` (
368 419 `document_id` int(10) NOT NULL,
369 420 `tag_id` int(10) NOT NULL,
370 421 PRIMARY KEY (`document_id`,`tag_id`),
371   - KEY `fk_document_tags_tag_id` (`tag_id`),
372   - CONSTRAINT `fk_document_tags_document_id` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
373   - CONSTRAINT `fk_document_tags_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `tag_words` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
  422 + KEY `tag_id` (`tag_id`),
  423 + CONSTRAINT `document_tags_ibfk_2` FOREIGN KEY (`tag_id`) REFERENCES `tag_words` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  424 + CONSTRAINT `document_tags_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
374 425 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
375 426  
376 427 --
... ... @@ -378,9 +429,9 @@ CREATE TABLE `document_tags` (
378 429 --
379 430  
380 431 CREATE TABLE `document_text` (
381   - `document_id` int(11) default NULL,
  432 + `document_id` int(11) NOT NULL default '0',
382 433 `document_text` longtext,
383   - KEY `document_text_document_id_indx` (`document_id`),
  434 + PRIMARY KEY (`document_id`),
384 435 FULLTEXT KEY `document_text` (`document_text`)
385 436 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
386 437  
... ... @@ -389,9 +440,9 @@ CREATE TABLE `document_text` (
389 440 --
390 441  
391 442 CREATE TABLE `document_transaction_text` (
392   - `document_id` int(11) default NULL,
  443 + `document_id` int(11) NOT NULL default '0',
393 444 `document_text` mediumtext,
394   - KEY `document_text_document_id_indx` (`document_id`),
  445 + PRIMARY KEY (`document_id`),
395 446 FULLTEXT KEY `document_text` (`document_text`)
396 447 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
397 448  
... ... @@ -403,8 +454,8 @@ CREATE TABLE `document_transaction_types_lookup` (
403 454 `id` int(11) NOT NULL default '0',
404 455 `name` varchar(100) NOT NULL default '',
405 456 `namespace` varchar(250) NOT NULL default '',
406   - UNIQUE KEY `id` (`id`),
407   - KEY `namespace` (`namespace`)
  457 + PRIMARY KEY (`id`),
  458 + UNIQUE KEY `namespace` (`namespace`)
408 459 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
409 460  
410 461 --
... ... @@ -413,9 +464,9 @@ CREATE TABLE `document_transaction_types_lookup` (
413 464  
414 465 CREATE TABLE `document_transactions` (
415 466 `id` int(11) NOT NULL default '0',
416   - `document_id` int(11) NOT NULL default '0',
  467 + `document_id` int(11) default NULL,
417 468 `version` char(50) default NULL,
418   - `user_id` int(11) NOT NULL default '0',
  469 + `user_id` int(11) default NULL,
419 470 `datetime` datetime NOT NULL default '0000-00-00 00:00:00',
420 471 `ip` char(30) default NULL,
421 472 `filename` char(255) NOT NULL default '',
... ... @@ -423,10 +474,12 @@ CREATE TABLE `document_transactions` (
423 474 `transaction_namespace` char(255) NOT NULL default 'ktcore.transactions.event',
424 475 `session_id` int(11) default NULL,
425 476 `admin_mode` tinyint(1) NOT NULL default '0',
426   - UNIQUE KEY `id` (`id`),
427   - KEY `fk_document_id` (`document_id`),
428   - KEY `fk_user_id` (`user_id`),
429   - KEY `session_id` (`session_id`)
  477 + PRIMARY KEY (`id`),
  478 + KEY `document_id` (`document_id`),
  479 + KEY `user_id` (`user_id`),
  480 + KEY `session_id` (`session_id`),
  481 + CONSTRAINT `document_transactions_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
  482 + CONSTRAINT `document_transactions_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
430 483 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
431 484  
432 485 --
... ... @@ -438,7 +491,11 @@ CREATE TABLE `document_type_fields_link` (
438 491 `document_type_id` int(11) NOT NULL default '0',
439 492 `field_id` int(11) NOT NULL default '0',
440 493 `is_mandatory` tinyint(1) NOT NULL default '0',
441   - UNIQUE KEY `id` (`id`)
  494 + PRIMARY KEY (`id`),
  495 + KEY `document_type_id` (`document_type_id`),
  496 + KEY `field_id` (`field_id`),
  497 + CONSTRAINT `document_type_fields_link_ibfk_1` FOREIGN KEY (`document_type_id`) REFERENCES `document_types_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  498 + CONSTRAINT `document_type_fields_link_ibfk_2` FOREIGN KEY (`field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
442 499 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
443 500  
444 501 --
... ... @@ -449,11 +506,11 @@ CREATE TABLE `document_type_fieldsets_link` (
449 506 `id` int(11) NOT NULL default '0',
450 507 `document_type_id` int(11) NOT NULL default '0',
451 508 `fieldset_id` int(11) NOT NULL default '0',
452   - UNIQUE KEY `id` (`id`),
  509 + PRIMARY KEY (`id`),
453 510 KEY `document_type_id` (`document_type_id`),
454 511 KEY `fieldset_id` (`fieldset_id`),
455   - CONSTRAINT `document_type_fieldsets_link_ibfk_1` FOREIGN KEY (`document_type_id`) REFERENCES `document_types_lookup` (`id`) ON DELETE CASCADE,
456   - CONSTRAINT `document_type_fieldsets_link_ibfk_2` FOREIGN KEY (`fieldset_id`) REFERENCES `fieldsets` (`id`) ON DELETE CASCADE
  512 + CONSTRAINT `document_type_fieldsets_link_ibfk_1` FOREIGN KEY (`document_type_id`) REFERENCES `document_types_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  513 + CONSTRAINT `document_type_fieldsets_link_ibfk_2` FOREIGN KEY (`fieldset_id`) REFERENCES `fieldsets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
457 514 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
458 515  
459 516 --
... ... @@ -464,9 +521,8 @@ CREATE TABLE `document_types_lookup` (
464 521 `id` int(11) NOT NULL default '0',
465 522 `name` char(100) default NULL,
466 523 `disabled` tinyint(4) NOT NULL default '0',
467   - UNIQUE KEY `id` (`id`),
468   - UNIQUE KEY `name` (`name`),
469   - KEY `disabled` (`disabled`)
  524 + PRIMARY KEY (`id`),
  525 + KEY `name` (`name`)
470 526 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
471 527  
472 528 --
... ... @@ -475,7 +531,7 @@ CREATE TABLE `document_types_lookup` (
475 531  
476 532 CREATE TABLE `documents` (
477 533 `id` int(11) NOT NULL default '0',
478   - `creator_id` int(11) NOT NULL default '0',
  534 + `creator_id` int(11) default NULL,
479 535 `modified` datetime NOT NULL default '0000-00-00 00:00:00',
480 536 `folder_id` int(11) default NULL,
481 537 `is_checked_out` tinyint(1) NOT NULL default '0',
... ... @@ -487,23 +543,31 @@ CREATE TABLE `documents` (
487 543 `permission_object_id` int(11) default NULL,
488 544 `permission_lookup_id` int(11) default NULL,
489 545 `metadata_version` int(11) NOT NULL default '0',
490   - `modified_user_id` int(11) NOT NULL default '0',
  546 + `modified_user_id` int(11) default NULL,
491 547 `metadata_version_id` int(11) default NULL,
492   - `owner_id` int(11) NOT NULL default '0',
  548 + `owner_id` int(11) default NULL,
493 549 `immutable` tinyint(1) NOT NULL default '0',
494 550 `restore_folder_id` int(11) default NULL,
495 551 `restore_folder_path` text,
496 552 `checkedout` datetime default NULL,
497   - UNIQUE KEY `id` (`id`),
498   - KEY `fk_creator_id` (`creator_id`),
499   - KEY `fk_folder_id` (`folder_id`),
500   - KEY `fk_checked_out_user_id` (`checked_out_user_id`),
501   - KEY `fk_status_id` (`status_id`),
502   - KEY `created` (`created`),
  553 + PRIMARY KEY (`id`),
  554 + KEY `creator_id` (`creator_id`),
  555 + KEY `folder_id` (`folder_id`),
  556 + KEY `checked_out_user_id` (`checked_out_user_id`),
  557 + KEY `status_id` (`status_id`),
503 558 KEY `permission_object_id` (`permission_object_id`),
504 559 KEY `permission_lookup_id` (`permission_lookup_id`),
505 560 KEY `modified_user_id` (`modified_user_id`),
506   - KEY `metadata_version_id` (`metadata_version_id`)
  561 + KEY `metadata_version_id` (`metadata_version_id`),
  562 + KEY `created` (`created`),
  563 + CONSTRAINT `documents_ibfk_1` FOREIGN KEY (`creator_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
  564 + CONSTRAINT `documents_ibfk_2` FOREIGN KEY (`folder_id`) REFERENCES `folders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  565 + CONSTRAINT `documents_ibfk_3` FOREIGN KEY (`checked_out_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
  566 + CONSTRAINT `documents_ibfk_4` FOREIGN KEY (`status_id`) REFERENCES `status_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  567 + CONSTRAINT `documents_ibfk_5` FOREIGN KEY (`permission_object_id`) REFERENCES `permission_objects` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  568 + CONSTRAINT `documents_ibfk_6` FOREIGN KEY (`permission_lookup_id`) REFERENCES `permission_lookups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  569 + CONSTRAINT `documents_ibfk_7` FOREIGN KEY (`modified_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
  570 + CONSTRAINT `documents_ibfk_8` FOREIGN KEY (`metadata_version_id`) REFERENCES `document_metadata_version` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
507 571 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
508 572  
509 573 --
... ... @@ -511,14 +575,15 @@ CREATE TABLE `documents` (
511 575 --
512 576  
513 577 CREATE TABLE `download_files` (
514   - `document_id` int(10) unsigned NOT NULL,
  578 + `document_id` int(11) NOT NULL,
515 579 `session` varchar(100) NOT NULL,
516 580 `download_date` timestamp NULL default CURRENT_TIMESTAMP,
517 581 `downloaded` int(10) unsigned NOT NULL default '0',
518 582 `filesize` int(10) unsigned NOT NULL,
519 583 `content_version` int(10) unsigned NOT NULL,
520 584 `hash` varchar(100) NOT NULL,
521   - PRIMARY KEY (`document_id`,`session`)
  585 + PRIMARY KEY (`document_id`,`session`),
  586 + CONSTRAINT `download_files_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
522 587 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
523 588  
524 589 --
... ... @@ -529,12 +594,12 @@ CREATE TABLE `field_behaviour_options` (
529 594 `behaviour_id` int(11) NOT NULL default '0',
530 595 `field_id` int(11) NOT NULL default '0',
531 596 `instance_id` int(11) NOT NULL default '0',
532   - KEY `behaviour_id` (`behaviour_id`),
533 597 KEY `field_id` (`field_id`),
534 598 KEY `instance_id` (`instance_id`),
535   - CONSTRAINT `field_behaviour_options_ibfk_1` FOREIGN KEY (`behaviour_id`) REFERENCES `field_behaviours` (`id`) ON DELETE CASCADE,
536   - CONSTRAINT `field_behaviour_options_ibfk_2` FOREIGN KEY (`field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE,
537   - CONSTRAINT `field_behaviour_options_ibfk_3` FOREIGN KEY (`instance_id`) REFERENCES `field_value_instances` (`id`) ON DELETE CASCADE
  599 + KEY `behaviour_id_field_id` (`behaviour_id`,`field_id`),
  600 + CONSTRAINT `field_behaviour_options_ibfk_1` FOREIGN KEY (`behaviour_id`) REFERENCES `field_behaviours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  601 + CONSTRAINT `field_behaviour_options_ibfk_2` FOREIGN KEY (`field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  602 + CONSTRAINT `field_behaviour_options_ibfk_3` FOREIGN KEY (`instance_id`) REFERENCES `field_value_instances` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
538 603 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
539 604  
540 605 --
... ... @@ -549,7 +614,7 @@ CREATE TABLE `field_behaviours` (
549 614 PRIMARY KEY (`id`),
550 615 KEY `field_id` (`field_id`),
551 616 KEY `name` (`name`),
552   - CONSTRAINT `field_behaviours_ibfk_1` FOREIGN KEY (`field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE
  617 + CONSTRAINT `field_behaviours_ibfk_1` FOREIGN KEY (`field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
553 618 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
554 619  
555 620 --
... ... @@ -560,12 +625,12 @@ CREATE TABLE `field_orders` (
560 625 `parent_field_id` int(11) NOT NULL default '0',
561 626 `child_field_id` int(11) NOT NULL default '0',
562 627 `fieldset_id` int(11) NOT NULL default '0',
563   - UNIQUE KEY `child_field` (`child_field_id`),
564   - KEY `parent_field` (`parent_field_id`),
  628 + UNIQUE KEY `child_field_id` (`child_field_id`),
  629 + KEY `parent_field_id` (`parent_field_id`),
565 630 KEY `fieldset_id` (`fieldset_id`),
566   - CONSTRAINT `field_orders_ibfk_1` FOREIGN KEY (`parent_field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE,
567   - CONSTRAINT `field_orders_ibfk_2` FOREIGN KEY (`child_field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE,
568   - CONSTRAINT `field_orders_ibfk_3` FOREIGN KEY (`fieldset_id`) REFERENCES `fieldsets` (`id`) ON DELETE CASCADE
  631 + CONSTRAINT `field_orders_ibfk_1` FOREIGN KEY (`child_field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  632 + CONSTRAINT `field_orders_ibfk_2` FOREIGN KEY (`parent_field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  633 + CONSTRAINT `field_orders_ibfk_3` FOREIGN KEY (`fieldset_id`) REFERENCES `fieldsets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
569 634 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
570 635  
571 636 --
... ... @@ -578,12 +643,12 @@ CREATE TABLE `field_value_instances` (
578 643 `field_value_id` int(11) NOT NULL default '0',
579 644 `behaviour_id` int(11) default '0',
580 645 PRIMARY KEY (`id`),
581   - KEY `field_id` (`field_id`),
582 646 KEY `field_value_id` (`field_value_id`),
583 647 KEY `behaviour_id` (`behaviour_id`),
584   - CONSTRAINT `field_value_instances_ibfk_1` FOREIGN KEY (`field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE,
585   - CONSTRAINT `field_value_instances_ibfk_2` FOREIGN KEY (`field_value_id`) REFERENCES `metadata_lookup` (`id`) ON DELETE CASCADE,
586   - CONSTRAINT `field_value_instances_ibfk_3` FOREIGN KEY (`behaviour_id`) REFERENCES `field_behaviours` (`id`) ON DELETE CASCADE
  648 + KEY `field_id` (`field_id`),
  649 + CONSTRAINT `field_value_instances_ibfk_1` FOREIGN KEY (`field_value_id`) REFERENCES `metadata_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  650 + CONSTRAINT `field_value_instances_ibfk_2` FOREIGN KEY (`behaviour_id`) REFERENCES `field_behaviours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  651 + CONSTRAINT `field_value_instances_ibfk_3` FOREIGN KEY (`field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
587 652 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
588 653  
589 654 --
... ... @@ -603,12 +668,25 @@ CREATE TABLE `fieldsets` (
603 668 `is_system` tinyint(1) unsigned NOT NULL default '0',
604 669 `description` mediumtext NOT NULL,
605 670 `disabled` tinyint(4) NOT NULL default '0',
606   - UNIQUE KEY `id` (`id`),
  671 + PRIMARY KEY (`id`),
  672 + KEY `master_field` (`master_field`),
607 673 KEY `is_generic` (`is_generic`),
608 674 KEY `is_complete` (`is_complete`),
609 675 KEY `is_system` (`is_system`),
610   - KEY `master_field` (`master_field`),
611   - CONSTRAINT `fieldsets_ibfk_1` FOREIGN KEY (`master_field`) REFERENCES `document_fields` (`id`) ON DELETE SET NULL
  676 + CONSTRAINT `fieldsets_ibfk_1` FOREIGN KEY (`master_field`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
  677 +) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  678 +
  679 +--
  680 +-- Table structure for table `folder_descendants`
  681 +--
  682 +
  683 +CREATE TABLE `folder_descendants` (
  684 + `parent_id` int(11) NOT NULL,
  685 + `folder_id` int(11) NOT NULL,
  686 + KEY `parent_id` (`parent_id`),
  687 + KEY `folder_id` (`folder_id`),
  688 + CONSTRAINT `folder_descendants_ibfk_2` FOREIGN KEY (`folder_id`) REFERENCES `folders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  689 + CONSTRAINT `folder_descendants_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `folders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
612 690 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
613 691  
614 692 --
... ... @@ -619,9 +697,11 @@ CREATE TABLE `folder_doctypes_link` (
619 697 `id` int(11) NOT NULL default '0',
620 698 `folder_id` int(11) NOT NULL default '0',
621 699 `document_type_id` int(11) NOT NULL default '0',
622   - UNIQUE KEY `id` (`id`),
623   - KEY `fk_folder_id` (`folder_id`),
624   - KEY `fk_document_type_id` (`document_type_id`)
  700 + PRIMARY KEY (`id`),
  701 + KEY `folder_id` (`folder_id`),
  702 + KEY `document_type_id` (`document_type_id`),
  703 + CONSTRAINT `folder_doctypes_link_ibfk_1` FOREIGN KEY (`folder_id`) REFERENCES `folders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  704 + CONSTRAINT `folder_doctypes_link_ibfk_2` FOREIGN KEY (`document_type_id`) REFERENCES `document_types_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
625 705 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
626 706  
627 707 --
... ... @@ -632,7 +712,6 @@ CREATE TABLE `folder_searchable_text` (
632 712 `folder_id` int(11) NOT NULL default '0',
633 713 `folder_text` mediumtext,
634 714 PRIMARY KEY (`folder_id`),
635   - KEY `folder_searchable_text_folder_indx` (`folder_id`),
636 715 FULLTEXT KEY `folder_text` (`folder_text`)
637 716 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
638 717  
... ... @@ -645,7 +724,11 @@ CREATE TABLE `folder_subscriptions` (
645 724 `user_id` int(11) NOT NULL default '0',
646 725 `folder_id` int(11) NOT NULL default '0',
647 726 `is_alerted` tinyint(1) default NULL,
648   - UNIQUE KEY `id` (`id`)
  727 + PRIMARY KEY (`id`),
  728 + KEY `user_id` (`user_id`),
  729 + KEY `folder_id` (`folder_id`),
  730 + CONSTRAINT `folder_subscriptions_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  731 + CONSTRAINT `folder_subscriptions_ibfk_2` FOREIGN KEY (`folder_id`) REFERENCES `folders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
649 732 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
650 733  
651 734 --
... ... @@ -654,20 +737,20 @@ CREATE TABLE `folder_subscriptions` (
654 737  
655 738 CREATE TABLE `folder_transactions` (
656 739 `id` int(11) NOT NULL default '0',
657   - `folder_id` int(11) NOT NULL default '0',
658   - `user_id` int(11) NOT NULL default '0',
  740 + `folder_id` int(11) default NULL,
  741 + `user_id` int(11) default NULL,
659 742 `datetime` datetime NOT NULL default '0000-00-00 00:00:00',
660 743 `ip` char(30) default NULL,
661 744 `comment` char(255) NOT NULL default '',
662 745 `transaction_namespace` char(255) NOT NULL default 'ktcore.transactions.event',
663 746 `session_id` int(11) default NULL,
664 747 `admin_mode` tinyint(1) NOT NULL default '0',
665   - UNIQUE KEY `id` (`id`),
  748 + PRIMARY KEY (`id`),
666 749 KEY `folder_id` (`folder_id`),
667 750 KEY `user_id` (`user_id`),
668 751 KEY `session_id` (`session_id`),
669   - CONSTRAINT `folder_transactions_ibfk_1` FOREIGN KEY (`folder_id`) REFERENCES `folders` (`id`) ON DELETE CASCADE,
670   - CONSTRAINT `folder_transactions_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
  752 + CONSTRAINT `folder_transactions_ibfk_1` FOREIGN KEY (`folder_id`) REFERENCES `folders` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
  753 + CONSTRAINT `folder_transactions_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
671 754 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
672 755  
673 756 --
... ... @@ -678,7 +761,9 @@ CREATE TABLE `folder_workflow_map` (
678 761 `folder_id` int(11) NOT NULL default '0',
679 762 `workflow_id` int(11) default NULL,
680 763 PRIMARY KEY (`folder_id`),
681   - UNIQUE KEY `folder_id` (`folder_id`)
  764 + KEY `workflow_id` (`workflow_id`),
  765 + CONSTRAINT `folder_workflow_map_ibfk_1` FOREIGN KEY (`folder_id`) REFERENCES `folders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  766 + CONSTRAINT `folder_workflow_map_ibfk_2` FOREIGN KEY (`workflow_id`) REFERENCES `workflows` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
682 767 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
683 768  
684 769 --
... ... @@ -697,12 +782,16 @@ CREATE TABLE `folders` (
697 782 `permission_object_id` int(11) default NULL,
698 783 `permission_lookup_id` int(11) default NULL,
699 784 `restrict_document_types` tinyint(1) NOT NULL default '0',
700   - `owner_id` int(11) NOT NULL default '0',
701   - UNIQUE KEY `id` (`id`),
702   - KEY `fk_parent_id` (`parent_id`),
703   - KEY `fk_creator_id` (`creator_id`),
  785 + `owner_id` int(11) default NULL,
  786 + PRIMARY KEY (`id`),
  787 + KEY `creator_id` (`creator_id`),
704 788 KEY `permission_object_id` (`permission_object_id`),
705   - KEY `permission_lookup_id` (`permission_lookup_id`)
  789 + KEY `permission_lookup_id` (`permission_lookup_id`),
  790 + KEY `parent_id_name` (`parent_id`,`name`),
  791 + CONSTRAINT `folders_ibfk_1` FOREIGN KEY (`creator_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  792 + CONSTRAINT `folders_ibfk_2` FOREIGN KEY (`permission_object_id`) REFERENCES `permission_objects` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  793 + CONSTRAINT `folders_ibfk_3` FOREIGN KEY (`permission_lookup_id`) REFERENCES `permission_lookups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  794 + CONSTRAINT `folders_ibfk_4` FOREIGN KEY (`parent_id`) REFERENCES `folders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
706 795 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
707 796  
708 797 --
... ... @@ -718,7 +807,11 @@ CREATE TABLE `folders_users_roles_link` (
718 807 `done` tinyint(1) default NULL,
719 808 `active` tinyint(1) default NULL,
720 809 `dependant_documents_created` tinyint(1) default NULL,
721   - UNIQUE KEY `id` (`id`)
  810 + PRIMARY KEY (`id`),
  811 + KEY `user_id` (`user_id`),
  812 + KEY `document_id` (`document_id`),
  813 + CONSTRAINT `folders_users_roles_link_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  814 + CONSTRAINT `folders_users_roles_link_ibfk_2` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
722 815 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
723 816  
724 817 --
... ... @@ -730,10 +823,10 @@ CREATE TABLE `groups_groups_link` (
730 823 `parent_group_id` int(11) NOT NULL default '0',
731 824 `member_group_id` int(11) NOT NULL default '0',
732 825 PRIMARY KEY (`id`),
733   - KEY `groups_groups_link_ibfk_1` (`parent_group_id`),
734   - KEY `groups_groups_link_ibfk_2` (`member_group_id`),
735   - CONSTRAINT `groups_groups_link_ibfk_1` FOREIGN KEY (`parent_group_id`) REFERENCES `groups_lookup` (`id`) ON DELETE CASCADE,
736   - CONSTRAINT `groups_groups_link_ibfk_2` FOREIGN KEY (`member_group_id`) REFERENCES `groups_lookup` (`id`) ON DELETE CASCADE
  826 + KEY `parent_group_id` (`parent_group_id`),
  827 + KEY `member_group_id` (`member_group_id`),
  828 + CONSTRAINT `groups_groups_link_ibfk_1` FOREIGN KEY (`parent_group_id`) REFERENCES `groups_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  829 + CONSTRAINT `groups_groups_link_ibfk_2` FOREIGN KEY (`member_group_id`) REFERENCES `groups_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
737 830 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
738 831  
739 832 --
... ... @@ -749,12 +842,11 @@ CREATE TABLE `groups_lookup` (
749 842 `authentication_details_s2` varchar(255) default NULL,
750 843 `authentication_details_s1` varchar(255) default NULL,
751 844 `authentication_source_id` int(11) default NULL,
752   - UNIQUE KEY `id` (`id`),
  845 + PRIMARY KEY (`id`),
753 846 UNIQUE KEY `name` (`name`),
754 847 KEY `unit_id` (`unit_id`),
755   - KEY `authentication_details_s1` (`authentication_details_s1`),
756   - KEY `authentication_source_id` (`authentication_source_id`),
757   - CONSTRAINT `groups_lookup_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units_lookup` (`id`)
  848 + KEY `authentication_source_id_authentication_details_s1` (`authentication_source_id`,`authentication_details_s1`),
  849 + CONSTRAINT `groups_lookup_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
758 850 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
759 851  
760 852 --
... ... @@ -765,7 +857,7 @@ CREATE TABLE `help` (
765 857 `id` int(11) NOT NULL default '0',
766 858 `fSection` varchar(100) NOT NULL default '',
767 859 `help_info` mediumtext NOT NULL,
768   - UNIQUE KEY `id` (`id`)
  860 + PRIMARY KEY (`id`)
769 861 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
770 862  
771 863 --
... ... @@ -785,12 +877,15 @@ CREATE TABLE `help_replacement` (
785 877 --
786 878  
787 879 CREATE TABLE `index_files` (
788   - `document_id` int(10) unsigned NOT NULL,
789   - `user_id` int(10) unsigned NOT NULL,
  880 + `document_id` int(11) NOT NULL,
  881 + `user_id` int(11) NOT NULL,
790 882 `indexdate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
791 883 `processdate` datetime default NULL,
792 884 `what` char(1) default NULL,
793   - PRIMARY KEY (`document_id`)
  885 + PRIMARY KEY (`document_id`),
  886 + KEY `user_id` (`user_id`),
  887 + CONSTRAINT `index_files_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  888 + CONSTRAINT `index_files_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
794 889 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
795 890  
796 891 --
... ... @@ -815,7 +910,7 @@ CREATE TABLE `links` (
815 910 `name` char(100) NOT NULL default '',
816 911 `url` char(100) NOT NULL default '',
817 912 `rank` int(11) NOT NULL default '0',
818   - UNIQUE KEY `id` (`id`)
  913 + PRIMARY KEY (`id`)
819 914 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
820 915  
821 916 --
... ... @@ -829,9 +924,10 @@ CREATE TABLE `metadata_lookup` (
829 924 `treeorg_parent` int(11) default NULL,
830 925 `disabled` tinyint(3) unsigned NOT NULL default '0',
831 926 `is_stuck` tinyint(1) NOT NULL default '0',
832   - UNIQUE KEY `id` (`id`),
  927 + PRIMARY KEY (`id`),
  928 + KEY `document_field_id` (`document_field_id`),
833 929 KEY `disabled` (`disabled`),
834   - KEY `is_stuck` (`is_stuck`)
  930 + CONSTRAINT `metadata_lookup_ibfk_1` FOREIGN KEY (`document_field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
835 931 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
836 932  
837 933 --
... ... @@ -843,9 +939,10 @@ CREATE TABLE `metadata_lookup_tree` (
843 939 `document_field_id` int(11) NOT NULL default '0',
844 940 `name` char(255) default NULL,
845 941 `metadata_lookup_tree_parent` int(11) default NULL,
846   - UNIQUE KEY `id` (`id`),
  942 + PRIMARY KEY (`id`),
  943 + KEY `document_field_id` (`document_field_id`),
847 944 KEY `metadata_lookup_tree_parent` (`metadata_lookup_tree_parent`),
848   - KEY `document_field_id` (`document_field_id`)
  945 + CONSTRAINT `metadata_lookup_tree_ibfk_1` FOREIGN KEY (`document_field_id`) REFERENCES `document_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
849 946 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
850 947  
851 948 --
... ... @@ -871,7 +968,11 @@ CREATE TABLE `mime_types` (
871 968 `friendly_name` char(255) default '',
872 969 `extractor` varchar(100) default NULL,
873 970 `mime_document_id` int(11) default NULL,
874   - UNIQUE KEY `id` (`id`)
  971 + PRIMARY KEY (`id`),
  972 + KEY `mime_document_id` (`mime_document_id`),
  973 + KEY `filetypes` (`filetypes`),
  974 + KEY `mimetypes` (`mimetypes`),
  975 + CONSTRAINT `mime_types_ibfk_1` FOREIGN KEY (`mime_document_id`) REFERENCES `mime_documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
875 976 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
876 977  
877 978 --
... ... @@ -887,7 +988,9 @@ CREATE TABLE `news` (
887 988 `image_size` int(11) default NULL,
888 989 `image_mime_type_id` int(11) default NULL,
889 990 `active` tinyint(1) default NULL,
890   - UNIQUE KEY `id` (`id`)
  991 + PRIMARY KEY (`id`),
  992 + KEY `image_mime_type_id` (`image_mime_type_id`),
  993 + CONSTRAINT `news_ibfk_1` FOREIGN KEY (`image_mime_type_id`) REFERENCES `mime_types` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
891 994 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
892 995  
893 996 --
... ... @@ -905,9 +1008,10 @@ CREATE TABLE `notifications` (
905 1008 `data_str_1` varchar(255) default NULL,
906 1009 `data_str_2` varchar(255) default NULL,
907 1010 `data_text_1` text,
908   - UNIQUE KEY `id` (`id`),
909   - KEY `type` (`type`),
910   - KEY `user_id` (`user_id`)
  1011 + PRIMARY KEY (`id`),
  1012 + KEY `user_id` (`user_id`),
  1013 + KEY `data_int_1` (`data_int_1`),
  1014 + CONSTRAINT `notifications_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
911 1015 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
912 1016  
913 1017 --
... ... @@ -917,7 +1021,7 @@ CREATE TABLE `notifications` (
917 1021 CREATE TABLE `organisations_lookup` (
918 1022 `id` int(11) NOT NULL default '0',
919 1023 `name` char(100) NOT NULL default '',
920   - UNIQUE KEY `id` (`id`),
  1024 + PRIMARY KEY (`id`),
921 1025 UNIQUE KEY `name` (`name`)
922 1026 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
923 1027  
... ... @@ -931,13 +1035,12 @@ CREATE TABLE `permission_assignments` (
931 1035 `permission_object_id` int(11) NOT NULL default '0',
932 1036 `permission_descriptor_id` int(11) default NULL,
933 1037 PRIMARY KEY (`id`),
934   - UNIQUE KEY `permission_and_object` (`permission_id`,`permission_object_id`),
  1038 + UNIQUE KEY `permission_object_id_permission_id` (`permission_object_id`,`permission_id`),
935 1039 KEY `permission_id` (`permission_id`),
936   - KEY `permission_object_id` (`permission_object_id`),
937 1040 KEY `permission_descriptor_id` (`permission_descriptor_id`),
938   - CONSTRAINT `permission_assignments_ibfk_1` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE,
939   - CONSTRAINT `permission_assignments_ibfk_2` FOREIGN KEY (`permission_object_id`) REFERENCES `permission_objects` (`id`) ON DELETE CASCADE,
940   - CONSTRAINT `permission_assignments_ibfk_3` FOREIGN KEY (`permission_descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE
  1041 + CONSTRAINT `permission_assignments_ibfk_1` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1042 + CONSTRAINT `permission_assignments_ibfk_2` FOREIGN KEY (`permission_object_id`) REFERENCES `permission_objects` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1043 + CONSTRAINT `permission_assignments_ibfk_3` FOREIGN KEY (`permission_descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
941 1044 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
942 1045  
943 1046 --
... ... @@ -947,11 +1050,10 @@ CREATE TABLE `permission_assignments` (
947 1050 CREATE TABLE `permission_descriptor_groups` (
948 1051 `descriptor_id` int(11) NOT NULL default '0',
949 1052 `group_id` int(11) NOT NULL default '0',
950   - UNIQUE KEY `descriptor_id` (`descriptor_id`,`group_id`),
951   - KEY `descriptor_id_2` (`descriptor_id`),
  1053 + PRIMARY KEY (`descriptor_id`,`group_id`),
952 1054 KEY `group_id` (`group_id`),
953   - CONSTRAINT `permission_descriptor_groups_ibfk_1` FOREIGN KEY (`descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE,
954   - CONSTRAINT `permission_descriptor_groups_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `groups_lookup` (`id`) ON DELETE CASCADE
  1055 + CONSTRAINT `permission_descriptor_groups_ibfk_1` FOREIGN KEY (`descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1056 + CONSTRAINT `permission_descriptor_groups_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `groups_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
955 1057 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
956 1058  
957 1059 --
... ... @@ -961,11 +1063,10 @@ CREATE TABLE `permission_descriptor_groups` (
961 1063 CREATE TABLE `permission_descriptor_roles` (
962 1064 `descriptor_id` int(11) NOT NULL default '0',
963 1065 `role_id` int(11) NOT NULL default '0',
964   - UNIQUE KEY `descriptor_id` (`descriptor_id`,`role_id`),
965   - KEY `descriptor_id_2` (`descriptor_id`),
  1066 + PRIMARY KEY (`descriptor_id`,`role_id`),
966 1067 KEY `role_id` (`role_id`),
967   - CONSTRAINT `permission_descriptor_roles_ibfk_1` FOREIGN KEY (`descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE,
968   - CONSTRAINT `permission_descriptor_roles_ibfk_2` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE
  1068 + CONSTRAINT `permission_descriptor_roles_ibfk_1` FOREIGN KEY (`descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1069 + CONSTRAINT `permission_descriptor_roles_ibfk_2` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
969 1070 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
970 1071  
971 1072 --
... ... @@ -975,11 +1076,10 @@ CREATE TABLE `permission_descriptor_roles` (
975 1076 CREATE TABLE `permission_descriptor_users` (
976 1077 `descriptor_id` int(11) NOT NULL default '0',
977 1078 `user_id` int(11) NOT NULL default '0',
978   - UNIQUE KEY `descriptor_id` (`descriptor_id`,`user_id`),
979   - KEY `descriptor_id_2` (`descriptor_id`),
  1079 + PRIMARY KEY (`descriptor_id`,`user_id`),
980 1080 KEY `user_id` (`user_id`),
981   - CONSTRAINT `permission_descriptor_users_ibfk_1` FOREIGN KEY (`descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE,
982   - CONSTRAINT `permission_descriptor_users_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
  1081 + CONSTRAINT `permission_descriptor_users_ibfk_1` FOREIGN KEY (`descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1082 + CONSTRAINT `permission_descriptor_users_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
983 1083 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
984 1084  
985 1085 --
... ... @@ -991,8 +1091,7 @@ CREATE TABLE `permission_descriptors` (
991 1091 `descriptor` varchar(32) NOT NULL default '',
992 1092 `descriptor_text` mediumtext NOT NULL,
993 1093 PRIMARY KEY (`id`),
994   - UNIQUE KEY `descriptor_2` (`descriptor`),
995   - KEY `descriptor` (`descriptor`)
  1094 + UNIQUE KEY `descriptor` (`descriptor`)
996 1095 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
997 1096  
998 1097 --
... ... @@ -1002,10 +1101,10 @@ CREATE TABLE `permission_descriptors` (
1002 1101 CREATE TABLE `permission_dynamic_assignments` (
1003 1102 `dynamic_condition_id` int(11) NOT NULL default '0',
1004 1103 `permission_id` int(11) NOT NULL default '0',
1005   - KEY `dynamic_conditiond_id` (`dynamic_condition_id`),
  1104 + KEY `dynamic_condition_id` (`dynamic_condition_id`),
1006 1105 KEY `permission_id` (`permission_id`),
1007   - CONSTRAINT `permission_dynamic_assignments_ibfk_2` FOREIGN KEY (`dynamic_condition_id`) REFERENCES `permission_dynamic_conditions` (`id`) ON DELETE CASCADE,
1008   - CONSTRAINT `permission_dynamic_assignments_ibfk_3` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE
  1106 + CONSTRAINT `permission_dynamic_assignments_ibfk_2` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1107 + CONSTRAINT `permission_dynamic_assignments_ibfk_1` FOREIGN KEY (`dynamic_condition_id`) REFERENCES `permission_dynamic_conditions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1009 1108 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1010 1109  
1011 1110 --
... ... @@ -1021,9 +1120,9 @@ CREATE TABLE `permission_dynamic_conditions` (
1021 1120 KEY `permission_object_id` (`permission_object_id`),
1022 1121 KEY `group_id` (`group_id`),
1023 1122 KEY `condition_id` (`condition_id`),
1024   - CONSTRAINT `permission_dynamic_conditions_ibfk_1` FOREIGN KEY (`permission_object_id`) REFERENCES `permission_objects` (`id`) ON DELETE CASCADE,
1025   - CONSTRAINT `permission_dynamic_conditions_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `groups_lookup` (`id`) ON DELETE CASCADE,
1026   - CONSTRAINT `permission_dynamic_conditions_ibfk_3` FOREIGN KEY (`condition_id`) REFERENCES `saved_searches` (`id`) ON DELETE CASCADE
  1123 + CONSTRAINT `permission_dynamic_conditions_ibfk_1` FOREIGN KEY (`permission_object_id`) REFERENCES `permission_objects` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1124 + CONSTRAINT `permission_dynamic_conditions_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `groups_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1125 + CONSTRAINT `permission_dynamic_conditions_ibfk_3` FOREIGN KEY (`condition_id`) REFERENCES `saved_searches` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1027 1126 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1028 1127  
1029 1128 --
... ... @@ -1036,13 +1135,12 @@ CREATE TABLE `permission_lookup_assignments` (
1036 1135 `permission_lookup_id` int(11) NOT NULL default '0',
1037 1136 `permission_descriptor_id` int(11) default NULL,
1038 1137 PRIMARY KEY (`id`),
1039   - UNIQUE KEY `permission_and_lookup` (`permission_id`,`permission_lookup_id`),
  1138 + UNIQUE KEY `permission_lookup_id_permission_id` (`permission_lookup_id`,`permission_id`),
1040 1139 KEY `permission_id` (`permission_id`),
1041   - KEY `permission_lookup_id` (`permission_lookup_id`),
1042 1140 KEY `permission_descriptor_id` (`permission_descriptor_id`),
1043   - CONSTRAINT `permission_lookup_assignments_ibfk_1` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE,
1044   - CONSTRAINT `permission_lookup_assignments_ibfk_2` FOREIGN KEY (`permission_lookup_id`) REFERENCES `permission_lookups` (`id`) ON DELETE CASCADE,
1045   - CONSTRAINT `permission_lookup_assignments_ibfk_3` FOREIGN KEY (`permission_descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE
  1141 + CONSTRAINT `permission_lookup_assignments_ibfk_1` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1142 + CONSTRAINT `permission_lookup_assignments_ibfk_2` FOREIGN KEY (`permission_lookup_id`) REFERENCES `permission_lookups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1143 + CONSTRAINT `permission_lookup_assignments_ibfk_3` FOREIGN KEY (`permission_descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1046 1144 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1047 1145  
1048 1146 --
... ... @@ -1085,8 +1183,10 @@ CREATE TABLE `plugin_rss` (
1085 1183 `user_id` int(11) NOT NULL,
1086 1184 `url` varchar(200) NOT NULL,
1087 1185 `title` varchar(20) NOT NULL,
1088   - PRIMARY KEY (`id`)
1089   -) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  1186 + PRIMARY KEY (`id`),
  1187 + KEY `user_id` (`user_id`),
  1188 + CONSTRAINT `plugin_rss_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
  1189 +) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1090 1190  
1091 1191 --
1092 1192 -- Table structure for table `plugins`
... ... @@ -1102,7 +1202,8 @@ CREATE TABLE `plugins` (
1102 1202 `unavailable` tinyint(1) NOT NULL default '0',
1103 1203 `friendly_name` varchar(255) default '',
1104 1204 PRIMARY KEY (`id`),
1105   - KEY `name` (`namespace`)
  1205 + UNIQUE KEY `namespace` (`namespace`),
  1206 + KEY `disabled` (`disabled`)
1106 1207 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1107 1208  
1108 1209 --
... ... @@ -1114,8 +1215,13 @@ CREATE TABLE `role_allocations` (
1114 1215 `folder_id` int(11) NOT NULL default '0',
1115 1216 `role_id` int(11) NOT NULL default '0',
1116 1217 `permission_descriptor_id` int(11) NOT NULL default '0',
1117   - UNIQUE KEY `id` (`id`),
1118   - KEY `folder_id` (`folder_id`)
  1218 + PRIMARY KEY (`id`),
  1219 + KEY `folder_id` (`folder_id`),
  1220 + KEY `role_id` (`role_id`),
  1221 + KEY `permission_descriptor_id` (`permission_descriptor_id`),
  1222 + CONSTRAINT `role_allocations_ibfk_1` FOREIGN KEY (`folder_id`) REFERENCES `folders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1223 + CONSTRAINT `role_allocations_ibfk_2` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1224 + CONSTRAINT `role_allocations_ibfk_3` FOREIGN KEY (`permission_descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1119 1225 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1120 1226  
1121 1227 --
... ... @@ -1125,7 +1231,7 @@ CREATE TABLE `role_allocations` (
1125 1231 CREATE TABLE `roles` (
1126 1232 `id` int(11) NOT NULL default '0',
1127 1233 `name` char(255) NOT NULL default '',
1128   - UNIQUE KEY `id` (`id`),
  1234 + PRIMARY KEY (`id`),
1129 1235 UNIQUE KEY `name` (`name`)
1130 1236 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1131 1237  
... ... @@ -1142,9 +1248,7 @@ CREATE TABLE `saved_searches` (
1142 1248 `user_id` int(10) default NULL,
1143 1249 `search` mediumtext NOT NULL,
1144 1250 PRIMARY KEY (`id`),
1145   - KEY `namespace` (`namespace`),
1146   - KEY `is_condition` (`is_condition`),
1147   - KEY `is_complete` (`is_complete`),
  1251 + UNIQUE KEY `namespace` (`namespace`),
1148 1252 KEY `user_id` (`user_id`),
1149 1253 CONSTRAINT `saved_searches_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1150 1254 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
... ... @@ -1162,9 +1266,10 @@ CREATE TABLE `scheduler_tasks` (
1162 1266 `is_background` tinyint(4) NOT NULL default '0',
1163 1267 `is_complete` tinyint(4) NOT NULL default '0',
1164 1268 `frequency` varchar(25) default NULL,
1165   - `run_time` datetime,
1166   - `previous_run_time` datetime,
1167   - `run_duration` float default NULL
  1269 + `run_time` datetime default NULL,
  1270 + `previous_run_time` datetime default NULL,
  1271 + `run_duration` float default NULL,
  1272 + PRIMARY KEY (`id`)
1168 1273 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1169 1274  
1170 1275 --
... ... @@ -1174,8 +1279,10 @@ CREATE TABLE `scheduler_tasks` (
1174 1279 CREATE TABLE `search_document_user_link` (
1175 1280 `document_id` int(11) default NULL,
1176 1281 `user_id` int(11) default NULL,
1177   - KEY `fk_user_id` (`user_id`),
1178   - KEY `fk_document_ids` (`document_id`)
  1282 + KEY `document_id` (`document_id`),
  1283 + KEY `user_id` (`user_id`),
  1284 + CONSTRAINT `search_document_user_link_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1285 + CONSTRAINT `search_document_user_link_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1179 1286 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1180 1287  
1181 1288 --
... ... @@ -1201,7 +1308,9 @@ CREATE TABLE `search_saved` (
1201 1308 `user_id` int(11) NOT NULL,
1202 1309 `type` enum('S','C','W','B') NOT NULL default 'S' COMMENT 'S=saved search, C=permission, w=workflow, B=subscription',
1203 1310 `shared` tinyint(4) NOT NULL default '0',
1204   - PRIMARY KEY (`id`)
  1311 + PRIMARY KEY (`id`),
  1312 + KEY `user_id` (`user_id`),
  1313 + CONSTRAINT `search_saved_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1205 1314 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1206 1315  
1207 1316 --
... ... @@ -1209,7 +1318,9 @@ CREATE TABLE `search_saved` (
1209 1318 --
1210 1319  
1211 1320 CREATE TABLE `search_saved_events` (
1212   - `document_id` int(11) NOT NULL
  1321 + `document_id` int(11) NOT NULL,
  1322 + PRIMARY KEY (`document_id`),
  1323 + CONSTRAINT `search_saved_events_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1213 1324 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1214 1325  
1215 1326 --
... ... @@ -1219,7 +1330,7 @@ CREATE TABLE `search_saved_events` (
1219 1330 CREATE TABLE `status_lookup` (
1220 1331 `id` int(11) NOT NULL default '0',
1221 1332 `name` char(255) default NULL,
1222   - UNIQUE KEY `id` (`id`)
  1333 + PRIMARY KEY (`id`)
1223 1334 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1224 1335  
1225 1336 --
... ... @@ -1230,7 +1341,8 @@ CREATE TABLE `system_settings` (
1230 1341 `id` int(11) NOT NULL default '0',
1231 1342 `name` char(255) NOT NULL default '',
1232 1343 `value` text NOT NULL,
1233   - UNIQUE KEY `id` (`id`)
  1344 + PRIMARY KEY (`id`),
  1345 + UNIQUE KEY `name` (`name`)
1234 1346 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1235 1347  
1236 1348 --
... ... @@ -1251,7 +1363,9 @@ CREATE TABLE `time_period` (
1251 1363 `id` int(11) NOT NULL default '0',
1252 1364 `time_unit_id` int(11) default NULL,
1253 1365 `units` int(11) default NULL,
1254   - UNIQUE KEY `id` (`id`)
  1366 + PRIMARY KEY (`id`),
  1367 + KEY `time_unit_id` (`time_unit_id`),
  1368 + CONSTRAINT `time_period_ibfk_1` FOREIGN KEY (`time_unit_id`) REFERENCES `time_unit_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1255 1369 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1256 1370  
1257 1371 --
... ... @@ -1261,7 +1375,7 @@ CREATE TABLE `time_period` (
1261 1375 CREATE TABLE `time_unit_lookup` (
1262 1376 `id` int(11) NOT NULL default '0',
1263 1377 `name` char(100) default NULL,
1264   - UNIQUE KEY `id` (`id`)
  1378 + PRIMARY KEY (`id`)
1265 1379 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1266 1380  
1267 1381 --
... ... @@ -1271,8 +1385,7 @@ CREATE TABLE `time_unit_lookup` (
1271 1385 CREATE TABLE `trigger_selection` (
1272 1386 `event_ns` varchar(255) NOT NULL default '',
1273 1387 `selection_ns` varchar(255) NOT NULL default '',
1274   - PRIMARY KEY (`event_ns`),
1275   - UNIQUE KEY `event_ns` (`event_ns`)
  1388 + PRIMARY KEY (`event_ns`)
1276 1389 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1277 1390  
1278 1391 --
... ... @@ -1281,9 +1394,11 @@ CREATE TABLE `trigger_selection` (
1281 1394  
1282 1395 CREATE TABLE `type_workflow_map` (
1283 1396 `document_type_id` int(11) NOT NULL default '0',
1284   - `workflow_id` int(10) unsigned default NULL,
  1397 + `workflow_id` int(11) default NULL,
1285 1398 PRIMARY KEY (`document_type_id`),
1286   - UNIQUE KEY `document_type_id` (`document_type_id`)
  1399 + KEY `workflow_id` (`workflow_id`),
  1400 + CONSTRAINT `type_workflow_map_ibfk_1` FOREIGN KEY (`document_type_id`) REFERENCES `document_types_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1401 + CONSTRAINT `type_workflow_map_ibfk_2` FOREIGN KEY (`workflow_id`) REFERENCES `workflows` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1287 1402 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1288 1403  
1289 1404 --
... ... @@ -1294,9 +1409,10 @@ CREATE TABLE `units_lookup` (
1294 1409 `id` int(11) NOT NULL default '0',
1295 1410 `name` char(100) NOT NULL default '',
1296 1411 `folder_id` int(11) NOT NULL default '0',
1297   - UNIQUE KEY `id` (`id`),
  1412 + PRIMARY KEY (`id`),
1298 1413 UNIQUE KEY `name` (`name`),
1299   - UNIQUE KEY `folder_id` (`folder_id`)
  1414 + UNIQUE KEY `folder_id` (`folder_id`),
  1415 + CONSTRAINT `units_lookup_ibfk_1` FOREIGN KEY (`folder_id`) REFERENCES `folders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1300 1416 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1301 1417  
1302 1418 --
... ... @@ -1307,9 +1423,11 @@ CREATE TABLE `units_organisations_link` (
1307 1423 `id` int(11) NOT NULL default '0',
1308 1424 `unit_id` int(11) NOT NULL default '0',
1309 1425 `organisation_id` int(11) NOT NULL default '0',
1310   - UNIQUE KEY `id` (`id`),
1311   - KEY `fk_unit_id` (`unit_id`),
1312   - KEY `fk_organisation_id` (`organisation_id`)
  1426 + PRIMARY KEY (`id`),
  1427 + KEY `unit_id` (`unit_id`),
  1428 + KEY `organisation_id` (`organisation_id`),
  1429 + CONSTRAINT `units_organisations_link_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `units_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1430 + CONSTRAINT `units_organisations_link_ibfk_2` FOREIGN KEY (`organisation_id`) REFERENCES `organisations_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1313 1431 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1314 1432  
1315 1433 --
... ... @@ -1338,7 +1456,12 @@ CREATE TABLE `uploaded_files` (
1338 1456 `userid` int(11) NOT NULL,
1339 1457 `uploaddate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1340 1458 `action` char(1) NOT NULL COMMENT 'A = Add, C = Checkin',
1341   - `document_id` int(11) default NULL
  1459 + `document_id` int(11) default NULL,
  1460 + PRIMARY KEY (`tempfilename`),
  1461 + KEY `userid` (`userid`),
  1462 + KEY `document_id` (`document_id`),
  1463 + CONSTRAINT `uploaded_files_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1464 + CONSTRAINT `uploaded_files_ibfk_2` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1342 1465 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1343 1466  
1344 1467 --
... ... @@ -1357,9 +1480,10 @@ CREATE TABLE `user_history` (
1357 1480 KEY `action_namespace` (`action_namespace`),
1358 1481 KEY `datetime` (`datetime`),
1359 1482 KEY `session_id` (`session_id`),
1360   - CONSTRAINT `user_history_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
  1483 + CONSTRAINT `user_history_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1361 1484 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1362 1485  
  1486 +
1363 1487 --
1364 1488 -- Table structure for table `users`
1365 1489 --
... ... @@ -1388,14 +1512,12 @@ CREATE TABLE `users` (
1388 1512 `authentication_details_b2` tinyint(1) default NULL,
1389 1513 `last_login` datetime default NULL,
1390 1514 `disabled` tinyint(1) NOT NULL,
1391   - UNIQUE KEY `id` (`id`),
  1515 + PRIMARY KEY (`id`),
1392 1516 UNIQUE KEY `username` (`username`),
1393   - KEY `authentication_source` (`authentication_source_id`),
1394   - KEY `authentication_details_b1` (`authentication_details_b1`),
1395   - KEY `authentication_details_b2` (`authentication_details_b2`),
  1517 + KEY `authentication_source_id` (`authentication_source_id`),
1396 1518 KEY `last_login` (`last_login`),
1397 1519 KEY `disabled` (`disabled`),
1398   - CONSTRAINT `users_ibfk_1` FOREIGN KEY (`authentication_source_id`) REFERENCES `authentication_sources` (`id`) ON DELETE SET NULL
  1520 + CONSTRAINT `users_ibfk_1` FOREIGN KEY (`authentication_source_id`) REFERENCES `authentication_sources` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1399 1521 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1400 1522  
1401 1523 --
... ... @@ -1406,11 +1528,11 @@ CREATE TABLE `users_groups_link` (
1406 1528 `id` int(11) NOT NULL default '0',
1407 1529 `user_id` int(11) NOT NULL default '0',
1408 1530 `group_id` int(11) NOT NULL default '0',
1409   - UNIQUE KEY `id` (`id`),
1410   - KEY `fk_user_id` (`user_id`),
1411   - KEY `fk_group_id` (`group_id`),
1412   - CONSTRAINT `users_groups_link_ibfk_1` FOREIGN KEY (`group_id`) REFERENCES `groups_lookup` (`id`) ON DELETE CASCADE,
1413   - CONSTRAINT `users_groups_link_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
  1531 + PRIMARY KEY (`id`),
  1532 + KEY `user_id` (`user_id`),
  1533 + KEY `group_id` (`group_id`),
  1534 + CONSTRAINT `users_groups_link_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1535 + CONSTRAINT `users_groups_link_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `groups_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1414 1536 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1415 1537  
1416 1538 --
... ... @@ -1420,8 +1542,7 @@ CREATE TABLE `users_groups_link` (
1420 1542 CREATE TABLE `workflow_actions` (
1421 1543 `workflow_id` int(11) NOT NULL default '0',
1422 1544 `action_name` char(255) NOT NULL default '',
1423   - KEY `workflow_id` (`workflow_id`),
1424   - KEY `action_name` (`action_name`)
  1545 + PRIMARY KEY (`workflow_id`)
1425 1546 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1426 1547  
1427 1548 --
... ... @@ -1434,7 +1555,10 @@ CREATE TABLE `workflow_documents` (
1434 1555 `state_id` int(11) NOT NULL default '0',
1435 1556 PRIMARY KEY (`document_id`),
1436 1557 KEY `workflow_id` (`workflow_id`),
1437   - KEY `state_id` (`state_id`)
  1558 + KEY `state_id` (`state_id`),
  1559 + CONSTRAINT `workflow_documents_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1560 + CONSTRAINT `workflow_documents_ibfk_2` FOREIGN KEY (`workflow_id`) REFERENCES `workflows` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1561 + CONSTRAINT `workflow_documents_ibfk_3` FOREIGN KEY (`state_id`) REFERENCES `workflow_states` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1438 1562 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1439 1563  
1440 1564 --
... ... @@ -1445,7 +1569,7 @@ CREATE TABLE `workflow_state_actions` (
1445 1569 `state_id` int(11) NOT NULL default '0',
1446 1570 `action_name` char(255) NOT NULL default '0',
1447 1571 KEY `state_id` (`state_id`),
1448   - KEY `action_name` (`action_name`)
  1572 + CONSTRAINT `workflow_state_actions_ibfk_1` FOREIGN KEY (`state_id`) REFERENCES `workflow_states` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1449 1573 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1450 1574  
1451 1575 --
... ... @@ -1456,7 +1580,7 @@ CREATE TABLE `workflow_state_disabled_actions` (
1456 1580 `state_id` int(11) NOT NULL default '0',
1457 1581 `action_name` char(255) NOT NULL default '0',
1458 1582 KEY `state_id` (`state_id`),
1459   - KEY `action_name` (`action_name`)
  1583 + CONSTRAINT `workflow_state_disabled_actions_ibfk_1` FOREIGN KEY (`state_id`) REFERENCES `workflow_states` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1460 1584 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1461 1585  
1462 1586 --
... ... @@ -1472,8 +1596,9 @@ CREATE TABLE `workflow_state_permission_assignments` (
1472 1596 KEY `permission_id` (`permission_id`),
1473 1597 KEY `permission_descriptor_id` (`permission_descriptor_id`),
1474 1598 KEY `workflow_state_id` (`workflow_state_id`),
1475   - CONSTRAINT `workflow_state_permission_assignments_ibfk_7` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE,
1476   - CONSTRAINT `workflow_state_permission_assignments_ibfk_8` FOREIGN KEY (`permission_descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE
  1599 + CONSTRAINT `workflow_state_permission_assignments_ibfk_1` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1600 + CONSTRAINT `workflow_state_permission_assignments_ibfk_2` FOREIGN KEY (`permission_descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1601 + CONSTRAINT `workflow_state_permission_assignments_ibfk_3` FOREIGN KEY (`workflow_state_id`) REFERENCES `workflow_states` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1477 1602 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1478 1603  
1479 1604 --
... ... @@ -1482,7 +1607,11 @@ CREATE TABLE `workflow_state_permission_assignments` (
1482 1607  
1483 1608 CREATE TABLE `workflow_state_transitions` (
1484 1609 `state_id` int(11) NOT NULL default '0',
1485   - `transition_id` int(11) NOT NULL default '0'
  1610 + `transition_id` int(11) NOT NULL default '0',
  1611 + PRIMARY KEY (`state_id`,`transition_id`),
  1612 + KEY `transition_id` (`transition_id`),
  1613 + CONSTRAINT `workflow_state_transitions_ibfk_2` FOREIGN KEY (`transition_id`) REFERENCES `workflow_transitions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1614 + CONSTRAINT `workflow_state_transitions_ibfk_1` FOREIGN KEY (`state_id`) REFERENCES `workflow_states` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1486 1615 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1487 1616  
1488 1617 --
... ... @@ -1501,8 +1630,8 @@ CREATE TABLE `workflow_states` (
1501 1630 KEY `workflow_id` (`workflow_id`),
1502 1631 KEY `name` (`name`),
1503 1632 KEY `inform_descriptor_id` (`inform_descriptor_id`),
1504   - CONSTRAINT `workflow_states_ibfk_1` FOREIGN KEY (`workflow_id`) REFERENCES `workflows` (`id`),
1505   - CONSTRAINT `workflow_states_ibfk_2` FOREIGN KEY (`inform_descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE SET NULL
  1633 + CONSTRAINT `workflow_states_ibfk_1` FOREIGN KEY (`workflow_id`) REFERENCES `workflows` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1634 + CONSTRAINT `workflow_states_ibfk_2` FOREIGN KEY (`inform_descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1506 1635 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1507 1636  
1508 1637 --
... ... @@ -1520,20 +1649,19 @@ CREATE TABLE `workflow_transitions` (
1520 1649 `guard_role_id` int(11) default '0',
1521 1650 `guard_condition_id` int(11) default NULL,
1522 1651 PRIMARY KEY (`id`),
1523   - UNIQUE KEY `workflow_id_2` (`workflow_id`,`name`),
1524   - KEY `workflow_id` (`workflow_id`),
1525   - KEY `name` (`name`),
  1652 + UNIQUE KEY `workflow_id_name` (`workflow_id`,`name`),
1526 1653 KEY `target_state_id` (`target_state_id`),
1527   - KEY `guard_permission_id` (`guard_permission_id`),
1528   - KEY `guard_condition` (`guard_condition_id`),
  1654 + KEY `guard_condition_id` (`guard_condition_id`),
1529 1655 KEY `guard_group_id` (`guard_group_id`),
1530 1656 KEY `guard_role_id` (`guard_role_id`),
1531   - CONSTRAINT `workflow_transitions_ibfk_45` FOREIGN KEY (`workflow_id`) REFERENCES `workflows` (`id`) ON DELETE CASCADE,
1532   - CONSTRAINT `workflow_transitions_ibfk_46` FOREIGN KEY (`target_state_id`) REFERENCES `workflow_states` (`id`) ON DELETE CASCADE,
1533   - CONSTRAINT `workflow_transitions_ibfk_47` FOREIGN KEY (`guard_permission_id`) REFERENCES `permissions` (`id`) ON DELETE SET NULL,
1534   - CONSTRAINT `workflow_transitions_ibfk_48` FOREIGN KEY (`guard_group_id`) REFERENCES `groups_lookup` (`id`) ON DELETE SET NULL,
1535   - CONSTRAINT `workflow_transitions_ibfk_49` FOREIGN KEY (`guard_role_id`) REFERENCES `roles` (`id`) ON DELETE SET NULL,
1536   - CONSTRAINT `workflow_transitions_ibfk_50` FOREIGN KEY (`guard_condition_id`) REFERENCES `saved_searches` (`id`) ON DELETE SET NULL
  1657 + KEY `name` (`name`),
  1658 + KEY `guard_permission_id` (`guard_permission_id`),
  1659 + CONSTRAINT `workflow_transitions_ibfk_1` FOREIGN KEY (`workflow_id`) REFERENCES `workflows` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1660 + CONSTRAINT `workflow_transitions_ibfk_2` FOREIGN KEY (`target_state_id`) REFERENCES `workflow_states` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1661 + CONSTRAINT `workflow_transitions_ibfk_3` FOREIGN KEY (`guard_permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1662 + CONSTRAINT `workflow_transitions_ibfk_4` FOREIGN KEY (`guard_condition_id`) REFERENCES `saved_searches` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1663 + CONSTRAINT `workflow_transitions_ibfk_5` FOREIGN KEY (`guard_group_id`) REFERENCES `groups_lookup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  1664 + CONSTRAINT `workflow_transitions_ibfk_6` FOREIGN KEY (`guard_role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1537 1665 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1538 1666  
1539 1667 --
... ... @@ -1547,7 +1675,8 @@ CREATE TABLE `workflow_trigger_instances` (
1547 1675 `config_array` text,
1548 1676 PRIMARY KEY (`id`),
1549 1677 KEY `workflow_transition_id` (`workflow_transition_id`),
1550   - KEY `namespace` (`namespace`)
  1678 + KEY `namespace` (`namespace`),
  1679 + CONSTRAINT `workflow_trigger_instances_ibfk_1` FOREIGN KEY (`workflow_transition_id`) REFERENCES `workflow_transitions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1551 1680 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
1552 1681  
1553 1682 --
... ... @@ -1563,7 +1692,7 @@ CREATE TABLE `workflows` (
1563 1692 PRIMARY KEY (`id`),
1564 1693 UNIQUE KEY `name` (`name`),
1565 1694 KEY `start_state_id` (`start_state_id`),
1566   - CONSTRAINT `workflows_ibfk_1` FOREIGN KEY (`start_state_id`) REFERENCES `workflow_states` (`id`)
  1695 + CONSTRAINT `workflows_ibfk_1` FOREIGN KEY (`start_state_id`) REFERENCES `workflow_states` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1567 1696 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1568 1697  
1569 1698 --
... ... @@ -2094,7 +2223,9 @@ CREATE TABLE `zseq_plugin_rss` (
2094 2223 CREATE TABLE `zseq_plugins` (
2095 2224 `id` int(10) unsigned NOT NULL auto_increment,
2096 2225 PRIMARY KEY (`id`)
2097   -) ENGINE=MyISAM AUTO_INCREMENT=72 DEFAULT CHARSET=latin1;
  2226 +) ENGINE=MyISAM AUTO_INCREMENT=82 DEFAULT CHARSET=latin1;
  2227 +
  2228 +
2098 2229  
2099 2230 --
2100 2231 -- Table structure for table `zseq_role_allocations`
... ... @@ -2210,7 +2341,7 @@ CREATE TABLE `zseq_units_organisations_link` (
2210 2341 CREATE TABLE `zseq_upgrades` (
2211 2342 `id` int(10) unsigned NOT NULL auto_increment,
2212 2343 PRIMARY KEY (`id`)
2213   -) ENGINE=MyISAM AUTO_INCREMENT=146 DEFAULT CHARSET=latin1;
  2344 +) ENGINE=MyISAM AUTO_INCREMENT=150 DEFAULT CHARSET=latin1;
2214 2345  
2215 2346 --
2216 2347 -- Table structure for table `zseq_user_history`
... ... @@ -2302,4 +2433,4 @@ CREATE TABLE `zseq_workflows` (
2302 2433 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
2303 2434 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
2304 2435  
2305   --- Dump completed on 2007-09-25 21:55:41
  2436 +-- Dump completed on 2007-10-11 15:46:20
... ...
sql/mysql/upgrade/3.5.0/relation_friendly.sql
... ... @@ -3,8 +3,19 @@ alter table `folders` change `owner_id` `owner_id` int NULL;
3 3 alter table `index_files` change `document_id` `document_id` int NOT NULL;
4 4 alter table `index_files` change `user_id` `user_id` int NOT NULL;
5 5 alter table `type_workflow_map` change `workflow_id` `workflow_id` int NULL;
  6 +
6 7 alter table document_content_version change mime_id mime_id int null default 9;
  8 +
7 9 alter table documents change owner_id owner_id int null;
8   -alter table documents change parent_id parent_id int null;
  10 +alter table documents change creator_id creator_id int null;
  11 +alter table documents change modified_user_id modified_user_id int null;
  12 +
  13 +alter table document_transactions change document_id document_id int null;
  14 +alter table document_transactions change user_id user_id int null;
  15 +
  16 +alter table folder_transactions change folder_id folder_id int null;
  17 +alter table folder_transactions change user_id user_id int null;
  18 +
  19 +alter table folders change parent_id parent_id int null;
9 20 update documents set owner_id=null where owner_id=0;
10 21 update folders set parent_id=null where parent_id=0;
... ...