示例#1
0
 function testDatabaseSelect()
 {
     $c = new Dase_Config(BASE_PATH);
     $c->load('inc/config.php');
     $c->load('inc/local_config.php');
     $db = new Dase_DB($c);
     $c = Dase_DBO_Collection::get($db, 'test');
     $this->assertTrue('Test Collection' == $c->collection_name);
 }
示例#2
0
 protected function setup($r)
 {
     $this->collection = Dase_DBO_Collection::get($this->db, $r->get('collection_ascii_id'));
     if (!$this->collection) {
         $r->renderError(404);
     }
     $this->user = $r->getUser();
     if (!$this->user->can('admin', $this->collection)) {
         $r->renderError(401);
     }
     //so proper menu item highlights
     $r->set('tab', $r->resource);
 }
示例#3
0
 public function setup($r)
 {
     if ($r->has('collection_ascii_id')) {
         $this->collection = Dase_DBO_Collection::get($this->db, $r->get('collection_ascii_id'));
     }
     if ($r->has('att_ascii_id') && $r->has('collection_ascii_id')) {
         $this->attribute = Dase_DBO_Attribute::get($this->db, $r->get('collection_ascii_id'), $r->get('att_ascii_id'));
     }
     if ($r->has('att_ascii_id') && !$r->has('collection_ascii_id')) {
         $this->attribute = Dase_DBO_Attribute::getAdmin($this->db, 'admin_' . $r->get('att_ascii_id'));
     }
     if (!$this->attribute) {
         $r->renderError('404');
     }
 }
示例#4
0
 public static function findOrCreate($db, $collection_ascii_id, $ascii_id)
 {
     $type = new Dase_DBO_ItemType($db);
     $coll = Dase_DBO_Collection::get($db, $collection_ascii_id);
     if (!$coll) {
         throw new Exception('no such collection');
     }
     $type->collection_id = $coll->id;
     $type->ascii_id = Dase_Util::dirify($ascii_id);
     if (!$type->findOne()) {
         $type->name = ucwords(str_replace('_', ' ', $ascii_id));
         $type->insert();
     }
     return $type;
 }
示例#5
0
 public function getList($r)
 {
     $t = new Dase_Template($r, true);
     $c = Dase_DBO_Collection::get($this->db, $r->get('coll_ascii'));
     if (!$c) {
         $r->renderError('404');
     }
     if ('public' != $c->visibility) {
         $r->renderError('401');
     }
     $url = 'https://dase.laits.utexas.edu/collection/' . $c->ascii_id . '/items.json';
     $json = file_get_contents($url);
     $php_data = json_decode($json, true);
     $t->assign('c', $c);
     $t->assign('items', $php_data['items']);
     $r->renderResponse($t->fetch('index.tpl'));
 }
示例#6
0
 function ingest($db, $r, $fetch_enclosures = false)
 {
     $user = $r->getUser();
     $coll_ascii_id = $this->getAsciiId();
     $count = $this->getItemCount();
     $collection_name = $this->getTitle();
     $ascii_id = $this->getAsciiId();
     $c = new Dase_DBO_Collection($db);
     $c->collection_name = $collection_name;
     if (Dase_DBO_Collection::get($db, $ascii_id) || $c->findOne()) {
         //$r->renderError(409,'collection already exists');
         Dase_Log::info(LOG_FILE, 'collection exists ' . $c->collection_name);
         return;
     }
     $c->ascii_id = $ascii_id;
     $c->is_public = 0;
     $c->created = date(DATE_ATOM);
     $c->updated = date(DATE_ATOM);
     if ($c->insert()) {
         $cache = $r->getCache();
         $cache->expire('app_data');
         Dase_Log::info(LOG_FILE, 'created collection ' . $c->collection_name);
         $coll_media_dir = MEDIA_DIR . '/' . $ascii_id;
         if (file_exists($coll_media_dir)) {
             //$r->renderError(409,'collection media archive exists');
             Dase_Log::info(LOG_FILE, 'collection media archive exists');
         } else {
             if (mkdir("{$coll_media_dir}")) {
                 chmod("{$coll_media_dir}", 0775);
                 foreach (Dase_Media::$sizes as $size => $access_level) {
                     mkdir("{$coll_media_dir}/{$size}");
                     Dase_Log::info(LOG_FILE, 'created directory ' . $coll_media_dir . '/' . $size);
                     chmod("{$coll_media_dir}/{$size}", 0775);
                 }
                 //todo: compat only!
                 symlink($coll_media_dir, $coll_media_dir . '_collection');
             }
         }
         foreach ($this->getEntries() as $entry) {
             if ('item' == $entry->getEntryType()) {
                 $r->set('collection_ascii_id', $c->ascii_id);
                 $entry->insert($db, $r, $fetch_enclosures);
             }
         }
     }
 }
示例#7
0
 protected function setup($r)
 {
     $this->collection = Dase_DBO_Collection::get($this->db, $r->get('collection_ascii_id'));
     if (!$this->collection) {
         $r->renderError(404);
     }
     if ('html' == $r->format && 'service' != $r->resource && 'ping' != $r->resource) {
         $this->user = $r->getUser();
         if (!$this->user->can('read', $this->collection)) {
             $r->renderError(401);
         }
     }
     /* todo: i guess anyone can read?
     		if ('atom' == $r->format) {
     			$this->user = $r->getUser('http');
     			if (!$this->user->can('read',$this->collection)) {
     			$r->renderError(401);
     			}
     		}
     		 */
 }
示例#8
0
 public function postToCollections($r)
 {
     $user = $r->getUser('http');
     if (!$user->is_superuser) {
         $r->renderError(401, $user->eid . ' is not permitted to create a collection');
     }
     $content_type = $r->getContentType();
     if ('application/atom+xml;type=entry' == $content_type || 'application/atom+xml' == $content_type) {
         $raw_input = $r->getBody();
         $client_md5 = $r->getHeader('Content-MD5');
         if ($client_md5 && md5($raw_input) != $client_md5) {
             //todo: fix this
             //$r->renderError(412,'md5 does not match');
         }
         try {
             $coll_entry = Dase_Atom_Entry::load($raw_input);
         } catch (Exception $e) {
             Dase_Log::debug(LOG_FILE, 'colls handler error: ' . $e->getMessage());
             $r->renderError(400, 'bad xml');
         }
         if ('collection' != $coll_entry->entrytype) {
             $r->renderError(400, 'must be a collection entry');
         }
         if ($r->slug) {
             $r->set('ascii_id', Dase_Util::dirify($r->slug));
         }
         $ascii_id = $coll_entry->create($this->db, $r);
         $user->expireDataCache($r->getCache());
         header("HTTP/1.1 201 Created");
         header("Content-Type: application/atom+xml;type=entry;charset='utf-8'");
         header("Location: " . $r->app_root . "/collection/" . $ascii_id . '.atom');
         echo Dase_DBO_Collection::get($this->db, $ascii_id)->asAtomEntry($r->app_root);
         exit;
     } else {
         $r->renderError(415, 'cannoot accept ' . $content_type);
     }
 }
示例#9
0
 public function isBulkEditable($user)
 {
     $prefix = $this->db->table_prefix;
     $dbh = $this->db->getDbh();
     $sql = "\n\t\t\tSELECT p_collection_ascii_id \n\t\t\tFROM {$prefix}tag_item \n\t\t\twhere tag_id = ?\n\t\t\tGROUP BY p_collection_ascii_id\n\t\t\t";
     $st = $dbh->prepare($sql);
     $st->execute(array($this->id));
     $colls = $st->fetchAll();
     if (1 === count($colls) && $colls[0]['p_collection_ascii_id']) {
         $c = Dase_DBO_Collection::get($this->db, $colls[0]['p_collection_ascii_id']);
         if ($c && $user->can('write', $c)) {
             return true;
         }
     }
     return false;
 }
示例#10
0
 public function getRecentUploadsJson($r)
 {
     //todo: implement http authorization!
     $coll = $r->get('collection_ascii_id');
     $items = new Dase_DBO_Item($this->db);
     $items->created_by_eid = $this->user->eid;
     $items->collection_id = Dase_DBO_Collection::get($this->db, $coll)->id;
     $items->orderBy('created DESC');
     if ($r->has('limit')) {
         $limit = $r->get('limit');
     } else {
         $limit = 50;
     }
     $items->setLimit($limit);
     $recent = array();
     foreach ($items->find() as $item) {
         $item = clone $item;
         $recent['a' . $item->serial_number]['title'] = $item->getTitle();
         $recent['a' . $item->serial_number]['thumbnail_href'] = $item->getMediaUrl('thumbnail', $r->app_root);
         $recent['a' . $item->serial_number]['item_record_href'] = $item->getUrl($r->app_root);
     }
     $r->renderResponse(Dase_Json::get($recent));
 }
示例#11
0
 function addLinks($db, $r)
 {
     $eid = $r->getUser()->eid;
     $sernum = $this->getSerialNumber();
     $c = Dase_DBO_Collection::get($db, $r->get('collection_ascii_id'));
     if (!$c) {
         return;
     }
     $item = Dase_DBO_Item::get($db, $c->ascii_id, $sernum);
     if (!$item) {
         return;
     }
     $item->updated = date(DATE_ATOM);
     $item->update();
     foreach ($this->getMetadataLinks() as $att => $keyval) {
         foreach ($keyval['values'] as $v) {
             if (trim($v['text'])) {
                 //check that it's proper collection
                 if ($c->ascii_id = $v['coll']) {
                     $val = $item->setValueLink($att, $v['text'], $v['url'], $v['mod']);
                 }
             }
         }
     }
     $item->buildSearchIndex();
     return $item;
 }
示例#12
0
<?php

include 'config.php';
$source = 'asian_studies';
$target = 'pkeane';
$c = Dase_DBO_Collection::get($db, $source);
foreach ($c->getItems() as $item) {
    $json_doc = $item->buildJson('http://dase.laits.utexas.edu');
    //print_r(json_decode($json_doc));
    $target_url = 'https://daseupload.laits.utexas.edu/collection/' . $target . '/ingester';
    print $target_url . "\n";
    $res = Dase_Http::post($target_url, $json_doc, 'pkeane', 'dupload', 'application/json');
    print_r($res);
}
示例#13
0
if ($limit) {
    print "\nCurrently set to index most recent {$limit} items\n";
}
$cs = new Dase_DBO_Collection($db);
$cs->orderBy('id DESC');
foreach ($cs->find() as $c) {
    $c = clone $c;
    $colls[] = $c->ascii_id;
}
//can enter collections on command line
if (isset($argv[1])) {
    array_shift($argv);
    $colls = $argv;
}
$engine = new Dase_Solr($db, $config);
$i = 0;
foreach ($colls as $coll) {
    $c = Dase_DBO_Collection::get($db, $coll);
    if ($c) {
        foreach ($c->getItems($limit) as $item) {
            $i++;
            $item = clone $item;
            print $c->collection_name . ':' . $item->serial_number . ':' . $item->buildSearchIndex(false, false);
            print " {$i}\n";
            print " memory: " . memory_get_usage() . "\n";
        }
        print "\ncommitting indexes for {$c->collection_name} ";
        $engine->commit();
        print "...done\n\n";
    }
}
示例#14
0
 /** for now, PUT of a collection entry can only add, NOT delete item_types & attributes */
 function update($db, $r)
 {
     $coll = $this->getAsciiId();
     foreach ($this->getAttributes() as $att) {
         Dase_DBO_Attribute::findOrCreate($db, $coll, $att['term']);
     }
     foreach ($this->getItemTypes() as $type) {
         Dase_DBO_ItemType::findOrCreate($db, $coll, $type['term']);
     }
     $coll = Dase_DBO_Collection::get($db, $coll);
     $coll->updateVisibility($this->getVisibility());
     $r->renderResponse('updated collection');
 }
示例#15
0
 public function putItem($r)
 {
     $user = $r->getUser('http');
     if ($this->item && !$user->can('write', $this->item)) {
         $r->renderError(401, 'cannot update item');
     }
     if (!$this->item) {
         $collection = Dase_DBO_Collection::get($this->db, $r->get('collection_ascii_id'));
         if (!$user->can('write', $collection)) {
             $r->renderError(401, 'cannot update collection');
         }
     }
     //just in case, save a copy in 'deleted' media dir
     if ($this->item) {
         $this->item->saveCopy(MEDIA_DIR);
     }
     $content_type = $r->getContentType();
     if ('application/atom+xml;type=entry' == $content_type || 'application/atom+xml' == $content_type) {
         $raw_input = $r->getBody();
         $client_md5 = $r->getHeader('Content-MD5');
         //if Content-MD5 header isn't set, we just won't check
         if ($client_md5 && md5($raw_input) != $client_md5) {
             $r->renderError(412, 'md5 does not match');
         }
         try {
             $item_entry = Dase_Atom_Entry::load($raw_input, 'item');
         } catch (Exception $e) {
             Dase_Log::debug(LOG_FILE, 'item handler error: ' . $e->getMessage());
             $r->renderError(400, 'bad xml');
         }
         if ('item' != $item_entry->entrytype) {
             //$item_entry->setEntryType('item');
             $r->renderError(400, 'must be an item entry');
         }
         $item = $item_entry->update($this->db, $r);
         if ($item) {
             $r->renderOk('item has been updated');
         } else {
             $r->renderError(500, 'item not updated');
         }
     } elseif ('application/json' == $content_type) {
         if (!$this->item) {
             $this->item = $collection->createNewItem($r->get('serial_number'));
         }
         //todo: this only updates metadata, does nothing to media (prob OK)
         $item_data = Dase_Json::toPhp($r->getBody());
         if (isset($item_data['metadata']) && count($item_data['metadata'])) {
             $this->item->deleteValues();
             //todo WILL this mess up VRC module??
             //metadata
             if (isset($item_data['metadata_extended'])) {
                 foreach ($item_data['metadata_extended'] as $key => $vals) {
                     foreach ($vals['values'] as $val) {
                         $text = $val['text'];
                         if (isset($val['modifier'])) {
                             $mod = $val['modifier'];
                         } else {
                             $mod = '';
                         }
                         if (isset($val['url'])) {
                             $url = $val['url'];
                         } else {
                             $url = '';
                         }
                         $this->item->setValue($key, $text, $url, $mod);
                     }
                 }
             } else {
                 foreach ($item_data['metadata'] as $key => $vals) {
                     foreach ($vals as $val) {
                         $this->item->setValue($key, $val);
                     }
                 }
             }
             $this->item->buildSearchIndex();
             $r->renderOk('item has been updated');
         }
         $r->renderError(400, 'must be a json item');
     } else {
         $r->renderError(415, 'cannot accept ' . $content_type);
     }
     $r->renderError(500, 'something went wrong');
 }
示例#16
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');
 }
示例#17
0
<?php

include 'config.php';
$c = Dase_DBO_Collection::get($db, 'cola_images');
$c = Dase_DBO_Collection::get($db, 'pkeane');
foreach ($c->getItems() as $item) {
    $item = clone $item;
    foreach ($item->getValues() as $v) {
        $v = clone $v;
        if (strpos($v->value_text, " ©")) {
            print $v->value_text . "\n";
            $v->value_text = str_replace(" ©", ' copyright', $v->value_text);
            $v->update();
            //$item->buildSearchIndex();
        }
    }
}
$c->buildSearchIndex('');
<?php

include 'config.php';
$c = Dase_DBO_Collection::get($db, 'keanepj');
$i = 0;
foreach ($c->getItems() as $item) {
    $item = clone $item;
    $item->p_collection_ascii_id = $c->ascii_id;
    $item->collection_name = $c->collection_name;
    $item->p_remote_media_host = $c->remote_media_host;
    if ($item->update()) {
        $i++;
    }
}
print "updated {$i} items in {$c->collection_name}\n";
<?php

include 'config.php';
//this script replaces characters which are valid utf8
//but invalid in XML (there are just a few)
$ascii_id = 'cumbojd';
$c = Dase_DBO_Collection::get($db, $ascii_id);
foreach ($c->getItems() as $item) {
    $item = clone $item;
    print "working\n";
    $item->deleteDocs();
    $item->storeDoc();
    foreach ($item->getValues() as $value) {
        $str = $value->value_text;
        //		print $str."\n";
        if ($str != strip_invalid_xml_chars2($str)) {
            $value->value_text = strip_invalid_xml_chars2($str);
            $value->update();
            print "updated item {$item->serial_number}\n";
        }
    }
}
function strip_invalid_xml_chars2($in)
{
    $out = "";
    $length = strlen($in);
    for ($i = 0; $i < $length; $i++) {
        $current = ord($in[$i]);
        if ($current == 0x9 || $current == 0xa || $current == 0xd || $current >= 0x20 && $current <= 0xd7ff || $current >= 0xe000 && $current <= 0xfffd || $current >= 0x10000 && $current <= 0x10ffff) {
            $out .= chr($current);
        } else {
示例#20
0
 function getDisplayValues($coll = null, $limit = 1000)
 {
     if (!$limit || !is_int($limit)) {
         $limit = 10000;
     }
     $prefix = $this->db->table_prefix;
     $dbh = $this->db->getDbh();
     $admin_sql = '';
     //presence of collection_id says it is an admin att
     if ($coll) {
         $c = Dase_DBO_Collection::get($this->db, $coll);
         $sql = "\n\t\t\t\tSELECT value_text, count(value_text)\n\t\t\t\tFROM {$prefix}value, {$prefix}item\n\t\t\t\tWHERE value. attribute_id = ?\n\t\t\t\tAND value.item_id = item.id\n\t\t\t\tAND item.collection_id = ?\n\t\t\t\tGROUP BY value_text\n\t\t\t\tORDER BY value_text\n\t\t\t\tLIMIT {$limit} \n\t\t\t";
         $st = $dbh->prepare($sql);
         $st->execute(array($this->id, $c->id));
     } else {
         $sql = "\n\t\t\t\tSELECT value_text, count(value_text)\n\t\t\t\tFROM {$prefix}value\n\t\t\t\tWHERE attribute_id = ?\n\t\t\t\tGROUP BY value_text\n\t\t\t\tORDER BY value_text\n\t\t\t\tLIMIT {$limit} \n\t\t\t";
         $st = $dbh->prepare($sql);
         $st->execute(array($this->id));
     }
     $display_values_array = array();
     while ($row = $st->fetch()) {
         //returns value and count (tally)
         $display_values_array[] = array('v' => $row[0], 't' => $row[1]);
     }
     //print_r($st->errorInfo()); exit;
     $this->display_values = $display_values_array;
     return $display_values_array;
 }