public function count_download($bnum, $type, $tracknum = NULL) { $couch = new couchClient($this->couchserver, $this->couchdatabase); try { $doc = $couch->getDoc($bnum); } catch (Exception $e) { return FALSE; } if ($tracknum) { if ($type == "play") { $count = $doc->tracks->{$tracknum}->plays ? $doc->tracks->{$tracknum}->plays : 0; $count++; $doc->tracks->{$tracknum}->plays = $count; } else { if ($type == "track") { $count = $doc->tracks->{$tracknum}->downloads ? $doc->tracks->{$tracknum}->downloads : 0; $count++; $doc->tracks->{$tracknum}->downloads = $count; } } } else { $key = "download_" . $type; $count = $doc->{$key} ? $doc->{$key} : 0; $count++; $doc->{$key} = $count; } $couch->storeDoc($doc); }
/** * Save a file * * @param File $file */ public function storeFile(File $file) { $document = $file->getDocument(); // save module data and id in document $module = $file->getModule(); $document->data = $module->getData(); $document->module = $this->moduleFactory->getMappedIdentifier($module); // store document in db $response = $this->client->storeDoc($document); $file->getDocument()->_rev = $response->rev; }
function recordActionViewed($resourceID, $dbgroup) { global $couchUrl; $resources = new couchClient($couchUrl, $dbgroup); $doc = $resources->getDoc($_GET['resid']); $doc->views = intval($doc->views) + 1; $resources->storeDoc($doc); }
*/ if (isset($_POST['title'])) { global $couchUrl; global $facilityId; $ttel_resources = new couchClient($couchUrl, "ttel_resources"); $doc = new stdClass(); $docType = end(explode(".", $_FILES['uploadedfile']['name'])); $doc->legacy = array("id" => "", "type" => strtolower($docType)); $doc->type = $_POST['resType']; $doc->kind = 'Resource'; $doc->language = $_POST['Language']; $doc->description = $_POST['discription']; $doc->title = $_POST['title']; $doc->author = $_POST['author']; $doc->created = date('Y-m-d'); $responce = $ttel_resources->storeDoc($doc); print_r($responce); try { // add attached to document with specified id from response $fileName = $responce->id . '.' . end(explode(".", $_FILES['uploadedfile']['name'])); $ttel_resources->storeAttachment($ttel_resources->getDoc($responce->id), $_FILES['uploadedfile']['tmp_name'], custom_mime_content_type($_FILES['uploadedfile']['tmp_name']), $fileName); ///$resources->storeAttachment($resources->getDoc($responce->id),$_FILES['uploadedfile']['tmp_name'], mime_content_type($_FILES['uploadedfile']['tmp_name'])); } catch (Exception $e) { print "No Resource to uploaded<br>"; } $resDoc = $ttel_resources->getDoc($responce->id); $resDoc->legacy->id = $responce->id; $ttel_resources->storeDoc($resDoc); /// recordAction($_SESSION['name'],"Uploaded resources... res title : ".$_POST['RTitle']); echo '<script type="text/javascript">alert("Successfully Uploaded ' . $_POST['title'] . '");</script>'; die("<br><br><br><br>Successfully saved - " . $_POST['title'] . "");
function set_monitor_status($server, $status) { $client = new couchClient('http://<hostname>:5984', 'watchcat_hosts'); $opts = array("key" => $server); $pre_doc = $client->setQueryParameters($opts)->getView('wc_hosts', 'by_hostname'); $doc = $client->getDoc($pre_doc->rows[0]->id); $doc->monitor_active = $status; try { $response = $client->storeDoc($doc); } catch (Exception $e) { echo "something weird happened: " . $e->getMessage() . "<BR>\n"; } var_dump($response); }
$doc->subject = $_POST['subject']; /*$doc->created=$_POST['systemDateForm'];*/ $audData = array(); foreach ($_POST['targetedAudience'] as $audience) { array_push($audData, $audience); } $doc->audience = $audData; /*$resLevels = array(); foreach($_POST['resLevel'] as $levels){ array_push($resLevels,$levels); } $doc->levels = $resLevels;*/ /*if($doc->type=="video lesson"){ $doc->questions= (object)array(); }*/ $responce = $resources->storeDoc($doc); print_r($responce); try { // add attached to document with specified id from response $fileName = $responce->id . '.' . end(explode(".", $_FILES['uploadedfile']['name'])); $resources->storeAttachment($resources->getDoc($responce->id), $_FILES['uploadedfile']['tmp_name'], mime_content_type($_FILES['uploadedfile']['tmp_name']), $fileName); } catch (Exception $e) { print "No Resource was uploaded<br>"; } $resDoc = $resources->getDoc($responce->id); $resDoc->legacy->id = $responce->id; $resources->storeDoc($resDoc); echo '<script type="text/javascript">alert("Successfully Uploaded ' . $_POST['title'] . '");</script>'; die('<span style="color:#FFF"><br><br><br><br>Successfully saved - ' . $_POST['title'] . '<br><br>' . $responce->id); } }
* The first step is to have a PHP object with properties being the document property. * * To store the document, we call the method $client->storeDoc($doc) * * Important : if the object got an _id property, it'll be the unique document id in the couchdb database. * If _id is not set, CouchDB will choose one for us. * */ echo "#### Storing a document\n"; $doc = new stdClass(); $doc->_id = "some_doc"; $doc->title = "Important documentation"; $doc->tags = array("documentation", "secret"); echo "Storing \$doc : \$client->storeDoc(\$doc)\n"; try { $response = $client->storeDoc($doc); } catch (Exception $e) { echo "Something weird happened: " . $e->getMessage() . " (errcode=" . $e->getCode() . ")\n"; exit(1); } echo "The document is stored. CouchDB response body: " . print_r($response, true) . "\n"; echo "#### Storing a document without _id property\n"; $doc = new stdClass(); $doc->title = "not really documentation"; $doc->tags = array("documentation", "fake"); echo "Storing \$doc : \$client->storeDoc(\$doc)\n"; try { $response = $client->storeDoc($doc); } catch (Exception $e) { echo "Something weird happened: " . $e->getMessage() . " (errcode=" . $e->getCode() . ")\n"; exit(1);
/** * Clear an erroneous cover image from the cache */ public function clear_covercache($bnum) { //$db = MDB2::connect($this->dsn); //$db->query("UPDATE locum_bib_items SET cover_img = '' WHERE bnum = " . $bnum); $couch = new couchClient($this->couchserver, $this->couchdatabase); try { $doc = $couch->getDoc((string) $bnum); } catch (Exception $e) { return FALSE; } unset($doc->cover_img); $couch->storeDoc($doc); }
/** * create a user * * @param string $login user login * @param string $password user password * @param array $roles add additionnal roles to the new user * @return stdClass CouchDB user creation response (the same as a document storage response) */ public function createUser($login, $password, $roles = array()) { $password = (string) $password; if (strlen($login) < 1) { throw new InvalidArgumentException("Login can't be empty"); } if (strlen($password) < 1) { throw new InvalidArgumentException("Password can't be empty"); } $user = new stdClass(); $user->salt = sha1(microtime() . mt_rand(1000000, 9999999), false); $user->password_sha = sha1($password . $user->salt, false); $user->name = $login; $user->type = "user"; $user->roles = $roles; $user->_id = "org.couchdb.user:" . $login; $client = new couchClient($this->client->dsn(), $this->userdb, $this->client->options()); return $client->storeDoc($user); }
} catch (Exception $e) { echo "Something weird happened: ".$e->getMessage()." (errcode=".$e->getCode().")\n"; exit(1); } print "Effacement en cours"; exit; } $obj = new stdClass(); $obj->_id="const"; try{ $obj = $couchdb->getDoc("const"); }catch(Exception $e) {} $obj->class="system"; $obj->values=$conf->global; //print_r($obj); //exit; try { print_r($couchdb->storeDoc($obj)); } catch (Exception $e) { $error = "Something weird happened: ".$e->getMessage()." (errcode=".$e->getCode().")\n"; dol_print_error("", $error); exit(1); } ?>
#!/usr/bin/php <?php /** * @file * Initialize the sphinx view. */ chdir('..'); require_once 'locum.php'; $locum = new locum(); $client = new couchClient($locum->couchserver, $locum->couchdatabase); // Create the view. try { $doc = $client->getDoc('_design/sphinx'); } catch (Exception $e) { if ($e->getCode() == 404) { // document doesn't exist. create a new one $doc = new stdClass(); $doc->_id = '_design/sphinx'; } else { var_dump($e); exit; } } $doc->views = new stdClass(); $doc->views->by_sphinxid = new stdClass(); $doc->views->by_sphinxid->map = "function(doc) { if (doc.bnum) { emit(doc.bnum, null); } }"; // Save view. $client->storeDoc($doc);
while (($file = readdir($handle)) !== false) { if (preg_match('/\.json$/i', $file)) { $fp = fopen($dir . $file, "r"); if ($fp) { $json = fread($fp, filesize($dir . $file)); $obj = json_decode($json); // Test if exist document in database : upgrade try { $result = $couchdb->getDoc($obj->_id); $obj->_rev = $result->_rev; } catch (Exception $e) { } $couchdb->storeDoc($obj); fclose($fp); } } } closedir($handle); } // Enable module User include_once($dolibarr_main_document_root . "/core/modules/modUser.class.php"); $module = new modUser($couchdb); $module->values->_id = "module:".$module->values->name;
include "lib/couch.php"; include "lib/couchClient.php"; include "lib/couchDocument.php"; if (isset($argv[2])) { //Display all available args //print_r($argv); $faci_ID = $argv[3]; $status = $argv[2]; $statusType = $argv[1]; $carrentStatus = new stdClass(); $carrentStatus->systemtime = date('Y-m-d H:i:s'); $carrentStatus->status = $status; $system = new couchClient($couchUrl, "system"); $doc = $system->getDoc($faci_ID); // get data from form and save it to couch $doc->kind = "Server_Status_Log"; $doc->lastUpdate = date('y-m-d'); if (!isset($doc->{$statusType})) { $doc->{$statusType} = array(); array_push($doc->{$statusType}, $carrentStatus); } else { if ($doc->{$statusType} != null) { array_push($doc->{$statusType}, $carrentStatus); } else { $doc->{$statusType} = array(); array_push($doc->{$statusType}, $carrentStatus); } } // save doc to couch and for responce->id $response = $system->storeDoc($doc); }
/** * Does the actual import of bib records. Called by the harvester. * It uses start and end parameters because this function can potentially be called by a * child process. * * @param int $start Bib number to start with * @param int $end Bib number to end with * @return array Array of information about the bibs imported */ public function import_bibs($start, $end, $force = TRUE) { if (is_callable(array(__CLASS__ . '_hook', __FUNCTION__))) { eval('$hook = new ' . __CLASS__ . '_hook;'); return $hook->{__FUNCTION__}($start, $end); } $db =& MDB2::connect($this->dsn); $couch = new couchClient($this->couchserver, $this->couchdatabase); $process_report['skipped'] = 0; $process_report['imported'] = 0; $utf = "SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'"; $utfprep = $db->query($utf); for ($i = $start; $i <= $end; $i++) { $sql = "SELECT * FROM locum_bib_items WHERE bnum = {$i}"; $init_result = $db->query($sql); $init_bib_arr = $init_result->fetchAll(MDB2_FETCHMODE_ASSOC); try { $doc = $couch->getDoc((string) $i); } catch (Exception $e) { if ($e->getCode() == 404) { // document doesn't exist. create a new one $doc = new stdClass(); $doc->_id = (string) $i; } else { // something probably wrong with the server. dump out $this->putlog("Problem with CouchDB server for record {$i}. " . $e->getCode()); exit(1); } } if ($doc->protected != 1) { $bib = $this->locum_cntl->scrape_bib($i, $this->locum_config['api_config']['skip_covers']); if ($bib == FALSE || $bib == 'skip' || $bib['suppress'] == 1) { if ($init_bib_arr) { $sql_prep =& $db->prepare('UPDATE locum_bib_items SET active = ? WHERE bnum = ?', array('text', 'integer')); $sql_prep->execute(array('0', $i)); } if ($doc->active) { $doc->active = 0; $couch->storeDoc($doc); require_once $this->locum_config['sphinx_config']['api_path'] . '/sphinxapi.php'; $cl = new SphinxClient(); $cl->SetServer($this->locum_config['sphinx_config']['server_addr'], (int) $this->locum_config['sphinx_config']['server_port']); $cl->UpdateAttributes("bib_items_keyword,bib_items_author,bib_items_title,bib_items_subject,bib_items_callnum,bib_items_tags,bib_items_reviews", array("active"), array($i => array(0))); $this->putlog("suppressed {$i}"); } $process_report['skipped']++; } else { if ($force || $doc->bib_lastupdate != $bib['bib_lastupdate']) { $subj = $bib['subjects']; $valid_vals = array('bib_created', 'bib_lastupdate', 'bib_prevupdate', 'bib_revs', 'lang', 'loc_code', 'mat_code', 'author', 'addl_author', 'title', 'title_medium', 'addl_title', 'edition', 'series', 'callnum', 'pub_info', 'pub_year', 'stdnum', 'upc', 'lccn', 'descr', 'notes', 'bnum', 'cover_img', 'non_romanized_title', 'non_romanized_author', 'genres', 'non_romanized_notes'); foreach ($bib as $bkey => $bval) { if (in_array($bkey, $valid_vals)) { if ($bval) { $doc->{$bkey} = $bval; } if (is_array($bval)) { if (count($bval) == 1) { $bval = $bval[0]; } else { $bval = serialize($bval); } } $bib_values[$bkey] = $bval; } } // unset items that are in couch but not mysql for now unset($bib_values['non_romanized_title']); unset($bib_values['non_romanized_author']); unset($bib_values['non_romanized_notes']); unset($bib_values['genres']); if ($init_bib_arr) { $bib_values['cover_img'] = $init_bib_arr[0]['cover_img']; } $bib_values['subjects_ser'] = serialize($subj); $types = array('date', 'date', 'date', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'text'); $sql_prep = $db->prepare('REPLACE INTO locum_bib_items VALUES (:bnum, :author, :addl_author, :title, :addl_title, :title_medium, :edition, :series, :callnum, :pub_info, :pub_year, :stdnum, :upc, :lccn, :descr, :notes, :subjects_ser, :lang, :loc_code, :mat_code, :cover_img, NOW(), :bib_created, :bib_lastupdate, :bib_prevupdate, :bib_revs, \'1\')'); $affrows = $sql_prep->execute($bib_values); $doc->subjects = $subj; $doc->active = 1; if ($doc->upc == '000000000000') { unset($doc->upc); } if (!$bib['pub_year']) { unset($doc->pub_year); } $couch->storeDoc($doc); $this->putlog("Importing bib # {$i} - {$bib['title']}"); $sql_prep->free(); /* if (is_array($subj) && count($subj)) { foreach ($subj as $subj_heading) { $insert_data = array($bib['bnum'], $subj_heading); $types = array('integer', 'text'); $sql_prep = $db->prepare('INSERT INTO locum_bib_items_subject VALUES (?, ?)', $types, MDB2_PREPARE_MANIP); $affrows = $sql_prep->execute($insert_data); $sql_prep->free(); } } */ $process_report['imported']++; } else { $process_report['skipped']++; $this->putlog("Skipping unchanged bib # {$i} - {$bib['title']}"); } } } } $db->disconnect(); return $process_report; }
if(doc.levels) { if(doc.roles=="student" && doc.status=="active" ){ for( var cnt=0; cnt<doc.levels.length; cnt++){ emit([doc.facilityId, doc.levels[cnt], doc.lastName],true); } } }}'), 'facilityLevelInactive_allStudent_sorted:' => array('map' => 'function(doc) { if(doc.levels) { if(doc.roles=="student" && doc.status=="inactive" ){ for( var cnt=0; cnt<doc.levels.length; cnt++){ emit([doc.facilityId, doc.levels[cnt], doc.lastName],true); } } } }')); $client->storeDoc($design_doc); // // // // //global $Assignments; //$Assignments = new couchClient($couchUrl, $dbNames['assignments']); //global $Members; //$Members = new couchClient($couchUrl, $dbNames['members']); //global $Actions; //$Actions = new couchClient($couchUrl, $dbNames['actions']); //global $Questions; //$Questions = new couchClient($couchUrl, $dbNames['questions']); //global $Feedback; //$Feedback = new couchClient($couchUrl, $dbNames['feedback']); //global $Groups;
$table = null; $head_title = null; $options = array('include_docs' => true, 'limit' => 99999, 'descending' => true); $response = $client->setQueryParameters($options); $get_posts = $response->getView('get_blog_posts', 'by_date'); $query_string = isset($_GET['action']) ? $_GET['action'] : null; switch ($query_string) { case 'edit': // update doc if (isset($_POST['update'])) { $get_doc = $client->getDoc($_GET['docid']); $get_doc->title = $_POST['title']; $get_doc->body = $_POST['body']; $get_doc->category = $_POST['category']; $d_res = (object) $get_doc; $client->storeDoc($d_res); header('Location:index.php'); } $doc = $client->getDoc($_GET['docid']); $head_title .= 'Edit'; $is_selected_hot = $doc->category === 'hot' ? 'selected="selected"' : ''; $is_selected_news = $doc->category === 'news' ? 'selected="selected"' : ''; $is_selected_tech = $doc->category === 'tech' ? 'selected="selected"' : ''; $table .= <<<table t\t<form method="post"> t\t<table border=1> t\t\t<tr> t\t\t\t<th>Title</th> t\t\t\t<td><input type="text" style="width:200px;" class="form" name="title" value="{$doc->title}"></td> t\t\t<tr> t\t\t<tr>