Esempio n. 1
0
 public function postToCollection($r)
 {
     $c = Dase_DBO_Collection::get($this->db, $r->get('collection_ascii_id'));
     if (!$this->user->can('write', $c)) {
         $r->renderError(401, 'cannot post media to this collection');
     }
     //hand off to item handler
     try {
         $item_handler = new Dase_Handler_Item($this->db, $this->config);
         //allows us to dictate serial number
         $sernum = Dase_Util::makeSerialNumber($r->slug);
         $item_handler->item = $c->createNewItem($sernum, $this->user->eid);
         $item_handler->postToMedia($r);
     } catch (Exception $e) {
         $r->renderError(409, $e->getMessage());
     }
     //if something goes wrong and control returns here
     $r->renderError(500, 'error in post to collection');
 }
Esempio n. 2
0
 function insert($db, $r, $fetch_enclosure = false)
 {
     $user = $r->getUser('http');
     //allows service user to  override created_by_eid
     $author = $this->getAuthorName();
     if ($user->is_serviceuser && $author) {
         $created_by_eid = $author;
     } else {
         $created_by_eid = $user->eid;
     }
     $c = Dase_DBO_Collection::get($db, $r->get('collection_ascii_id'));
     if (!$c) {
         return;
     }
     $sn = Dase_Util::makeSerialNumber($r->slug);
     $item = $c->createNewItem($sn, $created_by_eid);
     foreach ($this->getMetadata() as $att => $keyval) {
         //creates atribute if it doesn't exist!
         Dase_DBO_Attribute::findOrCreate($db, $c->ascii_id, $att);
         foreach ($keyval['values'] as $v) {
             if (trim($v['text'])) {
                 $val = $item->setValue($att, $v['text'], null, $v['mod']);
             }
         }
     }
     foreach ($this->getMetadataLinks() as $att => $keyval) {
         Dase_DBO_Attribute::findOrCreate($db, $c->ascii_id, $att);
         foreach ($keyval['values'] as $v) {
             if (trim($v['text'])) {
                 //check that it's proper collection
                 if ($c->ascii_id = $v['coll']) {
                     //don't index just yet (the false param)
                     $val = $item->setValueLink($att, $v['text'], $v['url'], $v['mod'], false);
                 }
             }
         }
     }
     //item_type
     $item_type = $this->getItemType();
     if ($item_type['term']) {
         $item->setItemType($item_type['term']);
     }
     //content
     if ($this->getContent()) {
         $item->setContent($this->getContent(), $eid, $this->getContentType());
     }
     //$item->setValue('title',$this->getTitle());
     //$item->setValue('description',$this->getSummary());
     if ($fetch_enclosure) {
         $enc = $this->getEnclosure();
         if ($enc) {
             $upload_dir = MEDIA_DIR . '/' . $c->ascii_id . '/uploaded_files';
             if (!file_exists($upload_dir)) {
                 $r->renderError(401, 'missing upload directory');
             }
             $ext = Dase_File::$types_map[$enc['type']]['ext'];
             $new_file = $upload_dir . '/' . $item->serial_number . '.' . $ext;
             file_put_contents($new_file, file_get_contents($enc['href']));
             try {
                 $file = Dase_File::newFile($db, $new_file, $enc['mime_type']);
                 $media_file = $file->addToCollection($item, false, MEDIA_DIR);
             } catch (Exception $e) {
                 $r->renderError(500, 'could not ingest enclosure file (' . $e->getMessage() . ')');
             }
         }
     }
     //messy
     $item->expireCaches($r->getCache());
     $item->buildSearchIndex();
     return $item;
 }
Esempio n. 3
0
 private function _newJsonItem($r)
 {
     $user = $r->getUser('http');
     if (!$user->can('write', $this->collection)) {
         $r->renderError(401, 'no go unauthorized');
     }
     $json = $r->getBody();
     $client_md5 = $r->getHeader('Content-MD5');
     //if Content-MD5 header isn't set, we just won't check
     if ($client_md5 && md5($json) != $client_md5) {
         $r->renderError(412, 'md5 does not match');
     }
     $slug = $r->slug ? $r->slug : '';
     $sernum = Dase_Util::makeSerialNumber($slug);
     try {
         $item = $this->collection->createNewItem($sernum, $user->eid);
         $item_data = Dase_Json::toPhp($json);
         //item type
         if (isset($item_data['item_type'])) {
             $item->setItemType($item_data['item_type']);
         }
         $metadata = $item_data['metadata'];
         foreach ($metadata as $key => $vals) {
             foreach ($vals as $val) {
                 $item->setValue($key, $val);
             }
         }
         $item->buildSearchIndex();
         header("HTTP/1.1 201 Created");
         header("Content-Type: application/atom+xml;type=entry;charset='utf-8'");
         header("Location: " . $r->app_root . "/item/" . $r->get('collection_ascii_id') . "/" . $item->serial_number . '.atom');
         echo $item->asAtomEntry($r->app_root);
         exit;
     } catch (Dase_Exception $e) {
         $r->renderError(409, $e->getMessage());
     }
 }