Skip to content

Commit

Permalink
Homepage|Fixed: Default object from empty value warning (ContentInfo)
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 15, 2012
1 parent 3d2ada8 commit de621b8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
41 changes: 22 additions & 19 deletions web/classes/contentcache.class.php
Expand Up @@ -81,12 +81,12 @@ public function store($file, $content)
/**
* Is the specified content element present in the cache?
*
* @param file (String) File name to look up.
* @param relPath (String) File name to look up.
* @return (Boolean) TRUE iff the content element is available.
*/
public function isPresent($file)
public function isPresent($relPath)
{
return (bool) file_exists(FrontController::nativePath($this->_docRoot."/$file"));
return (bool) file_exists(FrontController::nativePath($this->_docRoot."/$relPath"));
}

/**
Expand Down Expand Up @@ -116,47 +116,50 @@ public function retrieve($relPath)
/**
* Retrieve info about a file in the cache.
*
* @param file (String) Name of the file to get info for.
* @param relPath (String) Name of the file to get info for.
* @param info (ContentInfo) Info record to be populated.
* @return (Boolean) FALSE if the specified file does not exist.
*/
public function getInfo($file, &$ContentInfo)
public function getInfo($relPath, &$info)
{
$file = FrontController::nativePath($this->_docRoot."/$file");
if(!$file || !file_exists($file)) return FALSE;
if(!$info instanceof ContentInfo) return FALSE;

$ContentInfo->modifiedTime = filemtime($file);
$path = FrontController::nativePath($this->_docRoot."/$relPath");
if(!$path || !file_exists($path)) return FALSE;

$info->modifiedTime = filemtime($path);
return TRUE;
}

/**
* Touch a file in the cache (update modified time).
*
* @param file (String) Name of the file to touch.
* @param relPath (String) Name of the file to touch.
* @return (Boolean) FALSE if the specified file does not exist.
*/
public function touch($file)
public function touch($relPath)
{
$file = FrontController::nativePath($this->_docRoot."/$file");
if(!$file || !file_exists($file)) return FALSE;
$path = FrontController::nativePath($this->_docRoot."/$relPath");
if(!$path || !file_exists($path)) return FALSE;

touch($file);
touch($path);
return TRUE;
}

/**
* Attempt to import a content element from the cache, outputting
* its contents straight to the output buffer.
*
* @param file (String) File name to retrieve.
* @param relPath (String) File name to retrieve.
* @return (Boolean) TRUE iff the content element was imported.
*/
public function import($file)
public function import($relPath)
{
$file = FrontController::nativePath($this->_docRoot."/$file");
$path = FrontController::nativePath($this->_docRoot."/$relPath");

if(!$file || !file_exists($file))
throw new Exception(sprintf('file %s not present in content cache.', $file));
if(!$path || !file_exists($path))
throw new Exception(sprintf('file %s not present in content cache.', $relPath));

return @readfile($file);
return @readfile($path);
}
}
4 changes: 2 additions & 2 deletions web/plugins/buildrepository/buildrepository.php
Expand Up @@ -103,7 +103,7 @@ function mustUpdateCachedBuildLog(&$buildLogUri, &$cacheName)
// to determine when it is time to query (we touch the cached copy after
// each query attempt).
$cacheInfo = new ContentInfo();
$FrontController->contentCache()->getInfo($cacheName, &$cacheInfo);
$FrontController->contentCache()->getInfo($cacheName, $cacheInfo);
if(time() < strtotime('+5 minutes', $cacheInfo->modifiedTime))
return FALSE;

Expand Down Expand Up @@ -1060,7 +1060,7 @@ private function outputPackageGraph(&$pack)
if($FrontController->contentCache()->isPresent($cacheName))
{
$cacheInfo = new ContentInfo();
$FrontController->contentCache()->getInfo($cacheName, &$contentInfo);
$FrontController->contentCache()->getInfo($cacheName, $contentInfo);

header('Pragma: public');
header('Cache-Control: public');
Expand Down
2 changes: 1 addition & 1 deletion web/plugins/masterbrowser/masterbrowser.php
Expand Up @@ -54,7 +54,7 @@ private function mustUpdateServerSummaryHtml()
$this->db = new MasterServer();

$cacheInfo = new ContentInfo();
$FrontController->contentCache()->getInfo(self::$serverSummaryCacheName, &$cacheInfo);
$FrontController->contentCache()->getInfo(self::$serverSummaryCacheName, $cacheInfo);
return ($this->db->lastUpdate > $cacheInfo->modifiedTime);
}

Expand Down
2 changes: 1 addition & 1 deletion web/plugins/pages/pages.php
Expand Up @@ -45,7 +45,7 @@ public function mustUpdateCachedPage(&$pageFile, &$cacheName)
if(!$FrontController->contentCache()->isPresent($cacheName)) return TRUE;

$cacheInfo = new ContentInfo();
$FrontController->contentCache()->getInfo($cacheName, &$cacheInfo);
$FrontController->contentCache()->getInfo($cacheName, $cacheInfo);
return (filemtime($pageFile) > $cacheInfo->modifiedTime);
}

Expand Down

0 comments on commit de621b8

Please sign in to comment.