示例#1
0
文件: create.php 项目: nemein/openpsa
 /**
  * This is what Datamanager calls to actually create a document
  */
 public function &dm2_create_callback(&$datamanager)
 {
     $document = new org_openpsa_documents_document_dba();
     $document->topic = $this->_request_data['directory']->id;
     $document->orgOpenpsaAccesstype = org_openpsa_core_acl::ACCESS_WGPRIVATE;
     if (!$document->create()) {
         debug_print_r('We operated on this object:', $document);
         throw new midcom_error("Failed to create a new document. Error: " . midcom_connection::get_error_string());
     }
     $this->_document = $document;
     return $document;
 }
示例#2
0
 public function testCRUD()
 {
     $user = $this->create_user(true);
     midcom::get('auth')->request_sudo('org.openpsa.documents');
     $topic = $this->create_object('org_openpsa_documents_directory', array('name' => 'TEST_' . __CLASS__ . time()));
     $document = new org_openpsa_documents_document_dba();
     $document->topic = $topic->id;
     $stat = $document->create();
     $this->assertTrue($stat);
     $this->register_object($document);
     $document->refresh();
     $this->assertEquals('Document #' . $document->id, $document->title);
     $this->assertEquals($user->id, $document->author);
     $stat = $document->update();
     $this->assertTrue($stat);
     $stat = $document->delete();
     $this->assertTrue($stat);
     midcom::get('auth')->drop_sudo();
 }
示例#3
0
 function backup_version()
 {
     // Instantiate the backup object
     $backup = new org_openpsa_documents_document_dba();
     $properties = $this->get_properties();
     // Copy current properties
     foreach ($properties as $key) {
         if ($key != 'guid' && $key != 'id' && $key != 'metadata') {
             $backup->{$key} = $this->{$key};
         }
     }
     $backup->nextVersion = $this->id;
     $stat = $backup->create();
     if (!$stat) {
         return $stat;
     }
     $backup = new org_openpsa_documents_document_dba($backup->id);
     // Copy parameters
     $params = $this->list_parameters();
     if ($params) {
         foreach ($params as $domain => $array) {
             foreach ($array as $name => $value) {
                 if ($name == 'identifier') {
                     $value = $identifier = md5(time() . $backup_attachment->name);
                 }
                 $backup->set_parameter($domain, $name, $value);
             }
         }
     }
     // Find the attachment
     $attachments = $this->list_attachments();
     if (!$attachments) {
         return $stat;
     }
     foreach ($attachments as $original_attachment) {
         $backup_attachment = $backup->create_attachment($original_attachment->name, $original_attachment->title, $original_attachment->mimetype);
         $original_handle = $original_attachment->open('r');
         if (!$backup_attachment || !$original_handle) {
             // Failed to copy the attachment, abort
             return $backup->delete();
         }
         // Copy the contents
         $backup_handle = $backup_attachment->open('w');
         while (!feof($original_handle)) {
             fwrite($backup_handle, fread($original_handle, 4096), 4096);
         }
         fclose($original_handle);
         // Copy attachment parameters
         $params = $original_attachment->list_parameters();
         if ($params) {
             foreach ($params as $domain => $array) {
                 foreach ($array as $name => $value) {
                     if ($name == 'identifier') {
                         $value = md5(time() . $backup_attachment->name);
                         $backup->set_parameter('midcom.helper.datamanager2.type.blobs', 'guids_document', $value . ":" . $backup_attachment->guid);
                     }
                     $backup_attachment->set_parameter($domain, $name, $value);
                 }
             }
         }
     }
     return true;
 }