function addProg($prg, $fileid = '') { if (empty($fileid)) { // find a file to listen $fileid = $prg->selectFileToListen(); if (!$fileid) { raiseError("no_file_to_listen"); } } $file = new sotf_NodeObject("sotf_media_files", $fileid); if (!$prg->isLocal()) { raiseError("Currently you can listen only to programmes of local stations"); } if ($prg->get('published') != 't' || $file->get('stream_access') != 't') { raiseError("no_listen_access"); } // add jingle $station = $prg->getStation(); $jfile = $station->getJingle(); if ($jfile) { $this->add(array('path' => $jfile, 'jingle' => 1)); } // add program file $filepath = $prg->getFilePath($file); $this->add(array('path' => $filepath)); // temp: set title $this->name = urlencode($prg->get("title")); // save stats $prg->addStat($file->get('filename'), 'listens'); }
function createGenre($id, $english) { $o1 = new sotf_NodeObject("sotf_genres"); $o1->set('genre_id', $id); $o1->set('language', 'en'); $o1->set('name', $english); $o1->create(); }
function createRole($id, $english, $creator = 'f') { $o1 = new sotf_NodeObject("sotf_roles"); $o1->set('role_id', $id); $o1->set('creator', $creator); $o1->create(); $o2 = new sotf_NodeObject("sotf_role_names"); $o2->set('role_id', $id); $o2->set('language', 'en'); $o2->set('name', $english); $o2->create(); }
function addProg($prg, $fileid = '') { if (empty($fileid)) { // find a file to listen $fileid = $prg->selectFileToListen(); if (!$fileid) { raiseError("no_file_to_listen"); } } $file = new sotf_NodeObject("sotf_media_files", $fileid); if (!$prg->isLocal()) { $node = sotf_Node::getNodeById($file->getNodeId()); $path = $node->get('url') . "/listen.php?id=" . $prg->id . "&fileid=" . $file->id; $this->add(array('path' => $path, 'url' => $path)); return; } if ($prg->get('published') != 't' || $file->get('stream_access') != 't') { raiseError("no_listen_access"); } $filepath = $prg->getFilePath($file); $index = sotf_AudioCheck::getRequestIndex(new sotf_AudioFile($filepath)); debug("audio index", $index); if (!$index) { $index = '0'; } // add jingle for station (if exists) $station = $prg->getStation(); $jfile = $station->getJingle($index); if ($jfile) { $this->add(array('id' => $station->id, 'path' => $jfile, 'jingle' => 1, 'name' => 'station_jingle')); } // add jingle for series (if exists) $series = $prg->getSeries(); if ($series) { $jfile = $series->getJingle($index); if ($jfile) { $this->add(array('id' => $series->id, 'path' => $jfile, 'jingle' => 1, 'name' => 'series_jingle')); } } // add program file $filepath = $prg->getFilePath($file); $this->add(array('id' => $prg->id, 'path' => $filepath, 'name' => urlencode($prg->get('title')))); // temp: set title $title = $prg->get("title"); $title = preg_replace('/\\s+/', '_', $title); $this->name = urlencode($title); // save stats $prg->addStat($file->get('id'), 'listens'); }
function update() { parent::update(); if (parent::isLocal()) { $this->checkDirs(); $this->saveMetadataFile(); } }
} $x->update(); print "success"; } elseif ($name == "audiofilesd") { $x = new sotf_NodeObject("sotf_media_files", $id); if ($value == 'true') { $x->set('download_access', 'true'); } elseif ($value == 'false') { $x->set('download_access', 'false'); } else { print "<script type=\"text/javascript\" language=\"javascript1.1\">error();</script>"; } $x->update(); print "success"; } elseif ($name == "caption") { $x = new sotf_NodeObject("sotf_other_files", $id); $x->set('caption', addslashes($value)); $x->update(); print "success"; } elseif ($name == "addtree") { $vocabularies->addToTopic($id, $value); // doesnt work: print("<script type=\"text/javascript\">window.opener.opener.reload();</script>"); print "success"; } elseif ($name == "editorpub") { $x = new sotf_Programme($id); if ($value == 'true') { $x->publish(); } elseif ($value == 'false') { $x->withdraw(); } else { print "<script type=\"text/javascript\" language=\"javascript1.1\">error();</script>";
/** Imports genre translations from a text files into database */ function importGenres($lines, $language) { if (empty($lines)) { logError("importGenres: file is empty"); return; } reset($lines); while (list(, $line) = each($lines)) { if (preg_match('/^\\s*$/', $line) || preg_match('/^#/', $line)) { continue; } if (!preg_match('/^\\s*(\\d+)\\s+(.*)/', $line, $items)) { logError("bad line syntax: {$line}"); continue; } debug("genre item", $items); $id = $items[1]; $name = trim($items[2]); $o1 = new sotf_NodeObject("sotf_genres"); $o1->setID($o1->makeId(0, $o1->tablename, $id . $language)); $o1->set('genre_id', $id); $o1->set('language', $language); $o1->set('name', $name); $o1->create(); } }
function syncResponse($chunkInfo, $nodeData, $objects) { global $sotfVars; $timestamp = $this->db->getTimestampTz(); // save modified objects $updatedObjects = sotf_NodeObject::saveModifiedObjects($objects); debug("number of updatd objects", count($updatedObjects)); $remoteId = $this->get('node_id'); $currentStamp = $sotfVars->get('sync_stamp', 0); $lastSyncStamp = $this->lastSyncStamp(); $chunkInfo['old_stamp'] = $lastSyncStamp; $chunkInfo['current_stamp'] = $currentStamp; $count = sotf_NodeObject::countModifiedObjects($remoteId, $lastSyncStamp); if ($count > 0) { if ($chunkInfo['this_chunk'] == $chunkInfo['num_chunks']) { // last chunk: no limits $objectsPerPage = 1000000; } else { $objectsPerPage = ceil($count / $chunkInfo['num_chunks']); } $from = $objectsPerPage * ($chunkInfo['this_chunk'] - 1) + 1; debug("chunk info", $chunkInfo); // get new objects to send as reply $objects = sotf_NodeObject::getModifiedObjects($this->get('node_id'), $lastSyncStamp, $from, $objectsPerPage, $updatedObjects); } else { $objects = array(); } // save time of this sync $this->saveSyncStatus($timestamp, $currentStamp); return array($chunkInfo, $objects); }
/** Static: collects the objects to send to the neighbour node. */ function getModifiedObjects($remoteNode, $objectsPerPage) { global $db, $config, $repository; // an ordering in which objects should be retrieved because of foreign keys $tableOrder = $repository->tableOrder; // select objects to send to neighbour $result = $db->limitQuery("SELECT no.* FROM sotf_node_objects no, sotf_object_status os WHERE no.id = os.id AND no.node_id != '{$remoteNode}' AND os.node_id = '{$remoteNode}' ORDER BY strpos('{$tableOrder}', substring(no.id, 4, 2)), no.id", 0, $objectsPerPage); while (DB_OK === $result->fetchInto($row)) { $objects1[] = $row; } //debug("OBJECTS1", $objects1); // collect object data for selected objects $objects = array(); if (count($objects1) > 0) { reset($objects1); while (list(, $obj) = each($objects1)) { $tablename = $repository->getTable($obj['id']); if (empty($tablename)) { logError("No tablename found for ", $obj['id']); continue; } $data = $db->getRow("SELECT * FROM {$tablename} WHERE id = '" . $obj['id'] . "'"); // don't send occasional empty records if (count($data) > 1) { $obj['data'] = $data; $objects[] = $obj; debug("sending modified object", $obj['id']); //debug("", $obj); //if(is_array($data)) foreach($data as $k => $v) {if(is_null($v)) debug($k, "is_null"); if($v === NULL) debug($k, "is null"); } if ($tablename == 'sotf_blobs') { $size = $size + strlen($obj['data']['data']); debug("blobsize", $size); } } else { logError("DELETED object with empty fields", $obj['id']); $db->query("DELETE FROM sotf_node_objects WHERE id='" . $obj['id'] . "'"); } // delete from refresh table (will roll back if failed) sotf_NodeObject::removeFromRefreshTable($obj['id'], $remoteNode); // we cannot send too many blobs, it will result in memory allocation problems on the other side (but why??) if ($size >= 90000) { break; } } } //debug("OBJECTS__2", $objects); debug("sending " . count($objects) . " objects"); return $objects; }
if (!$prg->isLocal()) { raiseError("You can only edit programmes locally!"); } if ($prg->isVideoPrg()) { $video = true; } else { $video = false; } $converting = false; // admins or owners can change files checkPerm($id, 'change'); // delete link $delLink = sotf_Utils::getParameter('dellink'); $linkid = sotf_Utils::getParameter('linkid'); if ($delLink) { $link = new sotf_NodeObject("sotf_links", $linkid); $link->delete(); $page->redirect("editFiles.php?id={$id}#links"); exit; } // delete file $delFile = sotf_Utils::getParameter('delfile'); if ($delFile) { $prg->deleteFile($delFile); $page->redirect("editFiles.php?id={$id}#mfiles"); exit; } // generate output //$smarty->assign("OKURL",$okURL); if ($new) { $smarty->assign("NEW", 1);
$parent = sotf_Utils::getParameter('parent'); $name = sotf_Utils::getParameter('name'); $topic_id = sotf_Utils::getParameter('topic_id'); $topic_name = sotf_Utils::getParameter('topic_name'); $topic_counter = sotf_Utils::getParameter('topic_counter'); $find = sotf_Utils::getParameter('find'); $add = sotf_Utils::getParameter('add'); if ($name != "") { $x = new sotf_NodeObject("sotf_topic_tree_defs"); $x->set('supertopic', $parent); $x->set('name', $name); $x->create(); $id = $x->getID(); } if ($topic_name != "") { $x = new sotf_NodeObject("sotf_topics"); $x->set('topic_id', $topic_id); $x->set('language', "en"); $x->set('topic_name', $topic_name); $x->create(); $id = $x->getID(); print $id; } if ($topic_counter != "") { $x = new sotf_Object("sotf_topics_counter"); $x->set('topic_id', $topic_id); $x->set('number', $topic_counter); $x->create(); $id = $x->getID(); print $id; }
function processPortalEvent($event) { debug("processing event", $event); $progId = $event['prog_id']; if ($progId) { if ($this->looksLikeId($progId)) { $prg =& $this->getObject($progId); } if (!$prg) { debug("Invalid prog_id arrived in portal event", $progId); return -1; } } switch ($event['name']) { case 'programme_added': $obj = new sotf_NodeObject('sotf_prog_refs'); $obj->set('prog_id', $event['value']); $obj->set('url', $event['url']); $obj->find(); $obj->set('station_id', $prg->get('station_id')); $obj->set('start_date', $event['timestamp']); $obj->set('portal_name', $event['portal_name']); $obj->save(); break; case 'programme_deleted': $obj = new sotf_NodeObject('sotf_prog_refs'); $obj->set('prog_id', $event['value']); $obj->set('url', $event['url']); $obj->find(); if (!$obj->exists()) { debug("unknown prog ref arrives: " . $event['value'] . ' - ' . $event['url']); $obj->set('portal_name', $event['portal_name']); } $obj->set('station_id', $prg->get('station_id')); $obj->set('end_date', $event['timestamp']); //$obj->set('portal_name', $event['portal_name']); $obj->save(); break; case 'visit': $obj = new sotf_NodeObject('sotf_prog_refs'); $obj->set('prog_id', $event['value']['prog_id']); $obj->set('url', $event['url']); $obj->find(); if (!$obj->exists()) { // TODO: how can this happen? It happens too many times! debug("unknown prog ref arrives: " . $event['value']['prog_id'] . ' - ' . $event['url']); $obj->set('start_date', $event['timestamp']); $obj->set('portal_name', $event['portal_name']); } $obj->set('station_id', $prg->get('station_id')); $obj->set('visits', (int) $obj->get('visits') + 1); // TODO: count unique accesses $obj->save(); break; case 'page_impression': $obj = new sotf_NodeObject('sotf_portals'); $obj->set('url', $event['url']); $obj->find(); $obj->set('name', $event['portal_name']); $obj->set('page_impression', $event['value']); $obj->set('last_access', $event['timestamp']); $obj->save(); break; case 'portal_updated': $obj = new sotf_NodeObject('sotf_portals'); $obj->set('url', $event['url']); $obj->find(); $obj->set('name', $event['portal_name']); $obj->set('last_update', $event['timestamp']); $obj->save(); break; case 'users': $obj = new sotf_NodeObject('sotf_portals'); $obj->set('url', $event['url']); $obj->find(); if (!$obj->exists()) { $obj->set('name', $event['portal_name']); } $obj->set('last_update', $event['timestamp']); $obj->set('reg_users', $event['value']); if (!$obj->get('name') || !$obj->get('url')) { logError("Bad portal even teceived", implode(" | ", $event)); } else { $obj->save(); } break; case 'rating': // first save in prog_refs $obj = new sotf_NodeObject('sotf_prog_refs'); $obj->set('prog_id', $event['value']['prog_id']); $obj->set('url', $event['url']); $obj->find(); if (!$obj->exists()) { debug("unknown prog ref arrives: " . $event['url']); $obj->set('start_date', $event['timestamp']); $obj->set('portal_name', $event['portal_name']); } $obj->set('station_id', $prg->get('station_id')); $obj->set('rating', $event['value']['RATING_VALUE']); $obj->set('raters', $event['value']['RATING_COUNT']); $obj->save(); // TODO second, put into global rating database /* $rating = new sotf_Rating(); $id = $event['value']['prog_id']; $obj = & $this->getObject($id); if($obj->isLocal()) { $data = $event['value']; $rating->setRemoteRating($data); } else { logError("received rating for non-local object!"); } */ break; case 'comment': // first save in prog_refs $obj = new sotf_NodeObject('sotf_prog_refs'); $obj->set('prog_id', $event['value']['prog_id']); $obj->set('url', $event['url']); $obj->find(); if (!$obj->exists()) { logError("unknown prog ref arrives: " . $event['value']['prog_id'] . ' - ' . $event['url']); $obj->set('start_date', $event['timestamp']); $obj->set('portal_name', $event['portal_name']); } $obj->set('station_id', $prg->get('station_id')); $obj->set('comments', (int) $obj->get('comments') + 1); $obj->save(); // save comment $obj = new sotf_Object('sotf_comments'); $obj->set('prog_id', $event['value']['prog_id']); $obj->set('portal', $event['url']); $obj->set('entered', $event['timestamp']); $obj->set('comment_title', $event['value']['title']); $obj->set('comment_text', $event['value']['comment']); $obj->set('from_name', $event['value']['user_name']); $obj->set('from_email', $event['value']['email']); $obj->create(); // TODO forward to authors break; case 'query_added': //debug("query from portal", $event); //debug("query from portal", $event); case 'query_deleted': case 'file_uploaded': // silently ignored break; default: logError("unknown portal event: " . $event['name']); } }
$rights =& new sotf_NodeObject('sotf_rights', $rightId); $smarty->assign("START_TIME", $rights->get('start_time')); $smarty->assign("STOP_TIME", $rights->get('stop_time')); $smarty->assign("RIGHTS_TEXT", $rights->get('rights_text')); } else { $newRight = 1; $smarty->assign('NEW', 1); } if ($save) { $startTime = sotf_Utils::getParameter('start_time'); $stopTime = sotf_Utils::getParameter('stop_time'); $rightsText = sotf_Utils::getParameter('rights_text'); $fullProg = sotf_Utils::getParameter('fullprog'); // save if ($newRight) { $rights = new sotf_NodeObject("sotf_rights"); } if ($fullProg) { $rights->set('start_time', null); $rights->set('stop_time', null); } else { // check input params if (!is_int($startTime) || !is_int($stopTime)) { raiseError("not_integer"); } $rights->set('start_time', $startTime); $rights->set('stop_time', $stopTime); } $rights->set('rights_text', $rightsText); if ($newRight) { $rights->set('prog_id', $objectId);
function addChild($parent, $name, $topic_name = "", $lang = "en", $treeId = 2) { $x = new sotf_NodeObject("sotf_topic_tree_defs"); $x->set('supertopic', $parent); $x->set('name', $name); $x->set('tree_id', $treeId); $x->create(); $id = $x->getID(); if ($topic_name != "") { $y = new sotf_NodeObject("sotf_topics"); $y->set('topic_id', $id); $y->set('language', $lang); $y->set('topic_name', $topic_name); $y->create(); //print($id); } return $x->getID(); }
/** Creates a deletion record: used when a replicated object is deleted. */ function createDeletionRecord() { $dr = new sotf_NodeObject('sotf_deletions'); $dr->set('del_id', $this->id); $dr->create(); }
function putEvents($params) { global $config, $db, $repository; $events = xmlrpc_decoder($params->getParam(0)); foreach ($events as $event) { debug("PORTAL EVENT", $event); $progId = $event['prog_id']; if ($progId) { if ($repository->looksLikeId($progId)) { $prg =& $repository->getObject($progId); } if (!$prg) { debug("Invalid prog_id arrived in portal event", $progId); continue; } $nodeId = $prg->getNodeId(); //$nodeId = $repository->getNodeId($progId); if ($nodeId != $config['nodeId']) { // event for remote object sotf_NodeObject::createForwardObject('event', $event, $progId, $nodeId); continue; } } $repository->processPortalEvent($event); } $retval = xmlrpc_encoder(count($events)); return new xmlrpcresp($retval); }
$delrole = sotf_Utils::getParameter('delrole'); $roleid = sotf_Utils::getParameter('roleid'); if ($delrole) { $role = new sotf_NodeObject('sotf_object_roles', $roleid); $c = new sotf_Contact($role->get('contact_id')); $role->delete(); $msg = $page->getlocalizedWithParams("deleted_contact", $c->get('name')); $page->addStatusMsg($msg, false); $page->redirect("editMeta.php?id={$prgId}#roles"); exit; } // delete right $delright = sotf_Utils::getParameter('delright'); $rid = sotf_Utils::getParameter('rid'); if ($delright) { $right = new sotf_NodeObject('sotf_rights', $rid); $right->delete(); //$msg = $page->getlocalizedWithParams("deleted_", $c->get('name')); //$page->addStatusMsg($msg, false); $page->redirect("editMeta.php?id={$prgId}#rights"); exit; } // manage permissions $delperm = sotf_Utils::getParameter('delperm'); $username = sotf_Utils::getParameter('username'); if ($delperm) { $userid = $user->getUserid($username); if (empty($userid) || !is_numeric($userid)) { raiseError("Invalid username: {$username}"); } $permissions->delPermission($prg->id, $userid);
function delFromTopic($id) { global $db; // TODO: ha mar van, akkor ne adja hozza $obj = new sotf_NodeObject('sotf_prog_topics', $id); $topicId = $obj->get('topic_id'); $progId = $obj->get('prog_id'); $obj->delete(); $query = "UPDATE sotf_topics_counter SET number = number-1 WHERE topic_id = '" . $topicId . "'"; $result = $db->query($query); $query = "SELECT supertopic FROM sotf_topic_tree_defs WHERE id = '" . $topicId . "'"; $supertopic = $db->getOne($query); if (!$supertopic) { $supertopic = $topicId; } $query = "UPDATE sotf_topics_counter SET total = total-1 WHERE topic_id = '" . $supertopic . "'"; $result = $db->query($query); }
function updatePrgStats() { global $db, $repository; $id = $db->getOne("SELECT id FROM sotf_prog_stats WHERE prog_id='" . $this->get('prog_id') . "'"); if (!$id) { $obj = new sotf_NodeObject("sotf_prog_stats"); $obj->set('prog_id', $this->get('prog_id')); } else { $obj = $repository->getObject($id); } $obj->set('station_id', $this->get('station_id')); $obj->set('unique_visits', $this->get('unique_visits')); $obj->set('unique_listens', $this->get('unique_listens')); $obj->set('unique_downloads', $this->get('unique_downloads')); $prgId = $this->get('prog_id'); $data = $db->getRow("SELECT SUM(visits) as visits, SUM(listens) as listens, SUM(downloads) as downloads FROM sotf_stats WHERE prog_id='{$prgId}'"); $obj->set('visits', $data['visits']); $obj->set('listens', $data['listens']); $obj->set('downloads', $data['downloads']); $obj->save(); }
/** static: create contact record from metadata */ function importContact($contactData, $contactRole, $prgId, $stationId, $admins) { global $db, $permissions, $repository, $vocabularies, $config; $db->begin(); // find out what should go into the 'name' field if ($contactData['type'] == 'organisation') { $name = $contactData['organizationname']; } elseif ($contactData['type'] == 'individual') { $name = $contactData['firstname'] . ' ' . $contactData['lastname']; } else { logError("unknown type of contact: " . $contactData['type']); return null; } // if not exists, create new contact $id = sotf_Contact::findByNameLocal($name); if (!$id) { $contact = new sotf_Contact(); $status = $contact->create($name, $stationId); if (!$status) { //$page->addStatusMsg('contact_create_failed'); return null; } // add permissions for all station admins (??) while (list(, $adminId) = each($admins)) { $permissions->addPermission($contact->id, $adminId, 'admin'); } } else { $contact = $repository->getObject($id); } //debug("contactData", $contactData); // set/update contact data $contact->set('acronym', $contactData['organizationacronym']); $contact->set('alias', $contactData['alias']); $contact->set('url', $contactData['uri']); $contact->set('email', $contactData['email']); $contact->set('address', $contactData['address']); $contact->update(); // determine role if ($contactData['role']) { $language = 'eng'; // for now $rid = $vocabularies->getRoleId($contactData['role'], $language); if ($rid) { $contactRole = $rid; } } // create role if (!sotf_ComplexNodeObject::findRole($prgId, $contact->id, $contactRole)) { $role = new sotf_NodeObject("sotf_object_roles"); $role->set('object_id', $prgId); $role->set('contact_id', $contact->id); $role->set('role_id', $contactRole); $role->create(); } $db->commit(); // fetch logo from url and store if (!empty($contactData['logo'])) { $url = $contactData['logo']; if ($handle = @fopen($url, 'rb')) { $contents = ""; while (!feof($handle)) { $contents .= fread($handle, 8192); } /* do { $data = fread ($handle, 100000); if (strlen($data) == 0) { break; } //debug("received", strlen($data)); $contents .= $data; } while(0); */ fclose($handle); $tmpFile = tempnam($config['tmpDir'], 'logo_u'); debug("received logo from", $url); sotf_Utils::save($tmpFile, $contents); chmod($tmpFile, 0660); $contact->setIcon($tmpFile); unlink($tmpFile); } else { logError("Could not fetch icon from {$url}"); } } return $contact->id; }
$series->setWithParam('title'); $series->setWithParam('description'); $series->update(); } if ($finish || $finish2) { $page->redirect("closeAndRefresh.php?anchor=series"); } if ($save) { $page->redirect("editSeries.php?seriesid={$seriesid}"); } // manage roles $delrole = sotf_Utils::getParameter('delrole'); if ($delrole) { checkPerm($series->id, "change"); $roleid = sotf_Utils::getParameter('roleid'); $role = new sotf_NodeObject('sotf_object_roles', $roleid); $c = new sotf_Contact($role->get('contact_id')); $role->delete(); //$msg = $page->getlocalizedWithParams("deleted_contact", $c->get('name')); //$page->addStatusMsg($msg, false); $page->redirect("editSeries.php?seriesid={$seriesid}#roles"); exit; } // manage permissions $delperm = sotf_Utils::getParameter('delperm'); if ($delperm) { checkPerm($series->id, "authorize"); $username = sotf_Utils::getParameter('username'); $userid = $user->getUserid($username); if (empty($userid) || !is_numeric($userid)) { raiseError("Invalid username: {$username}");
if ($save) { if (!$roleSelected) { raiseError("No role selected!"); } // save if (is_object($role)) { $role->set('contact_id', $contactId); $role->set('role_id', $roleSelected); $role->update(); } else { if (sotf_ComplexNodeObject::findRole($objectId, $contactId, $roleSelected)) { // this role already exists $page->addStatusMsg("role_exists"); $page->redirectSelf(); } $role = new sotf_NodeObject("sotf_object_roles"); $role->set('object_id', $objectId); $role->set('contact_id', $contactId); $role->set('role_id', $roleSelected); $role->create(); } $page->redirect("closeAndRefresh.php?anchor=roles"); } // general data $obj =& $repository->getObject($objectId); $smarty->assign("OBJECT_ID", $objectId); $smarty->assign("STATION_ID", $obj->getStationId()); $smarty->assign("ROLE_ID", $roleId); $smarty->assign('ROLE_LIST', $vocabularies->getRoles()); if (!$scope) { $scope = 1;
function forwardResponse($chunkInfo, $objects) { global $db; $remoteId = $this->get('node_id'); // save modified objects $db->begin(true); $updatedObjects = sotf_NodeObject::saveForwardObjects($objects); // if db error: don't commit! $db->commit(); debug("number of processed forward objects", $updatedObjects); $replyInfo = array('received' => count($objects), 'updated' => $updatedObjects); if ($chunkInfo['objects_remaining'] == 0) { // last chunk, do something useful!! //temporarily taken out sotf_Object::doUpdates(); } return array($replyInfo); }
function syncResponse($chunkInfo, $objects) { global $db; if ($this->get('accept_incoming') != 't') { debug("node {$remoteId} is not allowed for incoming sync!"); return NULL; } $timestamp = $db->getTimestampTz(); $remoteId = $this->get('node_id'); // save modified objects $db->begin(true); // TODO: itt gaz van! ha nem sikerul egy objektumot elmenteni, akkor soha tobbe nem lesz neki elkuldve!!! $updatedObjects = sotf_NodeObject::saveModifiedObjects($objects, $remoteId); // if db error: don't commit! if (is_null($updatedObjects)) { return array(array('error' => "store object failed, sync aborted")); } $db->commit(); debug("number of updated objects", $updatedObjects); $replyInfo = array('received' => count($objects), 'updated' => $updatedObjects); if ($chunkInfo['objects_remaining'] == 0) { // last chunk, save node and neighbour stats $node = sotf_Node::getLocalNode(); $this->set('last_sync_in', $timestamp); $node->set('last_sync_in', $timestamp); // take out from pending nodes, update neighbour list if ($this->get('pending_url')) { $this->set('pending_url', ''); $node->set('neighbours', $this->getNeighbourString()); } $this->update(); $node->update(); //$replyInfo['node'] = $node->getAll(); } return array($replyInfo); }
$localNode->update(); $page->redirect("admin.php#network"); $page->logRequest(); exit; } // sync if (sotf_Utils::getParameter('sync')) { checkPerm('node', 'change'); // this can be long duty! set_time_limit(18000); // get neighbour object $nid = sotf_Utils::getParameter('nodeid'); $neighbour = sotf_Neighbour::getById($nid); // full sync? if (sotf_Utils::getParameter('full')) { sotf_NodeObject::newNodeInNetwork($nid); } // sync $neighbour->sync(true); if ($config['debug']) { echo "<h3>Sync completed.</h3>"; } else { $page->redirect("admin.php#network"); } $page->logRequest(); } // delete neighbour if (sotf_Utils::getParameter('delneighbour')) { checkPerm('node', 'change'); debug("delete neighbour", "!!"); $nid = sotf_Utils::getParameter('nodeid');
require "init.inc.php"; $id = sotf_Utils::getParameter('id'); $fileid = sotf_Utils::getParameter('fileid'); if (empty($id)) { raiseError("Missing parameters!"); } $prg = new sotf_Programme($id); if (empty($fileid)) { // find a file to listen $fileid = $prg->selectFileToListen(); if (!$fileid) { raiseError("no_file_to_listen"); } } $file = new sotf_NodeObject("sotf_media_files", $fileid); if (!$prg->isLocal()) { raiseError("Currently you can listen only to programmes of local stations"); } if ($prg->get('published') != 't' || $file->get('stream_access') != 't') { raiseError("no_listen_access"); } $filepath = $prg->getFilePath($file); $tmpfile = $tmpdir . "/{$id_}{$fileid}.m3u"; //$name = "$id_$fileid"; $name = "{$id_}" . time(); $url = 'http://' . $iceServer . ':' . $icePort . '/' . $name . "\n"; debug("file", $filepath); if (!is_file($filepath)) { raiseError("no_such_file"); }