Skip to content

Commit

Permalink
implemented clear-cache, blah! :P
Browse files Browse the repository at this point in the history
  • Loading branch information
till committed Nov 10, 2009
1 parent c8d30a2 commit 9e5374a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
39 changes: 31 additions & 8 deletions libs/aggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class aggregator
{
protected $mdb = null;
protected $hasUpdates = false;

public function __construct() {
$this->mdb = MDB2::connect($GLOBALS['BX_config']['dsn']);
Expand All @@ -21,10 +22,23 @@ public function __construct() {
}
}

/**
* This is to determine if we need to clear the cache after the aggregate script
* ran and tried to discover new blogs and entries.
*
* @return boolean
* @see self::aggregateAllBlogs()
* @see self::insertEntry()
*/
public function isNew()
{
return $this->hasUpdates;
}

function aggregateAllBlogs($id = null) {

$where = '';
if ($id) {
if ($id !== null) {
$where .= "where ID = $id";
}
$res = $this->mdb->query("select ID,blogsID as blogsid, link, cats, section from feeds $where");
Expand Down Expand Up @@ -79,6 +93,11 @@ function aggregateAllBlogs($id = null) {
}
$newBlog = false;
}

if ($newBlog === true) {
$this->hasUpdates = true;
}

// update id, if not the same
if ($row['blogsid'] != $id) {
$this->updateFeedBlogID($row['link'], $id);
Expand Down Expand Up @@ -166,7 +185,8 @@ function truncateEntries($item) {
return $item;
}

function getBody($html) {
function getBody($html)
{

$d = new DomDocument();
$html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>'.$html.'</body>';
Expand All @@ -180,14 +200,16 @@ function getBody($html) {
return $body;
}

function generateMD5($item) {
function generateMD5($item)
{
return md5($item['title'] .$item['link'] . $item['description'] .$item['content']['encoded']);
}

/**
* @todo Replace mysql_* calls with MDB2
*/
function updateEntry($item, $entryID) {
function updateEntry($item, $entryID)
{
$date = $this->getDcDate($item, 0,true);
$query = "update entries set " .
" link = '" .mysql_escape_string(utf2entities($item['link'])) . "'," .
Expand All @@ -205,9 +227,8 @@ function updateEntry($item, $entryID) {
if (MDB2::isError($res)) {
print "DB ERROR: ". $res->getMessage() . "\n". $res->getUserInfo(). "\n";
return false;
} else {
return true;
}
return true;
}

/**
Expand Down Expand Up @@ -247,9 +268,11 @@ function insertEntry($item,$feedID, $options = array()) {
if (MDB2::isError($res)) {
print "DB ERROR: ". $res->getMessage() . "\n". $res->getUserInfo(). "\n";
return false;
} else {
return $id;
}

$this->hasUpdates = true;

return $id;
}

function getDcDate($item, $nowOffset = 0, $returnNull = false) {
Expand Down
7 changes: 6 additions & 1 deletion libs/scripts/aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@

$agg = new aggregator();
$agg->aggregateAllBlogs($argv[1]);

if ($agg->isNew() === true) {
$tmp = dirname(__FILE__) . '/../../tmp';
foreach (glob($tmp . '/Index-*') as $file) {
unlink($file);
}
}

0 comments on commit 9e5374a

Please sign in to comment.