views:

37

answers:

1

Is this the right place to call the function that builds the RSS? its for a reddit type of site.

function save() {
    /*
            Here we do either a create or
            update operation depending
            on the value of the id field.
            Zero means create, non-zero
            update
    */

        if(!get_magic_quotes_gpc())
        {
            $this->title = addslashes($this->title);
            $this->description = addslashes($this->description);
        }

        try
        {
            $db = parent::getConnection();
            if($this->id == 0 )
            {
                $query = 'insert into articles (modified, username, url, title, description, points )';
                $query .= " values ('$this->getModified()', '$this->username', '$this->url', '$this->title', '$this->description', $this->points)";
       createRSS(); //**** rss function****
      }
            else if($this->id != 0)
            {
                $query = "update articles set modified = NOW()".", username = '$this->username', url = '$this->url', title = '".$this->title."', description = '".$this->description."', points = $this->points, ranking = $this->ranking where id = $this->id";
            }

            $lastid = parent::execSql2($query);

            if($this->id == 0 )
                $this->id = $lastid;

        }
        catch(Exception $e){
            throw $e;
        }
    }

Thanks a lot

+1  A: 

Probably not. There may be times when you want to save an article object without updating your RSS feed -- e.g. you might import an archive of articles at some point. As such, whatever is responsible for calling save() should call createRSS() itself immediately afterward.

e.g.

function createArticle($title, ...) {
  $article->setTitle($title);
  ...
  $article->save();
  createRSS();
}
Frank Farmer