Exemplo n.º 1
0
 function do_trytype()
 {
     $oForm = $this->form_changetype();
     $res = $oForm->validate();
     $data = $res['results'];
     $errors = $res['errors'];
     if (!empty($errors)) {
         $oForm->handleError();
     }
     $document_type = $data['type'];
     $doctypeid = $document_type->getId();
     // Get the current document type, fieldsets and metadata
     $iOldDocTypeID = $this->oDocument->getDocumentTypeID();
     $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $iOldDocTypeID);
     $mdlist = DocumentFieldLink::getByDocument($this->oDocument);
     $field_values = array();
     foreach ($mdlist as $oFieldLink) {
         $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue();
     }
     DBUtil::startTransaction();
     // Update the document with the new document type id
     $this->oDocument->startNewMetadataVersion($this->oUser);
     $this->oDocument->setDocumentTypeId($doctypeid);
     $res = $this->oDocument->update();
     if (PEAR::isError($res)) {
         DBUtil::rollback();
         return $res;
     }
     // Ensure all values for fieldsets common to both document types are retained
     $fs_ids = array();
     $doctype_fieldsets = KTFieldSet::getForDocumentType($doctypeid);
     foreach ($doctype_fieldsets as $fieldset) {
         $fs_ids[] = $fieldset->getId();
     }
     $MDPack = array();
     foreach ($fieldsets as $oFieldset) {
         if ($oFieldset->getIsGeneric() || in_array($oFieldset->getId(), $fs_ids)) {
             $fields = $oFieldset->getFields();
             foreach ($fields as $oField) {
                 $val = isset($field_values[$oField->getId()]) ? $field_values[$oField->getId()] : '';
                 if (!empty($val)) {
                     $MDPack[] = array($oField, $val);
                 }
             }
         }
     }
     $core_res = KTDocumentUtil::saveMetadata($this->oDocument, $MDPack, array('novalidate' => true));
     if (PEAR::isError($core_res)) {
         DBUtil::rollback();
         return $core_res;
     }
     DBUtil::commit();
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array("document" => $this->oDocument, "aOptions" => $MDPack);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
     }
     // Check if there are any dynamic conditions / permissions that need to be updated on the document
     // If there are dynamic conditions then update the permissions on the document
     // The dynamic condition test fails unless the changes exists in the DB therefore update permissions after committing the transaction.
     $iPermissionObjectId = $this->oDocument->getPermissionObjectID();
     $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId);
     if (!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)) {
         $res = KTPermissionUtil::updatePermissionLookup($this->oDocument);
     }
     $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. "), $data['type']->getName()));
 }
Exemplo n.º 2
0
 function &_in_add($oFolder, $sFilename, $oUser, $aOptions)
 {
     $aOrigOptions = $aOptions;
     $sFilename = KTDocumentUtil::getUniqueFilename($oFolder, $sFilename);
     $sName = KTUtil::arrayGet($aOptions, 'description', $sFilename);
     $sName = KTDocumentUtil::getUniqueDocumentName($oFolder, $sName);
     $aOptions['description'] = $sName;
     $oUploadChannel =& KTUploadChannel::getSingleton();
     $oUploadChannel->sendMessage(new KTUploadNewFile($sFilename));
     DBUtil::startTransaction();
     $oDocument =& KTDocumentUtil::_add($oFolder, $sFilename, $oUser, $aOptions);
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Document created')));
     if (PEAR::isError($oDocument)) {
         return $oDocument;
     }
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Scanning file')));
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'scan');
     $iTrigger = 0;
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $oTrigger->setDocument($oDocument);
         // $oUploadChannel->sendMessage(new KTUploadGenericMessage(sprintf(_kt("    (trigger %s)"), $sTrigger)));
         $ret = $oTrigger->scan();
         if (PEAR::isError($ret)) {
             $oDocument->delete();
             return $ret;
         }
     }
     // refresh the document object
     DBUtil::commit();
     $oDocument->clearAllCaches();
     // NEW SEARCH
     Indexer::index($oDocument);
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Creating transaction')));
     $aOptions = array('user' => $oUser);
     //create the document transaction record
     $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document created'), 'ktcore.transactions.create', $aOptions);
     $res = $oDocumentTransaction->create();
     if (PEAR::isError($res)) {
         $oDocument->delete();
         return $res;
     }
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Sending subscriptions')));
     // fire subscription alerts for the checked in document
     $oSubscriptionEvent = new SubscriptionEvent();
     $oFolder = Folder::get($oDocument->getFolderID());
     $oSubscriptionEvent->AddDocument($oDocument, $oFolder);
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('add', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array('document' => $oDocument, 'aOptions' => $aOrigOptions);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
     }
     // update document object with additional fields / data from the triggers
     $oDocument = Document::get($oDocument->iId);
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Checking permissions...')));
     // Check if there are any dynamic conditions / permissions that need to be updated on the document
     // If there are dynamic conditions then update the permissions on the document
     // The dynamic condition test fails unless the document exists in the DB therefore update permissions after committing the transaction.
     include_once KT_LIB_DIR . '/permissions/permissiondynamiccondition.inc.php';
     $iPermissionObjectId = $oFolder->getPermissionObjectID();
     $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId);
     if (!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)) {
         $res = KTPermissionUtil::updatePermissionLookup($oDocument);
     }
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('All done...')));
     return $oDocument;
 }