diff --git a/.htaccess b/.htaccess
index 9f88ff4..240960a 100644
--- a/.htaccess
+++ b/.htaccess
@@ -48,11 +48,11 @@ Options none
# malicious users to use up resources.
#
' . print_r($field_values, true) . '
';
$this->startTransaction();
- $res = KTDocumentUtil::createMetadataVersion($oDocument);
+ $oDocument->startNewMetadataVersion();
if (PEAR::isError($res)) {
$this->errorRedirectToMain('Unable to create a metadata version of the document.');
}
@@ -265,7 +265,6 @@ class KTEditDocumentDispatcher extends KTStandardDispatcher {
$oDocument->setName($title);
$oDocument->setLastModifiedDate(getCurrentDateTime());
$oDocument->setModifiedUserId($this->oUser->getId());
- $oDocument->setMetadataVersion($oDocument->getMetadataVersion() + 1);
$oDocumentTransaction = & new DocumentTransaction($oDocument, 'update metadata.', 'ktcore.transactions.update');
$res = $oDocumentTransaction->create();
@@ -280,6 +279,8 @@ class KTEditDocumentDispatcher extends KTStandardDispatcher {
$res = KTDocumentUtil::saveMetadata($oDocument, $field_values);
if (PEAR::isError($res)) {
+ var_dump($res);
+ exit(0);
$this->rollbackTransaction();
// right. we're rolled out. now we want to regenerate the page, + errors.
diff --git a/lib/browse/DocumentCollection.inc.php b/lib/browse/DocumentCollection.inc.php
index bceeb50..ad161df 100644
--- a/lib/browse/DocumentCollection.inc.php
+++ b/lib/browse/DocumentCollection.inc.php
@@ -57,7 +57,7 @@ class DocumentCollection {
// FIXME affect the column based on this.
// defaults
- $this->_sDocumentSortField = "D.name";
+ $this->_sDocumentSortField = "DM.name";
$this->_sFolderSortField = "F.name";
// then we start.
@@ -145,9 +145,7 @@ class DocumentCollection {
$this->activeset = array(
"folders" => $folderSet,
"documents" => $documentSet,
- );
-
-
+ );
}
// stub: fetch all relevant information about a document (that will reasonably be fetched).
diff --git a/lib/browse/PartialQuery.inc.php b/lib/browse/PartialQuery.inc.php
index a1ee65f..bfa6995 100644
--- a/lib/browse/PartialQuery.inc.php
+++ b/lib/browse/PartialQuery.inc.php
@@ -11,6 +11,7 @@
require_once(KT_LIB_DIR . "/util/ktutil.inc");
require_once(KT_LIB_DIR . "/database/dbutil.inc");
+require_once(KT_LIB_DIR . "/search/searchutil.inc.php");
// Abstract base class.
class PartialQuery {
@@ -80,7 +81,14 @@ class BrowseQuery extends PartialQuery{
$sSelect = KTUtil::arrayGet($aOptions, 'select', 'D.id');
- $sQuery = "SELECT $sSelect FROM " . KTUtil::getTableName("documents") . " AS D $sPermissionJoin $sWhere ";
+ $sQuery = sprintf("SELECT %s FROM %s AS D
+ LEFT JOIN %s AS DM ON D.metadata_version_id = DM.id
+ LEFT JOIN %s AS DC ON DM.content_version_id = DC.id
+ %s %s",
+ $sSelect, KTUtil::getTableName("documents"),
+ KTUtil::getTableName("document_metadata_version"),
+ KTUtil::getTableName("document_content_version"),
+ $sPermissionJoin, $sWhere);
$aParams = array();
$aParams = array_merge($aParams, $aPermissionParams);
$aParams[] = $this->folder_id;
diff --git a/lib/database/dbutil.inc b/lib/database/dbutil.inc
index 12573ad..9cddbef 100644
--- a/lib/database/dbutil.inc
+++ b/lib/database/dbutil.inc
@@ -50,7 +50,9 @@ class DBUtil {
$sQuery = $query;
}
$res = $db->query($sQuery, $aParams);
- $default->queryLog->debug('Query: ' . DBUtil::lastQuery($db));
+ if ($default->queryLog) {
+ $default->queryLog->debug('Query: ' . DBUtil::lastQuery($db));
+ }
return $res;
}
diff --git a/lib/documentmanagement/Document.inc b/lib/documentmanagement/Document.inc
index 038f568..98a4569 100644
--- a/lib/documentmanagement/Document.inc
+++ b/lib/documentmanagement/Document.inc
@@ -19,190 +19,98 @@ DEFINE("STATUS_VERSION", 6);
require_once(KT_LIB_DIR . "/foldermanagement/Folder.inc");
-class Document extends KTEntity {
- var $_bUsePearError = true;
-
- // {{{ attributes
- /** primary key */
+require_once(KT_LIB_DIR . '/documentmanagement/documentcontentversion.inc.php');
+require_once(KT_LIB_DIR . '/documentmanagement/documentcore.inc.php');
+require_once(KT_LIB_DIR . '/documentmanagement/documentmetadataversion.inc.php');
+
+class Document {
var $iId;
- /** document type primary key */
- var $iDocumentTypeID;
-
- /** document name */
- var $sName;
-
- /** document file name (path to document on file system) */
- var $sFileName;
-
- /** document file size */
- var $iSize;
-
- /** primary key of user who created document */
- var $iCreatorID;
-
- /** date the document was last modified */
- var $dModified;
-
- /** file description */
- var $sDescription;
-
- /** primary key of file mime type */
- var $iMimeTypeID;
+ var $_oDocumentCore = null;
+ var $_oDocumentContentVersion = null;
+ var $_oDocumentMetadataVersion = null;
+
- /** primary key of folder under which document is stored */
- var $iFolderID;
+ // {{{ getters/setters
- /** major revision number */
- var $iMajorVersion;
+ // locally stored info.
- /** minor revision number */
- var $iMinorVersion;
-
- /** document checked out status */
- var $bIsCheckedOut;
- //?? make checked out a status?
-
- /** document status **/
- var $iStatusID;
-
- /** the user that currently has the document checked out */
- var $iCheckedOutUserID;
-
- /** comma delimited string of folder hierarch this document falls under */
- var $sParentFolderIDs;
-
- /** forward slash deliminated path from repository root */
- var $sFullPath;
-
- /** date the document was created */
- var $dCreated;
-
- /** object which controls (read/write) permissions on this document */
- var $iPermissionObjectID;
-
- /** object which has quick lookups (read-only) on permissions on this document */
- var $iPermissionLookupID;
+ function getId() { return $this->iId; }
+
+ // Document Core
+
+ function getFolderID() { return $this->_oDocumentCore->getFolderId(); }
+ function setFolderID($iNewValue) { $this->_oDocumentCore->setFolderId($iNewValue); }
+
+ function getCreatorID() { return $this->_oDocumentCore->getCreatorId(); }
+ function setCreatorID($iNewValue) { $this->_oDocumentCore->setCreatorId($iNewValue); }
+
+ function getLastModifiedDate() { return $this->_oDocumentCore->getLastModifiedDate(); }
+ function setLastModifiedDate($dNewValue) { $this->_oDocumentCore->setLastModifiedDate($dNewValue); }
+
+ function getCreatedDateTime() { return $this->_oDocumentCore->getCreatedDateTime(); }
+
+ function getIsCheckedOut() { return $this->_oDocumentCore->getIsCheckedOut(); }
+ function setIsCheckedOut($bNewValue) { $this->_oDocumentCore->setIsCheckedOut(KTUtil::anyToBool($bNewValue)); }
+
+ function getCheckedOutUserID() { return $this->_oDocumentCore->getCheckedOutUserId(); }
+ function setCheckedOutUserID($iNewValue) { $this->_oDocumentCore->setCheckedOutUserId($iNewValue); }
+
+ function getPermissionObjectID() { return $this->_oDocumentCore->getPermissionObjectId(); }
+ function setPermissionObjectID($iNewValue) { $this->_oDocumentCore->setPermissionObjectId($iNewValue); }
+
+ function getPermissionLookupID() { return $this->_oDocumentCore->getPermissionLookupId(); }
+ function setPermissionLookupID($iNewValue) { $this->_oDocumentCore->setPermissionLookupId($iNewValue); }
+
+ function getModifiedUserId() { return $this->_oDocumentCore->getModifiedUserId(); }
+ function setModifiedUserId($iNewValue) { $this->_oDocumentCore->setModifiedUserId($iNewValue); }
+
+ // Document Metadata Items
+
+ function getDocumentTypeID() { return $this->_oDocumentMetadataVersion->getDocumentTypeId(); }
+ function setDocumentTypeID($sNewValue) { $this->_oDocumentMetadataVersion->setDocumentTypeId($sNewValue); }
+
+ function getName() { return $this->_oDocumentMetadataVersion->getName(); }
+ function setName($sNewValue) { $this->_oDocumentMetadataVersion->setName($sNewValue); }
- /** if this is a historic version, a pointer to the live document */
- var $iLiveDocumentID = null;
+ function getDescription() { return $this->_oDocumentMetadataVersion->getDescription(); }
+ function setDescription($sNewValue) { $this->_oDocumentMetadataVersion->setDescription($sNewValue); }
+
+ function getStatusID() { return $this->_oDocumentCore->getStatusId(); }
+ function setStatusID($iNewValue) { $this->_oDocumentMetadataVersion->setStatusId($iNewValue); $this->_oDocumentCore->setStatusId($iNewValue); }
+
+ function getMetadataVersion() { return $this->_oDocumentMetadataVersion->getMetadataVersion(); }
+ function setMetadataVersion($iNewValue) { $this->_oDocumentMetadataVersion->getMetadataVersion($iNewValue); }
- /** metadata revision number */
- var $iMetadataVersion;
+ function getMetadataVersionId() { return $this->_oDocumentCore->getMetadataVersionId(); }
+ function setMetadataVersionId($iNewValue) { $this->_oDocumentCore->setMetadataVersionId($iNewValue); }
- /** storage path to the file from the repository root */
- var $sStoragePath;
-
- // }}}
+ function getContentVersionId() { return $this->_oDocumentMetadataVersion->getContentVersionId(); }
+ function setContentVersionId($iNewValue) { $this->_oDocumentMetadataVersion->setContentVersionId($iNewValue); }
- // {{{ KTEntity stuff
- var $_aFieldToSelect = array(
- "iId" => "id",
- "iDocumentTypeID" => 'document_type_id',
- "sName" => 'name',
- "sFileName" => 'filename',
- "iSize" => 'size',
- "iCreatorID" => 'creator_id',
- "dModified" => 'modified',
- "sDescription" => 'description',
- "iMimeTypeID" => 'mime_id',
- "iFolderID" => 'folder_id',
- "iMajorVersion" => 'major_version',
- "iMinorVersion" => 'minor_version',
- "bIsCheckedOut" => 'is_checked_out',
- "iCheckedOutUserID" => 'checked_out_user_id',
- "sParentFolderIDs" => 'parent_folder_ids',
- "sFullPath" => 'full_path',
- "iStatusID" => 'status_id',
- "dCreated" => 'created',
- "iPermissionObjectID" => 'permission_object_id',
- "iPermissionLookupID" => 'permission_lookup_id',
- "iLiveDocumentID" => 'live_document_id',
- "iMetadataVersion" => 'metadata_version',
- "sStoragePath" => 'storage_path',
- "iModifiedUserId" => 'modified_user_id',
- );
- // }}}
-
- // {{{ constructor
- /**
- * Document class constructor
- *
- * @param $sName File Name
- * @param $iSize File size in bytes
- * @param $iCreatorID Primary key of user who created document
- * @param $sDescription Description
- * @param $iMimeID Primary key of file mime type
- * @param $iFolderID Primary key of folder to which document belongs
- *
- */
- function Document($sNewName = null, $sNewFileName = null, $iNewSize = null, $iNewCreatorID = null, $iNewMimeID = null, $iNewFolderID = null, $sNewDescription = "None") {
- $this->iId = -1; //primary key not set as document is not stored yet
- $this->sName = $sNewName;
- $this->iSize = $iNewSize;
- $this->iCreatorID = $iNewCreatorID;
- $this->sFileName = $sNewFileName;
- $this->sDescription = $sNewDescription;
- $this->iMimeTypeID = $iNewMimeID;
- $this->iFolderID = $iNewFolderID;
- if (!empty($this->iFolderID)) {
- $this->iDocumentTypeID = Folder::getDefaultFolderDocumentType($this->iFolderID);
- }
- $this->iMajorVersion = 0;
- $this->iMetadataVersion = 0;
- $this->iMinorVersion = 1;
- $this->bIsCheckedOut = false;
- $this->iCheckedOutUserID = -1;
- // FIXME: statuses
- $this->iStatusID = LIVE;
- }
- // }}}
+ // Document Content Version
+
+ function getFileName() { return $this->_oDocumentContentVersion->getFileName(); }
+ function setFileName($sNewValue) { $this->_oDocumentContentVersion->setFileName($sNewValue); }
+
+ function getFileSize() { return $this->_oDocumentContentVersion->getSize(); }
+ function setFileSize($iNewValue) { $this->_oDocumentContentVersion->setSize($iNewValue); }
+
+ function getSize() { return $this->_oDocumentContentVersion->getSize(); }
+ function setSize($iNewValue) { $this->_oDocumentContentVersion->setSize($iNewValue); }
+
+ function getMimeTypeID() { return $this->_oDocumentContentVersion->getMimeTypeId(); }
+ function setMimeTypeID($iNewValue) { $this->_oDocumentContentVersion->setMimeTypeId($iNewValue); }
+
+ function getMajorVersionNumber() { return $this->_oDocumentContentVersion->getMajorVersionNumber(); }
+ function setMajorVersionNumber($iNewValue) { $this->_oDocumentContentVersion->setMajorVersionNumber($iNewValue); }
+
+ function getMinorVersionNumber() { return $this->_oDocumentContentVersion->getMinorVersionNumber(); }
+ function setMinorVersionNumber($iNewValue) { $this->_oDocumentContentVersion->setMinorVersionNumber($iNewValue); }
- // {{{ getters/setters
- function getID() { return $this->iId; }
- function getDocumentTypeID() { return $this->iDocumentTypeID; }
- function setDocumentTypeID($sNewValue) { $this->iDocumentTypeID = $sNewValue; }
- function getName() { return $this->sName; }
- function setName($sNewValue) { $this->sName = $sNewValue; }
- function getFileName() { return $this->sFileName; }
- function setFileName($sNewValue) { $this->sFileName = $sNewValue; }
- function getFolderID() { return $this->iFolderID; }
- function setFolderID($iNewValue) { $this->iFolderID = $iNewValue; }
- function getFileSize() { return $this->iSize; }
- function setFileSize($iNewValue) { $this->iSize = $iNewValue; }
- function getSize() { return $this->iSize; }
- function setSize($iNewValue) { $this->iSize = $iNewValue; }
- function getCreatorID() { return $this->iCreatorID; }
- function setCreatorID($iNewValue) { $this->iCreatorID = $iNewValue; }
- function getLastModifiedDate() { return $this->dModified; }
- function setLastModifiedDate($dNewValue) { $this->dModified = $dNewValue; }
- function getCreatedDateTime() { return $this->dCreated; }
- function getDescription() { return $this->sDescription; }
- function setDescription($sNewValue) { $this->sDescription = $sNewValue; }
- function getMimeTypeID() { return $this->iMimeTypeID; }
- function setMimeTypeID($iNewValue) { $this->iMimeTypeID = $iNewValue; }
- function getMajorVersionNumber() { return $this->iMajorVersion; }
- function setMajorVersionNumber($iNewValue) { $this->iMajorVersion = $iNewValue; }
- function getMinorVersionNumber() { return $this->iMinorVersion; }
- function setMinorVersionNumber($iNewValue) { $this->iMinorVersion = $iNewValue; }
- function getIsCheckedOut() { return $this->bIsCheckedOut; }
- function setIsCheckedOut($bNewValue) { $this->bIsCheckedOut = KTUtil::anyToBool($bNewValue); }
- function getCheckedOutUserID() { return $this->iCheckedOutUserID; }
- function setCheckedOutUserID($iNewValue) { $this->iCheckedOutUserID = $iNewValue; }
- function getStatusID() { return $this->iStatusID; }
- function setStatusID($iNewValue) { $this->iStatusID = $iNewValue; }
- function getPermissionObjectID() { return $this->iPermissionObjectID; }
- function setPermissionObjectID($iNewValue) { $this->iPermissionObjectID = $iNewValue; }
- function getPermissionLookupID() { return $this->iPermissionLookupID; }
- function setPermissionLookupID($iNewValue) { $this->iPermissionLookupID = $iNewValue; }
- function getLiveDocumentID() { return $this->iLiveDocumentID; }
- function setLiveDocumentID($iNewValue) { $this->iLiveDocumentID = $iNewValue; }
- function getMetadataVersion() { return $this->iMetadataVersion; }
- function setMetadataVersion($iNewValue) { $this->iMetadataVersion = $iNewValue; }
- function getStoragePath() { return $this->sStoragePath; }
- function setStoragePath($sNewValue) { $this->sStoragePath = $sNewValue; }
- function getModifiedUserId() { return $this->iModifiedUserId; }
- function setModifiedUserId($iNewValue) { $this->iModifiedUserId = $iNewValue; }
+ function getStoragePath() { return $this->_oDocumentContentVersion->getStoragePath(); }
+ function setStoragePath($sNewValue) { $this->_oDocumentContentVersion->setStoragePath($sNewValue); }
+
// }}}
// {{{ getParentID
@@ -218,7 +126,7 @@ class Document extends KTEntity {
// {{{ getVersion
/** returns the complete version number as a string */
function getVersion() {
- return $this->iMajorVersion . "." . $this->iMinorVersion;
+ return $this->getMajorVersion() . "." . $this->getMinorVersion();
}
// }}}
@@ -236,164 +144,69 @@ class Document extends KTEntity {
}
// }}}
- // {{{ ktentity requirements
- function _fieldValues () {
- $this->sFullPath = Document::_generateFolderPath($this->iFolderID);
- $this->sParentFolderIDs = Document::_generateFolderIDs($this->iFolderID);
- return array(
- 'document_type_id' => $this->iDocumentTypeID,
- 'name' => $this->sName,
- 'filename' => $this->sFileName,
- 'size' => $this->iSize,
- 'creator_id' => $this->iCreatorID,
- 'modified' => $this->dModified,
- 'description' => $this->sDescription,
- 'mime_id' => $this->iMimeTypeID,
- 'folder_id' => $this->iFolderID,
- 'major_version' => $this->iMajorVersion,
- 'minor_version' => $this->iMinorVersion,
- 'is_checked_out' => KTUtil::anyToBool($this->bIsCheckedOut),
- 'checked_out_user_id' => $this->iCheckedOutUserID,
- 'parent_folder_ids' => $this->sParentFolderIDs,
- 'full_path' => $this->sFullPath,
- 'status_id' => $this->iStatusID,
- 'created' => $this->dCreated,
- 'permission_object_id' => $this->iPermissionObjectID,
- 'permission_lookup_id' => $this->iPermissionLookupID,
- 'live_document_id' => $this->iLiveDocumentID,
- 'metadata_version' => $this->iMetadataVersion,
- 'storage_path' => $this->sStoragePath,
- 'modified_user_id' => $this->iModifiedUserId,
- );
- }
-
- function _table () {
- global $default;
- return $default->documents_table;
- }
-
- /**
- * Recursive function to generate a comma delimited string containing
- * the parent folder ids
- *
- * @return String comma delimited string containing the parent folder ids
- */
- function _generateParentFolderIDS($iFolderID) {
- global $default;
- //if the folder is not the root folder
- if ($iFolderID != 0) {
- $sql = $default->db;
- $sql->query(array("SELECT parent_id FROM $default->folders_table WHERE ID = ?", $iFolderID));/*ok*/
- $sql->next_record();
- return Document::_generateParentFolderIDS($sql->f("parent_id")) . ",$iFolderID";
- }
- return;
- }
- /**
- * Returns a comma delimited string containing the parent folder ids, strips leading /
- *
- * @return String comma delimited string containing the parent folder ids
- */
- function _generateFolderIDs($iFolderID) {
- $sFolderIDs = Document::_generateParentFolderIDS($iFolderID);
- return substr($sFolderIDs, 1, strlen($sFolderIDs));
- }
-
- /**
- * Recursively generates forward slash deliminated string giving full path of document
- * from file system root url
- */
- function _generateFullFolderPath($iFolderID) {
- global $default;
- //if the folder is not the root folder
- if ($iFolderID != 0) {
- $sql = $default->db;
- $sql->query(array("SELECT name, parent_id FROM $default->folders_table WHERE ID = ?", $iFolderID));/*ok*/
- $sql->next_record();
- return Document::_generateFullFolderPath($sql->f("parent_id")) . "/" . $sql->f("name");
- }
- return;
- }
-
- /**
- * Returns a forward slash deliminated string giving full path of document, strips leading /
- */
- function _generateFolderPath($iFolderID) {
- global $default;
- $sPath = Document::_generateFullFolderPath($iFolderID);
- $sPath = substr($sPath, 1, strlen($sPath));
- $sPath = addslashes($sPath);
- return $sPath;
- }
- // }}}
-
- // {{{ create
- /**
- * Insert the current document into the database
- *
- * @return boolean true on successful insert, false otherwise
- */
- function create() {
- if (empty($this->dCreated)) {
- $this->dCreated = getCurrentDateTime();
- }
- if (empty($this->dModified)) {
- $this->dModified = getCurrentDateTime();
- }
- if (empty($this->iModifiedUserId)) {
- $this->iModifiedUserId = $this->iCreatorID;
- }
- $oFolder = Folder::get($this->getFolderID());
- $this->iPermissionObjectID = $oFolder->getPermissionObjectID();
- $res = parent::create();
-
- if ($res === true) {
- KTPermissionUtil::updatePermissionLookup($this);
- }
+ // {{{ update
+ function update($bPathMove = false) {
+ $res = $this->_oDocumentCore->update();
+ if (PEAR::isError($res)) { var_dump($res); return $res; }
+
+ $res = $this->_oDocumentContentVersion->update();
+ if (PEAR::isError($res)) { var_dump($res); return $res; }
+
+ $res = $this->_oDocumentMetadataVersion->update();
+ if (PEAR::isError($res)) { var_dump($res); return $res; }
return $res;
}
// }}}
- // {{{ update
- function update($bPathMove = false) {
- $res = parent::update();
- if (($res === true) && ($bPathMove === true)) {
- KTPermissionUtil::updatePermissionLookup($this);
+ // {{{ get
+ function &get($iId, $iMetadataVersion=null) {
+ $oDocument = new Document();
+ if (!is_numeric($iId)) { print "Document.inc: 162: "; var_dump($iId); print "
"; }
+ $res = $oDocument->load($iId, $iMetadataVersion);
+ if (PEAR::isError($res)) {
+ return $res;
}
- return $res;
+ return $oDocument;
}
// }}}
- // {{{ get
- function &get($iId) {
- return KTEntityUtil::get('Document', $iId);
+ function load($iId, $iMetadataVersionId = null) {
+ $this->iId = $iId;
+ $this->_oDocumentCore = KTDocumentCore::get($iId);
+ if (PEAR::isError($this->_oDocumentCore)) { return $this->_oDocumentCore; }
+
+ // FIXME add error $res if MDV > $_oDC->getMDV
+ if (is_null($iMetadataVersionId)) {
+ $this->_oDocumentMetadataVersion = KTDocumentMetadataVersion::get($this->_oDocumentCore->getMetadataVersionId());
+ } else {
+ $this->_oDocumentMetadataVersion = KTDocumentMetadataVersion::get($iMetadataVersionId);
+ }
+ if (PEAR::isError($this->_oDocumentMetadataVersion)) { var_dump($this->_oDocumentMetadataVersion); return $this->_oDocumentMetadataVersion; }
+
+ $this->_oDocumentContentVersion = KTDocumentContentVersion::get($this->_oDocumentMetadataVersion->getContentVersionId());
+ if (PEAR::isError($this->_oDocumentContentVersion)) { return $this->_oDocumentContentVersion; }
}
- // }}}
// {{{ getList
/**
* Static function
- * Get a list of Documents
+ * Get a list of Documents - CAN ONLY USE KTDOCUMENTCORE QUERIES
*
* @param String Where clause (not required)
*
* @return Array array of Documents objects, false otherwise.
*/
function getList($sWhereClause = null) {
- return KTEntityUtil::getList(Document::_table(), 'Document', $sWhereClause);
- }
- // }}}
+ $aOptions = array('ids' => true);
+ $aIds = KTDocumentCore::getList($sWhereClause, $aOptions);
+ $aList = array();
+ foreach($aIds as $iId) {
+ $aList[] = Document::get($iId);
+ };
+ return $aList;
- // {{{ getPath
- /**
- * Get the full path for a document
- *
- * @return string full path of document
- */
- function getPath() {
- return Folder::getFolderPath($this->iFolderID) . $this->sFileName;
}
// }}}
@@ -404,10 +217,10 @@ class Document extends KTEntity {
* @return string full path to document
*/
function getDisplayPath($bDisplayIcon = false) {
- $sFolderPath = Folder::getFolderDisplayPath($this->iFolderID);
+ $sFolderPath = Folder::getFolderDisplayPath($this->getFolderID());
// #3425 for consistency
return ($bDisplayIcon ? $this->getIcon() : "") .
- ($sFolderPath == "" ? "Deleted Folder" : $sFolderPath) . " » " . $this->sFileName;
+ ($sFolderPath == "" ? "Deleted Folder" : $sFolderPath) . " » " . $this->getName();
}
// }}}
@@ -422,6 +235,9 @@ class Document extends KTEntity {
* @return boolean true if document exists, false otherwise.
*/
function documentExists($sFileName, $iFolderID) {
+ return false;
+
+
global $default;
$sql = $default->db;
$sQuery = "SELECT * FROM $default->documents_table " ./*ok*/
@@ -446,7 +262,6 @@ class Document extends KTEntity {
* @return string full path to document
*/
function getDocumentDisplayPath($iDocumentID) {
- global $default;
$oDocument = & Document::get($iDocumentID);
return $oDocument->getDisplayPath();
}
@@ -466,21 +281,18 @@ class Document extends KTEntity {
}
// }}}
- // {{{ getByLiveDocument
- function &getByLiveDocument($oDocument) {
- return KTEntityUtil::getByDict('Document', array(
- 'live_document_id' => $oDocument->getID(),
- ), array('multi' => true, 'orderby' => 'modified DESC'));
- }
- // }}}
-
// {{{ getByFolderIDAndLookupID
function &getByFolderIDAndLookupID($iParentID, $iLookupID, $aOptions = null) {
- return KTEntityUtil::getByDict('Document', array(
+ $aIds = KTEntityUtil::getByDict('KTDocumentCore', array(
'folder_id' => $iParentID,
'permission_lookup_id' => $iLookupID,
'status_id' => LIVE,
- ), array('multi' => true));
+ ), array('multi' => true, 'ids' => true));
+
+ $aList = array();
+ foreach ($aIds as $iId) {
+ $aList[] = Document::get($iId);
+ }
}
// }}}
@@ -492,8 +304,112 @@ class Document extends KTEntity {
if (KTUtil::arrayGet($aOptions, "mimetypeid") === null) {
$aOptions['mimetypeid'] = 0;
}
- return KTEntityUtil::createFromArray('Document', $aOptions);
+ $oDocument = new Document();
+ $aOptions = array_change_key_case($aOptions);
+
+ $aCoreKeys = array(
+ "CreatorId",
+ "Created",
+ "ModifiedUserId",
+ "Modified",
+ "FolderId",
+ "StatusId",
+ );
+
+ $aCore = array();
+ foreach ($aCoreKeys as $sKey) {
+ $sKey = strtolower($sKey);
+ $sValue = KTUtil::arrayGet($aOptions, $sKey);
+ if (!is_null($sValue)) {
+ $aCore[$sKey] = $sValue;
+ }
+ }
+
+ $aMetadataVersionKeys = array(
+ "MetadataVersion",
+ "ContentVersionId",
+ "DocumentTypeId",
+ "Name",
+ "Description",
+ "StatusId",
+ "VersionCreated",
+ "VersionCreatorId",
+ );
+
+ $aMetadataVersion = array();
+ foreach ($aMetadataVersionKeys as $sKey) {
+ $sKey = strtolower($sKey);
+ $sValue = KTUtil::arrayGet($aOptions, $sKey);
+ if (!is_null($sValue)) {
+ $aMetadataVersion[$sKey] = $sValue;
+ }
+ }
+ $aMetadataVersion['VersionCreatorId'] = $aCore['creatorid'];
+
+ $aContentKeys = array(
+ "Filename",
+ "Size",
+ "MimeId",
+ "MajorVersion",
+ "MinorVersion",
+ "StoragePath",
+ );
+
+ $aContentVersion = array();
+ foreach ($aContentKeys as $sKey) {
+ $sKey = strtolower($sKey);
+ $sValue = KTUtil::arrayGet($aOptions, $sKey);
+ if (!is_null($sValue)) {
+ $aContentVersion[$sKey] = $sValue;
+ }
+ }
+
+ $oDocument->_oDocumentCore = KTDocumentCore::createFromArray($aCore);
+ if (PEAR::isError($oDocument->_oDocumentCore)) {
+ return $oDocument->_oDocumentCore;
+ }
+ $iId = $oDocument->_oDocumentCore->getId();
+ $aContentVersion["documentid"] = $iId;
+ $oDocument->_oDocumentContentVersion = KTDocumentContentVersion::createFromArray($aContentVersion);
+ if (PEAR::isError($oDocument->_oDocumentContentVersion)) { return $oDocument->_oDocumentContentVersion; }
+ $aMetadataVersion["documentid"] = $iId;
+ $aMetadataVersion["contentversionid"] = $oDocument->_oDocumentContentVersion->getId();
+ $oDocument->_oDocumentMetadataVersion = KTDocumentMetadataVersion::createFromArray($aMetadataVersion);
+ if (PEAR::isError($oDocument->_oDocumentMetadataVersion)) { return $oDocument->_oDocumentMetadataVersion; }
+ $oDocument->_oDocumentCore->setMetadataVersionId($oDocument->_oDocumentMetadataVersion->getId());
+ $res = $oDocument->_oDocumentCore->update();
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ $oDocument->iId = $iId;
+ return $oDocument;
+ }
+
+ function startNewMetadataVersion() {
+ $this->_oDocumentMetadataVersion->iId = -1;
+ $this->_oDocumentMetadataVersion->iMetadataVersion++;
+ $this->_oDocumentMetadataVersion->create();
+ $this->_oDocumentCore->iMetadataVersion = $this->_oDocumentMetadataVersion->iMetadataVersion;
+ $this->_oDocumentCore->iMetadataVersionId = $this->_oDocumentMetadataVersion->iId;
}
+ function startNewContentVersion() {
+ $this->_oDocumentContentVersion->iId = -1;
+ $res = $this->_oDocumentContentVersion->create();
+ if (PEAR::isError($res)) {
+ var_dump($res);
+ return $res;
+ }
+ $this->_oDocumentMetadataVersion->iId = -1;
+ $this->_oDocumentMetadataVersion->iMetadataVersion++;
+ $this->_oDocumentMetadataVersion->iContentVersionId = $this->_oDocumentContentVersion->getId();
+ $res = $this->_oDocumentMetadataVersion->create();
+ if (PEAR::isError($res)) {
+ var_dump($res);
+ return $res;
+ }
+ $this->_oDocumentCore->iMetadataVersion = $this->_oDocumentMetadataVersion->iMetadataVersion;
+ $this->_oDocumentCore->iMetadataVersionId = $this->_oDocumentMetadataVersion->iId;
+ }
}
?>
diff --git a/lib/documentmanagement/DocumentFieldLink.inc b/lib/documentmanagement/DocumentFieldLink.inc
index 12c70dc..f910948 100644
--- a/lib/documentmanagement/DocumentFieldLink.inc
+++ b/lib/documentmanagement/DocumentFieldLink.inc
@@ -29,7 +29,7 @@ class DocumentFieldLink extends KTEntity {
/** document field link primary key */
var $iId;
/** primary key of document to which field is linked */
- var $iDocumentId;
+ var $iMetadataVersionId;
/** primary key of field to which document is linked */
var $iDocumentFieldId;
/** field value */
@@ -37,7 +37,7 @@ class DocumentFieldLink extends KTEntity {
var $_aFieldToSelect = array(
'iId' => 'id',
- 'iDocumentId' => 'document_id',
+ 'iMetadataVersionId' => 'metadata_version_id',
'iDocumentFieldId' => 'document_field_id',
'sValue' => 'value',
);
@@ -74,8 +74,8 @@ class DocumentFieldLink extends KTEntity {
* @return int document primary key to which the field is linked
*
*/
- function getDocumentId() {
- return $this->iDocumentId;
+ function getMetadataVersionId() {
+ return $this->iMetadataVersionId;
}
/**
@@ -84,8 +84,8 @@ class DocumentFieldLink extends KTEntity {
* @param Document primary key to which field is linked
*
*/
- function setDocumentId($iNewValue) {
- $this->iDocumentId = $iNewValue;
+ function setMetadataVersionId($iNewValue) {
+ $this->iMetadataVersionId = $iNewValue;
}
/**
@@ -141,17 +141,8 @@ class DocumentFieldLink extends KTEntity {
*
* @return DocumentFieldLink populated DocumentFieldLink object on success, false otherwise and set $_SESSION["errorMessage"]
*/
- function & get($iDocumentFieldLinkId) {
- global $default, $lang_err_doc_not_exist;
- $sql = $default->db;
- $sql->query(array("SELECT * FROM " . $default->document_fields_link_table . " WHERE id = ?", $iDocumentFieldLinkId));/*ok*/
- if ($sql->next_record()) {
- $oDocumentFieldLink = & new DocumentFieldLink($sql->f("document_id"), $sql->f("document_field_id"), $sql->f("value"));
- $oDocumentFieldLink->iId = $iDocumentFieldLinkId;
- return $oDocumentFieldLink;
- }
- $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentId . " table = $default->document_fields_link_table";
- return false;
+ function &get($iId) {
+ return KTEntityUtil::get('DocumentFieldLink', $iId);
}
function &getList($sWhereClause = null) {
@@ -160,15 +151,18 @@ class DocumentFieldLink extends KTEntity {
function &getByDocument($oDocument) {
- $iDocumentId = KTUtil::getId($oDocument);
+ $oDocument =& KTUtil::getObject('Document', $oDocument);
+ $iMetadataVersionId = $oDocument->getMetadataVersionId();
return KTEntityUtil::getByDict('DocumentFieldLink', array(
- 'document_id' => $iDocumentId,
+ 'metadata_version_id' => $iMetadataVersionId,
), array('multi' => true));
}
function &getByDocumentAndField($oDocument, $oField) {
+ $oDocument =& KTUtil::getObject('Document', $oDocument);
+ $iMetadataVersionId = $oDocument->getMetadataVersionId();
return KTEntityUtil::getByDict('DocumentFieldLink', array(
- 'document_id' => KTUtil::getId($oDocument),
+ 'metadata_version_id' => $iMetadataVersionId,
'document_field_id' => KTUtil::getId($oDocument),
));
}
diff --git a/lib/documentmanagement/DocumentTransaction.inc b/lib/documentmanagement/DocumentTransaction.inc
index 8b6cbba..643a264 100644
--- a/lib/documentmanagement/DocumentTransaction.inc
+++ b/lib/documentmanagement/DocumentTransaction.inc
@@ -61,7 +61,7 @@ class DocumentTransaction {
$this->sComment = $sNewComment;
$this->sTransactionNS = $sTransactionNS;
$this->sVersion = $oDocument->getMajorVersionNumber() . "." . $oDocument->getMinorVersionNumber();
- $oFolder = Folder::get($oDocument->iFolderID);
+ $oFolder = Folder::get($oDocument->getFolderId());
$this->sFileName = addslashes($oFolder->sFullPath . "/" . $oFolder->getName() . "/" . $oDocument->getName());
$this->iUserID = $_SESSION["userID"];
diff --git a/lib/documentmanagement/documentcontentversion.inc.php b/lib/documentmanagement/documentcontentversion.inc.php
index c80029a..3de2b42 100644
--- a/lib/documentmanagement/documentcontentversion.inc.php
+++ b/lib/documentmanagement/documentcontentversion.inc.php
@@ -9,13 +9,13 @@ class KTDocumentContentVersion extends KTEntity {
var $iDocumentId;
/** What was the filename of the stored content */
- var $sFilename;
+ var $sFileName;
/** How big was the stored content */
var $iSize;
/** Which MIME type was this content */
- var $iMimeId;
+ var $iMimeTypeId;
/** User-specified major version for this content */
var $iMajorVersion;
@@ -31,9 +31,9 @@ class KTDocumentContentVersion extends KTEntity {
// transaction-related
"iDocumentId" => 'document_id',
- "sFilename" => 'filename',
+ "sFileName" => 'filename',
"iSize" => 'size',
- "iMimeId" => 'mime_id',
+ "iMimeTypeId" => 'mime_id',
"iMajorVersion" => 'major_version',
"iMinorVersion" => 'minor_version',
"sStoragePath" => 'storage_path',
@@ -42,7 +42,48 @@ class KTDocumentContentVersion extends KTEntity {
function KTDocumentContentVersion() {
}
-
+ function getFileName() { return $this->sFileName; }
+ function setFileName($sNewValue) { $this->sFileName = $sNewValue; }
+ function getFileSize() { return $this->iSize; }
+ function setFileSize($iNewValue) { $this->iSize = $iNewValue; }
+ function getSize() { return $this->iSize; }
+ function setSize($iNewValue) { $this->iSize = $iNewValue; }
+ function getMimeTypeId() { return $this->iMimeTypeId; }
+ function setMimeTypeId($iNewValue) { $this->iMimeTypeId = $iNewValue; }
+ function getMajorVersionNumber() { return $this->iMajorVersion; }
+ function setMajorVersionNumber($iNewValue) { $this->iMajorVersion = $iNewValue; }
+ function getMinorVersionNumber() { return $this->iMinorVersion; }
+ function setMinorVersionNumber($iNewValue) { $this->iMinorVersion = $iNewValue; }
+ function getStoragePath() { return $this->sStoragePath; }
+ function setStoragePath($sNewValue) { $this->sStoragePath = $sNewValue; }
+
+ function _table() {
+ return KTUtil::getTableName('document_content_version');
+ }
+
+ function &createFromArray($aOptions) {
+ return KTEntityUtil::createFromArray('KTDocumentContentVersion', $aOptions);
+ }
+
+ function create() {
+ if (empty($this->iSize)) {
+ $this->iSize = 0;
+ }
+ if (empty($this->iMimeTypeId)) {
+ $this->iMimeTypeId = 0;
+ }
+ if (empty($this->iMajorVersion)) {
+ $this->iMajorVersion = 0;
+ }
+ if (empty($this->iMinorVersion)) {
+ $this->iMinorVersion = 1;
+ }
+ return parent::create();
+ }
+
+ function &get($iId) {
+ return KTEntityUtil::get('KTDocumentContentVersion', $iId);
+ }
}
?>
diff --git a/lib/documentmanagement/documentcore.inc.php b/lib/documentmanagement/documentcore.inc.php
index 947c6dd..3a53b26 100644
--- a/lib/documentmanagement/documentcore.inc.php
+++ b/lib/documentmanagement/documentcore.inc.php
@@ -37,6 +37,11 @@ class KTDocumentCore extends KTEntity {
/** The most recent metadata version for the object */
var $iMetadataVersionId;
+ var $iMetadataVersion;
+
+ var $bIsCheckedOut;
+ var $iCheckedOutUserId;
+
var $_aFieldToSelect = array(
"iId" => "id",
@@ -45,7 +50,8 @@ class KTDocumentCore extends KTEntity {
"dCreated" => 'created',
"iModifiedUserId" => 'modified_user_id',
"dModified" => 'modified',
-
+ "iMetadataVersionId" => 'metadata_version_id',
+ "iMetadataVersion" => 'metadata_version',
// location-related
"iFolderId" => 'folder_id',
@@ -54,6 +60,8 @@ class KTDocumentCore extends KTEntity {
// status
"iStatusId" => 'status_id',
+ "bIsCheckedOut" => 'is_checked_out',
+ "iCheckedOutUserId" => 'checked_out_user_id',
// permission-related
"iPermissionObjectId" => 'permission_object_id',
@@ -77,11 +85,22 @@ class KTDocumentCore extends KTEntity {
function getStatusId() { return $this->iStatusId; }
function setStatusId($iNewValue) { $this->iStatusId = $iNewValue; }
+ function getIsCheckedOut() { return $this->bIsCheckedOut; }
+ function setIsCheckedOut($bNewValue) { $this->bIsCheckedOut = KTUtil::anyToBool($bNewValue); }
+ function getCheckedOutUserId() { return $this->iCheckedOutUserId; }
+ function setCheckedOutUserId($iNewValue) { $this->iCheckedOutUserId = $iNewValue; }
function getPermissionObjectId() { return $this->iPermissionObjectId; }
function setPermissionObjectId($iNewValue) { $this->iPermissionObjectId = $iNewValue; }
function getPermissionLookupId() { return $this->iPermissionLookupId; }
function setPermissionLookupId($iNewValue) { $this->iPermissionLookupId = $iNewValue; }
+
+ function getMetadataVersionId() { return $this->iMetadataVersionId; }
+ function setMetadataVersionId($iNewValue) { $this->iMetadataVersionId = $iNewValue; }
+
+ function getMetadataVersion() { return $this->iMetadataVersion; }
+ function setMetadataVersion($iNewValue) { $this->iMetadataVersion = $iNewValue; }
+
// }}}
// {{{ getParentId
@@ -96,8 +115,8 @@ class KTDocumentCore extends KTEntity {
// {{{ ktentity requirements
function _fieldValues () {
- $this->sFullPath = KTDocument::_generateFolderPath($this->iFolderId);
- $this->sParentFolderIds = KTDocument::_generateFolderIds($this->iFolderId);
+ $this->sFullPath = KTDocumentCore::_generateFolderPath($this->iFolderId);
+ $this->sParentFolderIds = KTDocumentCore::_generateFolderIds($this->iFolderId);
return parent::_fieldValues();
}
@@ -116,7 +135,7 @@ class KTDocumentCore extends KTEntity {
$sQuery = sprintf('SELECT parent_id FROM %s WHERE id = ?', $sTable);
$aParams = array($iFolderId);
$iParentId = DBUtil::getOneResultKey(array($sQuery, $aParams), 'parent_id');
- return Document::_generateParentFolderIds($iParentId) . ",$iFolderId";
+ return KTDocumentCore::_generateParentFolderIds($iParentId) . ",$iFolderId";
}
/**
@@ -125,7 +144,7 @@ class KTDocumentCore extends KTEntity {
* @return String comma delimited string containing the parent folder ids
*/
function _generateFolderIds($iFolderId) {
- $sFolderIds = Document::_generateParentFolderIds($iFolderId);
+ $sFolderIds = KTDocumentCore::_generateParentFolderIds($iFolderId);
return substr($sFolderIds, 1, strlen($sFolderIds));
}
@@ -134,23 +153,22 @@ class KTDocumentCore extends KTEntity {
* from file system root url
*/
function _generateFullFolderPath($iFolderId) {
- global $default;
//if the folder is not the root folder
if (empty($iFolderId)) {
return;
}
+ $sTable = KTUtil::getTableName('folders');
$sQuery = sprintf("SELECT name, parent_id FROM %s WHERE Id = ?", $sTable);
$aParams = array($iFolderId);
$aRow = DBUtil::getOneResult(array($sQuery, $aParams));
- return Document::_generateFullFolderPath($aRow["parent_id"]) . "/" . $aRow["name"];
+ return KTDocumentCore::_generateFullFolderPath($aRow["parent_id"]) . "/" . $aRow["name"];
}
/**
* Returns a forward slash deliminated string giving full path of document, strips leading /
*/
function _generateFolderPath($iFolderId) {
- global $default;
- $sPath = Document::_generateFullFolderPath($iFolderId);
+ $sPath = KTDocumentCore::_generateFullFolderPath($iFolderId);
$sPath = substr($sPath, 1, strlen($sPath));
return $sPath;
}
@@ -167,6 +185,12 @@ class KTDocumentCore extends KTEntity {
if (empty($this->iModifiedUserId)) {
$this->iModifiedUserId = $this->iCreatorId;
}
+ if (empty($this->iMetadataVersion)) {
+ $this->iMetadataVersion = 0;
+ }
+ if (empty($this->bIsCheckedOut)) {
+ $this->bIsCheckedOut = false;
+ }
$oFolder = Folder::get($this->getFolderId());
$this->iPermissionObjectId = $oFolder->getPermissionObjectId();
$res = parent::create();
@@ -191,11 +215,36 @@ class KTDocumentCore extends KTEntity {
// {{{ get
function &get($iId) {
- return KTEntityUtil::get('KTDocument', $iId);
+ return KTEntityUtil::get('KTDocumentCore', $iId);
}
// }}}
+ // {{{ getList
+ function &getList($sWhere = null, $aOptions) {
+ return KTEntityUtil::getList2('KTDocumentCore', $sWhere, $aOptions);
+ }
+ // }}}
+ // {{{ _table
+ function _table() {
+ return KTUtil::getTableName('documents');
+ }
+ // }}}
+
+ // {{{ getPath
+ /**
+ * Get the full path for a document
+ *
+ * @return string full path of document
+ */
+ function getPath() {
+ return Folder::getFolderPath($this->iFolderId) . $this->sFileName;
+ }
+ // }}}
+
+ function &createFromArray($aOptions) {
+ return KTEntityUtil::createFromArray('KTDocumentCore', $aOptions);
+ }
}
?>
diff --git a/lib/documentmanagement/documentmetadataversion.inc.php b/lib/documentmanagement/documentmetadataversion.inc.php
index e7bf630..58dcee3 100644
--- a/lib/documentmanagement/documentmetadataversion.inc.php
+++ b/lib/documentmanagement/documentmetadataversion.inc.php
@@ -58,19 +58,43 @@ class KTDocumentMetadataVersion extends KTEntity {
function setDocumentId($iNewValue) { $this->iDocumentId = $iNewValue; }
function getMetadataVersion() { return $this->iMetadataVersion; }
function setMetadataVersion($iNewValue) { $this->iMetadataVersion = $iNewValue; }
+ function getContentVersionId() { return $this->iContentVersionId; }
+ function setContentVersion($iNewValue) { $this->iContentVersion = $iNewValue; }
function getDocumentTypeId() { return $this->iDocumentTypeId; }
function setDocumentTypeId($iNewValue) { $this->iDocumentTypeId = $iNewValue; }
function getName() { return $this->sName; }
function setName($sNewValue) { $this->sName = $sNewValue; }
function getDescription() { return $this->sDescription; }
function setDescription($sNewValue) { $this->sDescription = $sNewValue; }
- function getStatusId() { return $this->sStatusId; }
- function setStatusId($iNewValue) { $this->sStatusId = $iNewValue; }
+ function getStatusId() { return $this->iStatusId; }
+ function setStatusId($iNewValue) { $this->iStatusId = $iNewValue; }
function getVersionCreated() { return $this->dVersionCreated; }
function setVersionCreated($dNewValue) { $this->dVersionCreated = $dNewValue; }
function getVersionCreatorId() { return $this->iVersionCreatorId; }
function setVersionCreatorId($iNewValue) { $this->iVersionCreatorId = $iNewValue; }
// }}}
+
+ function &createFromArray($aOptions) {
+ return KTEntityUtil::createFromArray('KTDocumentMetadataVersion', $aOptions);
+ }
+
+ function _table() {
+ return KTUtil::getTableName('document_metadata_version');
+ }
+
+ function create() {
+ if (is_null($this->iMetadataVersion)) {
+ $this->iMetadataVersion = 0;
+ }
+ if (is_null($this->dVersionCreated)) {
+ $this->dVersionCreated = getCurrentDateTime();
+ }
+ return parent::create();
+ }
+
+ function &get($iId) {
+ return KTEntityUtil::get('KTDocumentMetadataVersion', $iId);
+ }
}
?>
diff --git a/lib/documentmanagement/documentutil.inc.php b/lib/documentmanagement/documentutil.inc.php
index 9528a7f..216523e 100644
--- a/lib/documentmanagement/documentutil.inc.php
+++ b/lib/documentmanagement/documentutil.inc.php
@@ -99,19 +99,15 @@ class KTDocumentUtil {
}
function checkin($oDocument, $sFilename, $sCheckInComment, $oUser) {
- $sBackupPath = $oDocument->getPath() . "-" . $oDocument->getMajorVersionNumber() . "." . $oDocument->getMinorVersionNumber();
- $bSuccess = @copy($oDocument->getPath(), $sBackupPath);
- if ($bSuccess === false) {
- return PEAR::raiseError(_("Unable to backup document prior to upload"));
- }
- $oVersionedDocument = KTDocumentUtil::createMetadataVersion($oDocument);
- if (PEAR::isError($oVersionedDocument)) {
- return $oVersionedDocument;
- }
-
$oStorage =& KTStorageManagerUtil::getSingleton();
$iFileSize = filesize($sFilename);
+ $iPreviousMetadataVersion = $oDocument->getMetadataVersionId();
+
+ $oDocument->startNewContentVersion();
+
+ KTDocumentUtil::copyMetadata($oDocument, $iPreviousMetadataVersion);
+
if (!$oStorage->upload($oDocument, $sFilename)) {
// reinstate the backup
copy($sBackupPath, $oDocument->getPath());
@@ -120,8 +116,6 @@ class KTDocumentUtil {
return PEAR::raiseError(_("An error occurred while storing the new file"));
}
- $oDocument->setMetadataVersion($oDocument->getMetadataVersion()+1);
-
$oDocument->setLastModifiedDate(getCurrentDateTime());
$oDocument->setModifiedUserId($oUser->getId());
$oDocument->setIsCheckedOut(false);
@@ -201,6 +195,7 @@ class KTDocumentUtil {
if (is_null($oContents)) {
$res = KTDocumentUtil::setIncomplete($oDocument, "contents");
+ var_dump($res);
if (PEAR::isError($res)) {
$oDocument->delete();
return $res;
@@ -287,7 +282,8 @@ class KTDocumentUtil {
}
$aMetadata = $res;
- $res = DBUtil::runQuery(array("DELETE FROM $table WHERE document_id = ?", array($oDocument->getID())));
+ $iMetadataVersionId = $oDocument->getMetadataVersionId();
+ $res = DBUtil::runQuery(array("DELETE FROM $table WHERE metadata_version_id = ?", array($iMetadataVersionId)));
if (PEAR::isError($res)) {
return $res;
}
@@ -298,7 +294,7 @@ class KTDocumentUtil {
continue;
}
$res = DBUtil::autoInsert($table, array(
- "document_id" => $oDocument->getID(),
+ "metadata_version_id" => $iMetadataVersionId,
"document_field_id" => $oMetadata->getID(),
"value" => $sValue,
));
@@ -312,11 +308,22 @@ class KTDocumentUtil {
}
// }}}
+ function copyMetadata($oDocument, $iPreviousMetadataVersionId) {
+ $iNewMetadataVersion = $oDocument->getMetadataVersionId();
+ $sTable = KTUtil::getTableName('document_fields_link');
+ $aFields = DBUtil::getResultArray(array("SELECT * FROM $sTable WHERE metadata_version_id = ?", array($iPreviousMetadataVersionId)));
+ foreach ($aFields as $aRow) {
+ unset($aRow['id']);
+ $aRow['metadata_version_id'] = $iNewMetadataVersion;
+ DBUtil::autoInsert($sTable, $aRow);
+ }
+ }
+
// {{{ setIncomplete
function setIncomplete(&$oDocument, $reason) {
$oDocument->setStatusID(STATUS_INCOMPLETE);
$table = "document_incomplete";
- $iId = $oDocument->getID();
+ $iId = $oDocument->getId();
$aIncomplete = DBUtil::getOneResult(array("SELECT * FROM $table WHERE id = ?", array($iId)));
if (PEAR::isError($aIncomplete)) {
return $aIncomplete;
diff --git a/lib/metadata/metadatautil.inc.php b/lib/metadata/metadatautil.inc.php
index e7182e5..7319692 100644
--- a/lib/metadata/metadatautil.inc.php
+++ b/lib/metadata/metadatautil.inc.php
@@ -591,15 +591,15 @@ class KTMetadataUtil {
function fieldsetsForDocument($oDocument) {
global $default;
$oDocument = KTUtil::getObject('Document', $oDocument);
- $iDocumentId = $oDocument->getId();
+ $iMetadataVersionId = $oDocument->getMetadataVersionId();
$iDocumentTypeId = $oDocument->getDocumentTypeId();
$sQuery = "SELECT DISTINCT F.id AS fieldset_id " .
- "FROM $default->documents_table AS D INNER JOIN document_fields_link AS DFL ON D.id = DFL.document_id " .
+ "FROM $default->document_metadata_version_table AS DM INNER JOIN document_fields_link AS DFL ON DM.id = DFL.metadata_version_id " .
"INNER JOIN $default->document_fields_table AS DF ON DF.ID = DFL.document_field_id " .
"INNER JOIN $default->fieldsets_table AS F ON F.id = DF.parent_fieldset " .
- "WHERE D.id = ?";
- $aParam = array($iDocumentId);
+ "WHERE DM.id = ?";
+ $aParam = array($iMetadataVersionId);
$aDocumentFieldsetIds = DBUtil::getResultArrayKey(array($sQuery, $aParam), 'fieldset_id');
$aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => true));
diff --git a/lib/permissions/permissionutil.inc.php b/lib/permissions/permissionutil.inc.php
index c31f505..756803d 100644
--- a/lib/permissions/permissionutil.inc.php
+++ b/lib/permissions/permissionutil.inc.php
@@ -177,7 +177,32 @@ class KTPermissionUtil {
* non-recursively.
*/
function updatePermissionLookup(&$oFolderOrDocument) {
- $oPO = KTPermissionObject::get($oFolderOrDocument->getPermissionObjectID());
+ if (!is_a($oFolderOrDocument, 'Folder')) {
+ if (!is_a($oFolderOrDocument, 'Document')) {
+ if (!is_a($oFolderOrDocument, 'KTDocumentCore')) {
+ echo "";
+ var_dump($oFolderOrDocument);
+ echo "
";
+ }
+ }
+ }
+ $oChannel =& KTPermissionChannel::getSingleton();
+ if (is_a($oFolderOrDocument, 'Folder')) {
+ $msg = sprintf("Updating folder %s", join("/", $oFolderOrDocument->getPathArray()));
+ } else {
+ if (is_a($oFolderOrDocument, 'Document')) {
+ $msg = sprintf("Updating document %s", $oFolderOrDocument->getName());
+ } else {
+ $msg = sprintf("Updating document %d", $oFolderOrDocument->getId());
+ }
+ }
+ $oChannel->sendMessage(new KTPermissionGenericMessage($msg));
+
+ $iPermissionObjectId = $oFolderOrDocument->getPermissionObjectID();
+ if (empty($iPermissionObjectId)) {
+ return;
+ }
+ $oPO = KTPermissionObject::get($iPermissionObjectId);
$aPAs = KTPermissionAssignment::getByObjectMulti($oPO);
$aMapPermAllowed = array();
foreach ($aPAs as $oPA) {
@@ -476,4 +501,37 @@ class KTPermissionUtil {
// }}}
}
+class KTPermissionChannel {
+ var $observers = array();
+
+ function &getSingleton() {
+ if (!KTUtil::arrayGet($GLOBALS, 'KT_PermissionChannel')) {
+ $GLOBALS['KT_PermissionChannel'] = new KTPermissionChannel;
+ }
+ return $GLOBALS['KT_PermissionChannel'];
+ }
+
+ function sendMessage(&$msg) {
+ foreach ($this->observers as $oObserver) {
+ $oObserver->receiveMessage($msg);
+ }
+ }
+
+ function addObserver(&$obs) {
+ array_push($this->observers, $obs);
+ }
+}
+
+class KTPermissionGenericMessage {
+ function KTPermissionGenericMessage($sMessage) {
+ $this->sMessage = $sMessage;
+ }
+
+ function getString() {
+ return $this->sMessage;
+ }
+}
+
+
+
?>
diff --git a/lib/search/searchutil.inc.php b/lib/search/searchutil.inc.php
index 7fbcac3..f59857a 100644
--- a/lib/search/searchutil.inc.php
+++ b/lib/search/searchutil.inc.php
@@ -252,16 +252,20 @@ class KTSearchUtil {
}
//$sQuery = DBUtil::compactQuery("
- $sQuery = ("
+ $sQuery = sprintf("
SELECT
$sSelect
FROM
- $default->documents_table AS D
+ %s AS D
+ LEFT JOIN %s AS DM ON D.metadata_version_id = DM.id
+ LEFT JOIN %s AS DC ON DM.content_version_id = DC.id
INNER JOIN $default->status_table AS SL on D.status_id=SL.id
$sInitialJoin
$sCritJoinSQL
$sPermissionJoin
- $sWhere");
+ $sWhere", KTUtil::getTableName('documents'),
+ KTUtil::getTableName('document_metadata_version'),
+ KTUtil::getTableName('document_content_version'));
// GROUP BY D.id
$aParams = array();
diff --git a/lib/storage/ondiskpathstoragemanager.inc.php b/lib/storage/ondiskpathstoragemanager.inc.php
index 8caf97f..1bf4559 100644
--- a/lib/storage/ondiskpathstoragemanager.inc.php
+++ b/lib/storage/ondiskpathstoragemanager.inc.php
@@ -71,7 +71,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
}
function generateStoragePath(&$oDocument) {
- $sStoragePath = sprintf("%s/%s", Document::_generateFolderPath($oDocument->getFolderID()), $oDocument->getFileName());
+ $sStoragePath = sprintf("%s/%s-%s", KTDocumentCore::_generateFolderPath($oDocument->getFolderID()), $oDocument->getContentVersionId(), $oDocument->getFileName());
return $sStoragePath;
}
@@ -155,8 +155,8 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
global $default;
$oConfig =& KTConfig::getSingleton();
- $sCurrentPath = sprintf("%s/%s/%s", $oConfig->get('urls/documentRoot'), Document::_generateFolderPath($oSourceFolder->getID()), $oDocument->getFileName());
- $sDestinationPath = sprintf("%s/%s/%s", $oConfig->get('urls/documentRoot'), Document::_generateFolderPath($oDestinationFolder->getID()), $oDocument->getFileName());
+ $sCurrentPath = sprintf("%s/%s/%s", $oConfig->get('urls/documentRoot'), KTDocumentCore::_generateFolderPath($oSourceFolder->getID()), $oDocument->getFileName());
+ $sDestinationPath = sprintf("%s/%s/%s", $oConfig->get('urls/documentRoot'), KTDocumentCore::_generateFolderPath($oDestinationFolder->getID()), $oDocument->getFileName());
// find all the previous versions of this document and move them
// ie. interrogate transaction history for all CHECKIN transactions and retrieve the versions
@@ -191,7 +191,7 @@ class KTOnDiskPathStorageManager extends KTStorageManager {
$default->log->error("KTOnDiskPathStorageManager->moveDocument couldn't move $sCurrentPath to $sDestinationPath, documentID=" . $oDocument->getID());
return $res;
}
- $sStoragePath = sprintf("%s/%s", Document::_generateFolderPath($oDestinationFolder->getID()), $oDocument->getFileName());
+ $sStoragePath = sprintf("%s/%s", KTDocumentCore::_generateFolderPath($oDestinationFolder->getID()), $oDocument->getFileName());
$this->setPath($oDocument, $sStoragePath);
return true;
}
diff --git a/lib/upgrades/UpgradeFunctions.inc.php b/lib/upgrades/UpgradeFunctions.inc.php
index 7a737c5..d2d7f89 100644
--- a/lib/upgrades/UpgradeFunctions.inc.php
+++ b/lib/upgrades/UpgradeFunctions.inc.php
@@ -6,6 +6,7 @@ class UpgradeFunctions {
"2.0.6" => array("addTemplateMimeTypes"),
"2.0.8" => array("setPermissionObject"),
"2.99.1" => array("createFieldSets"),
+ "2.99.7" => array("normaliseDocuments"), #, "createLdapAuthenticationProvider"),
);
var $descriptions = array(
@@ -14,10 +15,12 @@ class UpgradeFunctions {
"addTemplateMimeTypes" => "Add MIME types for Excel and Word templates",
"setPermissionObject" => "Set the permission object in charge of a document or folder",
"createFieldSets" => "Create a fieldset for each field without one",
+ "normaliseDocuments" => "Normalise the documents table",
);
var $phases = array(
"setPermissionObject" => 1,
"createFieldSets" => 1,
+ "normaliseDocuments" => 1,
);
// {{{ _setPermissionFolder
@@ -265,6 +268,60 @@ class UpgradeFunctions {
}
}
// }}}
+
+ // {{{ normaliseDocuments
+ function normaliseDocuments() {
+ $sTable = KTUtil::getTableName('documents');
+ DBUtil::runQuery("SET FOREIGN_KEY_CHECKS=0");
+ $aDocuments = DBUtil::getResultArray("SELECT * FROM $sTable WHERE metadata_version_id IS NULL");
+ foreach ($aDocuments as $aRow) {
+ print "Document ID: " . $aRow['id'];
+ $aContentInfo = array(
+ 'document_id' => $aRow['id'],
+ 'filename' => $aRow['filename'],
+ 'size' => $aRow['size'],
+ 'mime_id' => $aRow['mime_id'],
+ 'major_version' => $aRow['major_version'],
+ 'minor_version' => $aRow['minor_version'],
+ 'storage_path' => $aRow['storage_path'],
+ );
+ $iContentId = DBUtil::autoInsert(KTUtil::getTableName('document_content_version'), $aContentInfo);
+ print "Content ID: " . $iContentId;
+ $aMetadataInfo = array(
+ 'document_id' => $aRow['id'],
+ 'content_version_id' => $iContentId,
+ 'document_type_id' => $aRow['document_type_id'],
+ 'name' => $aRow['name'],
+ 'description' => $aRow['description'],
+ 'status_id' => $aRow['status_id'],
+ 'metadata_version' => $aRow['metadata_version'],
+ 'version_created' => $aRow['created'],
+ 'version_creator_id' => $aRow['creator_id'],
+ );
+ $iMetadataId = DBUtil::autoInsert(KTUtil::getTableName('document_metadata_version'), $aMetadataInfo);
+ print "Metadata ID: " . $iMetadataId;
+ if (PEAR::isError($iMetadataId)) {
+ var_dump($iMetadataId);
+ }
+ DBUtil::runQuery(array("UPDATE $sTable SET metadata_version_id = ? WHERE id = ?", array($iMetadataId, $aRow['id'])));
+ print "\n";
+ }
+ DBUtil::runQuery("SET FOREIGN_KEY_CHECKS=1");
+
+ $aDocumentMap = array();
+ $sTable = KTUtil::getTableName('document_fields_link');
+ $sDocumentsTable = KTUtil::getTableName('documents');
+ $aInfo = DBUtil::getResultArray("SELECT id, document_id, document_field_id, value FROM $sTable WHERE metadata_version_id IS NULL");
+ foreach ($aInfo as $aRow) {
+ $iMetadataVersionId = KTUtil::arrayGet($aDocumentMap, $aRow['document_id']);
+ if (empty($iMetadataVersionId)) {
+ $iMetadataVersionId = DBUtil::getOneResultKey(array("SELECT metadata_version_id FROM $sDocumentsTable WHERE id = ?", array($aRow['document_id'])), 'metadata_version_id');
+ $aDocumentMap[$aRow['document_id']] = $iMetadataVersionId;
+ }
+ DBUtil::runQuery(array("UPDATE $sTable SET metadata_version_id = ? WHERE id = ?", array($iMetadataVersionId, $aRow['id'])));
+ }
+ }
+ // }}}
}
?>
diff --git a/lib/upgrades/UpgradeItems.inc.php b/lib/upgrades/UpgradeItems.inc.php
index 56971b7..45dd00d 100644
--- a/lib/upgrades/UpgradeItems.inc.php
+++ b/lib/upgrades/UpgradeItems.inc.php
@@ -256,7 +256,7 @@ class SQLUpgradeItem extends UpgradeItem {
$phase = 0;
return array($fromVersion, $toVersion, $description, $phase);
}
- $matched = preg_match('#^([\d.]*)/(?:(\d)-)?(.*)\.sql$#', $path, $matches);
+ $matched = preg_match('#^([\d.]*)/(?:(\d*)-)?(.*)\.sql$#', $path, $matches);
if ($matched != 0) {
$fromVersion = $matches[1];
$toVersion = $matches[1];
diff --git a/plugins/ktcore/KTFolderActions.php b/plugins/ktcore/KTFolderActions.php
index 603c527..9dc0b41 100644
--- a/plugins/ktcore/KTFolderActions.php
+++ b/plugins/ktcore/KTFolderActions.php
@@ -116,6 +116,7 @@ class KTFolderPermissionsAction extends KTFolderAction {
}
function do_update() {
+ require_once(KT_LIB_DIR . "/documentmanagement/observers.inc.php");
$oPO = KTPermissionObject::get($this->oFolder->getPermissionObjectId());
$aFoo = $_REQUEST['foo'];
$aPermissions = KTPermission::getList();
@@ -124,9 +125,17 @@ class KTFolderPermissionsAction extends KTFolderAction {
$aAllowed = KTUtil::arrayGet($aFoo, $iPermId, array());
KTPermissionUtil::setPermissionForId($oPermission, $oPO, $aAllowed);
}
+
+ $po =& new JavascriptObserver($this);
+ $po->start();
+ $oChannel =& KTPermissionChannel::getSingleton();
+ $oChannel->addObserver($po);
+
KTPermissionUtil::updatePermissionLookupForPO($oPO);
- return $this->successRedirectToMain(_('Permissions updated'),
- array('fFolderId' => $this->oFolder->getId()));
+
+ $this->commitTransaction();
+
+ $po->redirect(KTUtil::addQueryString($_SERVER['PHP_SELF'], "fFolderId=" . $this->oFolder->getId()));
}
function do_copyPermissions() {
diff --git a/setup/postcheckup.php b/setup/postcheckup.php
index 7bc57a3..0b1812d 100644
--- a/setup/postcheckup.php
+++ b/setup/postcheckup.php
@@ -64,8 +64,8 @@ if ($handle !== false) {
Logging support is not currently working. Error is: " .
- htmlentities($loggingSupport->toString()) . "
Logging support is not currently working. Error is: ' . + htmlentities($loggingSupport->toString()) . '
'; } else { ?>Logging support is operational.
diff --git a/setup/upgrade.php b/setup/upgrade.php index 6350259..18fe4ac 100644 --- a/setup/upgrade.php +++ b/setup/upgrade.php @@ -1,5 +1,7 @@ \n"; - $ret .= "| Description | Result |
|---|---|
| %s | %s |
| %s | %s |
The table below describes the upgrades that have occurred to upgrade your KnowledgeTree installation to $default->systemVersion. "; + + $upgradeTable = performAllUpgrades(); } print $upgradeTable; @@ -102,9 +104,6 @@ if ($upgradeTable) { } else { print '
'; } -} else { - -} ?>