Exemple #1
0
 public function testCompress()
 {
     $GLOBALS['_PX_config']['cache_apc_compress'] = true;
     $cache = Pluf_Cache::factory();
     $success = $cache->set('compressed', $this->_arrayData);
     $this->assertTrue($success);
     $this->assertCopy($this->_arrayData, $cache->get('compressed'));
 }
Exemple #2
0
 public function testSerialized()
 {
     $cache = Pluf_Cache::factory();
     $success = $cache->set('array', $this->_arrayData);
     $this->assertTrue($success);
     $this->assertCopy($this->_arrayData, $cache->get('array'));
     $obj = new stdClass();
     $obj->foo = 'bar';
     $obj->hello = 'world';
     $success = $cache->set('object', $obj);
     $this->assertTrue($success);
     $this->assertCopy($obj, $cache->get('object'));
     unset($obj);
     $this->assertIsA($cache->get('object'), 'stdClass');
     $this->assertEqual('world', $cache->get('object')->hello);
 }
Exemple #3
0
 public function tree($request, $match)
 {
     $scm = IDF_Scm::get($request->project);
     $commit = $match[2];
     if (!$scm->isAvailable()) {
         $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::help', array($request->project->shortname));
         return new Pluf_HTTP_Response_Redirect($url);
     }
     $fburl = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase', array($request->project->shortname, $scm->getMainBranch()));
     $request_file = $match[3];
     if (substr($request_file, -1) == '/') {
         $request_file = substr($request_file, 0, -1);
         $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::tree', array($match[1], $match[2], $request_file));
         return new Pluf_HTTP_Response_Redirect($url, 301);
     }
     if (!$scm->isValidRevision($commit, $request_file)) {
         // Redirect to the first branch
         return new Pluf_HTTP_Response_Redirect($fburl);
     }
     $request_file_info = $scm->getPathInfo($request_file, $commit);
     if (!$request_file_info) {
         // Redirect to the first branch
         return new Pluf_HTTP_Response_Redirect($fburl);
     }
     $branches = $scm->getBranches();
     $tags = $scm->getTags();
     if ($request_file_info->type != 'tree') {
         $info = self::getRequestedFileMimeType($request_file_info, $commit, $scm);
         if (!self::isText($info)) {
             $rep = new Pluf_HTTP_Response($scm->getFile($request_file_info), $info[0]);
             $rep->headers['Content-Disposition'] = 'attachment; filename="' . $info[1] . '"';
             return $rep;
         } else {
             // We want to display the content of the file as text
             $extra = array('branches' => $branches, 'tags' => $tags, 'commit' => $commit, 'request_file' => $request_file, 'request_file_info' => $request_file_info, 'mime' => $info);
             return $this->viewFile($request, $match, $extra);
         }
     }
     $bc = self::makeBreadCrumb($request->project, $commit, $request_file_info->fullpath);
     $title = sprintf(__('%1$s %2$s Source Tree'), $request->project, $this->getScmType($request));
     $page_title = $bc . ' - ' . $title;
     $cobject = $scm->getCommit($commit);
     if (!$cobject) {
         // Redirect to the first branch
         $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase', array($request->project->shortname, $scm->getMainBranch()));
         return new Pluf_HTTP_Response_Redirect($url);
     }
     $in_branches = $scm->inBranches($commit, $request_file);
     $in_tags = $scm->inTags($commit, $request_file);
     $cache = Pluf_Cache::factory();
     $key = sprintf('Project:%s::IDF_Views_Source::tree:%s::%s', $request->project->id, $commit, $request_file);
     if (null === ($res = $cache->get($key))) {
         $res = new Pluf_Template_ContextVars($scm->getTree($commit, $request_file));
         $cache->set($key, $res);
     }
     // try to find the previous level if it exists.
     $prev = explode('/', $request_file);
     $l = array_pop($prev);
     $previous = substr($request_file, 0, -strlen($l . ' '));
     $scmConf = $request->conf->getVal('scm', 'git');
     $props = $scm->getProperties($commit, $request_file);
     return Pluf_Shortcuts_RenderToResponse('idf/source/' . $scmConf . '/tree.html', array('page_title' => $page_title, 'title' => $title, 'breadcrumb' => $bc, 'files' => $res, 'commit' => $commit, 'cobject' => $cobject, 'base' => $request_file_info->file, 'prev' => $previous, 'tree_in' => $in_branches, 'branches' => $branches, 'tags' => $tags, 'tags_in' => $in_tags, 'props' => $props), $request);
 }
Exemple #4
0
 /**
  * Get the uid of a given request.
  *
  * @param $request Pluf_HTTP_Request
  */
 public static function getUid($request)
 {
     if (isset($request->COOKIE['pabuid']) and self::check_uid($request->COOKIE['pabuid'])) {
         return $request->COOKIE['pabuid'];
     }
     if (!isset($request->SERVER['HTTP_USER_AGENT']) or self::isBot($request->SERVER['HTTP_USER_AGENT'])) {
         return 'bot';
     }
     // Here we need to make an uid, first check if a user with
     // same ip/agent exists and was last seen within the last 1h.
     // We get that from MemcacheDB
     $cache = Pluf_Cache::factory();
     $key = 'pluf_ab_' . crc32($request->remote_addr . '#' . $request->SERVER['HTTP_USER_AGENT']);
     if ($uid = $cache->get($key, null)) {
         $cache->set($key, $uid, 3600);
         return $uid;
     }
     $uid = self::make_uid($request);
     $cache->set($key, $uid, 3600);
     return $uid;
 }
Exemple #5
0
 /**
  * Queries the certs for a given revision and returns them in an
  * associative array array("branch" => array("branch1", ...), ...)
  *
  * @param string
  * @param array
  */
 private function _getCerts($rev)
 {
     $cache = Pluf_Cache::factory();
     $cachekey = 'mtn-plugin-certs-for-rev-' . $rev;
     $certs = $cache->get($cachekey);
     if ($certs === null) {
         $out = $this->stdio->exec(array('certs', $rev));
         $stanzas = IDF_Scm_Monotone_BasicIO::parse($out);
         $certs = array();
         foreach ($stanzas as $stanza) {
             $certname = null;
             foreach ($stanza as $stanzaline) {
                 // luckily, name always comes before value
                 if ($stanzaline['key'] == 'name') {
                     $certname = $stanzaline['values'][0];
                     continue;
                 }
                 if ($stanzaline['key'] == 'value') {
                     if (!array_key_exists($certname, $certs)) {
                         $certs[$certname] = array();
                     }
                     $certs[$certname][] = $stanzaline['values'][0];
                     break;
                 }
             }
         }
         $cache->set($cachekey, $certs);
     }
     return $certs;
 }
Exemple #6
0
 /**
  * Sync the changes in the repository with the timeline.
  *
  */
 public static function syncTimeline($project, $force = false)
 {
     $cache = Pluf_Cache::factory();
     $key = 'IDF_Scm:' . $project->shortname . ':lastsync';
     if ($force or null === ($res = $cache->get($key))) {
         $scm = IDF_Scm::get($project);
         if ($scm->isAvailable()) {
             foreach ($scm->getChangeLog($scm->getMainBranch(), 25) as $change) {
                 IDF_Commit::getOrAdd($change, $project);
             }
             $cache->set($key, true, (int) (Pluf::f('cache_timeout', 300) / 2));
         }
     }
 }