<?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 #2
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 #3
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 #4
0
 public function postToSwapFile($r)
 {
     $item = new Dase_DBO_Item($this->db);
     if (!$item->load($r->get('id'))) {
         $r->renderError(404);
     }
     if ($this->user->eid != $item->created_by && !$this->user->is_admin) {
         $r->renderError(401);
     }
     //@unlink($old_path);
     $file = $r->_files['uploaded_file'];
     if ($file && is_file($file['tmp_name'])) {
         $name = $file['name'];
         $path = $file['tmp_name'];
         $type = $file['type'];
         if (!is_uploaded_file($path)) {
             $r->renderError(400, 'no go upload');
         }
         if (!isset(Dase_File::$types_map[$type])) {
             $r->renderError(415, 'unsupported media type: ' . $type);
         }
         $base_dir = $this->config->getMediaDir();
         $old_path = $base_dir . '/' . $item->name;
         @unlink($old_path);
         //we won't worry about deleting old thumbnail
         if (!file_exists($base_dir) || !is_writeable($base_dir)) {
             $r->renderError(403, 'not allowed');
         }
         $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
         $basename = Dase_Util::dirify(pathinfo($name, PATHINFO_FILENAME));
         if ('application/pdf' == $type) {
             $ext = 'pdf';
         }
         if ('application/msword' == $type) {
             $ext = 'doc';
         }
         if ('application/vnd.openxmlformats-officedocument.wordprocessingml.document' == $type) {
             $ext = 'docx';
         }
         $newname = $this->_findNextUnique($base_dir, $basename, $ext);
         $new_path = $base_dir . '/' . $newname;
         //move file to new home
         rename($path, $new_path);
         chmod($new_path, 0775);
         $size = @getimagesize($new_path);
         //ONLY update name if item had file already
         //adding file to text item shouldn't change name
         if ($item->file_url) {
             $item->name = $newname;
         }
         if (!$item->title) {
             $item->title = $item->name;
         }
         $item->file_url = 'file/' . $newname;
         $item->filesize = filesize($new_path);
         $item->mime = $type;
         $parts = explode('/', $type);
         if (isset($parts[0]) && 'image' == $parts[0]) {
             $thumb_path = $base_dir . '/thumb/' . $newname;
             $thumb_path = str_replace('.' . $ext, '.jpg', $thumb_path);
             $command = CONVERT . " \"{$new_path}\" -format jpeg -resize '100x100 >' -colorspace RGB {$thumb_path}";
             $exec_output = array();
             $results = exec($command, $exec_output);
             if (!file_exists($thumb_path)) {
                 //Dase_Log::info(LOG_FILE,"failed to write $thumb_path");
             }
             chmod($thumb_path, 0775);
             $newname = str_replace('.' . $ext, '.jpg', $newname);
             $item->thumbnail_url = 'file/thumb/' . $newname;
         } else {
             $item->thumbnail_url = 'www/img/mime_icons/' . Dase_File::$types_map[$type]['size'] . '.png';
         }
         if (isset($size[0]) && $size[0]) {
             $item->width = $size[0];
         }
         if (isset($size[1]) && $size[1]) {
             $item->height = $size[1];
         }
     }
     $item->updated_by = $this->user->eid;
     $item->updated = date(DATE_ATOM);
     $item->update();
     $r->renderRedirect('item/' . $item->id);
 }