Commit 6000a5bd667b6ba424c93a29081aee70d3b5043d

Authored by bshuttle
1 parent fafd719b

- transactions are now keyed on the namespace, so they should survive activati…

…on/de-activation better.
  - upgrade script for this change.
  - updated all components in this tree to use the new style transaction
  - pass a document, _not_ an id.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4425 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/DocumentTransaction.inc
1 1 <?php
2 2  
3   -DEFINE("CREATE", 1);
4   -DEFINE("UPDATE", 2);
5   -DEFINE("DELETE", 3);
6   -DEFINE("RENAME", 4);
7   -DEFINE("MOVE", 5);
8   -DEFINE("DOWNLOAD", 6);
9   -DEFINE("CHECKIN", 7);
10   -DEFINE("CHECKOUT", 8);
11   -DEFINE("COLLAB_ROLLBACK",9);
12   -DEFINE("VIEW", 10);
13   -DEFINE("EXPUNGE", 11);
14   -DEFINE("FORCE_CHECKIN", 12);
15   -DEFINE("EMAIL_LINK", 13);
16   -DEFINE("COLLAB_ACCEPT", 14);
17   -DEFINE("EMAIL_ATTACH", 15);
18   -DEFINE("WORKFLOW_TRANSITION", 16);
19 3 /**
20 4 * $Id$
21 5 *
... ... @@ -46,23 +30,15 @@ DEFINE(&quot;WORKFLOW_TRANSITION&quot;, 16);
46 30 class DocumentTransaction {
47 31  
48 32 /** primary key of document transaction */
49   - var $iId;
50   - /** primary key of document on which transaction occured */
  33 + var $iId = -1;
51 34 var $iDocumentID;
52   - /** version of document on which transaction occurs */
53 35 var $sVersion;
54   - /** primary key of user who performed transaction */
55 36 var $iUserID;
56   - /** time of transaction */
57 37 var $dDateTime;
58   - /** IP address of computer that user was logged onto */
59 38 var $sIP;
60   - /** path to documet on file system on which transaction was performed */
61 39 var $sFilename;
62   - /** user comment associated with transaction */
63 40 var $sComment;
64   - /** primary key of transaction type */
65   - var $iTransactionID;
  41 + var $sTransactionNS;
66 42  
67 43 /**
68 44 * Constructor
... ... @@ -72,45 +48,33 @@ class DocumentTransaction {
72 48 * @param Primary key of transaction type
73 49 *
74 50 */
75   - function DocumentTransaction($iNewDocumentID, $sNewComment, $iNewTransactionID, $aOptions = null) {
  51 + function DocumentTransaction($oDocument, $sNewComment, $sTransactionNS, $aOptions = null) {
76 52 if (is_null($aOptions)) {
77 53 $aOptions = array();
78 54 }
79 55 //object not stored yet, id = -1
80 56 $this->iId = -1;
81   - $this->iDocumentID = $iNewDocumentID;
  57 +
  58 + $this->iDocumentID = $oDocument->getID();
82 59 $this->sComment = $sNewComment;
83   - $this->iTransactionID = $iNewTransactionID;
84   - $oDocument = & Document::get($iNewDocumentID);
85   - if ($oDocument) {
86   - $this->sVersion = $oDocument->getMajorVersionNumber() . "." . $oDocument->getMinorVersionNumber();
87   - $oFolder = Folder::get($oDocument->iFolderID);
88   - $this->sFileName = addslashes($oFolder->sFullPath . "/" . $oFolder->getName() . "/" . $oDocument->getName());
89   - }
  60 + $this->sTransactionNS = $sTransactionNS;
  61 + $this->sVersion = $oDocument->getMajorVersionNumber() . "." . $oDocument->getMinorVersionNumber();
  62 + $oFolder = Folder::get($oDocument->iFolderID);
  63 + $this->sFileName = addslashes($oFolder->sFullPath . "/" . $oFolder->getName() . "/" . $oDocument->getName());
  64 +
90 65 $this->iUserID = $_SESSION["userID"];
91 66 $oUser = KTUtil::arrayGet($aOptions, 'user');
92   - if ($oUser) {
  67 +
  68 + if (!(PEAR::isError($oUser) || ($oUser == false))) {
93 69 $this->iUserID = $oUser->getID();
94 70 }
95 71 $this->dDateTime = getCurrentDateTime();
96 72 $this->sIP = KTUtil::arrayGet($_SERVER, "REMOTE_ADDR", '0.0.0.0');
97 73 }
98 74  
99   - /**
100   - * Returns the current version
101   - */
102   - function getVersion() {
103   - return $this->sVersion;
104   - }
105   -
106   - function getComment() {
107   - return $this->sComment;
108   - }
109   -
110   - function _table() {
111   - global $default;
112   - return $default->document_transactions_table;
113   - }
  75 + function getVersion() { return $this->sVersion; }
  76 + function getComment() { return $this->sComment; }
  77 + function _table() { return KTUtil::getTableName('document_transactions'); }
114 78  
115 79 /**
116 80 * Create the document transaction in the database
... ... @@ -130,7 +94,7 @@ class DocumentTransaction {
130 94 'ip' => $this->sIP,
131 95 'filename' => $this->sFileName,
132 96 'comment' => $this->sComment,
133   - 'transaction_id' => $this->iTransactionID,
  97 + 'transaction_namespace' => $this->sTransactionNS,
134 98 );
135 99 $id =& DBUtil::autoInsert($this->_table(), $aFieldValues);
136 100  
... ... @@ -180,7 +144,7 @@ class DocumentTransaction {
180 144 $sql = $default->db;
181 145 $sql->query(array("SELECT * FROM $default->document_transactions_table WHERE id = ?", $iDocumentTransactionID));/*ok*/
182 146 if ($sql->next_record()) {
183   - $oDocumentTransaction = & new DocumentTransaction($sql->f("document_id"), $sql->f("comment"), $sql->f("transaction_id"));
  147 + $oDocumentTransaction = & new DocumentTransaction(Document::get($sql->f("document_id")), $sql->f("comment"), $sql->f("transaction_namespace"));
184 148 $oDocumentTransaction->iId = $sql->f("id");
185 149 $oDocumentTransaction->sVersion = $sql->f("version");
186 150 $oDocumentTransaction->iUserID = $sql->f("user_id");
... ...
lib/documentmanagement/DocumentTransactionType.inc.php
1 1 <?php
2 2  
3 3 require_once(KT_LIB_DIR . "/ktentity.inc");
  4 +require_once(KT_LIB_DIR . "/util/ktutil.inc");
4 5  
5 6 class KTDocumentTransactionType extends KTEntity {
6 7 /** primary key */
7 8 var $iId = -1;
8   - /** help file name */
9   - var $sName;
10   - /** help file name */
11 9 var $sName;
  10 + var $sNamespace;
12 11  
13 12 var $_aFieldToSelect = array(
14 13 "iId" => "id",
... ... @@ -26,30 +25,13 @@ class KTDocumentTransactionType extends KTEntity {
26 25 function setNamespace($sNamespace) { $this->sNamespace = $sNamespace; }
27 26  
28 27 function _table () {
29   - global $default;
30   - return $default->transaction_types_table;
31   - }
32   -
33   - // STATIC
34   - function &get($iId) {
35   - return KTEntityUtil::get('KTDocumentTransactionType', $iId);
36   - }
37   -
38   - // STATIC
39   - function &createFromArray($aOptions) {
40   - return KTEntityUtil::createFromArray('KTDocumentTransactionType', $aOptions);
41   - }
42   -
43   - // STATIC
44   - function &getList($sWhereClause = null) {
45   - global $default;
46   - return KTEntityUtil::getList($default->permissions_table, 'KTDocumentTransactionType', $sWhereClause);
  28 + return KTUtil::getTableName('transaction_types');
47 29 }
48 30  
49   - // STATIC
50   - function &getByNamespace($sNamespace) {
51   - return KTEntityUtil::getBy('KTDocumentTransactionType', 'namespace', $sNamespace);
52   - }
  31 + function &get($iId) { return KTEntityUtil::get('KTDocumentTransactionType', $iId); }
  32 + function &createFromArray($aOptions) { return KTEntityUtil::createFromArray('KTDocumentTransactionType', $aOptions); }
  33 + function &getList($sWhereClause = null) { return KTEntityUtil::getList2('KTDocumentTransactionType', $sWhereClause); }
  34 + function &getByNamespace($sNamespace) { return KTEntityUtil::getBy('KTDocumentTransactionType', 'namespace', $sNamespace); }
53 35 }
54 36  
55 37 ?>
... ...
lib/documentmanagement/documentutil.inc.php
... ... @@ -135,7 +135,7 @@ class KTDocumentUtil {
135 135 }
136 136  
137 137 // create the document transaction record
138   - $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $sCheckInComment, CHECKIN);
  138 + $oDocumentTransaction = & new DocumentTransaction($oDocument, $sCheckInComment, 'ktcore.transactions.check_in');
139 139 $oDocumentTransaction->create();
140 140  
141 141 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
... ... @@ -423,7 +423,7 @@ class KTDocumentUtil {
423 423 $oUploadChannel->sendMessage(new KTUploadGenericMessage(_("Creating transaction")));
424 424 $aOptions = array('user' => $oUser);
425 425 //create the document transaction record
426   - $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), "Document created", CREATE, $aOptions);
  426 + $oDocumentTransaction = & new DocumentTransaction($oDocument, "Document created", 'ktcore.transactions.create', $aOptions);
427 427 $res = $oDocumentTransaction->create();
428 428 if (PEAR::isError($res)) {
429 429 $oDocument->delete();
... ...
lib/workflow/workflowutil.inc.php
... ... @@ -392,7 +392,7 @@ class KTWorkflowUtil {
392 392 if ($sComments) {
393 393 $sTransactionComments .= "; Reason given was: " . $sComments;
394 394 }
395   - $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), $sTransactionComments, WORKFLOW_TRANSITION);
  395 + $oDocumentTransaction = & new DocumentTransaction($oDocument, $sTransactionComments, 'ktcore.transactions.workflow_state_transition');
396 396 $oDocumentTransaction->create();
397 397  
398 398 return true;
... ...
plugins/ktcore/KTDocumentActions.php
... ... @@ -23,7 +23,7 @@ class KTDocumentViewAction extends KTDocumentAction {
23 23  
24 24 function do_main() {
25 25 $oStorage =& KTStorageManagerUtil::getSingleton();
26   - $oDocumentTransaction = & new DocumentTransaction($this->oDocument->getId(), "Document downloaded", DOWNLOAD);
  26 + $oDocumentTransaction = & new DocumentTransaction($this->oDocument, "Document downloaded", 'ktcore.transactions.download');
27 27 $oDocumentTransaction->create();
28 28 $oStorage->download($this->oDocument);
29 29 exit(0);
... ... @@ -114,7 +114,7 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
114 114 }
115 115 }
116 116  
117   - $oDocumentTransaction = & new DocumentTransaction($this->oDocument->getID(), $sReason, CHECKOUT);
  117 + $oDocumentTransaction = & new DocumentTransaction($this->oDocument, $sReason, 'ktcore.transactions.check_out');
118 118 $oDocumentTransaction->create();
119 119  
120 120 $oStorage =& KTStorageManagerUtil::getSingleton();
... ... @@ -289,7 +289,7 @@ class KTDocumentDeleteAction extends KTDocumentAction {
289 289 exit(0);
290 290 }
291 291  
292   - $oDocumentTransaction = & new DocumentTransaction($this->oDocument->getId(), "Document deleted: " . $sReason, DELETE);
  292 + $oDocumentTransaction = & new DocumentTransaction($this->oDocument, "Document deleted: " . $sReason, 'ktcore.transactions.delete');
293 293 $oDocumentTransaction->create();
294 294  
295 295 $this->commitTransaction();
... ... @@ -478,7 +478,8 @@ class KTDocumentMoveAction extends KTDocumentAction {
478 478 $sReason);
479 479  
480 480 // create the document transaction record
481   - $oDocumentTransaction = & new DocumentTransaction($this->oDocument->getID(), $sMoveMessage, MOVE);
  481 +
  482 + $oDocumentTransaction = & new DocumentTransaction($this->oDocument, $sMoveMessage, 'ktcore.transactions.move');
482 483 $oDocumentTransaction->create();
483 484  
484 485 $this->commitTransaction();
... ...
plugins/ktcore/admin/deletedDocuments.php
... ... @@ -81,7 +81,7 @@ class DeletedDocumentsDispatcher extends KTAdminDispatcher {
81 81 foreach ($aDocuments as $oDoc) {
82 82 if (!PhysicalDocumentManager::expunge($oDoc)) { $aErrorDocuments[] = $oDoc->getDisplayPath(); }
83 83 else {
84   - $oDocumentTransaction = & new DocumentTransaction($oDoc->getId(), "Document expunged", EXPUNGE);
  84 + $oDocumentTransaction = & new DocumentTransaction($oDoc, "Document expunged", 'ktcore.transactions.expunge');
85 85 $oDocumentTransaction->create();
86 86  
87 87 // delete this from the db now
... ...
plugins/ktcore/admin/documentCheckout.php
... ... @@ -108,7 +108,7 @@ class KTCheckoutAdminDispatcher extends KTAdminDispatcher {
108 108 }
109 109  
110 110 // checkout cancelled transaction
111   - $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), "Document checked out cancelled", FORCE_CHECKIN);
  111 + $oDocumentTransaction = & new DocumentTransaction($oDocument, "Document checked out cancelled", 'ktcore.transactions.force_checkin');
112 112 if ($oDocumentTransaction->create()) {
113 113 $default->log->debug("editDocCheckoutBL.php created forced checkin document transaction for document ID=" . $oDocument->getID());
114 114 } else {
... ...
plugins/ktstandard/KTEmail.php
... ... @@ -6,6 +6,7 @@ require_once(KT_LIB_DIR . &quot;/email/Email.inc&quot;);
6 6 require_once(KT_LIB_DIR . "/users/User.inc");
7 7 require_once(KT_LIB_DIR . "/groups/Group.inc");
8 8 require_once(KT_LIB_DIR . "/documentmanagement/DocumentTransaction.inc");
  9 +require_once(KT_LIB_DIR . "/documentmanagement/Document.inc");
9 10  
10 11 /**
11 12 * Sends emails to the selected groups
... ... @@ -122,7 +123,7 @@ function sendEmailDocument($sDestEmailAddress, $sDestUserName, $iDocumentID, $sD
122 123 }
123 124  
124 125 // emailed link transaction
125   - $oDocumentTransaction = & new DocumentTransaction($iDocumentID, "Document link emailed to $sDestEmailAddress", EMAIL_ATTACH);
  126 + $oDocumentTransaction = & new DocumentTransaction($oDocument, "Document link emailed to " . $sDestEmailAddress, 'ktcore.transactions.email_attachment');
126 127 if ($oDocumentTransaction->create()) {
127 128 $default->log->debug("emailBL.php created email link document transaction for document ID=$iDocumentID");
128 129 } else {
... ... @@ -164,7 +165,10 @@ function sendEmailHyperlink($sDestEmailAddress, $sDestUserName, $iDocumentID, $s
164 165 }
165 166  
166 167 // emailed link transaction
167   - $oDocumentTransaction = & new DocumentTransaction($iDocumentID, "Document link emailed to $sDestEmailAddress", EMAIL_LINK);
  168 + // need a document to do this.
  169 + $oDocument =& Document::get($iDocumentID);
  170 +
  171 + $oDocumentTransaction = & new DocumentTransaction($oDocument, "Document link emailed to " . $sDestEmailAddress, 'ktcore.transactions.email_link');
168 172 if ($oDocumentTransaction->create()) {
169 173 $default->log->debug("emailBL.php created email link document transaction for document ID=$iDocumentID");
170 174 } else {
... ...
presentation/lookAndFeel/knowledgeTree/documentmanagement/editDocument.php
... ... @@ -257,7 +257,7 @@ class KTEditDocumentDispatcher extends KTStandardDispatcher {
257 257 $oDocument->setLastModifiedDate(getCurrentDateTime());
258 258 $oDocument->setModifiedUserId($this->oUser->getId());
259 259 $oDocument->setMetadataVersion($oDocument->getMetadataVersion() + 1);
260   - $oDocumentTransaction = & new DocumentTransaction($oDocument->getID(), 'update metadata.', UPDATE);
  260 + $oDocumentTransaction = & new DocumentTransaction($oDocument, 'update metadata.', 'ktcore.transactions.update');
261 261  
262 262 $res = $oDocumentTransaction->create();
263 263 if (PEAR::isError($res)) {
... ...
presentation/lookAndFeel/knowledgeTree/documentmanagement/view.php
... ... @@ -162,7 +162,7 @@ class ViewDocumentDispatcher extends KTStandardDispatcher {
162 162 // FIXME do we really need to use a raw db-access here? probably...
163 163 $sQuery = "SELECT DTT.name AS transaction_name, U.name AS user_name, DT.version AS version, DT.comment AS comment, DT.datetime AS datetime " .
164 164 "FROM " . KTUtil::getTableName("document_transactions") . " AS DT INNER JOIN " . KTUtil::getTableName("users") . " AS U ON DT.user_id = U.id " .
165   - "INNER JOIN " . KTUtil::getTableName("transaction_types") . " AS DTT ON DTT.id = DT.transaction_id " .
  165 + "INNER JOIN " . KTUtil::getTableName("transaction_types") . " AS DTT ON DTT.namespace = DT.transaction_namespace " .
166 166 "WHERE DT.document_id = ? ORDER BY DT.datetime DESC";
167 167 $aParams = array($document_id);
168 168 $res = DBUtil::getResultArray(array($sQuery, $aParams));
... ...
sql/mysql/install/structure.sql
... ... @@ -367,11 +367,10 @@ CREATE TABLE `document_transactions` (
367 367 `ip` char(30) default NULL,
368 368 `filename` char(255) NOT NULL default '',
369 369 `comment` char(255) NOT NULL default '',
370   - `transaction_id` int(11) default NULL,
  370 + `transaction_namespace` char(255) NOT NULL default 'ktcore.transactions.event',
371 371 UNIQUE KEY `id` (`id`),
372 372 KEY `fk_document_id` (`document_id`),
373 373 KEY `fk_user_id` (`user_id`),
374   - KEY `fk_transaction_id` (`transaction_id`)
375 374 ) ENGINE=InnoDB ;
376 375  
377 376 -- --------------------------------------------------------
... ...
sql/mysql/upgrade/2.99.5/transaction_namespaces.sql 0 → 100644
  1 +SET FOREIGN_KEY_CHECKS=0;
  2 +
  3 +ALTER TABLE `document_transactions` ADD `transaction_namespace` char(255) NOT NULL default 'ktcore.transactions.event';
  4 +
  5 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.create' WHERE `transaction_id` = 1;
  6 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.update' WHERE `transaction_id` = 2;
  7 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.delete' WHERE `transaction_id` = 3;
  8 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.rename' WHERE `transaction_id` = 4;
  9 +UPDATE `document_transactions` SET `transaction_namespace` = 'tcore.transactions.move' WHERE `transaction_id` = 5;
  10 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.download' WHERE `transaction_id` = 6;
  11 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.check_in' WHERE `transaction_id` = 7;
  12 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.check_out' WHERE `transaction_id` = 8;
  13 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.collaboration_step_rollback' WHERE `transaction_id` = 9;
  14 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.view' WHERE `transaction_id` = 10;
  15 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.expunge' WHERE `transaction_id` = 11;
  16 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.force_checkin' WHERE `transaction_id` = 12;
  17 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.email_link' WHERE `transaction_id` = 13;
  18 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.collaboration_step_approve' WHERE `transaction_id` = 14;
  19 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.email_attachment' WHERE `transaction_id` = 15;
  20 +UPDATE `document_transactions` SET `transaction_namespace` = 'ktcore.transactions.workflow_state_transition' WHERE `transaction_id` = 16;
  21 +
  22 +ALTER TABLE `document_transactions` DROP `transaction_id`;
  23 +
  24 +SET FOREIGN_KEY_CHECKS=1;
... ...