예제 #1
0
<?php

require_once "../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/documentmanagement/documentutil.inc.php';
require_once KT_LIB_DIR . '/filelike/fsfilelike.inc.php';
$sLocalname = KT_DIR . "/tests/document/dataset1/critique-of-pure-reason.txt";
$sFilename = tempnam("/tmp", "kt_tests_document_add");
copy($sLocalname, $sFilename);
$oDocument =& Document::get(207);
if (PEAR::isError($oDocument)) {
    print "FAILURE\n";
    var_dump($oDocument);
}
$res = KTDocumentUtil::storeContents($oDocument, new KTFSFileLike($sFilename));
if (PEAR::isError($res)) {
    print "FAILURE\n";
    var_dump($res);
    exit(0);
}
// storeContents can update storage_path and also status id
$oDocument->update();
if (file_exists($sFilename)) {
    unlink($sFilename);
}
예제 #2
0
 function &_add($oFolder, $sFilename, $oUser, $aOptions)
 {
     global $default;
     //$oContents = KTUtil::arrayGet($aOptions, 'contents');
     $aMetadata = KTUtil::arrayGet($aOptions, 'metadata', null, false);
     $oDocumentType = KTUtil::arrayGet($aOptions, 'documenttype');
     $sDescription = KTUtil::arrayGet($aOptions, 'description', '');
     if (empty($sDescription)) {
         // If no document name is provided use the filename minus the extension
         $aFile = pathinfo($sFilename);
         $sDescription = isset($aFile['filename']) && !empty($aFile['filename']) ? $aFile['filename'] : $sFilename;
     }
     $oUploadChannel =& KTUploadChannel::getSingleton();
     if ($oDocumentType) {
         $iDocumentTypeId = KTUtil::getId($oDocumentType);
     } else {
         $iDocumentTypeId = 1;
     }
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Creating database entry')));
     $oDocument =& Document::createFromArray(array('name' => $sDescription, 'description' => $sDescription, 'filename' => $sFilename, 'folderid' => $oFolder->getID(), 'creatorid' => $oUser->getID(), 'documenttypeid' => $iDocumentTypeId));
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Storing contents')));
     $res = KTDocumentUtil::storeContents($oDocument, '', $aOptions);
     if (PEAR::isError($res)) {
         if (!PEAR::isError($oDocument)) {
             $oDocument->delete();
         }
         return $res;
     }
     if (is_null($aMetadata)) {
         $res = KTDocumentUtil::setIncomplete($oDocument, 'metadata');
         if (PEAR::isError($res)) {
             $oDocument->delete();
             return $res;
         }
     } else {
         $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Saving metadata')));
         $res = KTDocumentUtil::saveMetadata($oDocument, $aMetadata, $aOptions);
         if (PEAR::isError($res)) {
             $oDocument->delete();
             return $res;
         }
     }
     // setIncomplete and storeContents may change the document's status or
     // storage_path, so now is the time to update
     $oDocument->update();
     return $oDocument;
 }