コード例 #1
0
 /** static: applies changes suggested by objects forwarded from other nodes. */
 function saveForwardObjects($objects)
 {
     global $repository;
     if (count($objects) > 0) {
         reset($objects);
         while (list(, $obj) = each($objects)) {
             debug("saving forward object", $obj);
             $data = $obj['data'];
             switch ($obj['type']) {
                 case 'stat':
                     sotf_Statistics::addRemoteStat($data);
                     $count++;
                     break;
                 case 'rating':
                     $rating = new sotf_Rating();
                     $rating->setRemoteRating($data);
                     $count++;
                     break;
                 case 'event':
                     $repository->processPortalEvent($data);
                     break;
                 default:
                     logError("Unknown forward object type: " . $obj['type']);
             }
         }
     }
     return $count;
 }
コード例 #2
0
 function recordStat($data, $update = false)
 {
     global $db, $repository, $sotfVars;
     $type = $data['type'];
     if ($type != 'listens' && $type != 'downloads' && $type != 'visits') {
         raiseError("addStat: type should be 'listens' or 'downloads' or 'visits'");
     }
     // update periodic stat
     $date = $data['date'];
     //debug("date", $db->getTimestampTz($date));
     $now = getdate($date);
     //debug("now", $now);
     $year = $now['year'];
     $month = $now['mon'];
     $day = $now['mday'];
     $week = date('W', $date);
     $prgId = $data['prog_id'];
     $fileId = $data['file'];
     $where = " WHERE prog_id='{$prgId}' AND year='{$year}' AND month='{$month}' AND day='{$day}' AND week='{$week}'";
     $prg = $repository->getObject($prgId);
     if (!$prg) {
         // don't raiseError("addStat: no such programme: $prgId");
         return null;
     }
     $db->begin();
     // to avoid deadlocks I try this:
     $db->query("LOCK TABLE sotf_stats, sotf_unique_access, sotf_to_update IN ROW EXCLUSIVE MODE");
     $id = $db->getOne("SELECT id FROM sotf_stats {$where}");
     if ($id) {
         $obj = new sotf_Statistics($id);
         $obj->set($type, $obj->get($type) + 1);
         // station may change!!
         $obj->set('station_id', $prg->get('station_id'));
     } else {
         $obj = new sotf_Statistics();
         $obj->setAll(array('prog_id' => $prgId, 'station_id' => $prg->get('station_id'), 'year' => $year, 'month' => $month, 'week' => $week, 'day' => $day, $type => 1));
     }
     if ($obj->exists()) {
         $obj->update();
     } else {
         $obj->create();
         //debug("obj1", $obj);
         $obj->find();
         // to get the id
         //debug("obj2", $obj);
     }
     // update uniqueness memory
     sotf_Statistics::addUniqueAccess($data['ip'], $prgId, $fileId, $type);
     // would be too often:
     if ($update) {
         $obj->updateStats(false);
     } else {
         sotf_Object::addToUpdate('sotf_stats', $obj->id);
     }
     $db->commit();
     return $obj;
 }
コード例 #3
0
ファイル: index.php プロジェクト: BackupTheBerlios/sotf-svn
 *          at MTA SZTAKI DSD, http://dsd.sztaki.hu
 */
require "init.inc.php";
require $config['classdir'] . "/sotf_AdvSearch.class.php";
if ($_REQUEST['select_station']) {
    $page->redirect($config['localPrefix'] . "/showStation.php/" . $_POST['station']);
}
$db->begin();
$data['numNodes'] = sotf_Node::countAll();
if ($data['numNodes'] == 0) {
    $data['numNodes'] = 1;
}
$data['numStations'] = sotf_Station::countAll();
$data['numProgs'] = sotf_Programme::countAll();
$data['numProgs'] = sotf_Programme::countAll();
$allStats = sotf_Statistics::networkStats();
$allStats['l_and_d'] = $allStats['listens'] + $allStats['downloads'];
$data['access'] = $allStats;
$fileStats = sotf_Programme::getFileStats();
$fileStats['size_mb'] = sprintf('%d', $fileStats['filesize'] / 1024 / 1024);
$fileStats['length_hour'] = sprintf('%d', $fileStats['play_length'] / 60 / 60);
$data['files'] = $fileStats;
$data['numUsers'] = sotf_User::countUsers();
$smarty->assign($data);
$smarty->assign('STATIONS', sotf_Station::listStationNames());
$searchLangs = $config['languages'];
array_unshift($searchLangs, "any_language");
for ($i = 0; $i < count($searchLangs); $i++) {
    $langNames[$i] = $page->getlocalized($searchLangs[$i]);
}
$smarty->assign('searchLangs', $searchLangs);
コード例 #4
0
 /** static */
 function doUpdates()
 {
     global $db, $repository;
     debug("object updates started");
     $list = $db->getAll("SELECT * FROM sotf_to_update");
     while (list(, $item) = each($list)) {
         $db->begin(true);
         $tablename = $item['tablename'];
         $rowId = $item['row_id'];
         debug("to_update", "{$tablename}, {$rowId}");
         switch ($tablename) {
             case 'ratingUpdate':
                 $rating = new sotf_Rating();
                 $rating->updateInstant($rowId);
                 break;
             case 'sotf_stats':
                 $obj = new sotf_Statistics($rowId);
                 if ($obj->exists()) {
                     $obj->updateStats();
                 }
                 break;
             case 'updateMeta':
                 $obj = $repository->getObject($rowId);
                 if (is_object($obj)) {
                     $obj->saveMetadataFile();
                 }
                 break;
             default:
                 logError("Unknown to_update type: " . $tablename);
         }
         $db->query("DELETE FROM sotf_to_update WHERE tablename='{$tablename}' AND row_id='{$rowId}'");
         $db->commit();
     }
     debug("object updates finished");
 }
コード例 #5
0
 function getStats()
 {
     return sotf_Statistics::getGlobalStats($this->id);
 }