diff --git a/ktapi/KTAPIFolder.inc.php b/ktapi/KTAPIFolder.inc.php index a85423d..a118164 100644 --- a/ktapi/KTAPIFolder.inc.php +++ b/ktapi/KTAPIFolder.inc.php @@ -78,7 +78,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param int $folderid * @return KTAPI_Folder */ - function &get(&$ktapi, $folderid) + function get(&$ktapi, $folderid) { assert(!is_null($ktapi)); assert(is_a($ktapi, 'KTAPI')); @@ -157,14 +157,13 @@ class KTAPI_Folder extends KTAPI_FolderItem * @access protected * @return Folder */ - function &get_folder() + function get_folder() { return $this->folder; } - /** - * This returns detailed information on the document. + * This returns detailed information on the folder object. * * @author KnowledgeTree Team * @access public @@ -190,10 +189,47 @@ class KTAPI_Folder extends KTAPI_FolderItem unset($detail['linked_folder_id']); } + $folder = $this->folder; + + // get the creator + $userid = $folder->getCreatorID(); + $username='n/a'; + if (is_numeric($userid)) + { + $username = '* unknown *'; + $user = User::get($userid); + if (!is_null($user) && !PEAR::isError($user)) + { + $username = $user->getName(); + } + } + $detail['created_by'] = $username; + + // get the creation date + $detail['created_date'] = $folder->getCreatedDateTime(); + + // get the modified user + $userid = $folder->getModifiedUserId(); + $username='n/a'; + if (is_numeric($userid)) + { + $username = '* unknown *'; + $user = User::get($userid); + if (!is_null($user) && !PEAR::isError($user)) + { + $username = $user->getName(); + } + } + $detail['modified_by'] = $detail['updated_by'] = $username; + + // get the modified date + $detail['updated_date'] = $detail['modified_date'] = $folder->getLastModifiedDate(); + return $detail; } + /** - * This clears the global object cashe of the folder class. + * This clears the global object cache of the folder class. * * @author KnowledgeTree Team * @access public @@ -255,7 +291,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param int $folderid * @return KTAPI_Folder */ - function &_get_folder_by_name($ktapi, $foldername, $folderid) + function _get_folder_by_name($ktapi, $foldername, $folderid) { $foldername=trim($foldername); if (empty($foldername)) @@ -296,7 +332,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param string $foldername * @return KTAPI_Folder */ - function &get_folder_by_name($foldername) + function get_folder_by_name($foldername) { return KTAPI_Folder::_get_folder_by_name($this->ktapi, $foldername, $this->folderid); } @@ -325,7 +361,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param string $function * @return KTAPI_Document */ - function &_get_document_by_name($documentname, $function='getByNameAndFolder') + function _get_document_by_name($documentname, $function='getByNameAndFolder') { $documentname=trim($documentname); if (empty($documentname)) @@ -389,7 +425,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param string $documentname * @return KTAPI_Document */ - function &get_document_by_name($documentname) + function get_document_by_name($documentname) { return $this->_get_document_by_name($documentname,'getByNameAndFolder'); } @@ -402,7 +438,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param string $documentname * @return KTAPI_Document */ - function &get_document_by_filename($documentname) + function get_document_by_filename($documentname) { return $this->_get_document_by_name($documentname,'getByFilenameAndFolder'); } @@ -760,7 +796,6 @@ class KTAPI_Folder extends KTAPI_FolderItem } } - return $contents; } @@ -773,7 +808,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @return KTAPI_Document * */ - function &add_document_shortcut($document_id){ + function add_document_shortcut($document_id){ $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { @@ -806,7 +841,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param int $folder_id The ID of the folder to create a shortcut to * @return KTAPI_Folder */ - function &add_folder_shortcut($folder_id){ + function add_folder_shortcut($folder_id){ $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { @@ -849,7 +884,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param string $tempfilename This is a reference to the file that is accessible locally on the file system. * @return KTAPI_Document */ - function &add_document($title, $filename, $documenttype, $tempfilename) + function add_document($title, $filename, $documenttype, $tempfilename) { if (!is_file($tempfilename)) { @@ -924,7 +959,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param string $foldername * @return KTAPI_Folder */ - function &add_folder($foldername) + function add_folder($foldername) { $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_ADD_FOLDER); diff --git a/lib/foldermanagement/Folder.inc b/lib/foldermanagement/Folder.inc index 6fffd95..2a8e22f 100644 --- a/lib/foldermanagement/Folder.inc +++ b/lib/foldermanagement/Folder.inc @@ -53,6 +53,12 @@ class Folder extends KTEntity { var $iParentID; /** primary key of user who created folder */ var $iCreatorID; + /** The creation time of the folder */ + var $dCreated; + /** The user that last modified the folder */ + var $iModifiedUserID; + /** The time of the last modification to the folder */ + var $dModified; /** public status of folder */ var $bIsPublic = false; /** comma deliminated string of parent ids */ @@ -65,6 +71,8 @@ class Folder extends KTEntity { var $iPermissionLookupID; /** whether to restrict to only certain document types */ var $bRestrictDocumentTypes = false; + /** ID of folder owner */ + var $iOwnerID; /** ID of the folder this is a shortcut to(if any) */ var $iLinkedFolderId; @@ -75,6 +83,9 @@ class Folder extends KTEntity { 'sDescription' => 'description', 'iParentID' => 'parent_id', 'iCreatorID' => 'creator_id', + 'dCreated' => 'created', + 'iModifiedUserID' => 'modified_user_id', + 'dModified' => 'modified', 'bIsPublic' => 'is_public', 'sFullPath' => 'full_path', 'sParentFolderIDs' => 'parent_folder_ids', @@ -82,6 +93,7 @@ class Folder extends KTEntity { 'iPermissionLookupID' => 'permission_lookup_id', 'bRestrictDocumentTypes' => 'restrict_document_types', 'iLinkedFolderId' => 'linked_folder_id', + 'iOwnerID' => 'owner_id', ); // }}} @@ -94,6 +106,15 @@ class Folder extends KTEntity { function setParentID($iNewValue) { $this->iParentID = $iNewValue; } function getCreatorID() { return $this->iCreatorID; } function setCreatorID($iNewValue) { $this->iCreatorID = $iNewValue; } + + function getCreatedDateTime() { return $this->dCreated; } + function getModifiedUserID() { return $this->iModifiedUserID; } + function setModifiedUserID($iNewValue) { $this->iModifiedUserID = $iNewValue; } + function getLastModifiedDate() { return $this->dModified; } + function setLastModifiedDate($dNewValue) { $this->dModified = $dNewValue; } + function getOwnerID() { return $this->iOwnerID; } + function setOwnerID($iNewValue) { $this->iOwnerID = $iNewValue; } + function getIsPublic() { return $this->bIsPublic; } function setIsPublic($bNewValue) { $this->bIsPublic = $bNewValue; } function getFullPath() { return $this->sFullPath; } @@ -110,12 +131,24 @@ class Folder extends KTEntity { function getLinkedFolderId(){ return $this->iLinkedFolderId;} function setLinkedFolderId($iNewValue){ $this->iLinkedFolderId = $iNewValue;} - - // {{{ create() function create () { $oParentFolder =& Folder::get($this->iParentID); $this->iPermissionObjectID = $oParentFolder->getPermissionObjectID(); + + if (empty($this->dCreated)) { + $this->dCreated = getCurrentDateTime(); + } + if (empty($this->dModified)) { + $this->dModified = getCurrentDateTime(); + } + if (empty($this->iModifiedUserID)) { + $this->iModifiedUserID = $this->iCreatorID; + } + if (empty($this->iOwnerID)) { + $this->iOwnerID = $this->iCreatorID; + } + $res = parent::create(); if ($res === true) { KTPermissionUtil::updatePermissionLookup(Folder::get($this->getId())); @@ -144,7 +177,7 @@ class Folder extends KTEntity { /** * Returns a comma delimited string containing the parent folder ids, strips leading / * - * @return String comma delimited string containing the parent folder ids + * @return String comma delimited string containing the parent folder ids */ function generateFolderIDs($iFolderId) { if (empty($iFolderId)) { @@ -225,11 +258,15 @@ class Folder extends KTEntity { $this->sParentFolderIDs .= $this->iParentID; } return parent::_fieldValues(); + // NOTE below no longer needed? return array( 'name' => $this->sName, 'description' => $this->sDescription, 'parent_id' => $this->iParentID, 'creator_id' => $this->iCreatorID, + 'created' => $this->dCreated, + 'iModifiedUserId' => $this->iModifiedUserId, + 'modified' => $this->dModified, 'is_public' => KTUtil::anyToBool($this->bIsPublic), 'full_path' => $this->sFullPath, 'parent_folder_ids' => $this->sParentFolderIDs, @@ -428,7 +465,6 @@ class Folder extends KTEntity { function getFolderPathNamesAsArray($iFolderID) { global $default; - $oFolder = Folder::get($iFolderID); $aPathArray = array(); if ($oFolder) { @@ -534,7 +570,6 @@ class Folder extends KTEntity { $sQuery = "SELECT id, name FROM " . KTUtil::getTableName('folders') . " WHERE name = ? AND parent_id = ?";/*ok*/ $aParams = array($sName, $iParentID); $res = DBUtil::getResultArray(array($sQuery, $aParams)); - //var_dump($res); if (count($res) != 0) { // mysql is case-insensitive - check using php @@ -581,7 +616,6 @@ class Folder extends KTEntity { } } - function getByParentIDAndLookupID($iParentID, $iLookupID) { return KTEntityUtil::getByDict('Folder', array( 'parent_id' => $iParentID, diff --git a/lib/foldermanagement/folderutil.inc.php b/lib/foldermanagement/folderutil.inc.php index 438b4f3..57b3afb 100644 --- a/lib/foldermanagement/folderutil.inc.php +++ b/lib/foldermanagement/folderutil.inc.php @@ -58,12 +58,14 @@ class KTFolderUtil { return $oUser; } $oStorage =& KTStorageManagerUtil::getSingleton(); + $oFolder =& Folder::createFromArray(array( 'name' => ($sFolderName), 'description' => ($sFolderName), 'parentid' => $oParentFolder->getID(), 'creatorid' => $oUser->getID(), )); + if (PEAR::isError($oFolder)) { return $oFolder; } @@ -87,7 +89,6 @@ class KTFolderUtil { */ function add($oParentFolder, $sFolderName, $oUser, $bulk_action = false) { - $folderid=$oParentFolder->getId(); // check for conflicts first if (Folder::folderExistsName($sFolderName,$folderid)) { @@ -99,7 +100,6 @@ class KTFolderUtil { return $oFolder; } - $oTransaction = KTFolderTransaction::createFromArray(array( 'folderid' => $oFolder->getId(), 'comment' => _kt('Folder created'), @@ -289,6 +289,9 @@ class KTFolderUtil { $oFolder->setName($sNewName); $oFolder->setDescription($sNewName); + $oFolder->setLastModifiedDate(getCurrentDateTime()); + $oFolder->setModifiedUserId($oUser->getId()); + $res = $oFolder->update(); $oTransaction = KTFolderTransaction::createFromArray(array( @@ -614,7 +617,6 @@ class KTFolderUtil { // now we can go ahead. foreach ($aDocuments as $oDocument) { $oChildDestinationFolder = Folder::get($aFolderMap[$oDocument->getFolderID()]['parent_id']); - // var_dump($oDocument->getFolderID()); $res = KTDocumentUtil::copy($oDocument, $oChildDestinationFolder); if (PEAR::isError($res) || ($res === false)) { $oStorage->removeFolder($oNewBaseFolder); diff --git a/sql/mysql/install/structure.sql b/sql/mysql/install/structure.sql index 80e1d99..a85f90b 100644 --- a/sql/mysql/install/structure.sql +++ b/sql/mysql/install/structure.sql @@ -842,6 +842,9 @@ CREATE TABLE `folders` ( `description` varchar(255) default NULL, `parent_id` int(11) default NULL, `creator_id` int(11) default NULL, + `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , + `modified_user_id` INT( 11 ) NULL DEFAULT NULL , + `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' , `is_public` tinyint(1) NOT NULL default '0', `parent_folder_ids` mediumtext, `full_path` mediumtext, diff --git a/sql/mysql/upgrade/3.6.2/folders.sql b/sql/mysql/upgrade/3.6.2/folders.sql new file mode 100644 index 0000000..1c971c6 --- /dev/null +++ b/sql/mysql/upgrade/3.6.2/folders.sql @@ -0,0 +1,30 @@ +ALTER TABLE `folders` ADD `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `creator_id` , +ADD `modified_user_id` INT( 11 ) NULL DEFAULT NULL AFTER `created` , +ADD `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `modified_user_id` ; + +#The following lines are for inserting the data which should have been there if this table had always stored this data + +UPDATE folders f set f.created = + (SELECT datetime FROM folder_transactions ft + WHERE ft.transaction_namespace = 'ktcore.transactions.create' AND ft.folder_id = f.id AND ft.user_id = f.creator_id + ORDER BY datetime DESC LIMIT 1) ; + +#TODO check whether there are additional actions which should trigger a modified date/user change + +UPDATE folders f set f.modified = + (SELECT datetime FROM folder_transactions ft + WHERE (ft.transaction_namespace = 'ktcore.transactions.move' OR ft.transaction_namespace = 'ktcore.transactions.rename') + AND ft.folder_id = f.id + AND ft.datetime > f.created + ORDER BY datetime DESC LIMIT 1) ; + +UPDATE folders f set f.modified_user_id = + (SELECT user_id FROM folder_transactions ft + WHERE (ft.transaction_namespace = 'ktcore.transactions.move' OR ft.transaction_namespace = 'ktcore.transactions.rename') + AND ft.folder_id = f.id + AND ft.datetime > f.created + ORDER BY datetime DESC LIMIT 1) ; + +UPDATE folders f set f.modified = f.created WHERE f.modified IS NULL OR f.modified = '0000-00-00 00:00:00' ; + +UPDATE folders f set f.modified_user_id = f.creator_id WHERE f.modified_user_id IS NULL ; \ No newline at end of file