Commit 93601409ffc3250bbcac1a2f0a82100c58a827b8

Authored by Paul Barrett
1 parent ac7fc794

KTS-4308. Added support for time created, last modified user, last modified time, owner

For easier access to Create and Modify information for folders, Knowledgetree should save this information on the folders table

Fixed

Committed by: Paul Barrett

Reviewed by: Megan Watson
ktapi/KTAPIFolder.inc.php
@@ -78,7 +78,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -78,7 +78,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
78 * @param int $folderid 78 * @param int $folderid
79 * @return KTAPI_Folder 79 * @return KTAPI_Folder
80 */ 80 */
81 - function &get(&$ktapi, $folderid) 81 + function get(&$ktapi, $folderid)
82 { 82 {
83 assert(!is_null($ktapi)); 83 assert(!is_null($ktapi));
84 assert(is_a($ktapi, 'KTAPI')); 84 assert(is_a($ktapi, 'KTAPI'));
@@ -157,14 +157,13 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -157,14 +157,13 @@ class KTAPI_Folder extends KTAPI_FolderItem
157 * @access protected 157 * @access protected
158 * @return Folder 158 * @return Folder
159 */ 159 */
160 - function &get_folder() 160 + function get_folder()
161 { 161 {
162 return $this->folder; 162 return $this->folder;
163 } 163 }
164 164
165 -  
166 /** 165 /**
167 - * This returns detailed information on the document. 166 + * This returns detailed information on the folder object.
168 * 167 *
169 * @author KnowledgeTree Team 168 * @author KnowledgeTree Team
170 * @access public 169 * @access public
@@ -190,10 +189,47 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -190,10 +189,47 @@ class KTAPI_Folder extends KTAPI_FolderItem
190 unset($detail['linked_folder_id']); 189 unset($detail['linked_folder_id']);
191 } 190 }
192 191
  192 + $folder = $this->folder;
  193 +
  194 + // get the creator
  195 + $userid = $folder->getCreatorID();
  196 + $username='n/a';
  197 + if (is_numeric($userid))
  198 + {
  199 + $username = '* unknown *';
  200 + $user = User::get($userid);
  201 + if (!is_null($user) && !PEAR::isError($user))
  202 + {
  203 + $username = $user->getName();
  204 + }
  205 + }
  206 + $detail['created_by'] = $username;
  207 +
  208 + // get the creation date
  209 + $detail['created_date'] = $folder->getCreatedDateTime();
  210 +
  211 + // get the modified user
  212 + $userid = $folder->getModifiedUserId();
  213 + $username='n/a';
  214 + if (is_numeric($userid))
  215 + {
  216 + $username = '* unknown *';
  217 + $user = User::get($userid);
  218 + if (!is_null($user) && !PEAR::isError($user))
  219 + {
  220 + $username = $user->getName();
  221 + }
  222 + }
  223 + $detail['modified_by'] = $detail['updated_by'] = $username;
  224 +
  225 + // get the modified date
  226 + $detail['updated_date'] = $detail['modified_date'] = $folder->getLastModifiedDate();
  227 +
193 return $detail; 228 return $detail;
194 } 229 }
  230 +
195 /** 231 /**
196 - * This clears the global object cashe of the folder class. 232 + * This clears the global object cache of the folder class.
197 * 233 *
198 * @author KnowledgeTree Team 234 * @author KnowledgeTree Team
199 * @access public 235 * @access public
@@ -255,7 +291,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -255,7 +291,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
255 * @param int $folderid 291 * @param int $folderid
256 * @return KTAPI_Folder 292 * @return KTAPI_Folder
257 */ 293 */
258 - function &_get_folder_by_name($ktapi, $foldername, $folderid) 294 + function _get_folder_by_name($ktapi, $foldername, $folderid)
259 { 295 {
260 $foldername=trim($foldername); 296 $foldername=trim($foldername);
261 if (empty($foldername)) 297 if (empty($foldername))
@@ -296,7 +332,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -296,7 +332,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
296 * @param string $foldername 332 * @param string $foldername
297 * @return KTAPI_Folder 333 * @return KTAPI_Folder
298 */ 334 */
299 - function &get_folder_by_name($foldername) 335 + function get_folder_by_name($foldername)
300 { 336 {
301 return KTAPI_Folder::_get_folder_by_name($this->ktapi, $foldername, $this->folderid); 337 return KTAPI_Folder::_get_folder_by_name($this->ktapi, $foldername, $this->folderid);
302 } 338 }
@@ -325,7 +361,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -325,7 +361,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
325 * @param string $function 361 * @param string $function
326 * @return KTAPI_Document 362 * @return KTAPI_Document
327 */ 363 */
328 - function &_get_document_by_name($documentname, $function='getByNameAndFolder') 364 + function _get_document_by_name($documentname, $function='getByNameAndFolder')
329 { 365 {
330 $documentname=trim($documentname); 366 $documentname=trim($documentname);
331 if (empty($documentname)) 367 if (empty($documentname))
@@ -389,7 +425,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -389,7 +425,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
389 * @param string $documentname 425 * @param string $documentname
390 * @return KTAPI_Document 426 * @return KTAPI_Document
391 */ 427 */
392 - function &get_document_by_name($documentname) 428 + function get_document_by_name($documentname)
393 { 429 {
394 return $this->_get_document_by_name($documentname,'getByNameAndFolder'); 430 return $this->_get_document_by_name($documentname,'getByNameAndFolder');
395 } 431 }
@@ -402,7 +438,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -402,7 +438,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
402 * @param string $documentname 438 * @param string $documentname
403 * @return KTAPI_Document 439 * @return KTAPI_Document
404 */ 440 */
405 - function &get_document_by_filename($documentname) 441 + function get_document_by_filename($documentname)
406 { 442 {
407 return $this->_get_document_by_name($documentname,'getByFilenameAndFolder'); 443 return $this->_get_document_by_name($documentname,'getByFilenameAndFolder');
408 } 444 }
@@ -760,7 +796,6 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -760,7 +796,6 @@ class KTAPI_Folder extends KTAPI_FolderItem
760 } 796 }
761 } 797 }
762 798
763 -  
764 return $contents; 799 return $contents;
765 } 800 }
766 801
@@ -773,7 +808,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -773,7 +808,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
773 * @return KTAPI_Document 808 * @return KTAPI_Document
774 * 809 *
775 */ 810 */
776 - function &add_document_shortcut($document_id){ 811 + function add_document_shortcut($document_id){
777 $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE); 812 $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE);
778 if (PEAR::isError($user)) 813 if (PEAR::isError($user))
779 { 814 {
@@ -806,7 +841,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -806,7 +841,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
806 * @param int $folder_id The ID of the folder to create a shortcut to 841 * @param int $folder_id The ID of the folder to create a shortcut to
807 * @return KTAPI_Folder 842 * @return KTAPI_Folder
808 */ 843 */
809 - function &add_folder_shortcut($folder_id){ 844 + function add_folder_shortcut($folder_id){
810 $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE); 845 $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE);
811 if (PEAR::isError($user)) 846 if (PEAR::isError($user))
812 { 847 {
@@ -849,7 +884,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -849,7 +884,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
849 * @param string $tempfilename This is a reference to the file that is accessible locally on the file system. 884 * @param string $tempfilename This is a reference to the file that is accessible locally on the file system.
850 * @return KTAPI_Document 885 * @return KTAPI_Document
851 */ 886 */
852 - function &add_document($title, $filename, $documenttype, $tempfilename) 887 + function add_document($title, $filename, $documenttype, $tempfilename)
853 { 888 {
854 if (!is_file($tempfilename)) 889 if (!is_file($tempfilename))
855 { 890 {
@@ -924,7 +959,7 @@ class KTAPI_Folder extends KTAPI_FolderItem @@ -924,7 +959,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
924 * @param string $foldername 959 * @param string $foldername
925 * @return KTAPI_Folder 960 * @return KTAPI_Folder
926 */ 961 */
927 - function &add_folder($foldername) 962 + function add_folder($foldername)
928 { 963 {
929 $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_ADD_FOLDER); 964 $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_ADD_FOLDER);
930 965
lib/foldermanagement/Folder.inc
@@ -53,6 +53,12 @@ class Folder extends KTEntity { @@ -53,6 +53,12 @@ class Folder extends KTEntity {
53 var $iParentID; 53 var $iParentID;
54 /** primary key of user who created folder */ 54 /** primary key of user who created folder */
55 var $iCreatorID; 55 var $iCreatorID;
  56 + /** The creation time of the folder */
  57 + var $dCreated;
  58 + /** The user that last modified the folder */
  59 + var $iModifiedUserID;
  60 + /** The time of the last modification to the folder */
  61 + var $dModified;
56 /** public status of folder */ 62 /** public status of folder */
57 var $bIsPublic = false; 63 var $bIsPublic = false;
58 /** comma deliminated string of parent ids */ 64 /** comma deliminated string of parent ids */
@@ -65,6 +71,8 @@ class Folder extends KTEntity { @@ -65,6 +71,8 @@ class Folder extends KTEntity {
65 var $iPermissionLookupID; 71 var $iPermissionLookupID;
66 /** whether to restrict to only certain document types */ 72 /** whether to restrict to only certain document types */
67 var $bRestrictDocumentTypes = false; 73 var $bRestrictDocumentTypes = false;
  74 + /** ID of folder owner */
  75 + var $iOwnerID;
68 /** ID of the folder this is a shortcut to(if any) */ 76 /** ID of the folder this is a shortcut to(if any) */
69 var $iLinkedFolderId; 77 var $iLinkedFolderId;
70 78
@@ -75,6 +83,9 @@ class Folder extends KTEntity { @@ -75,6 +83,9 @@ class Folder extends KTEntity {
75 'sDescription' => 'description', 83 'sDescription' => 'description',
76 'iParentID' => 'parent_id', 84 'iParentID' => 'parent_id',
77 'iCreatorID' => 'creator_id', 85 'iCreatorID' => 'creator_id',
  86 + 'dCreated' => 'created',
  87 + 'iModifiedUserID' => 'modified_user_id',
  88 + 'dModified' => 'modified',
78 'bIsPublic' => 'is_public', 89 'bIsPublic' => 'is_public',
79 'sFullPath' => 'full_path', 90 'sFullPath' => 'full_path',
80 'sParentFolderIDs' => 'parent_folder_ids', 91 'sParentFolderIDs' => 'parent_folder_ids',
@@ -82,6 +93,7 @@ class Folder extends KTEntity { @@ -82,6 +93,7 @@ class Folder extends KTEntity {
82 'iPermissionLookupID' => 'permission_lookup_id', 93 'iPermissionLookupID' => 'permission_lookup_id',
83 'bRestrictDocumentTypes' => 'restrict_document_types', 94 'bRestrictDocumentTypes' => 'restrict_document_types',
84 'iLinkedFolderId' => 'linked_folder_id', 95 'iLinkedFolderId' => 'linked_folder_id',
  96 + 'iOwnerID' => 'owner_id',
85 ); 97 );
86 // }}} 98 // }}}
87 99
@@ -94,6 +106,15 @@ class Folder extends KTEntity { @@ -94,6 +106,15 @@ class Folder extends KTEntity {
94 function setParentID($iNewValue) { $this->iParentID = $iNewValue; } 106 function setParentID($iNewValue) { $this->iParentID = $iNewValue; }
95 function getCreatorID() { return $this->iCreatorID; } 107 function getCreatorID() { return $this->iCreatorID; }
96 function setCreatorID($iNewValue) { $this->iCreatorID = $iNewValue; } 108 function setCreatorID($iNewValue) { $this->iCreatorID = $iNewValue; }
  109 +
  110 + function getCreatedDateTime() { return $this->dCreated; }
  111 + function getModifiedUserID() { return $this->iModifiedUserID; }
  112 + function setModifiedUserID($iNewValue) { $this->iModifiedUserID = $iNewValue; }
  113 + function getLastModifiedDate() { return $this->dModified; }
  114 + function setLastModifiedDate($dNewValue) { $this->dModified = $dNewValue; }
  115 + function getOwnerID() { return $this->iOwnerID; }
  116 + function setOwnerID($iNewValue) { $this->iOwnerID = $iNewValue; }
  117 +
97 function getIsPublic() { return $this->bIsPublic; } 118 function getIsPublic() { return $this->bIsPublic; }
98 function setIsPublic($bNewValue) { $this->bIsPublic = $bNewValue; } 119 function setIsPublic($bNewValue) { $this->bIsPublic = $bNewValue; }
99 function getFullPath() { return $this->sFullPath; } 120 function getFullPath() { return $this->sFullPath; }
@@ -110,12 +131,24 @@ class Folder extends KTEntity { @@ -110,12 +131,24 @@ class Folder extends KTEntity {
110 function getLinkedFolderId(){ return $this->iLinkedFolderId;} 131 function getLinkedFolderId(){ return $this->iLinkedFolderId;}
111 function setLinkedFolderId($iNewValue){ $this->iLinkedFolderId = $iNewValue;} 132 function setLinkedFolderId($iNewValue){ $this->iLinkedFolderId = $iNewValue;}
112 133
113 -  
114 -  
115 // {{{ create() 134 // {{{ create()
116 function create () { 135 function create () {
117 $oParentFolder =& Folder::get($this->iParentID); 136 $oParentFolder =& Folder::get($this->iParentID);
118 $this->iPermissionObjectID = $oParentFolder->getPermissionObjectID(); 137 $this->iPermissionObjectID = $oParentFolder->getPermissionObjectID();
  138 +
  139 + if (empty($this->dCreated)) {
  140 + $this->dCreated = getCurrentDateTime();
  141 + }
  142 + if (empty($this->dModified)) {
  143 + $this->dModified = getCurrentDateTime();
  144 + }
  145 + if (empty($this->iModifiedUserID)) {
  146 + $this->iModifiedUserID = $this->iCreatorID;
  147 + }
  148 + if (empty($this->iOwnerID)) {
  149 + $this->iOwnerID = $this->iCreatorID;
  150 + }
  151 +
119 $res = parent::create(); 152 $res = parent::create();
120 if ($res === true) { 153 if ($res === true) {
121 KTPermissionUtil::updatePermissionLookup(Folder::get($this->getId())); 154 KTPermissionUtil::updatePermissionLookup(Folder::get($this->getId()));
@@ -144,7 +177,7 @@ class Folder extends KTEntity { @@ -144,7 +177,7 @@ class Folder extends KTEntity {
144 /** 177 /**
145 * Returns a comma delimited string containing the parent folder ids, strips leading / 178 * Returns a comma delimited string containing the parent folder ids, strips leading /
146 * 179 *
147 - * @return String comma delimited string containing the parent folder ids 180 + * @return String comma delimited string containing the parent folder ids
148 */ 181 */
149 function generateFolderIDs($iFolderId) { 182 function generateFolderIDs($iFolderId) {
150 if (empty($iFolderId)) { 183 if (empty($iFolderId)) {
@@ -225,11 +258,15 @@ class Folder extends KTEntity { @@ -225,11 +258,15 @@ class Folder extends KTEntity {
225 $this->sParentFolderIDs .= $this->iParentID; 258 $this->sParentFolderIDs .= $this->iParentID;
226 } 259 }
227 return parent::_fieldValues(); 260 return parent::_fieldValues();
  261 + // NOTE below no longer needed?
228 return array( 262 return array(
229 'name' => $this->sName, 263 'name' => $this->sName,
230 'description' => $this->sDescription, 264 'description' => $this->sDescription,
231 'parent_id' => $this->iParentID, 265 'parent_id' => $this->iParentID,
232 'creator_id' => $this->iCreatorID, 266 'creator_id' => $this->iCreatorID,
  267 + 'created' => $this->dCreated,
  268 + 'iModifiedUserId' => $this->iModifiedUserId,
  269 + 'modified' => $this->dModified,
233 'is_public' => KTUtil::anyToBool($this->bIsPublic), 270 'is_public' => KTUtil::anyToBool($this->bIsPublic),
234 'full_path' => $this->sFullPath, 271 'full_path' => $this->sFullPath,
235 'parent_folder_ids' => $this->sParentFolderIDs, 272 'parent_folder_ids' => $this->sParentFolderIDs,
@@ -428,7 +465,6 @@ class Folder extends KTEntity { @@ -428,7 +465,6 @@ class Folder extends KTEntity {
428 function getFolderPathNamesAsArray($iFolderID) { 465 function getFolderPathNamesAsArray($iFolderID) {
429 global $default; 466 global $default;
430 467
431 -  
432 $oFolder = Folder::get($iFolderID); 468 $oFolder = Folder::get($iFolderID);
433 $aPathArray = array(); 469 $aPathArray = array();
434 if ($oFolder) { 470 if ($oFolder) {
@@ -534,7 +570,6 @@ class Folder extends KTEntity { @@ -534,7 +570,6 @@ class Folder extends KTEntity {
534 $sQuery = "SELECT id, name FROM " . KTUtil::getTableName('folders') . " WHERE name = ? AND parent_id = ?";/*ok*/ 570 $sQuery = "SELECT id, name FROM " . KTUtil::getTableName('folders') . " WHERE name = ? AND parent_id = ?";/*ok*/
535 $aParams = array($sName, $iParentID); 571 $aParams = array($sName, $iParentID);
536 $res = DBUtil::getResultArray(array($sQuery, $aParams)); 572 $res = DBUtil::getResultArray(array($sQuery, $aParams));
537 - //var_dump($res);  
538 if (count($res) != 0) { 573 if (count($res) != 0) {
539 574
540 // mysql is case-insensitive - check using php 575 // mysql is case-insensitive - check using php
@@ -581,7 +616,6 @@ class Folder extends KTEntity { @@ -581,7 +616,6 @@ class Folder extends KTEntity {
581 } 616 }
582 } 617 }
583 618
584 -  
585 function getByParentIDAndLookupID($iParentID, $iLookupID) { 619 function getByParentIDAndLookupID($iParentID, $iLookupID) {
586 return KTEntityUtil::getByDict('Folder', array( 620 return KTEntityUtil::getByDict('Folder', array(
587 'parent_id' => $iParentID, 621 'parent_id' => $iParentID,
lib/foldermanagement/folderutil.inc.php
@@ -58,12 +58,14 @@ class KTFolderUtil { @@ -58,12 +58,14 @@ class KTFolderUtil {
58 return $oUser; 58 return $oUser;
59 } 59 }
60 $oStorage =& KTStorageManagerUtil::getSingleton(); 60 $oStorage =& KTStorageManagerUtil::getSingleton();
  61 +
61 $oFolder =& Folder::createFromArray(array( 62 $oFolder =& Folder::createFromArray(array(
62 'name' => ($sFolderName), 63 'name' => ($sFolderName),
63 'description' => ($sFolderName), 64 'description' => ($sFolderName),
64 'parentid' => $oParentFolder->getID(), 65 'parentid' => $oParentFolder->getID(),
65 'creatorid' => $oUser->getID(), 66 'creatorid' => $oUser->getID(),
66 )); 67 ));
  68 +
67 if (PEAR::isError($oFolder)) { 69 if (PEAR::isError($oFolder)) {
68 return $oFolder; 70 return $oFolder;
69 } 71 }
@@ -87,7 +89,6 @@ class KTFolderUtil { @@ -87,7 +89,6 @@ class KTFolderUtil {
87 */ 89 */
88 function add($oParentFolder, $sFolderName, $oUser, $bulk_action = false) { 90 function add($oParentFolder, $sFolderName, $oUser, $bulk_action = false) {
89 91
90 -  
91 $folderid=$oParentFolder->getId(); 92 $folderid=$oParentFolder->getId();
92 // check for conflicts first 93 // check for conflicts first
93 if (Folder::folderExistsName($sFolderName,$folderid)) { 94 if (Folder::folderExistsName($sFolderName,$folderid)) {
@@ -99,7 +100,6 @@ class KTFolderUtil { @@ -99,7 +100,6 @@ class KTFolderUtil {
99 return $oFolder; 100 return $oFolder;
100 } 101 }
101 102
102 -  
103 $oTransaction = KTFolderTransaction::createFromArray(array( 103 $oTransaction = KTFolderTransaction::createFromArray(array(
104 'folderid' => $oFolder->getId(), 104 'folderid' => $oFolder->getId(),
105 'comment' => _kt('Folder created'), 105 'comment' => _kt('Folder created'),
@@ -289,6 +289,9 @@ class KTFolderUtil { @@ -289,6 +289,9 @@ class KTFolderUtil {
289 289
290 $oFolder->setName($sNewName); 290 $oFolder->setName($sNewName);
291 $oFolder->setDescription($sNewName); 291 $oFolder->setDescription($sNewName);
  292 + $oFolder->setLastModifiedDate(getCurrentDateTime());
  293 + $oFolder->setModifiedUserId($oUser->getId());
  294 +
292 $res = $oFolder->update(); 295 $res = $oFolder->update();
293 296
294 $oTransaction = KTFolderTransaction::createFromArray(array( 297 $oTransaction = KTFolderTransaction::createFromArray(array(
@@ -614,7 +617,6 @@ class KTFolderUtil { @@ -614,7 +617,6 @@ class KTFolderUtil {
614 // now we can go ahead. 617 // now we can go ahead.
615 foreach ($aDocuments as $oDocument) { 618 foreach ($aDocuments as $oDocument) {
616 $oChildDestinationFolder = Folder::get($aFolderMap[$oDocument->getFolderID()]['parent_id']); 619 $oChildDestinationFolder = Folder::get($aFolderMap[$oDocument->getFolderID()]['parent_id']);
617 - // var_dump($oDocument->getFolderID());  
618 $res = KTDocumentUtil::copy($oDocument, $oChildDestinationFolder); 620 $res = KTDocumentUtil::copy($oDocument, $oChildDestinationFolder);
619 if (PEAR::isError($res) || ($res === false)) { 621 if (PEAR::isError($res) || ($res === false)) {
620 $oStorage->removeFolder($oNewBaseFolder); 622 $oStorage->removeFolder($oNewBaseFolder);
sql/mysql/install/structure.sql
@@ -842,6 +842,9 @@ CREATE TABLE `folders` ( @@ -842,6 +842,9 @@ CREATE TABLE `folders` (
842 `description` varchar(255) default NULL, 842 `description` varchar(255) default NULL,
843 `parent_id` int(11) default NULL, 843 `parent_id` int(11) default NULL,
844 `creator_id` int(11) default NULL, 844 `creator_id` int(11) default NULL,
  845 + `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' ,
  846 + `modified_user_id` INT( 11 ) NULL DEFAULT NULL ,
  847 + `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' ,
845 `is_public` tinyint(1) NOT NULL default '0', 848 `is_public` tinyint(1) NOT NULL default '0',
846 `parent_folder_ids` mediumtext, 849 `parent_folder_ids` mediumtext,
847 `full_path` mediumtext, 850 `full_path` mediumtext,
sql/mysql/upgrade/3.6.2/folders.sql 0 → 100644
  1 +ALTER TABLE `folders` ADD `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `creator_id` ,
  2 +ADD `modified_user_id` INT( 11 ) NULL DEFAULT NULL AFTER `created` ,
  3 +ADD `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `modified_user_id` ;
  4 +
  5 +#The following lines are for inserting the data which should have been there if this table had always stored this data
  6 +
  7 +UPDATE folders f set f.created =
  8 + (SELECT datetime FROM folder_transactions ft
  9 + WHERE ft.transaction_namespace = 'ktcore.transactions.create' AND ft.folder_id = f.id AND ft.user_id = f.creator_id
  10 + ORDER BY datetime DESC LIMIT 1) ;
  11 +
  12 +#TODO check whether there are additional actions which should trigger a modified date/user change
  13 +
  14 +UPDATE folders f set f.modified =
  15 + (SELECT datetime FROM folder_transactions ft
  16 + WHERE (ft.transaction_namespace = 'ktcore.transactions.move' OR ft.transaction_namespace = 'ktcore.transactions.rename')
  17 + AND ft.folder_id = f.id
  18 + AND ft.datetime > f.created
  19 + ORDER BY datetime DESC LIMIT 1) ;
  20 +
  21 +UPDATE folders f set f.modified_user_id =
  22 + (SELECT user_id FROM folder_transactions ft
  23 + WHERE (ft.transaction_namespace = 'ktcore.transactions.move' OR ft.transaction_namespace = 'ktcore.transactions.rename')
  24 + AND ft.folder_id = f.id
  25 + AND ft.datetime > f.created
  26 + ORDER BY datetime DESC LIMIT 1) ;
  27 +
  28 +UPDATE folders f set f.modified = f.created WHERE f.modified IS NULL OR f.modified = '0000-00-00 00:00:00' ;
  29 +
  30 +UPDATE folders f set f.modified_user_id = f.creator_id WHERE f.modified_user_id IS NULL ;
0 \ No newline at end of file 31 \ No newline at end of file