Beispiel #1
0
 public function getCount()
 {
     $items = new Dase_DBO_Item($this->db);
     $items->list_id = $this->id;
     $items->hidden = false;
     $this->count = $items->findCount();
     return $this->count;
 }
Beispiel #2
0
 public function getItems()
 {
     foreach ($this->getItemIds() as $item_id) {
         $item = new Dase_DBO_Item($this->db);
         $item->load($item_id);
         $this->items[] = $item;
     }
     return $this->items;
 }
Beispiel #3
0
 public function getItem()
 {
     if (!$this->item) {
         $item = new Dase_DBO_Item($this->db);
         $item->load($this->item_id);
         $this->item = $item;
     }
     return $this->item;
 }
Beispiel #4
0
 public static function getByTitle($db, $r, $title)
 {
     $item = new Dase_DBO_Item($db);
     $item->title = $title;
     if ($item->findOne()) {
         return $item->asArray($r);
     } else {
         return false;
     }
 }
Beispiel #5
0
 public function getSearchMd5($r)
 {
     $file = new Dase_DBO_MediaFile($this->db);
     $file->md5 = $r->get('q');
     $res = "files matching {$file->md5}\n";
     foreach ($file->find() as $mf) {
         $item = new Dase_DBO_Item($this->db);
         $item->load($mf->item_id);
         $res .= $item->getUrl($r->app_root) . "\n";
     }
     $r->renderResponse($res);
 }
Beispiel #6
0
 function getItem()
 {
     if (!$this->item) {
         $this->item = Dase_DBO_Item::get($this->db, $this->p_collection_ascii_id, $this->p_serial_number);
     }
     return $this->item;
 }
Beispiel #7
0
 public static function getByUnique($db, $unique)
 {
     $sections = explode('/', $unique);
     $sernum = array_pop($sections);
     $coll = array_pop($sections);
     //will return false if no such item
     return Dase_DBO_Item::get($db, $coll, $sernum);
 }
Beispiel #8
0
 protected function setup($r)
 {
     //do we really want to hit db w/ every request?
     $this->item = Dase_DBO_Item::get($this->db, $r->get('collection_ascii_id'), $r->get('serial_number'));
     if (!$this->item && 'put' != $r->method) {
         $r->renderError(404);
     }
     //all auth happens in individual methods
 }
Beispiel #9
0
 public function getItem($r)
 {
     $t = new Dase_Template($r, true);
     $item = Dase_DBO_Item::get($this->db, $r->get('coll_ascii'), $r->get('serial_number'));
     $json = $item->asJson($r->app_root);
     $php_data = json_decode($json, true);
     $t->assign('item', $php_data);
     $t->assign('coll_ascii', $r->get('coll_ascii'));
     $r->renderResponse($t->fetch('item.tpl'));
 }
Beispiel #10
0
 function getItem()
 {
     $item = new Dase_DBO_Item($this->db);
     if ($item->load($this->item_id)) {
         $item->getCollection();
         return $item;
     } else {
         if ($this->p_collection_ascii_id && $this->p_serial_number) {
             $item = Dase_DBO_Item::get($this->db, $this->p_collection_ascii_id, $this->p_serial_number);
             if ($item) {
                 $item->getCollection();
                 return $item;
             }
         }
     }
     return false;
 }
Beispiel #11
0
function scrubIndex($collection_ascii_id, $config, $db, $display = true)
{
    $solr_version = '2.2';
    $solr_base_url = $config->getSearch('solr_base_url');
    $solr_update_url = $solr_base_url . '/update';
    $j = 0;
    for ($i = 0; $i < 999999; $i++) {
        if (0 === $i % 100) {
            $solr_search_url = $solr_base_url . '/select/?q=c:' . $collection_ascii_id . '&version=' . $solr_version . '&rows=100&start=' . $i;
            list($http_code, $res) = Dase_Http::get($solr_search_url, null, null);
            $sx = simplexml_load_string($res);
            $num = 0;
            foreach ($sx->result as $result) {
                if (count($result->doc)) {
                    foreach ($result->doc as $doc) {
                        foreach ($doc->str as $str) {
                            if ('_id' == $str['name']) {
                                $j++;
                                if ($display) {
                                    print "START {$i} ({$j}) ";
                                }
                                $unique = (string) $str;
                                if (Dase_DBO_Item::getByUnique($db, $unique)) {
                                    if ($display) {
                                        print "FOUND {$unique}\n";
                                    }
                                } else {
                                    $num++;
                                    $delete_doc = '<delete><id>' . $unique . '</id></delete>';
                                    $resp = Dase_Http::post($solr_update_url, $delete_doc, null, null, 'text/xml');
                                    if ($display) {
                                        print "SCRUBBED {$unique}\n";
                                    }
                                }
                            }
                        }
                    }
                } else {
                    Dase_Http::post($solr_update_url, '<commit/>', null, null, 'text/xml');
                    return "scrubbed {$num} records";
                }
            }
        }
    }
}
Beispiel #12
0
 public function postToItemEditForm($r)
 {
     $item = new Dase_DBO_Item($this->db);
     $item->load($r->get('id'));
     $item->text = $r->get('text');
     $item->update();
     $list = $item->getList();
     $r->renderRedirect($list->uniq_id);
 }
Beispiel #13
0
 public function deleteMedia($r)
 {
     $item = Dase_DBO_Item::get($this->db, $this->collection_ascii_id, $this->serial_number);
     if (!$item) {
         $r->renderError(404, 'no such item');
     }
     if (!$this->user->can('write', $item)) {
         $r->renderError(401, 'cannot delete media in this item');
     }
     try {
         $item->deleteAdminValues();
         //move actual files to 'deleted' directory
         $item->deleteMedia(MEDIA_DIR);
     } catch (Exception $e) {
         Dase_Log::debug(LOG_FILE, 'media handler error: ' . $e->getMessage());
         $r->renderError(500, 'could not delete media (' . $e->getMessage() . ')');
     }
     $item->buildSearchIndex();
     $r->renderOk('deleted resource');
 }
Beispiel #14
0
 public function getItemsCount()
 {
     $i = new Dase_DBO_Item($this->db);
     $i->item_type_id = $this->id;
     return $i->findCount();
 }
Beispiel #15
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;
 }
Beispiel #16
0
 public function postToCart($r)
 {
     $u = $this->user;
     $u->expireDataCache($r->getCache());
     $tag = new Dase_DBO_Tag($this->db);
     $tag->dase_user_id = $u->id;
     $tag->type = 'cart';
     if ($tag->findOne()) {
         $tag_item = new Dase_DBO_TagItem($this->db);
         $item_uniq = str_replace($r->app_root . '/', '', $r->getBody());
         list($coll, $sernum) = explode('/', $item_uniq);
         //todo: compat
         $item = Dase_DBO_Item::get($this->db, $coll, $sernum);
         $tag_item->item_id = $item->id;
         $tag_item->p_collection_ascii_id = $coll;
         $tag_item->p_serial_number = $sernum;
         $tag_item->tag_id = $tag->id;
         $tag_item->updated = date(DATE_ATOM);
         $tag_item->sort_order = 99999;
         if ($tag_item->insert()) {
             //will not need this when we use item_unique:
             //writes are expensive ;-)
             //$tag_item->persist();
             $tag->updateItemCount();
             $r->renderResponse("added cart item {$tag_item->id}");
         } else {
             $r->renderResponse("add to cart failed");
         }
     } else {
         $r->renderResponse("no such cart");
     }
 }
<?php

include 'config.php';
$comms = new Dase_DBO_Comment($db);
foreach ($comms->find() as $c) {
    $item = new Dase_DBO_Item($db);
    $item->load($c->item_id);
    $item->comments_updated = $c->updated;
    $item->comments_count = $item->comment_count + 1;
    $item;
    $item->update();
}
$cs = new Dase_DBO_Collection($db);
$i = 0;
foreach ($cs->find() as $c) {
    print "\nworking on {$c->collection_name}\n\n";
    foreach ($c->getItems() as $item) {
        $i++;
        $item = clone $item;
        if (!$item->collection_name) {
            $item->collection_name = $c->collection_name;
            $type = $item->getItemType();
            $item->item_type_ascii_id = $type->ascii_id;
            $item->item_type_name = $type->name;
            $item->update();
        }
        print "\n{$i}";
    }
}
Beispiel #18
0
 private function _findUniqueName($name, $iter = 0)
 {
     if ($iter) {
         $checkname = $name . '_' . $iter;
     } else {
         $checkname = $name;
     }
     $item = new Dase_DBO_Item($this->db);
     $item->name = $checkname;
     if (!$item->findOne()) {
         return $checkname;
     } else {
         $iter++;
         return $this->_findUniqueName($name, $iter);
     }
 }
Beispiel #19
0
 function createNewItem($serial_number = null, $eid = null)
 {
     if (!$eid) {
         $eid = '_dase';
     }
     $item = new Dase_DBO_Item($this->db);
     $item->collection_id = $this->id;
     if ($serial_number) {
         $item->serial_number = $serial_number;
         if ($item->findOne()) {
             Dase_Log::info(LOG_FILE, "duplicate serial number: " . $serial_number);
             throw new Dase_Exception('duplicate serial number!');
             return;
         }
         $item->status = 'public';
         $item->item_type_id = 0;
         $item->item_type_ascii_id = 'default';
         $item->item_type_name = 'default';
         $item->created = date(DATE_ATOM);
         $item->updated = date(DATE_ATOM);
         $item->created_by_eid = $eid;
         $item->p_collection_ascii_id = $this->ascii_id;
         $item->p_remote_media_host = $this->remote_media_host;
         $item->collection_name = $this->collection_name;
         $item->insert();
         $this->updateItemCount();
         return $item;
     } else {
         $item->status = 'public';
         $item->item_type_id = 0;
         $item->item_type_ascii_id = 'default';
         $item->item_type_name = 'default';
         $item->created = date(DATE_ATOM);
         $item->created_by_eid = $eid;
         $item->p_collection_ascii_id = $this->ascii_id;
         $item->p_remote_media_host = $this->remote_media_host;
         $item->collection_name = $this->collection_name;
         $item->insert();
         //after move to mysql to avoid collisions w/ old sernums
         //replace first '0' w/ '1'
         //todo: better way to generate unique sernum.
         // (do NOT forget to enforce uniqueness in DB)
         //$item->serial_number = sprintf("%09d",$item->id);
         $item->serial_number = '1' . sprintf("%08d", $item->id);
         $item->updated = date(DATE_ATOM);
         $item->update();
         $this->updateItemCount();
         return $item;
     }
 }
Beispiel #20
0
 function addItemEntry(Dase_DBO_Item $item, $app_root)
 {
     $dom = new DOMDocument('1.0', 'utf-8');
     $xml = $item->asAtom($app_root);
     $xml = str_replace('{APP_ROOT}', $app_root, $xml);
     if ($xml) {
         $dom->loadXml($xml);
         $e = $dom->getElementsByTagNameNS(Dase_Atom::$ns['atom'], 'entry');
         $root = $e->item(0);
         $root = $this->dom->importNode($root, true);
         $entry = new Dase_Atom_Entry_Item($this->dom, $root);
         $this->_entries[] = $entry;
         return $entry;
     }
 }
Beispiel #21
0
 public function getDeleteItems($r)
 {
     $tpl = new Dase_Template($r);
     $items = new Dase_DBO_Item($this->db);
     $items->collection_id = $this->collection->id;
     $items->status = 'delete';
     $doomed = array();
     foreach ($items->find() as $item) {
         $doomed[] = $item->getUrl($r->app_root);
     }
     $tpl->assign('collection', $this->collection);
     $tpl->assign('doomed', $doomed);
     $r->renderResponse($tpl->fetch('manage/delete_items.tpl'));
 }
Beispiel #22
0
    print "updating user {$user->eid}\n";
    if ($update) {
        $user->update();
    }
}
$cms = new Dase_DBO_CollectionManager();
foreach ($cms->find() as $cm) {
    if ($cm->dase_user_eid != strtolower($cm->dase_user_eid)) {
        print "updating manager {$cm->dase_user_eid}\n";
        $cm->dase_user_eid = strtolower($cm->dase_user_eid);
        if ($update) {
            $cm->update();
        }
    }
}
$items = new Dase_DBO_Item();
foreach ($items->find() as $item) {
    if ($item->created_by_eid != strtolower($item->created_by_eid)) {
        print "updating item {$item->created_by_eid}\n";
        $item->created_by_eid = strtolower($item->created_by_eid);
        if ($update) {
            $item->update();
        }
    }
}
$vrhs = new Dase_DBO_ValueRevisionHistory();
foreach ($vrhs->find() as $vrh) {
    if ($vrh->dase_user_eid != strtolower($vrh->dase_user_eid)) {
        print "updating history {$vrh->dase_user_eid}\n";
        $vrh->dase_user_eid = strtolower($vrh->dase_user_eid);
        if ($update) {
Beispiel #23
0
 public function getItemsMarkedToBeDeletedUris($r)
 {
     $output = '';
     $items = new Dase_DBO_Item($this->db);
     $items->collection_id = $this->collection->id;
     $items->status = 'delete';
     foreach ($items->find() as $item) {
         $output .= $item->getUrl($r->app_root) . "\n";
     }
     $r->renderResponse($output);
 }
Beispiel #24
0
 function removeItem($item_unique, $update_count = false)
 {
     $tag_item = new Dase_DBO_TagItem($this->db);
     $tag_item->tag_id = $this->id;
     list($coll, $sernum) = explode('/', $item_unique);
     //todo: compat
     $item = Dase_DBO_Item::get($this->db, $coll, $sernum);
     $tag_item->item_id = $item->id;
     $tag_item->p_collection_ascii_id = $coll;
     $tag_item->p_serial_number = $sernum;
     if ($tag_item->findOne()) {
         $log_text = "removing {$item_unique} from set {$this->eid}/{$this->ascii_id}";
         Dase_Log::info(LOG_FILE, $log_text);
         $tag_item->delete();
         //this is too expensive when many items are being removed in one request
         if ($update_count) {
             $this->updateItemCount();
         }
     }
 }
Beispiel #25
0
 function getItem()
 {
     $item = new Dase_DBO_Item($this->db);
     $item->load($this->item_id);
     return $item;
 }